50 lines
1 KiB
Bash
Executable file
50 lines
1 KiB
Bash
Executable file
# nix-shell -p lxc debootstrap distrobuilder
|
|
|
|
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
|
|
}
|
|
|
|
|
|
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"
|
|
|
|
# normal command
|
|
distrobuilder build-lxc "$config.tmp" $location
|
|
|
|
# cleanup
|
|
rm "$config.tmp"
|
|
else
|
|
distrobuilder build-lxc $config $location
|
|
fi
|
|
}
|
|
|
|
function main(){
|
|
setup
|
|
|
|
build base.yaml ./images/base
|
|
build base_trainee.yaml ./images/base_trainee
|
|
|
|
cleanup
|
|
}
|
|
|
|
|
|
main
|