Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
70 lines (62 loc) · 2.51 KB
/
Copy pathbootstrap.sh
File metadata and controls
70 lines (62 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#
# Run ONCE on a fresh box to prepare it for remote setup.
# This script creates the maintenance user, installs my SSH key, installs
# Tailscale, and joins your Tailscale account.
#
# After this finishes, follow the printed instructions to share the machine with me.
#
# Run as root (or with sudo). Example:
# sudo bash bootstrap.sh
#
set -euo pipefail
PROVIDER_SSH_KEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH9EpC2CTbbzP5rkFLHLRi/74OdX6q7lSIEuJIJA5HFD server-maintenance"
DEPLOY_USER="deploy"
if [ "$(id -u)" -ne 0 ]; then
echo "Please run with sudo: sudo bash bootstrap.sh"
exit 1
fi
echo "==> Updating packages and installing prerequisites..."
apt-get update -y
apt-get install -y sudo curl
echo "==> Creating the '${DEPLOY_USER}' maintenance user..."
if ! id "${DEPLOY_USER}" >/dev/null 2>&1; then
adduser --disabled-password --gecos "" "${DEPLOY_USER}"
fi
usermod -aG sudo "${DEPLOY_USER}"
echo "==> Installing the provider's SSH key..."
install -d -m 700 -o "${DEPLOY_USER}" -g "${DEPLOY_USER}" "/home/${DEPLOY_USER}/.ssh"
echo "${PROVIDER_SSH_KEY}" > "/home/${DEPLOY_USER}/.ssh/authorized_keys"
chown "${DEPLOY_USER}:${DEPLOY_USER}" "/home/${DEPLOY_USER}/.ssh/authorized_keys"
chmod 600 "/home/${DEPLOY_USER}/.ssh/authorized_keys"
echo "==> Granting passwordless sudo to '${DEPLOY_USER}'..."
echo "${DEPLOY_USER} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/${DEPLOY_USER}"
chmod 440 "/etc/sudoers.d/${DEPLOY_USER}"
visudo -c >/dev/null
echo "==> Installing Tailscale..."
if ! command -v tailscale >/dev/null 2>&1; then
curl -fsSL https://tailscale.com/install.sh | sh
fi
systemctl enable --now tailscaled
echo ""
echo "============================================================"
echo " Almost done. Two steps left:"
echo "============================================================"
echo ""
echo "1) Connect this machine to your Tailscale account by running:"
echo ""
echo " sudo tailscale up"
echo ""
echo " A URL will appear. Open it in your browser and log in"
echo " (or create a free Tailscale account). This machine will"
echo " then appear in your Tailscale device list."
echo ""
echo "2) Share this machine with me so I can finish the setup remotely:"
echo ""
echo " - Go to https://login.tailscale.com/admin/machines"
echo " - Find this machine (named: $(hostname))"
echo " - Click the '...' menu -> Share..."
echo " - Enter brockhansen56@gmail.com and send the share"
echo ""
echo " Then let me know that the machine is shared."
echo "============================================================"