installer.sh 13 KB

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