blob: d8deb614faf1ff3455492b88618261130ab73a22 (
plain)
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
|
#!/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
|