installer.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. # TODO: wsl?
  255. # TODO: synology? qnap?
  256. esac
  257. fi
  258. # If we failed to detect something through os-release, consult
  259. # uname and try to infer things from that.
  260. if [ -z "$OS" ]; then
  261. if type uname >/dev/null 2>&1; then
  262. case "$(uname)" in
  263. FreeBSD)
  264. # FreeBSD before 12.2 doesn't have
  265. # /etc/os-release, so we wouldn't have found it in
  266. # the os-release probing above.
  267. OS="freebsd"
  268. VERSION="$(freebsd-version | cut -f1 -d.)"
  269. PACKAGETYPE="pkg"
  270. ;;
  271. OpenBSD)
  272. OS="openbsd"
  273. VERSION="$(uname -r)"
  274. PACKAGETYPE=""
  275. ;;
  276. Darwin)
  277. OS="macos"
  278. VERSION="$(sw_vers -productVersion | cut -f1-2 -d.)"
  279. PACKAGETYPE="appstore"
  280. ;;
  281. Linux)
  282. OS="other-linux"
  283. VERSION=""
  284. PACKAGETYPE=""
  285. ;;
  286. esac
  287. fi
  288. fi
  289. # Step 2: having detected an OS we support, is it one of the
  290. # versions we support?
  291. OS_UNSUPPORTED=
  292. case "$OS" in
  293. ubuntu)
  294. if [ "$VERSION" != "xenial" ] && \
  295. [ "$VERSION" != "bionic" ] && \
  296. [ "$VERSION" != "eoan" ] && \
  297. [ "$VERSION" != "focal" ] && \
  298. [ "$VERSION" != "groovy" ] && \
  299. [ "$VERSION" != "hirsute" ] && \
  300. [ "$VERSION" != "impish" ] && \
  301. [ "$VERSION" != "jammy" ] && \
  302. [ "$VERSION" != "kinetic" ]
  303. then
  304. OS_UNSUPPORTED=1
  305. fi
  306. ;;
  307. debian)
  308. if [ "$VERSION" != "stretch" ] && \
  309. [ "$VERSION" != "buster" ] && \
  310. [ "$VERSION" != "bullseye" ] && \
  311. [ "$VERSION" != "bookworm" ] && \
  312. [ "$VERSION" != "sid" ]
  313. then
  314. OS_UNSUPPORTED=1
  315. fi
  316. ;;
  317. raspbian)
  318. if [ "$VERSION" != "stretch" ] && \
  319. [ "$VERSION" != "buster" ] && \
  320. [ "$VERSION" != "bullseye" ]
  321. then
  322. OS_UNSUPPORTED=1
  323. fi
  324. ;;
  325. centos)
  326. if [ "$VERSION" != "7" ] && \
  327. [ "$VERSION" != "8" ] && \
  328. [ "$VERSION" != "9" ]
  329. then
  330. OS_UNSUPPORTED=1
  331. fi
  332. ;;
  333. oracle)
  334. if [ "$VERSION" != "7" ] && \
  335. [ "$VERSION" != "8" ]
  336. then
  337. OS_UNSUPPORTED=1
  338. fi
  339. ;;
  340. rhel)
  341. if [ "$VERSION" != "7" ] && \
  342. [ "$VERSION" != "8" ] && \
  343. [ "$VERSION" != "9" ]
  344. then
  345. OS_UNSUPPORTED=1
  346. fi
  347. ;;
  348. amazon-linux)
  349. if [ "$VERSION" != "2" ] && \
  350. [ "$VERSION" != "2022" ] && \
  351. [ "$VERSION" != "2023" ]
  352. then
  353. OS_UNSUPPORTED=1
  354. fi
  355. ;;
  356. opensuse)
  357. if [ "$VERSION" != "leap/15.1" ] && \
  358. [ "$VERSION" != "leap/15.2" ] && \
  359. [ "$VERSION" != "leap/15.3" ] && \
  360. [ "$VERSION" != "leap/15.4" ] && \
  361. [ "$VERSION" != "tumbleweed" ]
  362. then
  363. OS_UNSUPPORTED=1
  364. fi
  365. ;;
  366. fedora)
  367. # All versions supported, no version checking required.
  368. ;;
  369. arch)
  370. # Rolling release, no version checking needed.
  371. ;;
  372. manjaro)
  373. # Rolling release, no version checking needed.
  374. ;;
  375. alpine)
  376. # All versions supported, no version checking needed.
  377. # TODO: is that true? When was tailscale packaged?
  378. ;;
  379. void)
  380. # Rolling release, no version checking needed.
  381. ;;
  382. gentoo)
  383. # Rolling release, no version checking needed.
  384. ;;
  385. freebsd)
  386. if [ "$VERSION" != "12" ] && \
  387. [ "$VERSION" != "13" ]
  388. then
  389. OS_UNSUPPORTED=1
  390. fi
  391. ;;
  392. openbsd)
  393. OS_UNSUPPORTED=1
  394. ;;
  395. macos)
  396. # We delegate macOS installation to the app store, it will
  397. # perform version checks for us.
  398. ;;
  399. other-linux)
  400. OS_UNSUPPORTED=1
  401. ;;
  402. *)
  403. OS_UNSUPPORTED=1
  404. ;;
  405. esac
  406. if [ "$OS_UNSUPPORTED" = "1" ]; then
  407. case "$OS" in
  408. other-linux)
  409. echo "Couldn't determine what kind of Linux is running."
  410. echo "You could try the static binaries at:"
  411. echo "https://pkgs.tailscale.com/$TRACK/#static"
  412. ;;
  413. "")
  414. echo "Couldn't determine what operating system you're running."
  415. ;;
  416. *)
  417. echo "$OS $VERSION isn't supported by this script yet."
  418. ;;
  419. esac
  420. echo
  421. echo "If you'd like us to support your system better, please email [email protected]"
  422. echo "and tell us what OS you're running."
  423. echo
  424. echo "Please include the following information we gathered from your system:"
  425. echo
  426. echo "OS=$OS"
  427. echo "VERSION=$VERSION"
  428. echo "PACKAGETYPE=$PACKAGETYPE"
  429. if type uname >/dev/null 2>&1; then
  430. echo "UNAME=$(uname -a)"
  431. else
  432. echo "UNAME="
  433. fi
  434. echo
  435. if [ -f /etc/os-release ]; then
  436. cat /etc/os-release
  437. else
  438. echo "No /etc/os-release"
  439. fi
  440. exit 1
  441. fi
  442. # Step 3: work out if we can run privileged commands, and if so,
  443. # how.
  444. CAN_ROOT=
  445. SUDO=
  446. if [ "$(id -u)" = 0 ]; then
  447. CAN_ROOT=1
  448. SUDO=""
  449. elif type sudo >/dev/null; then
  450. CAN_ROOT=1
  451. SUDO="sudo"
  452. elif type doas >/dev/null; then
  453. CAN_ROOT=1
  454. SUDO="doas"
  455. fi
  456. if [ "$CAN_ROOT" != "1" ]; then
  457. echo "This installer needs to run commands as root."
  458. echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
  459. echo "Either re-run this script as root, or set up sudo/doas."
  460. exit 1
  461. fi
  462. # Step 4: run the installation.
  463. echo "Installing Tailscale for $OS $VERSION, using method $PACKAGETYPE"
  464. case "$PACKAGETYPE" in
  465. apt)
  466. # Ideally we want to use curl, but on some installs we
  467. # only have wget. Detect and use what's available.
  468. CURL=
  469. if type curl >/dev/null; then
  470. CURL="curl -fsSL"
  471. elif type wget >/dev/null; then
  472. CURL="wget -q -O-"
  473. fi
  474. if [ -z "$CURL" ]; then
  475. echo "The installer needs either curl or wget to download files."
  476. echo "Please install either curl or wget to proceed."
  477. exit 1
  478. fi
  479. export DEBIAN_FRONTEND=noninteractive
  480. if [ "$APT_KEY_TYPE" = "legacy" ] && ! type gpg >/dev/null; then
  481. $SUDO apt-get update
  482. $SUDO apt-get install -y gnupg
  483. fi
  484. set -x
  485. $SUDO mkdir -p --mode=0755 /usr/share/keyrings
  486. case "$APT_KEY_TYPE" in
  487. legacy)
  488. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.asc" | $SUDO apt-key add -
  489. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  490. ;;
  491. keyring)
  492. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.noarmor.gpg" | $SUDO tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
  493. $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.tailscale-keyring.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
  494. ;;
  495. esac
  496. $SUDO apt-get update
  497. $SUDO apt-get install -y tailscale tailscale-archive-keyring
  498. if [ "$APT_SYSTEMCTL_START" = "true" ]; then
  499. $SUDO systemctl enable --now tailscaled
  500. $SUDO systemctl start tailscaled
  501. fi
  502. set +x
  503. ;;
  504. yum)
  505. set -x
  506. $SUDO yum install yum-utils -y
  507. $SUDO yum-config-manager -y --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  508. $SUDO yum install tailscale -y
  509. $SUDO systemctl enable --now tailscaled
  510. set +x
  511. ;;
  512. dnf)
  513. set -x
  514. $SUDO dnf config-manager --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  515. $SUDO dnf install -y tailscale
  516. $SUDO systemctl enable --now tailscaled
  517. set +x
  518. ;;
  519. zypper)
  520. set -x
  521. $SUDO zypper ar -g -r "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
  522. $SUDO zypper ref
  523. $SUDO zypper in tailscale
  524. $SUDO systemctl enable --now tailscaled
  525. set +x
  526. ;;
  527. pacman)
  528. set -x
  529. $SUDO pacman -S tailscale --noconfirm
  530. $SUDO systemctl enable --now tailscaled
  531. set +x
  532. ;;
  533. pkg)
  534. set -x
  535. $SUDO pkg install tailscale
  536. $SUDO service tailscaled enable
  537. $SUDO service tailscaled start
  538. set +x
  539. ;;
  540. apk)
  541. set -x
  542. $SUDO apk add tailscale
  543. $SUDO rc-update add tailscale
  544. set +x
  545. ;;
  546. xbps)
  547. set -x
  548. $SUDO xbps-install tailscale -y
  549. set +x
  550. ;;
  551. emerge)
  552. set -x
  553. $SUDO emerge --ask=n net-vpn/tailscale
  554. set +x
  555. ;;
  556. appstore)
  557. set -x
  558. open "https://apps.apple.com/us/app/tailscale/id1475387142"
  559. set +x
  560. ;;
  561. *)
  562. echo "unexpected: unknown package type $PACKAGETYPE"
  563. exit 1
  564. ;;
  565. esac
  566. echo "Installation complete! Log in to start using Tailscale by running:"
  567. echo
  568. if [ -z "$SUDO" ]; then
  569. echo "tailscale up"
  570. else
  571. echo "$SUDO tailscale up"
  572. fi
  573. }
  574. main