misc_lxc-template-generator/run.sh

59 lines
1.2 KiB
Bash
Raw Permalink Normal View History

# could add handling to call teh cleanup on
tmp_files=()
function setup(){
cp /etc/resolv.conf /etc/resolv.conf.bak
}
function cleanup(){
cp /etc/resolv.conf.bak /etc/resolv.conf
# 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
# remove all the tmp tmp_files
for tmp_file in ${tmp_files[@]}; do
rm $tmp_file
done
}
function build () {
local config="$1"
2024-01-24 22:01:39 +00:00
local configs="./configs"
local images="./images"
# file:// cannot have relative paths, so use a bit of subsitution to fix
2024-01-24 22:01:39 +00:00
if grep -q SKYNET_ROOT_DIR "$configs/$config.yaml"; then
# create a copy with the file
2024-01-24 22:01:39 +00:00
cp "$configs/$config.yaml" "$configs/$config.tmp"
# sed normally uses / but that conflcts with file paths so use @ instead
2024-01-24 22:01:39 +00:00
sed -i "s@SKYNET_ROOT_DIR@$PWD@g" "$configs/$config.tmp"
# add to tmp tmp_files
2024-01-24 22:01:39 +00:00
tmp_files+=("$configs/$config.tmp")
# normal command
2024-01-24 22:01:39 +00:00
distrobuilder build-lxc "$configs/$config.tmp" "$images/$config"
else
2024-01-24 22:01:39 +00:00
distrobuilder build-lxc "$configs/$config.yaml" "$images/$config"
fi
}
function main(){
setup
2024-01-24 22:01:39 +00:00
build base
build base_trainee
2024-01-24 22:47:46 +00:00
build games_wing
cleanup
}
main