misc_lxc-template-generator/run.sh

57 lines
1.2 KiB
Bash
Raw 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"
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"
# add to tmp tmp_files
tmp_files+=("$config.tmp")
# normal command
distrobuilder build-lxc "$config.tmp" $location
else
distrobuilder build-lxc $config $location
fi
}
function main(){
setup
build ./configs/base.yaml ./images/base
build ./configs/base_trainee.yaml ./images/base_trainee
cleanup
}
main