installer.sh 11 KB

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