installer.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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|tuxedo)
  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|kaisen)
  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. VERSION="buster"
  159. else
  160. APT_KEY_TYPE="keyring"
  161. VERSION="bullseye"
  162. fi
  163. ;;
  164. centos)
  165. OS="$ID"
  166. VERSION="$VERSION_ID"
  167. PACKAGETYPE="dnf"
  168. if [ "$VERSION" = "7" ]; then
  169. PACKAGETYPE="yum"
  170. fi
  171. ;;
  172. ol)
  173. OS="oracle"
  174. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  175. PACKAGETYPE="dnf"
  176. if [ "$VERSION" = "7" ]; then
  177. PACKAGETYPE="yum"
  178. fi
  179. ;;
  180. rhel)
  181. OS="$ID"
  182. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  183. PACKAGETYPE="dnf"
  184. if [ "$VERSION" = "7" ]; then
  185. PACKAGETYPE="yum"
  186. fi
  187. ;;
  188. fedora)
  189. OS="$ID"
  190. VERSION=""
  191. PACKAGETYPE="dnf"
  192. ;;
  193. rocky|almalinux|nobara|openmandriva|sangoma|risios|cloudlinux|alinux|fedora-asahi-remix)
  194. OS="fedora"
  195. VERSION=""
  196. PACKAGETYPE="dnf"
  197. ;;
  198. amzn)
  199. OS="amazon-linux"
  200. VERSION="$VERSION_ID"
  201. PACKAGETYPE="yum"
  202. ;;
  203. xenenterprise)
  204. OS="centos"
  205. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  206. PACKAGETYPE="yum"
  207. ;;
  208. opensuse-leap|sles)
  209. OS="opensuse"
  210. VERSION="leap/$VERSION_ID"
  211. PACKAGETYPE="zypper"
  212. ;;
  213. opensuse-tumbleweed)
  214. OS="opensuse"
  215. VERSION="tumbleweed"
  216. PACKAGETYPE="zypper"
  217. ;;
  218. sle-micro-rancher)
  219. OS="opensuse"
  220. VERSION="leap/15.4"
  221. PACKAGETYPE="zypper"
  222. ;;
  223. arch|archarm|endeavouros|blendos|garuda)
  224. OS="arch"
  225. VERSION="" # rolling release
  226. PACKAGETYPE="pacman"
  227. ;;
  228. manjaro|manjaro-arm)
  229. OS="manjaro"
  230. VERSION="" # rolling release
  231. PACKAGETYPE="pacman"
  232. ;;
  233. alpine)
  234. OS="$ID"
  235. VERSION="$VERSION_ID"
  236. PACKAGETYPE="apk"
  237. ;;
  238. postmarketos)
  239. OS="alpine"
  240. VERSION="$VERSION_ID"
  241. PACKAGETYPE="apk"
  242. ;;
  243. nixos)
  244. echo "Please add Tailscale to your NixOS configuration directly:"
  245. echo
  246. echo "services.tailscale.enable = true;"
  247. exit 1
  248. ;;
  249. void)
  250. OS="$ID"
  251. VERSION="" # rolling release
  252. PACKAGETYPE="xbps"
  253. ;;
  254. gentoo)
  255. OS="$ID"
  256. VERSION="" # rolling release
  257. PACKAGETYPE="emerge"
  258. ;;
  259. freebsd)
  260. OS="$ID"
  261. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  262. PACKAGETYPE="pkg"
  263. ;;
  264. osmc)
  265. OS="debian"
  266. PACKAGETYPE="apt"
  267. VERSION="bullseye"
  268. APT_KEY_TYPE="keyring"
  269. ;;
  270. photon)
  271. OS="photon"
  272. VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
  273. PACKAGETYPE="tdnf"
  274. ;;
  275. # TODO: wsl?
  276. # TODO: synology? qnap?
  277. esac
  278. fi
  279. # If we failed to detect something through os-release, consult
  280. # uname and try to infer things from that.
  281. if [ -z "$OS" ]; then
  282. if type uname >/dev/null 2>&1; then
  283. case "$(uname)" in
  284. FreeBSD)
  285. # FreeBSD before 12.2 doesn't have
  286. # /etc/os-release, so we wouldn't have found it in
  287. # the os-release probing above.
  288. OS="freebsd"
  289. VERSION="$(freebsd-version | cut -f1 -d.)"
  290. PACKAGETYPE="pkg"
  291. ;;
  292. OpenBSD)
  293. OS="openbsd"
  294. VERSION="$(uname -r)"
  295. PACKAGETYPE=""
  296. ;;
  297. Darwin)
  298. OS="macos"
  299. VERSION="$(sw_vers -productVersion | cut -f1-2 -d.)"
  300. PACKAGETYPE="appstore"
  301. ;;
  302. Linux)
  303. OS="other-linux"
  304. VERSION=""
  305. PACKAGETYPE=""
  306. ;;
  307. esac
  308. fi
  309. fi
  310. # Ideally we want to use curl, but on some installs we
  311. # only have wget. Detect and use what's available.
  312. CURL=
  313. if type curl >/dev/null; then
  314. CURL="curl -fsSL"
  315. elif type wget >/dev/null; then
  316. CURL="wget -q -O-"
  317. fi
  318. if [ -z "$CURL" ]; then
  319. echo "The installer needs either curl or wget to download files."
  320. echo "Please install either curl or wget to proceed."
  321. exit 1
  322. fi
  323. TEST_URL="https://pkgs.tailscale.com/"
  324. RC=0
  325. TEST_OUT=$($CURL "$TEST_URL" 2>&1) || RC=$?
  326. if [ $RC != 0 ]; then
  327. echo "The installer cannot reach $TEST_URL"
  328. echo "Please make sure that your machine has internet access."
  329. echo "Test output:"
  330. echo $TEST_OUT
  331. exit 1
  332. fi
  333. # Step 2: having detected an OS we support, is it one of the
  334. # versions we support?
  335. OS_UNSUPPORTED=
  336. case "$OS" in
  337. ubuntu|debian|raspbian|centos|oracle|rhel|amazon-linux|opensuse|photon)
  338. # Check with the package server whether a given version is supported.
  339. URL="https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/installer-supported"
  340. $CURL "$URL" 2> /dev/null | grep -q OK || OS_UNSUPPORTED=1
  341. ;;
  342. fedora)
  343. # All versions supported, no version checking required.
  344. ;;
  345. arch)
  346. # Rolling release, no version checking needed.
  347. ;;
  348. manjaro)
  349. # Rolling release, no version checking needed.
  350. ;;
  351. alpine)
  352. # All versions supported, no version checking needed.
  353. # TODO: is that true? When was tailscale packaged?
  354. ;;
  355. void)
  356. # Rolling release, no version checking needed.
  357. ;;
  358. gentoo)
  359. # Rolling release, no version checking needed.
  360. ;;
  361. freebsd)
  362. if [ "$VERSION" != "12" ] && \
  363. [ "$VERSION" != "13" ]
  364. then
  365. OS_UNSUPPORTED=1
  366. fi
  367. ;;
  368. openbsd)
  369. OS_UNSUPPORTED=1
  370. ;;
  371. macos)
  372. # We delegate macOS installation to the app store, it will
  373. # perform version checks for us.
  374. ;;
  375. other-linux)
  376. OS_UNSUPPORTED=1
  377. ;;
  378. *)
  379. OS_UNSUPPORTED=1
  380. ;;
  381. esac
  382. if [ "$OS_UNSUPPORTED" = "1" ]; then
  383. case "$OS" in
  384. other-linux)
  385. echo "Couldn't determine what kind of Linux is running."
  386. echo "You could try the static binaries at:"
  387. echo "https://pkgs.tailscale.com/$TRACK/#static"
  388. ;;
  389. "")
  390. echo "Couldn't determine what operating system you're running."
  391. ;;
  392. *)
  393. echo "$OS $VERSION isn't supported by this script yet."
  394. ;;
  395. esac
  396. echo
  397. echo "If you'd like us to support your system better, please email [email protected]"
  398. echo "and tell us what OS you're running."
  399. echo
  400. echo "Please include the following information we gathered from your system:"
  401. echo
  402. echo "OS=$OS"
  403. echo "VERSION=$VERSION"
  404. echo "PACKAGETYPE=$PACKAGETYPE"
  405. if type uname >/dev/null 2>&1; then
  406. echo "UNAME=$(uname -a)"
  407. else
  408. echo "UNAME="
  409. fi
  410. echo
  411. if [ -f /etc/os-release ]; then
  412. cat /etc/os-release
  413. else
  414. echo "No /etc/os-release"
  415. fi
  416. exit 1
  417. fi
  418. # Step 3: work out if we can run privileged commands, and if so,
  419. # how.
  420. CAN_ROOT=
  421. SUDO=
  422. if [ "$(id -u)" = 0 ]; then
  423. CAN_ROOT=1
  424. SUDO=""
  425. elif type sudo >/dev/null; then
  426. CAN_ROOT=1
  427. SUDO="sudo"
  428. elif type doas >/dev/null; then
  429. CAN_ROOT=1
  430. SUDO="doas"
  431. fi
  432. if [ "$CAN_ROOT" != "1" ]; then
  433. echo "This installer needs to run commands as root."
  434. echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
  435. echo "Either re-run this script as root, or set up sudo/doas."
  436. exit 1
  437. fi
  438. # Step 4: run the installation.
  439. OSVERSION="$OS"
  440. [ "$VERSION" != "" ] && OSVERSION="$OSVERSION $VERSION"
  441. echo "Installing Tailscale for $OSVERSION, using method $PACKAGETYPE"
  442. case "$PACKAGETYPE" in
  443. apt)
  444. export DEBIAN_FRONTEND=noninteractive
  445. if [ "$APT_KEY_TYPE" = "legacy" ] && ! type gpg >/dev/null; then
  446. $SUDO apt-get update
  447. $SUDO apt-get install -y gnupg
  448. fi
  449. set -x
  450. $SUDO mkdir -p --mode=0755 /usr/share/keyrings
  451. case "$APT_KEY_TYPE" in
  452. legacy)
  453. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.asc" | $SUDO apt-key add -
  454. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  455. ;;
  456. keyring)
  457. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.noarmor.gpg" | $SUDO tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
  458. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.tailscale-keyring.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  459. ;;
  460. esac
  461. $SUDO apt-get update
  462. $SUDO apt-get install -y tailscale tailscale-archive-keyring
  463. if [ "$APT_SYSTEMCTL_START" = "true" ]; then
  464. $SUDO systemctl enable --now tailscaled
  465. $SUDO systemctl start tailscaled
  466. fi
  467. set +x
  468. ;;
  469. yum)
  470. set -x
  471. $SUDO yum install yum-utils -y
  472. $SUDO yum-config-manager -y --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  473. $SUDO yum install tailscale -y
  474. $SUDO systemctl enable --now tailscaled
  475. set +x
  476. ;;
  477. dnf)
  478. set -x
  479. $SUDO dnf install -y 'dnf-command(config-manager)'
  480. $SUDO dnf config-manager --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  481. $SUDO dnf install -y tailscale
  482. $SUDO systemctl enable --now tailscaled
  483. set +x
  484. ;;
  485. tdnf)
  486. set -x
  487. curl -fsSL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo" > /etc/yum.repos.d/tailscale.repo
  488. $SUDO tdnf install -y tailscale
  489. $SUDO systemctl enable --now tailscaled
  490. set +x
  491. ;;
  492. zypper)
  493. set -x
  494. $SUDO rpm --import "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/repo.gpg"
  495. $SUDO zypper --non-interactive ar -g -r "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  496. $SUDO zypper --non-interactive --gpg-auto-import-keys refresh
  497. $SUDO zypper --non-interactive install tailscale
  498. $SUDO systemctl enable --now tailscaled
  499. set +x
  500. ;;
  501. pacman)
  502. set -x
  503. $SUDO pacman -S tailscale --noconfirm
  504. $SUDO systemctl enable --now tailscaled
  505. set +x
  506. ;;
  507. pkg)
  508. set -x
  509. $SUDO pkg install tailscale
  510. $SUDO service tailscaled enable
  511. $SUDO service tailscaled start
  512. set +x
  513. ;;
  514. apk)
  515. set -x
  516. if ! grep -Eq '^http.*/community$' /etc/apk/repositories; then
  517. if type setup-apkrepos >/dev/null; then
  518. $SUDO setup-apkrepos -c -1
  519. else
  520. echo "installing tailscale requires the community repo to be enabled in /etc/apk/repositories"
  521. exit 1
  522. fi
  523. fi
  524. $SUDO apk add tailscale
  525. $SUDO rc-update add tailscale
  526. $SUDO rc-service tailscale start
  527. set +x
  528. ;;
  529. xbps)
  530. set -x
  531. $SUDO xbps-install tailscale -y
  532. set +x
  533. ;;
  534. emerge)
  535. set -x
  536. $SUDO emerge --ask=n net-vpn/tailscale
  537. set +x
  538. ;;
  539. appstore)
  540. set -x
  541. open "https://apps.apple.com/us/app/tailscale/id1475387142"
  542. set +x
  543. ;;
  544. *)
  545. echo "unexpected: unknown package type $PACKAGETYPE"
  546. exit 1
  547. ;;
  548. esac
  549. echo "Installation complete! Log in to start using Tailscale by running:"
  550. echo
  551. if [ -z "$SUDO" ]; then
  552. echo "tailscale up"
  553. else
  554. echo "$SUDO tailscale up"
  555. fi
  556. }
  557. main