installer.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. #!/bin/sh
  2. # Copyright (c) Tailscale Inc & AUTHORS
  3. # SPDX-License-Identifier: BSD-3-Clause
  4. #
  5. # This script detects the current operating system, and installs
  6. # Tailscale according to that OS's conventions.
  7. set -eu
  8. # All the code is wrapped in a main function that gets called at the
  9. # bottom of the file, so that a truncated partial download doesn't end
  10. # up executing half a script.
  11. main() {
  12. # Step 1: detect the current linux distro, version, and packaging system.
  13. #
  14. # We rely on a combination of 'uname' and /etc/os-release to find
  15. # an OS name and version, and from there work out what
  16. # installation method we should be using.
  17. #
  18. # The end result of this step is that the following three
  19. # variables are populated, if detection was successful.
  20. OS=""
  21. VERSION=""
  22. PACKAGETYPE=""
  23. APT_KEY_TYPE="" # Only for apt-based distros
  24. APT_SYSTEMCTL_START=false # Only needs to be true for Kali
  25. TRACK="${TRACK:-stable}"
  26. case "$TRACK" in
  27. stable|unstable)
  28. ;;
  29. *)
  30. echo "unsupported track $TRACK"
  31. exit 1
  32. ;;
  33. esac
  34. if [ -f /etc/os-release ]; then
  35. # /etc/os-release populates a number of shell variables. We care about the following:
  36. # - ID: the short name of the OS (e.g. "debian", "freebsd")
  37. # - VERSION_ID: the numeric release version for the OS, if any (e.g. "18.04")
  38. # - VERSION_CODENAME: the codename of the OS release, if any (e.g. "buster")
  39. # - UBUNTU_CODENAME: if it exists, use instead of VERSION_CODENAME
  40. . /etc/os-release
  41. case "$ID" in
  42. ubuntu|pop|neon|zorin)
  43. OS="ubuntu"
  44. if [ "${UBUNTU_CODENAME:-}" != "" ]; then
  45. VERSION="$UBUNTU_CODENAME"
  46. else
  47. VERSION="$VERSION_CODENAME"
  48. fi
  49. PACKAGETYPE="apt"
  50. # Third-party keyrings became the preferred method of
  51. # installation in Ubuntu 20.04.
  52. if expr "$VERSION_ID" : "2.*" >/dev/null; then
  53. APT_KEY_TYPE="keyring"
  54. else
  55. APT_KEY_TYPE="legacy"
  56. fi
  57. ;;
  58. debian)
  59. OS="$ID"
  60. VERSION="$VERSION_CODENAME"
  61. PACKAGETYPE="apt"
  62. # Third-party keyrings became the preferred method of
  63. # installation in Debian 11 (Bullseye).
  64. if [ -z "${VERSION_ID:-}" ]; then
  65. # rolling release. If you haven't kept current, that's on you.
  66. APT_KEY_TYPE="keyring"
  67. elif [ "$VERSION_ID" -lt 11 ]; then
  68. APT_KEY_TYPE="legacy"
  69. else
  70. APT_KEY_TYPE="keyring"
  71. fi
  72. ;;
  73. linuxmint)
  74. if [ "${UBUNTU_CODENAME:-}" != "" ]; then
  75. OS="ubuntu"
  76. VERSION="$UBUNTU_CODENAME"
  77. elif [ "${DEBIAN_CODENAME:-}" != "" ]; then
  78. OS="debian"
  79. VERSION="$DEBIAN_CODENAME"
  80. else
  81. OS="ubuntu"
  82. VERSION="$VERSION_CODENAME"
  83. fi
  84. PACKAGETYPE="apt"
  85. if [ "$VERSION_ID" -lt 5 ]; then
  86. APT_KEY_TYPE="legacy"
  87. else
  88. APT_KEY_TYPE="keyring"
  89. fi
  90. ;;
  91. elementary)
  92. OS="ubuntu"
  93. VERSION="$UBUNTU_CODENAME"
  94. PACKAGETYPE="apt"
  95. if [ "$VERSION_ID" -lt 6 ]; then
  96. APT_KEY_TYPE="legacy"
  97. else
  98. APT_KEY_TYPE="keyring"
  99. fi
  100. ;;
  101. parrot|mendel)
  102. OS="debian"
  103. PACKAGETYPE="apt"
  104. if [ "$VERSION_ID" -lt 5 ]; then
  105. VERSION="buster"
  106. APT_KEY_TYPE="legacy"
  107. else
  108. VERSION="bullseye"
  109. APT_KEY_TYPE="keyring"
  110. fi
  111. ;;
  112. galliumos)
  113. OS="ubuntu"
  114. PACKAGETYPE="apt"
  115. VERSION="bionic"
  116. APT_KEY_TYPE="legacy"
  117. ;;
  118. pureos)
  119. OS="debian"
  120. PACKAGETYPE="apt"
  121. VERSION="bullseye"
  122. APT_KEY_TYPE="keyring"
  123. ;;
  124. raspbian)
  125. OS="$ID"
  126. VERSION="$VERSION_CODENAME"
  127. PACKAGETYPE="apt"
  128. # Third-party keyrings became the preferred method of
  129. # installation in Raspbian 11 (Bullseye).
  130. if [ "$VERSION_ID" -lt 11 ]; then
  131. APT_KEY_TYPE="legacy"
  132. else
  133. APT_KEY_TYPE="keyring"
  134. fi
  135. ;;
  136. kali)
  137. OS="debian"
  138. PACKAGETYPE="apt"
  139. YEAR="$(echo "$VERSION_ID" | cut -f1 -d.)"
  140. APT_SYSTEMCTL_START=true
  141. # Third-party keyrings became the preferred method of
  142. # installation in Debian 11 (Bullseye), which Kali switched
  143. # to in roughly 2021.x releases
  144. if [ "$YEAR" -lt 2021 ]; then
  145. # Kali VERSION_ID is "kali-rolling", which isn't distinguishing
  146. VERSION="buster"
  147. APT_KEY_TYPE="legacy"
  148. else
  149. VERSION="bullseye"
  150. APT_KEY_TYPE="keyring"
  151. fi
  152. ;;
  153. Deepin) # https://github.com/tailscale/tailscale/issues/7862
  154. OS="debian"
  155. PACKAGETYPE="apt"
  156. if [ "$VERSION_ID" -lt 20 ]; then
  157. APT_KEY_TYPE="legacy"
  158. else
  159. APT_KEY_TYPE="keyring"
  160. fi
  161. ;;
  162. centos)
  163. OS="$ID"
  164. VERSION="$VERSION_ID"
  165. PACKAGETYPE="dnf"
  166. if [ "$VERSION" = "7" ]; then
  167. PACKAGETYPE="yum"
  168. fi
  169. ;;
  170. ol)
  171. OS="oracle"
  172. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  173. PACKAGETYPE="dnf"
  174. if [ "$VERSION" = "7" ]; then
  175. PACKAGETYPE="yum"
  176. fi
  177. ;;
  178. rhel)
  179. OS="$ID"
  180. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  181. PACKAGETYPE="dnf"
  182. if [ "$VERSION" = "7" ]; then
  183. PACKAGETYPE="yum"
  184. fi
  185. ;;
  186. fedora)
  187. OS="$ID"
  188. VERSION=""
  189. PACKAGETYPE="dnf"
  190. ;;
  191. rocky|almalinux|nobara|openmandriva|sangoma|risios)
  192. OS="fedora"
  193. VERSION=""
  194. PACKAGETYPE="dnf"
  195. ;;
  196. amzn)
  197. OS="amazon-linux"
  198. VERSION="$VERSION_ID"
  199. PACKAGETYPE="yum"
  200. ;;
  201. xenenterprise)
  202. OS="centos"
  203. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  204. PACKAGETYPE="yum"
  205. ;;
  206. opensuse-leap|sles)
  207. OS="opensuse"
  208. VERSION="leap/$VERSION_ID"
  209. PACKAGETYPE="zypper"
  210. ;;
  211. opensuse-tumbleweed)
  212. OS="opensuse"
  213. VERSION="tumbleweed"
  214. PACKAGETYPE="zypper"
  215. ;;
  216. sle-micro-rancher)
  217. OS="opensuse"
  218. VERSION="leap/15.4"
  219. PACKAGETYPE="zypper"
  220. ;;
  221. arch|archarm|endeavouros|blendos)
  222. OS="arch"
  223. VERSION="" # rolling release
  224. PACKAGETYPE="pacman"
  225. ;;
  226. manjaro|manjaro-arm)
  227. OS="manjaro"
  228. VERSION="" # rolling release
  229. PACKAGETYPE="pacman"
  230. ;;
  231. alpine)
  232. OS="$ID"
  233. VERSION="$VERSION_ID"
  234. PACKAGETYPE="apk"
  235. ;;
  236. postmarketos)
  237. OS="alpine"
  238. VERSION="$VERSION_ID"
  239. PACKAGETYPE="apk"
  240. ;;
  241. nixos)
  242. echo "Please add Tailscale to your NixOS configuration directly:"
  243. echo
  244. echo "services.tailscale.enable = true;"
  245. exit 1
  246. ;;
  247. void)
  248. OS="$ID"
  249. VERSION="" # rolling release
  250. PACKAGETYPE="xbps"
  251. ;;
  252. gentoo)
  253. OS="$ID"
  254. VERSION="" # rolling release
  255. PACKAGETYPE="emerge"
  256. ;;
  257. freebsd)
  258. OS="$ID"
  259. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  260. PACKAGETYPE="pkg"
  261. ;;
  262. osmc)
  263. OS="debian"
  264. PACKAGETYPE="apt"
  265. VERSION="bullseye"
  266. APT_KEY_TYPE="keyring"
  267. ;;
  268. photon)
  269. OS="photon"
  270. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  271. PACKAGETYPE="tdnf"
  272. ;;
  273. # TODO: wsl?
  274. # TODO: synology? qnap?
  275. esac
  276. fi
  277. # If we failed to detect something through os-release, consult
  278. # uname and try to infer things from that.
  279. if [ -z "$OS" ]; then
  280. if type uname >/dev/null 2>&1; then
  281. case "$(uname)" in
  282. FreeBSD)
  283. # FreeBSD before 12.2 doesn't have
  284. # /etc/os-release, so we wouldn't have found it in
  285. # the os-release probing above.
  286. OS="freebsd"
  287. VERSION="$(freebsd-version | cut -f1 -d.)"
  288. PACKAGETYPE="pkg"
  289. ;;
  290. OpenBSD)
  291. OS="openbsd"
  292. VERSION="$(uname -r)"
  293. PACKAGETYPE=""
  294. ;;
  295. Darwin)
  296. OS="macos"
  297. VERSION="$(sw_vers -productVersion | cut -f1-2 -d.)"
  298. PACKAGETYPE="appstore"
  299. ;;
  300. Linux)
  301. OS="other-linux"
  302. VERSION=""
  303. PACKAGETYPE=""
  304. ;;
  305. esac
  306. fi
  307. fi
  308. # Ideally we want to use curl, but on some installs we
  309. # only have wget. Detect and use what's available.
  310. CURL=
  311. if type curl >/dev/null; then
  312. CURL="curl -fsSL"
  313. elif type wget >/dev/null; then
  314. CURL="wget -q -O-"
  315. fi
  316. if [ -z "$CURL" ]; then
  317. echo "The installer needs either curl or wget to download files."
  318. echo "Please install either curl or wget to proceed."
  319. exit 1
  320. fi
  321. TEST_URL="https://pkgs.tailscale.com/"
  322. RC=0
  323. TEST_OUT=$($CURL "$TEST_URL" 2>&1) || RC=$?
  324. if [ $RC != 0 ]; then
  325. echo "The installer cannot reach $TEST_URL"
  326. echo "Please make sure that your machine has internet access."
  327. echo "Test output:"
  328. echo $TEST_OUT
  329. exit 1
  330. fi
  331. # Step 2: having detected an OS we support, is it one of the
  332. # versions we support?
  333. OS_UNSUPPORTED=
  334. case "$OS" in
  335. ubuntu|debian|raspbian|centos|oracle|rhel|amazon-linux|opensuse|photon)
  336. # Check with the package server whether a given version is supported.
  337. URL="https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/installer-supported"
  338. $CURL "$URL" 2> /dev/null | grep -q OK || OS_UNSUPPORTED=1
  339. ;;
  340. fedora)
  341. # All versions supported, no version checking required.
  342. ;;
  343. arch)
  344. # Rolling release, no version checking needed.
  345. ;;
  346. manjaro)
  347. # Rolling release, no version checking needed.
  348. ;;
  349. alpine)
  350. # All versions supported, no version checking needed.
  351. # TODO: is that true? When was tailscale packaged?
  352. ;;
  353. void)
  354. # Rolling release, no version checking needed.
  355. ;;
  356. gentoo)
  357. # Rolling release, no version checking needed.
  358. ;;
  359. freebsd)
  360. if [ "$VERSION" != "12" ] && \
  361. [ "$VERSION" != "13" ]
  362. then
  363. OS_UNSUPPORTED=1
  364. fi
  365. ;;
  366. openbsd)
  367. OS_UNSUPPORTED=1
  368. ;;
  369. macos)
  370. # We delegate macOS installation to the app store, it will
  371. # perform version checks for us.
  372. ;;
  373. other-linux)
  374. OS_UNSUPPORTED=1
  375. ;;
  376. *)
  377. OS_UNSUPPORTED=1
  378. ;;
  379. esac
  380. if [ "$OS_UNSUPPORTED" = "1" ]; then
  381. case "$OS" in
  382. other-linux)
  383. echo "Couldn't determine what kind of Linux is running."
  384. echo "You could try the static binaries at:"
  385. echo "https://pkgs.tailscale.com/$TRACK/#static"
  386. ;;
  387. "")
  388. echo "Couldn't determine what operating system you're running."
  389. ;;
  390. *)
  391. echo "$OS $VERSION isn't supported by this script yet."
  392. ;;
  393. esac
  394. echo
  395. echo "If you'd like us to support your system better, please email [email protected]"
  396. echo "and tell us what OS you're running."
  397. echo
  398. echo "Please include the following information we gathered from your system:"
  399. echo
  400. echo "OS=$OS"
  401. echo "VERSION=$VERSION"
  402. echo "PACKAGETYPE=$PACKAGETYPE"
  403. if type uname >/dev/null 2>&1; then
  404. echo "UNAME=$(uname -a)"
  405. else
  406. echo "UNAME="
  407. fi
  408. echo
  409. if [ -f /etc/os-release ]; then
  410. cat /etc/os-release
  411. else
  412. echo "No /etc/os-release"
  413. fi
  414. exit 1
  415. fi
  416. # Step 3: work out if we can run privileged commands, and if so,
  417. # how.
  418. CAN_ROOT=
  419. SUDO=
  420. if [ "$(id -u)" = 0 ]; then
  421. CAN_ROOT=1
  422. SUDO=""
  423. elif type sudo >/dev/null; then
  424. CAN_ROOT=1
  425. SUDO="sudo"
  426. elif type doas >/dev/null; then
  427. CAN_ROOT=1
  428. SUDO="doas"
  429. fi
  430. if [ "$CAN_ROOT" != "1" ]; then
  431. echo "This installer needs to run commands as root."
  432. echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
  433. echo "Either re-run this script as root, or set up sudo/doas."
  434. exit 1
  435. fi
  436. # Step 4: run the installation.
  437. OSVERSION="$OS"
  438. [ "$VERSION" != "" ] && OSVERSION="$OSVERSION $VERSION"
  439. echo "Installing Tailscale for $OSVERSION, using method $PACKAGETYPE"
  440. case "$PACKAGETYPE" in
  441. apt)
  442. export DEBIAN_FRONTEND=noninteractive
  443. if [ "$APT_KEY_TYPE" = "legacy" ] && ! type gpg >/dev/null; then
  444. $SUDO apt-get update
  445. $SUDO apt-get install -y gnupg
  446. fi
  447. set -x
  448. $SUDO mkdir -p --mode=0755 /usr/share/keyrings
  449. case "$APT_KEY_TYPE" in
  450. legacy)
  451. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.asc" | $SUDO apt-key add -
  452. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  453. ;;
  454. keyring)
  455. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.noarmor.gpg" | $SUDO tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
  456. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.tailscale-keyring.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  457. ;;
  458. esac
  459. $SUDO apt-get update
  460. $SUDO apt-get install -y tailscale tailscale-archive-keyring
  461. if [ "$APT_SYSTEMCTL_START" = "true" ]; then
  462. $SUDO systemctl enable --now tailscaled
  463. $SUDO systemctl start tailscaled
  464. fi
  465. set +x
  466. ;;
  467. yum)
  468. set -x
  469. $SUDO yum install yum-utils -y
  470. $SUDO yum-config-manager -y --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  471. $SUDO yum install tailscale -y
  472. $SUDO systemctl enable --now tailscaled
  473. set +x
  474. ;;
  475. dnf)
  476. set -x
  477. $SUDO dnf install -y 'dnf-command(config-manager)'
  478. $SUDO dnf config-manager --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  479. $SUDO dnf install -y tailscale
  480. $SUDO systemctl enable --now tailscaled
  481. set +x
  482. ;;
  483. tdnf)
  484. set -x
  485. curl -fsSL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo" > /etc/yum.repos.d/tailscale.repo
  486. $SUDO tdnf install -y tailscale
  487. $SUDO systemctl enable --now tailscaled
  488. set +x
  489. ;;
  490. zypper)
  491. set -x
  492. $SUDO zypper --non-interactive ar -g -r "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  493. $SUDO zypper --non-interactive --gpg-auto-import-keys refresh
  494. $SUDO zypper --non-interactive install tailscale
  495. $SUDO systemctl enable --now tailscaled
  496. set +x
  497. ;;
  498. pacman)
  499. set -x
  500. $SUDO pacman -Sy
  501. $SUDO pacman -S tailscale --noconfirm
  502. $SUDO systemctl enable --now tailscaled
  503. set +x
  504. ;;
  505. pkg)
  506. set -x
  507. $SUDO pkg install tailscale
  508. $SUDO service tailscaled enable
  509. $SUDO service tailscaled start
  510. set +x
  511. ;;
  512. apk)
  513. set -x
  514. $SUDO apk add tailscale
  515. $SUDO rc-update add tailscale
  516. set +x
  517. ;;
  518. xbps)
  519. set -x
  520. $SUDO xbps-install tailscale -y
  521. set +x
  522. ;;
  523. emerge)
  524. set -x
  525. $SUDO emerge --ask=n net-vpn/tailscale
  526. set +x
  527. ;;
  528. appstore)
  529. set -x
  530. open "https://apps.apple.com/us/app/tailscale/id1475387142"
  531. set +x
  532. ;;
  533. *)
  534. echo "unexpected: unknown package type $PACKAGETYPE"
  535. exit 1
  536. ;;
  537. esac
  538. echo "Installation complete! Log in to start using Tailscale by running:"
  539. echo
  540. if [ -z "$SUDO" ]; then
  541. echo "tailscale up"
  542. else
  543. echo "$SUDO tailscale up"
  544. fi
  545. }
  546. main