updated pnd_make.sh based on comments from the ML and irc:
authorNils Kneuper <crazy-ivanovic@gmx.net>
Tue, 8 Mar 2011 13:41:02 +0000 (14:41 +0100)
committerNils Kneuper <crazy-ivanovic@gmx.net>
Tue, 8 Mar 2011 13:41:02 +0000 (14:41 +0100)
* use genpxml.sh and the schema from the dir in which pnd_make.sh is if
* no param is supplied
* check if a PXML file was actually created during the genpxml step
* add some checks for required programs (iso and squashfs stuff)
* add some more sanity checks including aborts if an error was detected
* add missing help info for the param --genpxml
* add comment at the top of the file mentioning what the file is about
* fix various typos

testdata/scripts/pnd_make.sh

index 15248c2..c645a29 100644 (file)
@@ -1,9 +1,20 @@
 #!/bin/bash
-
-######adjust path of genpxml.sh if you want to use that "feture"#####
-
-PXML_schema="PXML_schema.xsd"
-GENPXML_PATH="genpxml.sh"
+#
+# pnd_make.sh
+#
+# This script is meant to ease generation of a pnd file. Please consult the output
+# when running --help for a list of available parameters and an explaination of
+# those.
+#
+# Required tools when running the script:
+# bash
+# echo, cat, mv, rm
+# mkisofs or mksquashfs (the latter when using the -c param!)
+# xmllint (optional, only for validation of the PXML against the schema)
+
+
+PXML_schema=$(dirname ${0})/PXML_schema.xsd
+GENPXML_PATH=$(dirname ${0})/genpxml.sh
 
 # useful functions ...
 black='\E[30m'
@@ -15,6 +26,16 @@ magenta='\E[35m'
 cyan='\E[36m'
 white='\E[37m'
 
