installer.sh 14 KB

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