@ -17,6 +17,7 @@ const (
Arch = Distro ( "arch" )
Arch = Distro ( "arch" )
Synology = Distro ( "synology" )
Synology = Distro ( "synology" )
OpenWrt = Distro ( "openwrt" )
OpenWrt = Distro ( "openwrt" )
NixOS = Distro ( "nixos" )
)
)
// Get returns the current distro, or the empty string if unknown.
// Get returns the current distro, or the empty string if unknown.
@ -27,18 +28,28 @@ func Get() Distro {
return ""
return ""
}
}
func have ( file string ) bool {
_ , err := os . Stat ( file )
return err == nil
}
func haveDir ( file string ) bool {
fi , err := os . Stat ( file )
return err == nil && fi . IsDir ( )
}
func linuxDistro ( ) Distro {
func linuxDistro ( ) Distro {
if fi , err := os . Stat ( "/usr/syno" ) ; err == nil && fi . IsDir ( ) {
switch {
case haveDir ( "usr/syno" ) :
return Synology
return Synology
}
case have ( "/etc/debian_version" ) :
if _ , err := os . Stat ( "/etc/debian_version" ) ; err == nil {
return Debian
return Debian
}
case have ( "/etc/arch-release" ) :
if _ , err := os . Stat ( "/etc/arch-release" ) ; err == nil {
return Arch
return Arch
}
case have ( "/etc/openwrt_version" ) :
if _ , err := os . Stat ( "/etc/openwrt_version" ) ; err == nil {
return OpenWrt
return OpenWrt
case have ( "/run/current-system/sw/bin/nixos-version" ) :
return NixOS
}
}
return ""
return ""
}
}