forked from lutris/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-container.sh
executable file
·60 lines (52 loc) · 1.56 KB
/
setup-container.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -e
container=$1
user='ubuntu'
InstallDependencies() {
lxc exec $container -- apt update
lxc exec $container -- apt -y install wget curl build-essential git python openssh-server zsh
}
SetupSSH() {
lxc exec $container -- mkdir -p /home/$user/.ssh
if [[ $container == *"64"* ]]; then
key_folder=./ssh/buildbot64
else
key_folder=./ssh/buildbot32
fi
lxc file push ./ssh/authorized_keys $container/home/$user/.ssh/
lxc file push ./ssh/config $container/home/$user/.ssh/
lxc file push ${key_folder}/id_rsa $container/home/$user/.ssh/
lxc file push ${key_folder}/id_rsa.pub $container/home/$user/.ssh/
}
SetupUser() {
lxc exec $container -- passwd $user
lxc exec $container -- chsh -s /bin/zsh $user
lxc file push --uid=1000 --gid=1000 ./setup-userspace.sh $container/home/$user/
}
SetupUserspace() {
lxc exec $container -- chmod +x /home/$user/setup-userspace.sh
}
SetupHost() {
if [[ $container == *"64"* ]]; then
other_container="${container%amd64}i386"
other_hostname="buildbot32"
else
other_container="${container%i386}amd64"
other_hostname="buildbot64"
fi
other_ip=$(lxc list $other_container -c 4 | grep eth0 | cut -d" " -f 2)
if [[ "$other_ip" = "" ]]; then
echo "Other container $other_container is not reachable"
exit 2
fi
lxc exec $container -- bash -c "echo $other_ip $other_hostname >> /etc/hosts"
}
if [ $2 ]; then
$2
else
InstallDependencies
SetupHost
SetupSSH
SetupUser
SetupUserspace
fi