clientupdate.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package clientupdate implements tailscale client update for all supported
  4. // platforms. This package can be used from both tailscaled and tailscale
  5. // binaries.
  6. package clientupdate
  7. import (
  8. "archive/tar"
  9. "bufio"
  10. "bytes"
  11. "compress/gzip"
  12. "context"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. "io"
  17. "maps"
  18. "net/http"
  19. "os"
  20. "os/exec"
  21. "path"
  22. "path/filepath"
  23. "regexp"
  24. "runtime"
  25. "strconv"
  26. "strings"
  27. "tailscale.com/types/logger"
  28. "tailscale.com/util/cmpver"
  29. "tailscale.com/version"
  30. "tailscale.com/version/distro"
  31. )
  32. const (
  33. StableTrack = "stable"
  34. UnstableTrack = "unstable"
  35. )
  36. var CurrentTrack = func() string {
  37. if version.IsUnstableBuild() {
  38. return UnstableTrack
  39. } else {
  40. return StableTrack
  41. }
  42. }()
  43. func versionToTrack(v string) (string, error) {
  44. _, rest, ok := strings.Cut(v, ".")
  45. if !ok {
  46. return "", fmt.Errorf("malformed version %q", v)
  47. }
  48. minorStr, _, ok := strings.Cut(rest, ".")
  49. if !ok {
  50. return "", fmt.Errorf("malformed version %q", v)
  51. }
  52. minor, err := strconv.Atoi(minorStr)
  53. if err != nil {
  54. return "", fmt.Errorf("malformed version %q", v)
  55. }
  56. if minor%2 == 0 {
  57. return "stable", nil
  58. }
  59. return "unstable", nil
  60. }
  61. // Arguments contains arguments needed to run an update.
  62. type Arguments struct {
  63. // Version is the specific version to install.
  64. // Mutually exclusive with Track.
  65. Version string
  66. // Track is the release track to use:
  67. //
  68. // - CurrentTrack will use the latest version from the same track as the
  69. // running binary
  70. // - StableTrack and UnstableTrack will use the latest versions of the
  71. // corresponding tracks
  72. //
  73. // Leaving this empty will use Version or fall back to CurrentTrack if both
  74. // Track and Version are empty.
  75. Track string
  76. // Logf is a logger for update progress messages.
  77. Logf logger.Logf
  78. // Stdout and Stderr should be used for output instead of os.Stdout and
  79. // os.Stderr.
  80. Stdout io.Writer
  81. Stderr io.Writer
  82. // Confirm is called when a new version is available and should return true
  83. // if this new version should be installed. When Confirm returns false, the
  84. // update is aborted.
  85. Confirm func(newVer string) bool
  86. // PkgsAddr is the address of the pkgs server to fetch updates from.
  87. // Defaults to "https://pkgs.tailscale.com".
  88. PkgsAddr string
  89. // ForAutoUpdate should be true when Updater is created in auto-update
  90. // context. When true, NewUpdater returns an error if it cannot be used for
  91. // auto-updates (even if Updater.Update field is non-nil).
  92. ForAutoUpdate bool
  93. }
  94. func (args Arguments) validate() error {
  95. if args.Confirm == nil {
  96. return errors.New("missing Confirm callback in Arguments")
  97. }
  98. if args.Logf == nil {
  99. return errors.New("missing Logf callback in Arguments")
  100. }
  101. if args.Version != "" && args.Track != "" {
  102. return fmt.Errorf("only one of Version(%q) or Track(%q) can be set", args.Version, args.Track)
  103. }
  104. switch args.Track {
  105. case StableTrack, UnstableTrack, "":
  106. // All valid values.
  107. default:
  108. return fmt.Errorf("unsupported track %q", args.Track)
  109. }
  110. return nil
  111. }
  112. type Updater struct {
  113. Arguments
  114. // Update is a platform-specific method that updates the installation. May be
  115. // nil (not all platforms support updates from within Tailscale).
  116. Update func() error
  117. // currentVersion is the short form of the current client version as
  118. // returned by version.Short(), typically "x.y.z". Used for tests to
  119. // override the actual current version.
  120. currentVersion string
  121. }
  122. func NewUpdater(args Arguments) (*Updater, error) {
  123. up := Updater{
  124. Arguments: args,
  125. currentVersion: version.Short(),
  126. }
  127. if up.Stdout == nil {
  128. up.Stdout = os.Stdout
  129. }
  130. if up.Stderr == nil {
  131. up.Stderr = os.Stderr
  132. }
  133. var canAutoUpdate bool
  134. up.Update, canAutoUpdate = up.getUpdateFunction()
  135. if up.Update == nil {
  136. return nil, errors.ErrUnsupported
  137. }
  138. if args.ForAutoUpdate && !canAutoUpdate {
  139. return nil, errors.ErrUnsupported
  140. }
  141. if up.Track == "" {
  142. if up.Version != "" {
  143. var err error
  144. up.Track, err = versionToTrack(args.Version)
  145. if err != nil {
  146. return nil, err
  147. }
  148. } else {
  149. up.Track = CurrentTrack
  150. }
  151. }
  152. if up.Arguments.PkgsAddr == "" {
  153. up.Arguments.PkgsAddr = "https://pkgs.tailscale.com"
  154. }
  155. return &up, nil
  156. }
  157. type updateFunction func() error
  158. func (up *Updater) getUpdateFunction() (fn updateFunction, canAutoUpdate bool) {
  159. switch runtime.GOOS {
  160. case "windows":
  161. return up.updateWindows, true
  162. case "linux":
  163. switch distro.Get() {
  164. case distro.NixOS:
  165. // NixOS packages are immutable and managed with a system-wide
  166. // configuration.
  167. return up.updateNixos, false
  168. case distro.Synology:
  169. // Synology updates use our own pkgs.tailscale.com instead of the
  170. // Synology Package Center. We should eventually get to a regular
  171. // release cadence with Synology Package Center and use their
  172. // auto-update mechanism.
  173. return up.updateSynology, false
  174. case distro.Debian: // includes Ubuntu
  175. return up.updateDebLike, true
  176. case distro.Arch:
  177. if up.archPackageInstalled() {
  178. // Arch update func just prints a message about how to update,
  179. // it doesn't support auto-updates.
  180. return up.updateArchLike, false
  181. }
  182. return up.updateLinuxBinary, true
  183. case distro.Alpine:
  184. return up.updateAlpineLike, true
  185. case distro.Unraid:
  186. return up.updateUnraid, true
  187. case distro.QNAP:
  188. return up.updateQNAP, true
  189. }
  190. switch {
  191. case haveExecutable("pacman"):
  192. if up.archPackageInstalled() {
  193. // Arch update func just prints a message about how to update,
  194. // it doesn't support auto-updates.
  195. return up.updateArchLike, false
  196. }
  197. return up.updateLinuxBinary, true
  198. case haveExecutable("apt-get"): // TODO(awly): add support for "apt"
  199. // The distro.Debian switch case above should catch most apt-based
  200. // systems, but add this fallback just in case.
  201. return up.updateDebLike, true
  202. case haveExecutable("dnf"):
  203. return up.updateFedoraLike("dnf"), true
  204. case haveExecutable("yum"):
  205. return up.updateFedoraLike("yum"), true
  206. case haveExecutable("apk"):
  207. return up.updateAlpineLike, true
  208. }
  209. // If nothing matched, fall back to tarball updates.
  210. if up.Update == nil {
  211. return up.updateLinuxBinary, true
  212. }
  213. case "darwin":
  214. switch {
  215. case version.IsMacAppStore():
  216. // App store update func just opens the store page, it doesn't
  217. // support auto-updates.
  218. return up.updateMacAppStore, false
  219. case version.IsMacSysExt():
  220. // Macsys update func kicks off Sparkle. Auto-updates are done by
  221. // Sparkle.
  222. return up.updateMacSys, false
  223. default:
  224. return nil, false
  225. }
  226. case "freebsd":
  227. return up.updateFreeBSD, true
  228. }
  229. return nil, false
  230. }
  231. // CanAutoUpdate reports whether auto-updating via the clientupdate package
  232. // is supported for the current os/distro.
  233. func CanAutoUpdate() bool {
  234. if version.IsMacSysExt() {
  235. // Macsys uses Sparkle for auto-updates, which doesn't have an update
  236. // function in this package.
  237. return true
  238. }
  239. _, canAutoUpdate := (&Updater{}).getUpdateFunction()
  240. return canAutoUpdate
  241. }
  242. // Update runs a single update attempt using the platform-specific mechanism.
  243. //
  244. // On Windows, this copies the calling binary and re-executes it to apply the
  245. // update. The calling binary should handle an "update" subcommand and call
  246. // this function again for the re-executed binary to proceed.
  247. func Update(args Arguments) error {
  248. if err := args.validate(); err != nil {
  249. return err
  250. }
  251. up, err := NewUpdater(args)
  252. if err != nil {
  253. return err
  254. }
  255. return up.Update()
  256. }
  257. func (up *Updater) confirm(ver string) bool {
  258. // Only check version when we're not switching tracks.
  259. if up.Track == "" || up.Track == CurrentTrack {
  260. switch c := cmpver.Compare(up.currentVersion, ver); {
  261. case c == 0:
  262. up.Logf("already running %v version %v; no update needed", up.Track, ver)
  263. return false
  264. case c > 0:
  265. up.Logf("installed %v version %v is newer than the latest available version %v; no update needed", up.Track, up.currentVersion, ver)
  266. return false
  267. }
  268. }
  269. if up.Confirm != nil {
  270. return up.Confirm(ver)
  271. }
  272. return true
  273. }
  274. const synoinfoConfPath = "/etc/synoinfo.conf"
  275. func (up *Updater) updateSynology() error {
  276. if up.Version != "" {
  277. return errors.New("installing a specific version on Synology is not supported")
  278. }
  279. if err := requireRoot(); err != nil {
  280. return err
  281. }
  282. // Get the latest version and list of SPKs from pkgs.tailscale.com.
  283. dsmVersion := distro.DSMVersion()
  284. osName := fmt.Sprintf("dsm%d", dsmVersion)
  285. arch, err := synoArch(runtime.GOARCH, synoinfoConfPath)
  286. if err != nil {
  287. return err
  288. }
  289. latest, err := latestPackages(up.Track)
  290. if err != nil {
  291. return err
  292. }
  293. spkName := latest.SPKs[osName][arch]
  294. if spkName == "" {
  295. return fmt.Errorf("cannot find Synology package for os=%s arch=%s, please report a bug with your device model", osName, arch)
  296. }
  297. if !up.confirm(latest.SPKsVersion) {
  298. return nil
  299. }
  300. up.cleanupOldDownloads(filepath.Join(os.TempDir(), "tailscale-update*", "*.spk"))
  301. // Download the SPK into a temporary directory.
  302. spkDir, err := os.MkdirTemp("", "tailscale-update")
  303. if err != nil {
  304. return err
  305. }
  306. pkgsPath := fmt.Sprintf("%s/%s", up.Track, spkName)
  307. spkPath := filepath.Join(spkDir, path.Base(pkgsPath))
  308. if err := up.downloadURLToFile(pkgsPath, spkPath); err != nil {
  309. return err
  310. }
  311. // Install the SPK. Run via nohup to allow install to succeed when we're
  312. // connected over tailscale ssh and this parent process dies. Otherwise, if
  313. // you abort synopkg install mid-way, tailscaled is not restarted.
  314. cmd := exec.Command("nohup", "synopkg", "install", spkPath)
  315. // Don't attach cmd.Stdout to Stdout because nohup will redirect that into
  316. // nohup.out file. synopkg doesn't have any progress output anyway, it just
  317. // spits out a JSON result when done.
  318. out, err := cmd.CombinedOutput()
  319. if err != nil {
  320. if dsmVersion == 6 && bytes.Contains(out, []byte("error = [290]")) {
  321. return fmt.Errorf("synopkg install failed: %w\noutput:\n%s\nplease make sure that packages from 'Any publisher' are allowed in the Package Center (Package Center -> Settings -> Trust Level -> Any publisher)", err, out)
  322. }
  323. return fmt.Errorf("synopkg install failed: %w\noutput:\n%s", err, out)
  324. }
  325. if dsmVersion == 6 {
  326. // DSM6 does not automatically restart the package on install. Do it
  327. // manually.
  328. cmd := exec.Command("nohup", "synopkg", "start", "Tailscale")
  329. out, err := cmd.CombinedOutput()
  330. if err != nil {
  331. return fmt.Errorf("synopkg start failed: %w\noutput:\n%s", err, out)
  332. }
  333. }
  334. return nil
  335. }
  336. // synoArch returns the Synology CPU architecture matching one of the SPK
  337. // architectures served from pkgs.tailscale.com.
  338. func synoArch(goArch, synoinfoPath string) (string, error) {
  339. // Most Synology boxes just use a different arch name from GOARCH.
  340. arch := map[string]string{
  341. "amd64": "x86_64",
  342. "386": "i686",
  343. "arm64": "armv8",
  344. }[goArch]
  345. if arch == "" {
  346. // Here's the fun part, some older ARM boxes require you to use SPKs
  347. // specifically for their CPU. See
  348. // https://github.com/SynoCommunity/spksrc/wiki/Synology-and-SynoCommunity-Package-Architectures
  349. // for a complete list.
  350. //
  351. // Some CPUs will map to neither this list nor the goArch map above, and we
  352. // don't have SPKs for them.
  353. cpu, err := parseSynoinfo(synoinfoPath)
  354. if err != nil {
  355. return "", fmt.Errorf("failed to get CPU architecture: %w", err)
  356. }
  357. switch cpu {
  358. case "88f6281", "88f6282", "hi3535", "alpine", "armada370",
  359. "armada375", "armada38x", "armadaxp", "comcerto2k", "monaco":
  360. arch = cpu
  361. default:
  362. return "", fmt.Errorf("unsupported Synology CPU architecture %q (Go arch %q), please report a bug at https://github.com/tailscale/tailscale/issues/new/choose", cpu, goArch)
  363. }
  364. }
  365. return arch, nil
  366. }
  367. func parseSynoinfo(path string) (string, error) {
  368. f, err := os.Open(path)
  369. if err != nil {
  370. return "", err
  371. }
  372. defer f.Close()
  373. // Look for a line like:
  374. // unique="synology_88f6282_413j"
  375. // Extract the CPU in the middle (88f6282 in the above example).
  376. s := bufio.NewScanner(f)
  377. for s.Scan() {
  378. l := s.Text()
  379. if !strings.HasPrefix(l, "unique=") {
  380. continue
  381. }
  382. parts := strings.SplitN(l, "_", 3)
  383. if len(parts) != 3 {
  384. return "", fmt.Errorf(`malformed %q: found %q, expected format like 'unique="synology_$cpu_$model'`, path, l)
  385. }
  386. return parts[1], nil
  387. }
  388. return "", fmt.Errorf(`missing "unique=" field in %q`, path)
  389. }
  390. func (up *Updater) updateDebLike() error {
  391. if err := requireRoot(); err != nil {
  392. return err
  393. }
  394. if err := exec.Command("dpkg", "--status", "tailscale").Run(); err != nil && isExitError(err) {
  395. // Tailscale was not installed via apt, update via tarball download
  396. // instead.
  397. return up.updateLinuxBinary()
  398. }
  399. ver, err := requestedTailscaleVersion(up.Version, up.Track)
  400. if err != nil {
  401. return err
  402. }
  403. if !up.confirm(ver) {
  404. return nil
  405. }
  406. if updated, err := updateDebianAptSourcesList(up.Track); err != nil {
  407. return err
  408. } else if updated {
  409. up.Logf("Updated %s to use the %s track", aptSourcesFile, up.Track)
  410. }
  411. cmd := exec.Command("apt-get", "update",
  412. // Only update the tailscale repo, not the other ones, treating
  413. // the tailscale.list file as the main "sources.list" file.
  414. "-o", "Dir::Etc::SourceList=sources.list.d/tailscale.list",
  415. // Disable the "sources.list.d" directory:
  416. "-o", "Dir::Etc::SourceParts=-",
  417. // Don't forget about packages in the other repos just because
  418. // we're not updating them:
  419. "-o", "APT::Get::List-Cleanup=0",
  420. )
  421. if out, err := cmd.CombinedOutput(); err != nil {
  422. return fmt.Errorf("apt-get update failed: %w; output:\n%s", err, out)
  423. }
  424. for range 2 {
  425. out, err := exec.Command("apt-get", "install", "--yes", "--allow-downgrades", "tailscale="+ver).CombinedOutput()
  426. if err != nil {
  427. if !bytes.Contains(out, []byte(`dpkg was interrupted`)) {
  428. return fmt.Errorf("apt-get install failed: %w; output:\n%s", err, out)
  429. }
  430. up.Logf("apt-get install failed: %s; output:\n%s", err, out)
  431. up.Logf("running dpkg --configure tailscale")
  432. out, err = exec.Command("dpkg", "--force-confdef,downgrade", "--configure", "tailscale").CombinedOutput()
  433. if err != nil {
  434. return fmt.Errorf("dpkg --configure tailscale failed: %w; output:\n%s", err, out)
  435. }
  436. continue
  437. }
  438. break
  439. }
  440. return nil
  441. }
  442. const aptSourcesFile = "/etc/apt/sources.list.d/tailscale.list"
  443. // updateDebianAptSourcesList updates the /etc/apt/sources.list.d/tailscale.list
  444. // file to make sure it has the provided track (stable or unstable) in it.
  445. //
  446. // If it already has the right track (including containing both stable and
  447. // unstable), it does nothing.
  448. func updateDebianAptSourcesList(dstTrack string) (rewrote bool, err error) {
  449. was, err := os.ReadFile(aptSourcesFile)
  450. if err != nil {
  451. return false, err
  452. }
  453. newContent, err := updateDebianAptSourcesListBytes(was, dstTrack)
  454. if err != nil {
  455. return false, err
  456. }
  457. if bytes.Equal(was, newContent) {
  458. return false, nil
  459. }
  460. return true, os.WriteFile(aptSourcesFile, newContent, 0644)
  461. }
  462. func updateDebianAptSourcesListBytes(was []byte, dstTrack string) (newContent []byte, err error) {
  463. trackURLPrefix := []byte("https://pkgs.tailscale.com/" + dstTrack + "/")
  464. var buf bytes.Buffer
  465. var changes int
  466. bs := bufio.NewScanner(bytes.NewReader(was))
  467. hadCorrect := false
  468. commentLine := regexp.MustCompile(`^\s*\#`)
  469. pkgsURL := regexp.MustCompile(`\bhttps://pkgs\.tailscale\.com/((un)?stable)/`)
  470. for bs.Scan() {
  471. line := bs.Bytes()
  472. if !commentLine.Match(line) {
  473. line = pkgsURL.ReplaceAllFunc(line, func(m []byte) []byte {
  474. if bytes.Equal(m, trackURLPrefix) {
  475. hadCorrect = true
  476. } else {
  477. changes++
  478. }
  479. return trackURLPrefix
  480. })
  481. }
  482. buf.Write(line)
  483. buf.WriteByte('\n')
  484. }
  485. if hadCorrect || (changes == 1 && bytes.Equal(bytes.TrimSpace(was), bytes.TrimSpace(buf.Bytes()))) {
  486. // Unchanged or close enough.
  487. return was, nil
  488. }
  489. if changes != 1 {
  490. // No changes, or an unexpected number of changes (what?). Bail.
  491. // They probably editted it by hand and we don't know what to do.
  492. return nil, fmt.Errorf("unexpected/unsupported %s contents", aptSourcesFile)
  493. }
  494. return buf.Bytes(), nil
  495. }
  496. func (up *Updater) archPackageInstalled() bool {
  497. err := exec.Command("pacman", "--query", "tailscale").Run()
  498. return err == nil
  499. }
  500. func (up *Updater) updateArchLike() error {
  501. // Arch maintainer asked us not to implement "tailscale update" or
  502. // auto-updates on Arch-based distros:
  503. // https://github.com/tailscale/tailscale/issues/6995#issuecomment-1687080106
  504. return errors.New(`individual package updates are not supported on Arch-based distros, only full-system updates are: https://wiki.archlinux.org/title/System_maintenance#Partial_upgrades_are_unsupported.
  505. you can use "pacman --sync --refresh --sysupgrade" or "pacman -Syu" to upgrade the system, including Tailscale.`)
  506. }
  507. func (up *Updater) updateNixos() error {
  508. // NixOS package updates are managed on a system level and not individually.
  509. // Direct users to update their nix channel or nixpkgs flake input to
  510. // receive the latest version.
  511. return errors.New(`individual package updates are not supported on NixOS installations. Update your system channel or flake inputs to get the latest Tailscale version from nixpkgs.`)
  512. }
  513. const yumRepoConfigFile = "/etc/yum.repos.d/tailscale.repo"
  514. // updateFedoraLike updates tailscale on any distros in the Fedora family,
  515. // specifically anything that uses "dnf" or "yum" package managers. The actual
  516. // package manager is passed via packageManager.
  517. func (up *Updater) updateFedoraLike(packageManager string) func() error {
  518. return func() (err error) {
  519. if err := requireRoot(); err != nil {
  520. return err
  521. }
  522. if err := exec.Command(packageManager, "info", "--installed", "tailscale").Run(); err != nil && isExitError(err) {
  523. // Tailscale was not installed via yum/dnf, update via tarball
  524. // download instead.
  525. return up.updateLinuxBinary()
  526. }
  527. defer func() {
  528. if err != nil {
  529. err = fmt.Errorf(`%w; you can try updating using "%s upgrade tailscale"`, err, packageManager)
  530. }
  531. }()
  532. ver, err := requestedTailscaleVersion(up.Version, up.Track)
  533. if err != nil {
  534. return err
  535. }
  536. if !up.confirm(ver) {
  537. return nil
  538. }
  539. if updated, err := updateYUMRepoTrack(yumRepoConfigFile, up.Track); err != nil {
  540. return err
  541. } else if updated {
  542. up.Logf("Updated %s to use the %s track", yumRepoConfigFile, up.Track)
  543. }
  544. cmd := exec.Command(packageManager, "install", "--assumeyes", fmt.Sprintf("tailscale-%s-1", ver))
  545. cmd.Stdout = up.Stdout
  546. cmd.Stderr = up.Stderr
  547. if err := cmd.Run(); err != nil {
  548. return err
  549. }
  550. return nil
  551. }
  552. }
  553. // updateYUMRepoTrack updates the repoFile file to make sure it has the
  554. // provided track (stable or unstable) in it.
  555. func updateYUMRepoTrack(repoFile, dstTrack string) (rewrote bool, err error) {
  556. was, err := os.ReadFile(repoFile)
  557. if err != nil {
  558. return false, err
  559. }
  560. urlRe := regexp.MustCompile(`^(baseurl|gpgkey)=https://pkgs\.tailscale\.com/(un)?stable/`)
  561. urlReplacement := fmt.Sprintf("$1=https://pkgs.tailscale.com/%s/", dstTrack)
  562. s := bufio.NewScanner(bytes.NewReader(was))
  563. newContent := bytes.NewBuffer(make([]byte, 0, len(was)))
  564. for s.Scan() {
  565. line := s.Text()
  566. // Handle repo section name, like "[tailscale-stable]".
  567. if len(line) > 0 && line[0] == '[' {
  568. if !strings.HasPrefix(line, "[tailscale-") {
  569. return false, fmt.Errorf("%q does not look like a tailscale repo file, it contains an unexpected %q section", repoFile, line)
  570. }
  571. fmt.Fprintf(newContent, "[tailscale-%s]\n", dstTrack)
  572. continue
  573. }
  574. // Update the track mentioned in repo name.
  575. if strings.HasPrefix(line, "name=") {
  576. fmt.Fprintf(newContent, "name=Tailscale %s\n", dstTrack)
  577. continue
  578. }
  579. // Update the actual repo URLs.
  580. if strings.HasPrefix(line, "baseurl=") || strings.HasPrefix(line, "gpgkey=") {
  581. fmt.Fprintln(newContent, urlRe.ReplaceAllString(line, urlReplacement))
  582. continue
  583. }
  584. fmt.Fprintln(newContent, line)
  585. }
  586. if bytes.Equal(was, newContent.Bytes()) {
  587. return false, nil
  588. }
  589. return true, os.WriteFile(repoFile, newContent.Bytes(), 0644)
  590. }
  591. func (up *Updater) updateAlpineLike() (err error) {
  592. if up.Version != "" {
  593. return errors.New("installing a specific version on Alpine-based distros is not supported")
  594. }
  595. if err := requireRoot(); err != nil {
  596. return err
  597. }
  598. if err := exec.Command("apk", "info", "--installed", "tailscale").Run(); err != nil && isExitError(err) {
  599. // Tailscale was not installed via apk, update via tarball download
  600. // instead.
  601. return up.updateLinuxBinary()
  602. }
  603. defer func() {
  604. if err != nil {
  605. err = fmt.Errorf(`%w; you can try updating using "apk upgrade tailscale"`, err)
  606. }
  607. }()
  608. out, err := exec.Command("apk", "update").CombinedOutput()
  609. if err != nil {
  610. return fmt.Errorf("failed refresh apk repository indexes: %w, output:\n%s", err, out)
  611. }
  612. out, err = exec.Command("apk", "info", "tailscale").CombinedOutput()
  613. if err != nil {
  614. return fmt.Errorf("failed checking apk for latest tailscale version: %w, output:\n%s", err, out)
  615. }
  616. ver, err := parseAlpinePackageVersion(out)
  617. if err != nil {
  618. return fmt.Errorf(`failed to parse latest version from "apk info tailscale": %w`, err)
  619. }
  620. if !up.confirm(ver) {
  621. if err := checkOutdatedAlpineRepo(up.Logf, ver, up.Track); err != nil {
  622. up.Logf("failed to check whether Alpine release is outdated: %v", err)
  623. }
  624. return nil
  625. }
  626. cmd := exec.Command("apk", "upgrade", "tailscale")
  627. cmd.Stdout = up.Stdout
  628. cmd.Stderr = up.Stderr
  629. if err := cmd.Run(); err != nil {
  630. return fmt.Errorf("failed tailscale update using apk: %w", err)
  631. }
  632. return nil
  633. }
  634. func parseAlpinePackageVersion(out []byte) (string, error) {
  635. s := bufio.NewScanner(bytes.NewReader(out))
  636. var maxVer string
  637. for s.Scan() {
  638. // The line should look like this:
  639. // tailscale-1.44.2-r0 description:
  640. line := strings.TrimSpace(s.Text())
  641. if !strings.HasPrefix(line, "tailscale-") {
  642. continue
  643. }
  644. parts := strings.SplitN(line, "-", 3)
  645. if len(parts) < 3 {
  646. return "", fmt.Errorf("malformed info line: %q", line)
  647. }
  648. ver := parts[1]
  649. if cmpver.Compare(ver, maxVer) > 0 {
  650. maxVer = ver
  651. }
  652. }
  653. if maxVer != "" {
  654. return maxVer, nil
  655. }
  656. return "", errors.New("tailscale version not found in output")
  657. }
  658. var apkRepoVersionRE = regexp.MustCompile(`v[0-9]+\.[0-9]+`)
  659. func checkOutdatedAlpineRepo(logf logger.Logf, apkVer, track string) error {
  660. latest, err := LatestTailscaleVersion(track)
  661. if err != nil {
  662. return err
  663. }
  664. if latest == apkVer {
  665. // Actually on latest release.
  666. return nil
  667. }
  668. f, err := os.Open("/etc/apk/repositories")
  669. if err != nil {
  670. return err
  671. }
  672. defer f.Close()
  673. // Read the first repo line. Typically, there are multiple repos that all
  674. // contain the same version in the path, like:
  675. // https://dl-cdn.alpinelinux.org/alpine/v3.20/main
  676. // https://dl-cdn.alpinelinux.org/alpine/v3.20/community
  677. s := bufio.NewScanner(f)
  678. if !s.Scan() {
  679. return s.Err()
  680. }
  681. alpineVer := apkRepoVersionRE.FindString(s.Text())
  682. if alpineVer != "" {
  683. logf("The latest Tailscale release for Linux is %q, but your apk repository only provides %q.\nYour Alpine version is %q, you may need to upgrade the system to get the latest Tailscale version: https://wiki.alpinelinux.org/wiki/Upgrading_Alpine", latest, apkVer, alpineVer)
  684. }
  685. return nil
  686. }
  687. func (up *Updater) updateMacSys() error {
  688. return errors.New("NOTREACHED: On MacSys builds, `tailscale update` is handled in Swift to launch the GUI updater")
  689. }
  690. func (up *Updater) updateMacAppStore() error {
  691. // We can't trigger the update via App Store from the sandboxed app. At
  692. // most, we can open the App Store page for them.
  693. up.Logf("Please use the App Store to update Tailscale.\nConsider enabling Automatic Updates in the App Store Settings, if you haven't already.\nOpening the Tailscale app page...")
  694. out, err := exec.Command("open", "https://apps.apple.com/us/app/tailscale/id1475387142").CombinedOutput()
  695. if err != nil {
  696. return fmt.Errorf("can't open the Tailscale page in App Store: %w, output:\n%s", err, string(out))
  697. }
  698. return nil
  699. }
  700. // cleanupOldDownloads removes all files matching glob (see filepath.Glob).
  701. // Only regular files are removed, so the glob must match specific files and
  702. // not directories.
  703. func (up *Updater) cleanupOldDownloads(glob string) {
  704. matches, err := filepath.Glob(glob)
  705. if err != nil {
  706. up.Logf("cleaning up old downloads: %v", err)
  707. return
  708. }
  709. for _, m := range matches {
  710. s, err := os.Lstat(m)
  711. if err != nil {
  712. up.Logf("cleaning up old downloads: %v", err)
  713. continue
  714. }
  715. if !s.Mode().IsRegular() {
  716. continue
  717. }
  718. if err := os.Remove(m); err != nil {
  719. up.Logf("cleaning up old downloads: %v", err)
  720. }
  721. }
  722. }
  723. func (up *Updater) updateFreeBSD() (err error) {
  724. if up.Version != "" {
  725. return errors.New("installing a specific version on FreeBSD is not supported")
  726. }
  727. if err := requireRoot(); err != nil {
  728. return err
  729. }
  730. if err := exec.Command("pkg", "query", "%n", "tailscale").Run(); err != nil && isExitError(err) {
  731. // Tailscale was not installed via pkg and we don't pre-compile
  732. // binaries for it.
  733. return errors.New("Tailscale was not installed via pkg, binary updates on FreeBSD are not supported; please reinstall Tailscale using pkg or update manually")
  734. }
  735. defer func() {
  736. if err != nil {
  737. err = fmt.Errorf(`%w; you can try updating using "pkg upgrade tailscale"`, err)
  738. }
  739. }()
  740. out, err := exec.Command("pkg", "update").CombinedOutput()
  741. if err != nil {
  742. return fmt.Errorf("failed refresh pkg repository indexes: %w, output:\n%s", err, out)
  743. }
  744. out, err = exec.Command("pkg", "rquery", "%v", "tailscale").CombinedOutput()
  745. if err != nil {
  746. return fmt.Errorf("failed checking pkg for latest tailscale version: %w, output:\n%s", err, out)
  747. }
  748. ver := string(bytes.TrimSpace(out))
  749. if !up.confirm(ver) {
  750. return nil
  751. }
  752. cmd := exec.Command("pkg", "upgrade", "-y", "tailscale")
  753. cmd.Stdout = up.Stdout
  754. cmd.Stderr = up.Stderr
  755. if err := cmd.Run(); err != nil {
  756. return fmt.Errorf("failed tailscale update using pkg: %w", err)
  757. }
  758. // pkg does not automatically restart services after upgrade.
  759. out, err = exec.Command("service", "tailscaled", "restart").CombinedOutput()
  760. if err != nil {
  761. return fmt.Errorf("failed to restart tailscaled after update: %w, output:\n%s", err, out)
  762. }
  763. return nil
  764. }
  765. func (up *Updater) updateLinuxBinary() error {
  766. // Root is needed to overwrite binaries and restart systemd unit.
  767. if err := requireRoot(); err != nil {
  768. return err
  769. }
  770. ver, err := requestedTailscaleVersion(up.Version, up.Track)
  771. if err != nil {
  772. return err
  773. }
  774. if !up.confirm(ver) {
  775. return nil
  776. }
  777. dlPath, err := up.downloadLinuxTarball(ver)
  778. if err != nil {
  779. return err
  780. }
  781. up.Logf("Extracting %q", dlPath)
  782. if err := up.unpackLinuxTarball(dlPath); err != nil {
  783. return err
  784. }
  785. if err := os.Remove(dlPath); err != nil {
  786. up.Logf("failed to clean up %q: %v", dlPath, err)
  787. }
  788. if err := restartSystemdUnit(context.Background()); err != nil {
  789. if errors.Is(err, errors.ErrUnsupported) {
  790. up.Logf("Tailscale binaries updated successfully.\nPlease restart tailscaled to finish the update.")
  791. } else {
  792. up.Logf("Tailscale binaries updated successfully, but failed to restart tailscaled: %s.\nPlease restart tailscaled to finish the update.", err)
  793. }
  794. } else {
  795. up.Logf("Success")
  796. }
  797. return nil
  798. }
  799. func restartSystemdUnit(ctx context.Context) error {
  800. if _, err := exec.LookPath("systemctl"); err != nil {
  801. // Likely not a systemd-managed distro.
  802. return errors.ErrUnsupported
  803. }
  804. if out, err := exec.Command("systemctl", "daemon-reload").CombinedOutput(); err != nil {
  805. return fmt.Errorf("systemctl daemon-reload failed: %w\noutput: %s", err, out)
  806. }
  807. if out, err := exec.Command("systemctl", "restart", "tailscaled.service").CombinedOutput(); err != nil {
  808. return fmt.Errorf("systemctl restart failed: %w\noutput: %s", err, out)
  809. }
  810. return nil
  811. }
  812. func (up *Updater) downloadLinuxTarball(ver string) (string, error) {
  813. dlDir, err := os.UserCacheDir()
  814. if err != nil {
  815. dlDir = os.TempDir()
  816. }
  817. dlDir = filepath.Join(dlDir, "tailscale-update")
  818. if err := os.MkdirAll(dlDir, 0700); err != nil {
  819. return "", err
  820. }
  821. pkgsPath := fmt.Sprintf("%s/tailscale_%s_%s.tgz", up.Track, ver, runtime.GOARCH)
  822. dlPath := filepath.Join(dlDir, path.Base(pkgsPath))
  823. if err := up.downloadURLToFile(pkgsPath, dlPath); err != nil {
  824. return "", err
  825. }
  826. return dlPath, nil
  827. }
  828. func (up *Updater) unpackLinuxTarball(path string) error {
  829. tailscale, tailscaled, err := binaryPaths()
  830. if err != nil {
  831. return err
  832. }
  833. f, err := os.Open(path)
  834. if err != nil {
  835. return err
  836. }
  837. defer f.Close()
  838. gr, err := gzip.NewReader(f)
  839. if err != nil {
  840. return err
  841. }
  842. defer gr.Close()
  843. tr := tar.NewReader(gr)
  844. files := make(map[string]int)
  845. wantFiles := map[string]int{
  846. "tailscale": 1,
  847. "tailscaled": 1,
  848. }
  849. for {
  850. th, err := tr.Next()
  851. if err == io.EOF {
  852. break
  853. }
  854. if err != nil {
  855. return fmt.Errorf("failed extracting %q: %w", path, err)
  856. }
  857. // TODO(awly): try to also extract tailscaled.service. The tricky part
  858. // is fixing up binary paths in that file if they differ from where
  859. // local tailscale/tailscaled are installed. Also, this may not be a
  860. // systemd distro.
  861. switch filepath.Base(th.Name) {
  862. case "tailscale":
  863. files["tailscale"]++
  864. if err := writeFile(tr, tailscale+".new", 0755); err != nil {
  865. return fmt.Errorf("failed extracting the new tailscale binary from %q: %w", path, err)
  866. }
  867. case "tailscaled":
  868. files["tailscaled"]++
  869. if err := writeFile(tr, tailscaled+".new", 0755); err != nil {
  870. return fmt.Errorf("failed extracting the new tailscaled binary from %q: %w", path, err)
  871. }
  872. }
  873. }
  874. if !maps.Equal(files, wantFiles) {
  875. return fmt.Errorf("%q has missing or duplicate files: got %v, want %v", path, files, wantFiles)
  876. }
  877. // Only place the files in final locations after everything extracted correctly.
  878. if err := os.Rename(tailscale+".new", tailscale); err != nil {
  879. return err
  880. }
  881. up.Logf("Updated %s", tailscale)
  882. if err := os.Rename(tailscaled+".new", tailscaled); err != nil {
  883. return err
  884. }
  885. up.Logf("Updated %s", tailscaled)
  886. return nil
  887. }
  888. func (up *Updater) updateQNAP() (err error) {
  889. if up.Version != "" {
  890. return errors.New("installing a specific version on QNAP is not supported")
  891. }
  892. if err := requireRoot(); err != nil {
  893. return err
  894. }
  895. defer func() {
  896. if err != nil {
  897. err = fmt.Errorf(`%w; you can try updating using "qpkg_cli --add Tailscale"`, err)
  898. }
  899. }()
  900. out, err := exec.Command("qpkg_cli", "--upgradable", "Tailscale").CombinedOutput()
  901. if err != nil {
  902. return fmt.Errorf("failed to check if Tailscale is upgradable using qpkg_cli: %w, output: %q", err, out)
  903. }
  904. // Output should look like this:
  905. //
  906. // $ qpkg_cli -G Tailscale
  907. // [Tailscale]
  908. // upgradeStatus = 1
  909. statusRe := regexp.MustCompile(`upgradeStatus = (\d)`)
  910. m := statusRe.FindStringSubmatch(string(out))
  911. if len(m) < 2 {
  912. return fmt.Errorf("failed to check if Tailscale is upgradable using qpkg_cli, output: %q", out)
  913. }
  914. status, err := strconv.Atoi(m[1])
  915. if err != nil {
  916. return fmt.Errorf("cannot parse upgradeStatus from qpkg_cli output %q: %w", out, err)
  917. }
  918. // Possible status values:
  919. // 0:can upgrade
  920. // 1:can not upgrade
  921. // 2:error
  922. // 3:can not get rss information
  923. // 4:qpkg not found
  924. // 5:qpkg not installed
  925. //
  926. // We want status 0.
  927. switch status {
  928. case 0: // proceed with upgrade
  929. case 1:
  930. up.Logf("no update available")
  931. return nil
  932. case 2, 3, 4:
  933. return fmt.Errorf("failed to check update status with qpkg_cli (upgradeStatus = %d)", status)
  934. case 5:
  935. return errors.New("Tailscale was not found in the QNAP App Center")
  936. default:
  937. return fmt.Errorf("failed to check update status with qpkg_cli (upgradeStatus = %d)", status)
  938. }
  939. // There doesn't seem to be a way to fetch what the available upgrade
  940. // version is. Use the generic "latest" version in confirmation prompt.
  941. if up.Confirm != nil && !up.Confirm("latest") {
  942. return nil
  943. }
  944. up.Logf("c2n: running qpkg_cli --add Tailscale")
  945. cmd := exec.Command("qpkg_cli", "--add", "Tailscale")
  946. cmd.Stdout = up.Stdout
  947. cmd.Stderr = up.Stderr
  948. if err := cmd.Run(); err != nil {
  949. return fmt.Errorf("failed tailscale update using qpkg_cli: %w", err)
  950. }
  951. return nil
  952. }
  953. func (up *Updater) updateUnraid() (err error) {
  954. if up.Version != "" {
  955. return errors.New("installing a specific version on Unraid is not supported")
  956. }
  957. if err := requireRoot(); err != nil {
  958. return err
  959. }
  960. defer func() {
  961. if err != nil {
  962. err = fmt.Errorf(`%w; you can try updating using "plugin check tailscale.plg && plugin update tailscale.plg"`, err)
  963. }
  964. }()
  965. // We need to run `plugin check` for the latest tailscale.plg to get
  966. // downloaded. Unfortunately, the output of this command does not contain
  967. // the latest tailscale version available. So we'll parse the downloaded
  968. // tailscale.plg file manually below.
  969. out, err := exec.Command("plugin", "check", "tailscale.plg").CombinedOutput()
  970. if err != nil {
  971. return fmt.Errorf("failed to check if Tailscale plugin is upgradable: %w, output: %q", err, out)
  972. }
  973. // Note: 'plugin check' downloads plugins to /tmp/plugins.
  974. // The installed .plg files are in /boot/config/plugins/, but the pending
  975. // ones are in /tmp/plugins. We should parse the pending file downloaded by
  976. // 'plugin check'.
  977. latest, err := parseUnraidPluginVersion("/tmp/plugins/tailscale.plg")
  978. if err != nil {
  979. return fmt.Errorf("failed to find latest Tailscale version in /boot/config/plugins/tailscale.plg: %w", err)
  980. }
  981. if !up.confirm(latest) {
  982. return nil
  983. }
  984. up.Logf("c2n: running 'plugin update tailscale.plg'")
  985. cmd := exec.Command("plugin", "update", "tailscale.plg")
  986. cmd.Stdout = up.Stdout
  987. cmd.Stderr = up.Stderr
  988. if err := cmd.Run(); err != nil {
  989. return fmt.Errorf("failed tailscale plugin update: %w", err)
  990. }
  991. return nil
  992. }
  993. func parseUnraidPluginVersion(plgPath string) (string, error) {
  994. plg, err := os.ReadFile(plgPath)
  995. if err != nil {
  996. return "", err
  997. }
  998. re := regexp.MustCompile(`<FILE Name="/boot/config/plugins/tailscale/tailscale_(\d+\.\d+\.\d+)_[a-z0-9]+.tgz">`)
  999. match := re.FindStringSubmatch(string(plg))
  1000. if len(match) < 2 {
  1001. return "", errors.New("version not found in plg file")
  1002. }
  1003. return match[1], nil
  1004. }
  1005. func writeFile(r io.Reader, path string, perm os.FileMode) error {
  1006. if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
  1007. return fmt.Errorf("failed to remove existing file at %q: %w", path, err)
  1008. }
  1009. f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
  1010. if err != nil {
  1011. return err
  1012. }
  1013. defer f.Close()
  1014. if _, err := io.Copy(f, r); err != nil {
  1015. return err
  1016. }
  1017. return f.Close()
  1018. }
  1019. // Var allows overriding this in tests.
  1020. var binaryPaths = func() (tailscale, tailscaled string, err error) {
  1021. // This can be either tailscale or tailscaled.
  1022. this, err := os.Executable()
  1023. if err != nil {
  1024. return "", "", err
  1025. }
  1026. otherName := "tailscaled"
  1027. if filepath.Base(this) == "tailscaled" {
  1028. otherName = "tailscale"
  1029. }
  1030. // Try to find the other binary in the same directory.
  1031. other := filepath.Join(filepath.Dir(this), otherName)
  1032. _, err = os.Stat(other)
  1033. if os.IsNotExist(err) {
  1034. // If it's not in the same directory, try to find it in $PATH.
  1035. other, err = exec.LookPath(otherName)
  1036. }
  1037. if err != nil {
  1038. return "", "", fmt.Errorf("cannot find %q in neither %q nor $PATH: %w", otherName, filepath.Dir(this), err)
  1039. }
  1040. if otherName == "tailscaled" {
  1041. return this, other, nil
  1042. } else {
  1043. return other, this, nil
  1044. }
  1045. }
  1046. func haveExecutable(name string) bool {
  1047. path, err := exec.LookPath(name)
  1048. return err == nil && path != ""
  1049. }
  1050. func requestedTailscaleVersion(ver, track string) (string, error) {
  1051. if ver != "" {
  1052. return ver, nil
  1053. }
  1054. return LatestTailscaleVersion(track)
  1055. }
  1056. // LatestTailscaleVersion returns the latest released version for the given
  1057. // track from pkgs.tailscale.com.
  1058. func LatestTailscaleVersion(track string) (string, error) {
  1059. if track == "" {
  1060. track = CurrentTrack
  1061. }
  1062. latest, err := latestPackages(track)
  1063. if err != nil {
  1064. return "", err
  1065. }
  1066. ver := latest.Version
  1067. switch runtime.GOOS {
  1068. case "windows":
  1069. ver = latest.MSIsVersion
  1070. case "darwin":
  1071. ver = latest.MacZipsVersion
  1072. case "linux":
  1073. ver = latest.TarballsVersion
  1074. if distro.Get() == distro.Synology {
  1075. ver = latest.SPKsVersion
  1076. }
  1077. }
  1078. if ver == "" {
  1079. return "", fmt.Errorf("no latest version found for OS %q on %q track", runtime.GOOS, track)
  1080. }
  1081. return ver, nil
  1082. }
  1083. type trackPackages struct {
  1084. Version string
  1085. Tarballs map[string]string
  1086. TarballsVersion string
  1087. Exes []string
  1088. ExesVersion string
  1089. MSIs map[string]string
  1090. MSIsVersion string
  1091. MacZips map[string]string
  1092. MacZipsVersion string
  1093. SPKs map[string]map[string]string
  1094. SPKsVersion string
  1095. }
  1096. func latestPackages(track string) (*trackPackages, error) {
  1097. url := fmt.Sprintf("https://pkgs.tailscale.com/%s/?mode=json&os=%s", track, runtime.GOOS)
  1098. res, err := http.Get(url)
  1099. if err != nil {
  1100. return nil, fmt.Errorf("fetching latest tailscale version: %w", err)
  1101. }
  1102. defer res.Body.Close()
  1103. var latest trackPackages
  1104. if err := json.NewDecoder(res.Body).Decode(&latest); err != nil {
  1105. return nil, fmt.Errorf("decoding JSON: %v: %w", res.Status, err)
  1106. }
  1107. return &latest, nil
  1108. }
  1109. func requireRoot() error {
  1110. if os.Geteuid() == 0 {
  1111. return nil
  1112. }
  1113. switch runtime.GOOS {
  1114. case "linux":
  1115. return errors.New("must be root; use sudo")
  1116. case "freebsd", "openbsd":
  1117. return errors.New("must be root; use doas")
  1118. default:
  1119. return errors.New("must be root")
  1120. }
  1121. }
  1122. func isExitError(err error) bool {
  1123. var exitErr *exec.ExitError
  1124. return errors.As(err, &exitErr)
  1125. }