refactor container provisioning stuff into separate script

This commit is contained in:
Michael Becker 2024-12-17 00:53:28 -05:00
parent f947bde4c9
commit 5a6cf55420

57
carafe
View File

@ -18,27 +18,13 @@ if [ "$1" == "new" ]; then
if [ ! -d "images/$BASE" ]; then if [ ! -d "images/$BASE" ]; then
mkdir "images/$BASE" mkdir "images/$BASE"
fi fi
if [ ! -d "$BASEPATH" ]; then container-provisioner/provision.sh $FLAVOR $BASEPATH
debootstrap $FLAVOR "$BASEPATH"
fi
if [ ! -d "$BASEPATH" ]; then
echo "base path not found: $BASEPATH"
exit 2
fi
echo "deb http://archive.ubuntu.com/ubuntu noble main universe
deb http://archive.ubuntu.com/ubuntu noble-updates main universe
deb http://archive.ubuntu.com/ubuntu noble-backports main universe
deb http://archive.ubuntu.com/ubuntu noble-security main universe" > $BASEPATH/etc/apt/sources.list
if [ ! -d "$BASEPATH/usr/lib/mocha/carafe" ]; then if [ ! -d "$BASEPATH/usr/lib/mocha/carafe" ]; then
mkdir -p "$BASEPATH/usr/lib/mocha/carafe" mkdir -p "$BASEPATH/usr/lib/mocha/carafe"
fi fi
if [ ! -d "$BASEPATH/usr/share/mocha/system" ]; then if [ ! -d "$BASEPATH/usr/share/mocha/system" ]; then
mkdir -p "$BASEPATH/usr/share/mocha/system" mkdir -p "$BASEPATH/usr/share/mocha/system"
fi fi
@ -87,6 +73,8 @@ deb http://archive.ubuntu.com/ubuntu noble-security main universe" > $BASEPATH/e
fi fi
cp libexec/mocha/mocha-* $BASEPATH/usr/lib/mocha cp libexec/mocha/mocha-* $BASEPATH/usr/lib/mocha
cp libexec/mocha/mocha $BASEPATH/usr/bin cp libexec/mocha/mocha $BASEPATH/usr/bin
cp libexec/mocha/spot_register_for_shutdown $BASEPATH/usr/lib/mocha
chmod a+x $BASEPATH/usr/lib/mocha/* chmod a+x $BASEPATH/usr/lib/mocha/*
chmod a+x $BASEPATH/usr/bin/mocha chmod a+x $BASEPATH/usr/bin/mocha
@ -96,37 +84,8 @@ deb http://archive.ubuntu.com/ubuntu noble-security main universe" > $BASEPATH/e
# ! FIXME: we don't want to run this in chroot, we need to run it in lxc! # ! FIXME: we don't want to run this in chroot, we need to run it in lxc!
chroot $BASEPATH /usr/lib/mocha/carafe/postinstall.sh chroot $BASEPATH /usr/lib/mocha/carafe/postinstall.sh
echo "architecture: \"x86_64\" container-provisioner/build.sh "ubuntu" "noble" "x86_64" "Ubuntu Noble with Apache2 and PHP" $BASE $BASEPATH
creation_date: $(date +%s) # To get current date in Unix time, use \`date +%s\` command
properties:
architecture: \"x86_64\"
description: \"Ubuntu Noble with Apache2 and PHP (20171227)\"
os: \"ubuntu\"
release: \"noble\"" > images/$BASE/metadata.yaml
tar -cvzf images/$BASE/metadata.tar.gz -C images/$BASE metadata.yaml
rm images/$BASE/metadata.yaml
if [ ! -f images/$BASE/$BASE.tar.gz ]; then
tar -cvzf images/$BASE/$BASE.tar.gz -C $BASEPATH .
# rm -rf $BASEPATH
else
echo "$BASE.tar.gz already exists; not overwriting"
fi
EXISTS=$(lxc image list | grep $BASE )
if [ "$EXISTS" == "" ]; then
lxc image import images/$BASE/metadata.tar.gz images/$BASE/$BASE.tar.gz --alias $BASE
else
echo "not importing image; already exists as $BASE"
fi
SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom) SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom)
CONTAINER_NAME=i-0$SUV_ID CONTAINER_NAME=i-0$SUV_ID