#!/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 apt-utils lxc-attach $NAME -- apt-get install -y sudo openssh-server x11-xserver-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