installer.sh 13 KB

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