From 63062abadc206bcf90588765c997cf9dd91ae4b8 Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Tue, 7 Nov 2023 14:09:30 -0700 Subject: [PATCH] clientupdate: check whether running as root early (#10161) Check for root early, before we fetch the pkgs index. This avoids several seconds delay for the command to tell you to sudo. Updates #cleanup Signed-off-by: Andrew Lytvynov --- clientupdate/clientupdate.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/clientupdate/clientupdate.go b/clientupdate/clientupdate.go index b94c21bab..74942427e 100644 --- a/clientupdate/clientupdate.go +++ b/clientupdate/clientupdate.go @@ -260,6 +260,9 @@ func (up *Updater) updateSynology() error { if up.Version != "" { return errors.New("installing a specific version on Synology is not supported") } + if err := requireRoot(); err != nil { + return err + } // Get the latest version and list of SPKs from pkgs.tailscale.com. dsmVersion := distro.DSMVersion() @@ -277,9 +280,6 @@ func (up *Updater) updateSynology() error { return fmt.Errorf("cannot find Synology package for os=%s arch=%s, please report a bug with your device model", osName, arch) } - if err := requireRoot(); err != nil { - return err - } if !up.confirm(latest.SPKsVersion) { return nil } @@ -713,14 +713,6 @@ func (up *Updater) updateWindows() error { up.Logf("success.") return nil } - ver, err := requestedTailscaleVersion(up.Version, up.track) - if err != nil { - return err - } - arch := runtime.GOARCH - if arch == "386" { - arch = "x86" - } if !winutil.IsCurrentProcessElevated() { return errors.New(`update must be run as Administrator @@ -730,6 +722,14 @@ you can run the command prompt as Administrator one of these ways: * press Windows+x, then press a * press Windows+r, type in "cmd", then press Ctrl+Shift+Enter`) } + ver, err := requestedTailscaleVersion(up.Version, up.track) + if err != nil { + return err + } + arch := runtime.GOARCH + if arch == "386" { + arch = "x86" + } if !up.confirm(ver) { return nil } @@ -946,14 +946,14 @@ func (up *Updater) updateFreeBSD() (err error) { } func (up *Updater) updateLinuxBinary() error { - ver, err := requestedTailscaleVersion(up.Version, up.track) - if err != nil { - return err - } // Root is needed to overwrite binaries and restart systemd unit. if err := requireRoot(); err != nil { return err } + ver, err := requestedTailscaleVersion(up.Version, up.track) + if err != nil { + return err + } if !up.confirm(ver) { return nil }