forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlxd_build_all.sh
More file actions
95 lines (73 loc) · 2.6 KB
/
lxd_build_all.sh
File metadata and controls
95 lines (73 loc) · 2.6 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
#
# Script for preparing lxd enviorment and building Hestia packages for all supported distros
# - Run with sudo, not directly as root!
#
# Arguments:
# ./lxd_build_all --cleanup
# - Stop and delete all containers
#
# ./lxd_build_all --background
# - Execute the build script on all containers simultaneously
#
# Configs:
oslist=('debian=9,10' 'ubuntu=16.04,18.04,20.04')
branch='master'
function setup_container() {
if [ "$osname" = 'ubuntu' ]; then
lxc init $osname:$osver "${containername}"
else
lxc init images:$osname/$osver "${containername}"
fi
mkdir -p "${__DIR__}/build/${containername}"
chown $user: "${__DIR__}/build/${containername}"
lxc config set ${containername} raw.idmap "both $user_id $user_gid"
lxc config device add ${containername} debdir disk path=/opt/hestiacp source=${__DIR__}/build/${containername}
}
cmd=$1
__DIR__="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" #"
# user=$(logname)
user=$SUDO_USER
user_id=$(id -u $user)
user_gid=$(id -g $user)
if [ -z "$user" ] || [ -z "$user_id" ] || [ -z "$user_gid" ] || [ "$user" = 'root' ]; then
echo "Script must be run with sudo, not directly as root" && exit 1
fi
if ! dpkg-query -s lxd >/dev/null 2>&1; then
apt -y install lxd
lxd init --auto
echo "root:$user_id:1" | sudo tee -a /etc/subuid
echo "root:$user_gid:1" | sudo tee -a /etc/subgid
fi
for osdef in "${oslist[@]}"; do
osname=${osdef%%=*}
osversions=$(echo ${osdef##*=} | tr "," "\n")
for osver in $osversions; do
containername="hst-${osname}-${osver/\./}"
container_ip=""
echo "Container $containername"
if [ "$cmd" = '--cleanup' ]; then
# Stop and delete container
lxc stop $containername
lxc rm $containername
continue
fi
if ! lxc info $containername > /dev/null 2>&1; then
setup_container
fi
lxc start $containername > /dev/null 2>&1
# Wait for container to start
while [ -z "$container_ip" ]; do
sleep 1
container_ip=$(lxc list --format csv -c 4,n |grep ",$containername$"| cut -d "," -f 1)
done
echo $container_ip
cp -f "${__DIR__}/lxd_compile.sh" "${__DIR__}/build/${containername}/lxd_compile.sh"
if [ "$cmd" = '--background' ]; then
# Run build script in background
lxc exec $containername -- /opt/hestiacp/lxd_compile.sh $branch >/dev/null 2>&1 &
else
lxc exec $containername -- /opt/hestiacp/lxd_compile.sh $branch
fi
done
done