-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·43 lines (37 loc) · 1.52 KB
/
setup.sh
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
#!/bin/bash
echo
echo "Hetzner Bootstrap"
echo
BRANCH=$(git rev-parse --abbrev-ref HEAD)
REMOTE=$(git ls-remote --get-url origin | sed 's,github\.com[:/],raw.github.com/,;s,^git@,https://,;s,\.git$,,')
BASE_URL=$REMOTE/$BRANCH
echo "Base-URL: $BASE_URL"
sed "s,%%BASE_URL%%,${BASE_URL},g" hetzner-installimage.sh.template > hetzner-installimage.sh
sed "s,%%BASE_URL%%,${BASE_URL},g" hetzner-postinstall.sh.template > hetzner-postinstall.sh
cat custom-postinstall.sh >> hetzner-postinstall.sh
ROOT_USERS="$@"
if [[ -z $ROOT_USERS ]]
then
echo
echo "Please provide a space-separated list of github users whose"
echo "ssh public keys you want to add to /root/ssh/.authorized_keys"
echo "Leave blank if you don't want to grab keys from github."
echo "Example: leitmedium ctavan"
read ROOT_USERS
else
echo
echo "Fetching ssh keys for: $ROOT_USERS"
fi
for USER in $ROOT_USERS
do
MAIL_ADDRESS=$(wget -qO - https://api.github.com/users/$USER | awk -F'"' '/"email": /{print $4}')
wget -qO - https://api.github.com/users/$USER/keys |
awk -v user="$MAIL_ADDRESS - github user $USER" -F'"' '/"key": /{print $4, user}' >> root-ssh-authorizedkeys.pub
done
echo
echo "After pushing the new files to github you should be able to set up"
echo "a new server from the console by running the following command from"
echo "rescue mode (think twice before eventually losing data):"
echo
echo "SERVERNAME=your.fully.qualified.server.name bash < <(wget -qO - ${BASE_URL}/hetzner-installimage.sh)" | tee install-command.txt
echo