misc_lxc-template-generator/run.sh

58 lines
1.2 KiB
Bash
Executable file

# 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"
local configs="./configs"
local images="./images"
# file:// cannot have relative paths, so use a bit of subsitution to fix
if grep -q SKYNET_ROOT_DIR "$configs/$config.yaml"; then
# create a copy with the file
cp "$configs/$config.yaml" "$configs/$config.tmp"
# sed normally uses / but that conflcts with file paths so use @ instead
sed -i "s@SKYNET_ROOT_DIR@$PWD@g" "$configs/$config.tmp"
# add to tmp tmp_files
tmp_files+=("$configs/$config.tmp")
# normal command
distrobuilder build-lxc "$configs/$config.tmp" "$images/$config"
else
distrobuilder build-lxc "$configs/$config.yaml" "$images/$config"
fi
}
function main(){
setup
build base
build base_trainee
build games_wing
cleanup
}
main