summaryrefslogtreecommitdiff
path: root/scripts/roll
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/roll')
-rwxr-xr-xscripts/roll41
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/roll b/scripts/roll
new file mode 100755
index 0000000..d8deb61
--- /dev/null
+++ b/scripts/roll
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -e
+
+NAME=$1
+USER=tom
+PASS=tom
+ROOT_PASS=root
+
+# init
+lxc-create $NAME -t download -- --dist debian --release buster --arch amd64
+lxc-start $NAME
+# TODO maybe just info until ip shows up?
+sleep 15
+
+# install basics
+lxc-attach $NAME -- apt-get update
+lxc-attach $NAME -- apt-get dist-upgrade
+lxc-attach $NAME -- apt-get install -y sudo openssh-server x11-xserver-utils apt-utils
+
+# setup users
+lxc-attach $NAME -- bash -c 'echo -e "'$ROOT_PASS'\n'$ROOT_PASS'" | passwd'
+lxc-attach $NAME -- adduser $USER --gecos "" --disabled-password
+lxc-attach $NAME -- bash -c 'echo -e "'$PASS'\n'$PASS'" | passwd $USER'
+
+# setup x11 forwarding
+lxc-attach $NAME -- bash -c 'echo "AllowTcpForwarding yes" >> /etc/ssh/sshd_config'
+lxc-attach $NAME -- bash -c 'echo "X11UseLocalhost yes" >> /etc/ssh/sshd_config'
+lxc-attach $NAME -- bash -c 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
+lxc-attach $NAME -- systemctl restart sshd
+
+# setup networking
+IP="$(lxc-info $NAME | grep IP | tr -s ' ' | cut -d ' ' -f 2)"
+DESIRED_IP="$(grep $NAME configs/hosts | cut -d ' ' -f 1)"
+
+sed "s/ADDRESS/$DESIRED_IP/" configs/interfaces > tmp/interfaces
+sshpass -p $ROOT_PASS scp -o "StrictHostKeyChecking=no" tmp/interfaces root@$IP:/etc/network/interfaces
+sshpass -p $ROOT_PASS scp -o "StrictHostKeyChecking=no" configs/hosts root@$IP:/etc/hosts
+lxc-attach $NAME -- systemctl restart networking
+
+# add ssh key
+sshpass -p $ROOT_PASS ssh-copy-id -o "StrictHostKeyChecking=no" root@$DESIRED_IP