-
Notifications
You must be signed in to change notification settings - Fork 0
/
doit.sh
executable file
·46 lines (33 loc) · 1.14 KB
/
doit.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
44
45
46
#!/bin/sh
# Run this from any OS
if [ -z "$HCLOUD_TOKEN" ]; then
echo "Meh.. no token no server"
echo "Please set HCLOUD_TOKEN env var"
echo "You will get one from the Hetzner cloud console"
exit 1
fi
if [ -z "$(which nix)" ]; then
echo "Nix is not installed.. installing"
curl https://nixos.org/nix/install | sh
source $HOME/.nix-profile/etc/profile.d/nix.sh
fi
nix-env -i python hcloud
BUNDLE=$(nix-build --no-out-link -j4 release.nix -A kexec_bundle)
MYIP=$(ip addr show scope global | grep -Po 'inet \K[\d.]+' | head -1)
# Serve up the kexec_bundle on http://$MYIP:8000/kexec_bundle
ln -sf $BUNDLE kexec_bundle
NAME="nixos-$(date --rfc-3339=seconds | tr ' :+' '---')"
echo "Creating server $NAME"
cat >user-data.yaml <<EOF
#!/bin/bash
echo "$(cat $HOME/.ssh/authorized_keys)" > /ssh_pubkey
curl -o kexec_bundle http://$MYIP:8000/kexec_bundle && chmod 755 ./kexec_bundle
curl http://$MYIP:8000/nothing
./kexec_bundle
EOF
hcloud server create --image ubuntu-16.04 \
--name "$NAME" \
--type cx11 \
--user-data-from-file user-data.yaml
echo "Waiting for cloud-init to download file"
python -m SimpleHTTPServer 8000