#!/bin/bash # usage: ./mocha-carafe new BASE if [ "$1" == "new" ]; then if [ "$USER" != "root" ]; then echo "must be run as root" exit 2 fi BASE=$2 BASEPATH=images/$BASE/$BASE FLAVOR=noble if [ ! -d "images" ]; then mkdir "images" fi if [ ! -d "images/$BASE" ]; then mkdir "images/$BASE" fi container-provisioner/provision.sh $FLAVOR $BASEPATH if [ ! -d "$BASEPATH/usr/lib/mocha/carafe" ]; then mkdir -p "$BASEPATH/usr/lib/mocha/carafe" fi if [ ! -d "$BASEPATH/usr/share/mocha/system" ]; then mkdir -p "$BASEPATH/usr/share/mocha/system" fi cp -r libexec/mocha/carafe $BASEPATH/usr/lib/mocha cp -r fs/* $BASEPATH/ if [ ! -d "$BASEPATH/usr/lib/mocha/oms" ]; then mkdir -p $BASEPATH/usr/lib/mocha/oms fi ./copy-oms $BASEPATH/usr/lib/mocha/oms cp ./mocha-common/mocha-common/output/*.mcl $BASEPATH/usr/share/mocha/system if [ ! -d "$BASEPATH/var/mocha/uploads" ]; then mkdir -p "$BASEPATH/var/mocha/uploads" fi cp ./mocha-php/mocha-php/src/mocha-php/images/logo.svg $BASEPATH/var/mocha/uploads/c4f31b1aaede4e919fa0511537f098a5.svg chroot $BASEPATH /usr/lib/mocha/carafe/preinstall.sh if [ $? -ne 0 ]; then echo "preinstall failed, try running 'chroot \$BASEPATH /usr/lib/mocha/carafe/preinstall.sh' again" exit 2 fi echo "Listen 443" > $BASEPATH/etc/apache2/ports.conf cp site.conf $BASEPATH/etc/apache2/sites-available/000-default.conf cp certs/localhost.crt certs/localhost.key $BASEPATH/etc/ssl/certs cp -r mocha-php/mocha-php/src/mocha-php/* $BASEPATH/var/www/html cp mocha-php/mocha-php/src/mocha-php/.htaccess $BASEPATH/var/www/html rm -rf $BASEPATH/var/www/html/lib/phast cp -r mocha-php/phast/lib/phast/server $BASEPATH/var/www/html/lib/phast # mocha etc if [ ! -d $BASEPATH/etc/mocha/include ]; then mkdir -p $BASEPATH/etc/mocha/include fi cp mocha-php/mocha-php/src/mocha-php/include/Configuration.inc.php.template $BASEPATH/etc/mocha/include/Configuration.inc.php.template # mocha libexec if [ ! -d $BASEPATH/usr/lib/mocha ]; then mkdir -p $BASEPATH/usr/lib/mocha fi cp libexec/mocha/mocha-* $BASEPATH/usr/lib/mocha 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/bin/mocha if [ -d $BASEPATH/var/www/html/index.html ]; then rm $BASEPATH/var/www/html/index.html fi # ! 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 container-provisioner/build.sh "ubuntu" "noble" "x86_64" "Ubuntu Noble with Apache2 and PHP" $BASE $BASEPATH SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom) CONTAINER_NAME=i-0$SUV_ID lxc init $BASE $CONTAINER_NAME echo "Instance name is: $CONTAINER_NAME" lxc start $CONTAINER_NAME lxc shell $CONTAINER_NAME -- bash -c "echo \"$CONTAINER_NAME\" > /etc/mocha/container" sleep 5 CONTAINER_IP=$(lxc exec $CONTAINER_NAME ip addr | grep 'scope global' | sed -e 's/ inet6 //' -e 's/\/64 scope global dynamic mngtmpaddr//') lxc shell $CONTAINER_NAME mocha up SUV_DOMAINNAME=".privatesuv.com" echo "enter sudo password to add entry to /etc/hosts if desired" echo "$CONTAINER_IP $CONTAINER_NAME$SUV_DOMAINNAME" | sudo tee -a /etc/hosts elif [ "$1" == "list" ]; then lxc list elif [ "$1" == "up" ]; then lxc start "$2" elif [ "$1" == "shell" ]; then lxc shell "$2" elif [ "$1" == "reset" ]; then BASE="$2" echo "deleting compiled files..." rm images/$BASE/*.gz echo "removing the image..." lxc image delete $BASE elif [ "$1" == "destroy" ]; then ./carafe reset $2 rm -rf images/$2 # elif [ "$1" == "build" ]; then # # else echo "usage: mocha carafe new BASE" fi