@ -29,6 +29,7 @@ import (
"github.com/google/uuid"
"github.com/google/uuid"
"tailscale.com/clientupdate/distsign"
"tailscale.com/clientupdate/distsign"
"tailscale.com/hostinfo"
"tailscale.com/types/logger"
"tailscale.com/types/logger"
"tailscale.com/util/cmpver"
"tailscale.com/util/cmpver"
"tailscale.com/util/winutil"
"tailscale.com/util/winutil"
@ -162,9 +163,10 @@ func NewUpdater(args Arguments) (*Updater, error) {
type updateFunction func ( ) error
type updateFunction func ( ) error
func ( up * Updater ) getUpdateFunction ( ) ( fn updateFunction , canAutoUpdate bool ) {
func ( up * Updater ) getUpdateFunction ( ) ( fn updateFunction , canAutoUpdate bool ) {
canAutoUpdate = ! hostinfo . New ( ) . Container . EqualBool ( true ) // EqualBool(false) would return false if the value is not set.
switch runtime . GOOS {
switch runtime . GOOS {
case "windows" :
case "windows" :
return up . updateWindows , tru e
return up . updateWindows , canAutoUpdat e
case "linux" :
case "linux" :
switch distro . Get ( ) {
switch distro . Get ( ) {
case distro . NixOS :
case distro . NixOS :
@ -178,20 +180,20 @@ func (up *Updater) getUpdateFunction() (fn updateFunction, canAutoUpdate bool) {
// auto-update mechanism.
// auto-update mechanism.
return up . updateSynology , false
return up . updateSynology , false
case distro . Debian : // includes Ubuntu
case distro . Debian : // includes Ubuntu
return up . updateDebLike , tru e
return up . updateDebLike , canAutoUpdat e
case distro . Arch :
case distro . Arch :
if up . archPackageInstalled ( ) {
if up . archPackageInstalled ( ) {
// Arch update func just prints a message about how to update,
// Arch update func just prints a message about how to update,
// it doesn't support auto-updates.
// it doesn't support auto-updates.
return up . updateArchLike , false
return up . updateArchLike , false
}
}
return up . updateLinuxBinary , tru e
return up . updateLinuxBinary , canAutoUpdat e
case distro . Alpine :
case distro . Alpine :
return up . updateAlpineLike , tru e
return up . updateAlpineLike , canAutoUpdat e
case distro . Unraid :
case distro . Unraid :
return up . updateUnraid , tru e
return up . updateUnraid , canAutoUpdat e
case distro . QNAP :
case distro . QNAP :
return up . updateQNAP , tru e
return up . updateQNAP , canAutoUpdat e
}
}
switch {
switch {
case haveExecutable ( "pacman" ) :
case haveExecutable ( "pacman" ) :
@ -200,21 +202,21 @@ func (up *Updater) getUpdateFunction() (fn updateFunction, canAutoUpdate bool) {
// it doesn't support auto-updates.
// it doesn't support auto-updates.
return up . updateArchLike , false
return up . updateArchLike , false
}
}
return up . updateLinuxBinary , tru e
return up . updateLinuxBinary , canAutoUpdat e
case haveExecutable ( "apt-get" ) : // TODO(awly): add support for "apt"
case haveExecutable ( "apt-get" ) : // TODO(awly): add support for "apt"
// The distro.Debian switch case above should catch most apt-based
// The distro.Debian switch case above should catch most apt-based
// systems, but add this fallback just in case.
// systems, but add this fallback just in case.
return up . updateDebLike , tru e
return up . updateDebLike , canAutoUpdat e
case haveExecutable ( "dnf" ) :
case haveExecutable ( "dnf" ) :
return up . updateFedoraLike ( "dnf" ) , tru e
return up . updateFedoraLike ( "dnf" ) , canAutoUpdat e
case haveExecutable ( "yum" ) :
case haveExecutable ( "yum" ) :
return up . updateFedoraLike ( "yum" ) , tru e
return up . updateFedoraLike ( "yum" ) , canAutoUpdat e
case haveExecutable ( "apk" ) :
case haveExecutable ( "apk" ) :
return up . updateAlpineLike , tru e
return up . updateAlpineLike , canAutoUpdat e
}
}
// If nothing matched, fall back to tarball updates.
// If nothing matched, fall back to tarball updates.
if up . Update == nil {
if up . Update == nil {
return up . updateLinuxBinary , tru e
return up . updateLinuxBinary , canAutoUpdat e
}
}
case "darwin" :
case "darwin" :
switch {
switch {
@ -230,7 +232,7 @@ func (up *Updater) getUpdateFunction() (fn updateFunction, canAutoUpdate bool) {
return nil , false
return nil , false
}
}
case "freebsd" :
case "freebsd" :
return up . updateFreeBSD , tru e
return up . updateFreeBSD , canAutoUpdat e
}
}
return nil , false
return nil , false
}
}