Shell Can someone test my attempt to get org babel working?

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:-
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.
 
shell should be sh
dont use cat

you need a separate code blocks for json, conf and php

var are used when you when you call a noweb block from another block

you are misunderstanding what tangling does
it only writes out the code to a text file

tangling doesnt run code
 
you dont use cat at all
thats what the code blocks are for

with separate code blocks for each language
and each tangled ( written out ) to a text file at a specific location

specified by :tangle

eg

Code:
#+begin_src json

#+end_src

Code:
#+begin_src conf :tangle "/zroot/iocage/jails/apache/root/usr/local/etc/apache24/modules.d/001_php.conf"

#+end_src

Code:
#+begin_src php tangle: "/zroot/iocage/jails/apache/root/usr/local/www/apache24/data/index.php"

#+end_src

tangling is only for write the code blocks to a text file
thats it, it doesnt run code its not a shell script

you need to read the manual so you understand org babel code blocks
and what tangling then does
 
Back
Top