Here is my attempt to create an org babel script which in turn generates a shell script which creates a jail with apache running in it:-
All comments, especially anything which shows how to improve this, are welcomed.
I should mention that this is for creating IOCAGE jails and assumes you have IOCAGE installed.
Code:
#+begin_src shell :var JAIL="apache" :var pkgs='("apache24" "mod_php84") :tangle create-apache-jail.sh :shebang "#!/usr/bin/env sh" :results none
JAIL="$JAIL"
BASE="/zroot/iocage/jails/${JAIL}/root/usr/local"
# Create package list
cat <<EOF > ${JAIL}.json
{
"pkgs": [
$(for pkg in $pkgs; do echo " \"$pkg\","; done | sed '$s/,$//')
]
}
EOF
# Create and start the jail
iocage create -r latest -p ./${JAIL}.json -n ${JAIL} vnet=on dhcp=on
iocage start ${JAIL}
# Configure PHP for Apache
cat <<EOF > ${BASE}/etc/apache24/modules.d/001_php.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
EOF
# Create test PHP file
echo '<?php phpinfo(); ?>' > ${BASE}/www/apache24/data/index.php
# Enable and start Apache
iocage exec ${JAIL} sysrc apache24_enable=YES
iocage exec ${JAIL} service apache24 start
#+end_src
All comments, especially anything which shows how to improve this, are welcomed.
I should mention that this is for creating IOCAGE jails and assumes you have IOCAGE installed.