2024-01-24 20:30:04 +00:00
|
|
|
# could add handling to call teh cleanup on
|
|
|
|
|
|
|
|
tmp_files=()
|
2024-01-24 16:56:57 +00:00
|
|
|
|
2024-01-24 18:05:04 +00:00
|
|
|
function setup(){
|
|
|
|
cp /etc/resolv.conf /etc/resolv.conf.bak
|
|
|
|
}
|
2024-01-24 16:56:57 +00:00
|
|
|
|
2024-01-24 18:05:04 +00:00
|
|
|
function cleanup(){
|
|
|
|
cp /etc/resolv.conf.bak /etc/resolv.conf
|
2024-01-24 16:56:57 +00:00
|
|
|
|
2024-01-24 18:05:04 +00:00
|
|
|
# reset permissions of output folder to the owner
|
|
|
|
local owner=$(ls -ld $PWD | awk '{print $3}')
|
|
|
|
local group=$(ls -ld $PWD | awk '{print $4}')
|
|
|
|
chown -R "$owner:$group" ./images
|
2024-01-24 20:30:04 +00:00
|
|
|
|
|
|
|
# remove all the tmp tmp_files
|
|
|
|
for tmp_file in ${tmp_files[@]}; do
|
|
|
|
rm $tmp_file
|
|
|
|
done
|
2024-01-24 18:05:04 +00:00
|
|
|
}
|
2024-01-24 16:56:57 +00:00
|
|
|
|
2024-01-24 18:05:04 +00:00
|
|
|
|
|
|
|
function build () {
|
|
|
|
local config="$1"
|
|
|
|
local location="$2"
|
|
|
|
|
|
|
|
# file:// cannot have relative paths, so use a bit of subsitution to fix
|
|
|
|
if grep -q SKYNET_ROOT_DIR "$config"; then
|
|
|
|
|
|
|
|
# create a copy with the file
|
|
|
|
cp "$config" "$config.tmp"
|
|
|
|
# sed normally uses / but that conflcts with file paths so use @ instead
|
|
|
|
sed -i "s@SKYNET_ROOT_DIR@$PWD@g" "$config.tmp"
|
|
|
|
|
2024-01-24 20:30:04 +00:00
|
|
|
# add to tmp tmp_files
|
|
|
|
tmp_files+=("$config.tmp")
|
|
|
|
|
2024-01-24 18:05:04 +00:00
|
|
|
# normal command
|
|
|
|
distrobuilder build-lxc "$config.tmp" $location
|
|
|
|
else
|
|
|
|
distrobuilder build-lxc $config $location
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(){
|
|
|
|
setup
|
|
|
|
|
2024-01-24 21:08:03 +00:00
|
|
|
build ./configs/base.yaml ./images/base
|
|
|
|
build ./configs/base_trainee.yaml ./images/base_trainee
|
2024-01-24 18:05:04 +00:00
|
|
|
|
|
|
|
cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main
|