Script to create an extension place holder

Hey guys!

If you ever wanted to create an extension for a FreeNAS and never wanted to be bothered with all the linking and correct extensions folder structure, then here's a script that will do all that for your automatically on the background.

Most of you will find this script rather useless since there are a lot of users who run an embedded version of a FreeNAS and/or don't have a large enough system partition. If you can use it, I'm glad and I hope that it'll be useful!

Script has 2 modes:
1) Create an empty extension:
Script will create a place holder for your extension. Extension then visible by FreeNAS's UI. All that you have to do then is write your extension code.

2) Create an extension from previously written code.
If you have already written your extension code and just want to "plug it in" to FreeNAS's extension UI, you can point to your code file and your extension is created and is ready to use immediately.

Script usage:
create_extensions help will display help menu
create_extensions extName will create an extension called extName
create_extensions extName scriptFile will create an extension called extName with contents of scriptFile in it

Once you dowload this script, make sure that your allow execution for it by setting right permissions or by typing sh in front of a script name.

Here's the script (you can also download it from here:)

# This script is going to create the placeholder for the extension that one
# is about to start writing. In other words, this script will create the
# following folder structure:
# /usr/local/www/ext
# | - extension name
# | | -
# | | - extension name.php
# After folder structure is created, extension is going to link everything

# make sure that there was at least 1 input argument
if [ $# -lt 1 ] ; then
echo 'There has to be at least 1 parameter'
exit 1

if [ $1 = help ] ; then
echo 'Usage help:'
echo 'sh create_extension name <= Creates an empty extension named "name"'
echo 'sh create_extension name sourceCodeFile <= Creates an extension and populates it with predefined source code'
exit 1

if [ ! -f $2 ] ; then
echo 'Second parameter MUST be a text file!'
exit 1


# Make sure that web folder exits
if [ ! -d $webFolder ] ; then
echo Web folder does not exist!
echo Please make sure that you have specified correct path
exit 1

# make sure that there is no folder present with the same
# name as this extension
if [ -d $extFolder/$extName ] ; then
echo An extension with name \'$extName\' already exists.
echo Please choose a different name for your extension.
exit 1

# Create extension folder
echo Creating folder: $extFolder/$extName
mkdir -p $extFolder/$extName

# create a file
echo '

<ul><a class="navlink" href="$extName%27.php">'$extName'</a></ul>
' >> $extFolder/$extName/

if [ $# -eq 2 ] ; then
cp $2 $extFile
# create a dummy extension file
echo ' $extFile
echo >> $extFile
echo 'require("");' >> $extFile
echo 'require("");' >> $extFile
echo '$pgtitle = array(gettext("Extensions"),gettext("'$extName'"));' >> $extFile
echo >> $extFile
echo 'include("");' >> $extFile
echo '?>' >> $extFile
echo 'Paste contents of your extension script into <b>'$extFile'</b> and refresh this page' >> $extFile
echo >> $extFile
echo '' >> $extFile

# link your extension.php file to the web folder
ln -s $extFile $webFolder
echo 'Extension has been created!'
echo Please navigate to Extensions "|" $extName to see your extension page