+check_for_tool()
+{
+       which $1 &> /dev/null
+       if [ "$?" -ne "0" ];
+       then
+               cecho "ERROR: Could not find the program '$1'. Please make sure
+that it is available in your PATH since it is required to complete your request." $red
+               exit 1
+       fi
+}
 
 cecho ()       # Color-echo. Argument $1 = message, Argument $2 = color
 {
@@ -39,7 +60,7 @@ Usage:
 
 
 Switches:
-  --compress-squashfs / -c  Define wether or not the pnd should be compressed using
+  --compress-squashfs / -c  Define whether or not the pnd should be compressed using
                             squashfs. If this parameter is selected, a compressed pnd
                             will be created.
 
@@ -47,7 +68,12 @@ Switches:
                             to <folder>. This option is mandatory for the script to
                             function correctly.
 
-  --genpxml                 
+  --genpxml                 Sets the script used for generating a PXML file (if none
+                            is available already) to <file>. Please make sure to either
+                            provide a full path or prefix a script in the current folder
+                            with './' so that the script can actually be executed. If
+                            this variable is not specified, $GENPXML_PATH
+                            will be used.
 
   --help / -h               Displays this help text.
 
@@ -60,13 +86,13 @@ Switches:
   --pxml / -x               Sets the PXML file that is to be used to <file>. If you
                             neither provide a PXML file or set this entry to 'guess',
                             an existing 'PXML.xml' in your selected '--directory'
-                            will be used, or the script $GENPXML_PATH will be called
-                            to try to generate a basic PXML file for your.
+                            will be used, or the script $GENPXML_PATH
+                            will be called to try to generate a basic PXML file for you.
 
   --schema / -s             Sets the schema file, that is to be used for validation,
                             to <file. If this is not defined, the script will try to
-                            use the file 'PXML_schema.xsd'. If this fails, a warning
-                            is issued.
+                            use the file '$PXML_schema'. If this fails,
+                            a warning is issued.
 
 If you select the option to create a compressed squashfs, a version >=4.0 of squashfs
 is required to be available in your PATH.
@@ -111,7 +137,7 @@ while [ "${1}" != "" ]; do
        else
                cecho "ERROR: '$1' is not a known argument. Printing --help and aborting." $red
                print_help
-               exit 1;
+               exit 1
        fi
 done
 
@@ -125,10 +151,23 @@ then
                PXML=$FOLDER/PXML.xml
                PWML_ALREADY_EXISTING="true"
        else
-               PXMLtxt=$($GENPXML_PATH $FOLDER $ICON)
-               PXML=$FOLDER/PXML.xml
-               echo "$PXMLtxt" > $FOLDER/PXML.xml
-               PXML_GENERATED="true"
+               if [ -f $GENPXML_PATH ];
+               then
+                       PXMLtxt=$($GENPXML_PATH $FOLDER $ICON)
+                       if [ -z $PXMLtxt ];
+                       then
+                               cecho "ERROR: Generating a PXML file using '$GENPXML_PATH' failed.
+Please generate a PXML file manually." $red
+                               exit 1
+                       else
+                               PXML=$FOLDER/PXML.xml
+                               echo "$PXMLtxt" > $FOLDER/PXML.xml
+                               PXML_GENERATED="true"
+                       fi
+               else
+                       cecho "ERROR: Could not find '$GENPXML_PATH' for generating a PXML file." $red
+                       exit 1
+               fi
        fi
 fi
 
@@ -150,7 +189,7 @@ fi
 if [ ! -d $FOLDER ];
 then
        echo -e
-       cecho "ERROR: '$FOLDER' doesnt exist or is not a folder." $red
+       cecho "ERROR: '$FOLDER' doesn't exist or is not a folder." $red
        exit 1
 else
        echo "FOLDER set to '$FOLDER'."
@@ -159,13 +198,13 @@ fi
 if [ ! -f $PXML ];
 then
        echo -e
-       cecho "ERROR: '$PXML' doesnt exist or is not a file." $red
+       cecho "ERROR: '$PXML' doesn't exist or is not a file." $red
        exit 1
 else
        if [ $PWML_ALREADY_EXISTING ];
        then
                echo "You have not explicitly specified a PXML to use, but an existing file was
-fount. Will be using this one."
+found. Will be using this one."
        elif [ $PXML_GENERATED ];
        then
                echo "A PXML file was generated for you using '$GENPXML_PATH'. This file will
@@ -181,7 +220,7 @@ if [ $ICON ];
 then
        if [ ! -f $ICON ]
        then
-               cecho "'$ICON' doesn't exist, will not append the selected icon to the pnd." $red
+               cecho "WARNING: '$ICON' doesn't exist, will not append the selected icon to the pnd." $red
        else
                echo "ICON set to '$ICON'."
                USE_ICON="true"
@@ -206,8 +245,8 @@ else
        if [ ! -f "$PXML_schema" ];
        then
                VALIDATED=false
-               cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your PXML file
-please make sure to provide a schema using the --schema option." $red
+               cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your
+PXML file please make sure to provide a schema using the --schema option." $red
        else
                xmllint --noout --schema $PXML_schema $PXML
                if [ "$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
@@ -230,24 +269,34 @@ echo -e
 cecho "Creating an iso file based on '$FOLDER'." $green
 if [ $SQUASH ];
 then
+       check_for_tool mksquashfs
        if [ $(mksquashfs -version | awk 'BEGIN{r=0} $3>=4{r=1} END{print r}') -eq 0 ];
        then
-               cecho "ERROR: Your squashfs version is older then version 4, pleas upgrade to 4.0 or later" $red
+               cecho "ERROR: Your squashfs version is older then version 4, please upgrade to 4.0 or later" $red
                exit 1
        fi
        mksquashfs $FOLDER $PNDNAME.iso -nopad -no-recovery
 else
+       check_for_tool mkisofs
        mkisofs -o $PNDNAME.iso -R $FOLDER
 fi
 
+# Check that the iso file was actually created before continuing
+if [ ! -f $PNDNAME.iso ];
+then
+       cecho "ERROR: The temporary file '$PNDNAME.iso' could not be created.
+Please check the output above for any errors and retry after fixing them. Aborting." $red
+       exit 1
+fi
+
 
 # Append pxml to iso
 echo -e
 cecho "Appending '$PXML' to the created iso file." $green
 cat $PNDNAME.iso $PXML > $PNDNAME
 rm $PNDNAME.iso #cleanup
+
+
 # Append icon if specified and available
 if [ $USE_ICON ];
 then
@@ -263,10 +312,12 @@ fi
 echo -e
 if [ -f $PNDNAME ];
 then
-       cecho "Finished creating the pnd '$PNDNAME'." $green
+       cecho "Successfully finished creating the pnd '$PNDNAME'." $green
 else
        cecho "There seems to have been a problem and '$PNDNAME' was not created. Please check
-the output above for any error messages." $red
+the output above for any error messages. A possible cause for this is that there was
+not enough space available." $red
+       exit 1
 fi