summaryrefslogtreecommitdiff
path: root/scripts/debian_roll
blob: 83b7d7608144e6d1d66f02da7eebca3d39662b0a (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 -n $NAME -t download -- --dist debian --release buster --arch amd64
lxc-start  -n $NAME
# TODO maybe just info until ip shows up?
sleep 15

# install basics
lxc-attach -n $NAME -- apt-get update
lxc-attach -n $NAME -- apt-get dist-upgrade
lxc-attach -n $NAME -- apt-get install -y apt-utils
lxc-attach -n $NAME -- apt-get install -y sudo openssh-server x11-xserver-utils

# setup users
lxc-attach -n $NAME -- bash -c 'echo -e "'$ROOT_PASS'\n'$ROOT_PASS'" | passwd'
lxc-attach -n $NAME -- adduser $USER --gecos "" --disabled-password
lxc-attach -n $NAME -- bash -c 'echo -e "'$PASS'\n'$PASS'" | passwd $USER'

# setup x11 forwarding
lxc-attach -n $NAME -- bash -c 'echo "AllowTcpForwarding yes" >> /etc/ssh/sshd_config'
lxc-attach -n $NAME -- bash -c 'echo "X11UseLocalhost yes" >> /etc/ssh/sshd_config'
lxc-attach -n $NAME -- bash -c 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
lxc-attach -n $NAME -- systemctl restart sshd

# setup networking
IP="$(lxc-info -n $NAME | grep IP | tr -s ' ' | cut -d ' ' -f 2)"
sshpass -p $ROOT_PASS ssh-copy-id -o "StrictHostKeyChecking=no" root@$IP
scp configs/$NAME/interfaces root@$IP:/etc/network/
scp configs/hosts root@$IP:/etc/
lxc-attach -n $NAME -- systemctl restart networking
ssh-keygen -R "$IP"

IP="$(lxc-info -n $NAME | grep IP | tr -s ' ' | cut -d ' ' -f 2)"
sshpass -p $ROOT_PASS ssh-copy-id -o "StrictHostKeyChecking=no" root@$IP