diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2020-03-20 04:43:01 -0500 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2020-03-20 04:43:01 -0500 |
commit | c146a0ea62b03d9650bdb43986acb0afdf2ecba0 (patch) | |
tree | 2aa44962f79db4f1443c2679028cc81ce2225dda /scripts/roll | |
parent | eab5eca5bda076aae57e6cc82b6e08dbd5025ff3 (diff) |
Diffstat (limited to 'scripts/roll')
-rwxr-xr-x | scripts/roll | 41 |
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 |