3 ######adjust path of genpxml.sh if you want to use that "feture"#####
5 PXML_schema="PXML_schema.xsd"
6 GENPXML_PATH="genpxml.sh"
19 cecho () # Color-echo. Argument $1 = message, Argument $2 = color
21 local default_msg="No message passed." # Doesn't really need to be a local variable.
22 message=${1:-$default_msg} # Defaults to default message.
23 color=${2:-$black} # Defaults to black, if not specified.
24 echo -e "$color$message"
25 tput sgr0 # Reset to normal.
33 pnd_make.sh - A script to package "something" into a PND.
36 $(basename ${0}) {--directory|-d} <folder> {--pndname|-p} <file> [{--compress-squashfs|-c}]
37 [{--genpxml} <file>] [{--icon|-i} <file>] [{--pxml|-x} <file>]
38 [{--schema|-s} <file>] [{--help|-h}]
42 --compress-squashfs / -c Define wether or not the pnd should be compressed using
43 squashfs. If this parameter is selected, a compressed pnd
46 --directory / -d Sets the folder that is to be used for the resulting pnd
47 to <folder>. This option is mandatory for the script to
52 --help / -h Displays this help text.
54 --icon / -i Sets the icon that will be appended in the pnd to <file>.
56 --pndname / -p Sets the output filename of the resulting pnd to <file>.
57 This option is mandatory for the script to function
60 --pxml / -x Sets the PXML file that is to be used to <file>. If you
61 neither provide a PXML file or set this entry to 'guess',
62 an existing 'PXML.xml' in your selected '--directory'
63 will be used, or the script $GENPXML_PATH will be called
64 to try to generate a basic PXML file for your.
66 --schema / -s Sets the schema file, that is to be used for validation,
67 to <file. If this is not defined, the script will try to
68 use the file 'PXML_schema.xsd'. If this fails, a warning
71 If you select the option to create a compressed squashfs, a version >=4.0 of squashfs
72 is required to be available in your PATH.
77 # Parse command line parameters
78 while [ "${1}" != "" ]; do
79 if [ "${1}" = "--compress-squashfs" ] || [ "${1}" = "-c" ];
83 elif [ "${1}" = "--directory" ] || [ "${1}" = "-d" ];
87 elif [ "${1}" = "--genpxml" ];
91 elif [ "${1}" = "--help" ] || [ "${1}" = "-h" ];
95 elif [ "${1}" = "--icon" ] || [ "${1}" = "-i" ];
99 elif [ "${1}" = "--pndname" ] || [ "${1}" = "-p" ];
103 elif [ "${1}" = "--pxml" ] || [ "${1}" = "-x" ];
107 elif [ "${1}" = "--schema" ] || [ "${1}" = "-f" ]
112 cecho "ERROR: '$1' is not a known argument. Printing --help and aborting." $red
119 # Generate a PXML if the param is set to Guess or it is empty.
120 #TODO: make sure this does still work nicely with the latest genpxml that sebt3 is working on!
121 if [ ! $PXML ] || [ $PXML = "guess" ] && [ $PNDNAME ] && [ $FOLDER ];
123 if [ -f $FOLDER/PXML.xml ]; # use the already existing PXML.xml file if there is one...
125 PXML=$FOLDER/PXML.xml
126 PWML_ALREADY_EXISTING="true"
128 PXMLtxt=$($GENPXML_PATH $FOLDER $ICON)
129 PXML=$FOLDER/PXML.xml
130 echo "$PXMLtxt" > $FOLDER/PXML.xml
131 PXML_GENERATED="true"
136 # Probe if required variables were set
138 cecho "Checking if all required variables were set." $green
139 if [ ! $PNDNAME ] || [ ! $FOLDER ] || [ ! $PXML ];
142 cecho "ERROR: Not all required options were set! Please see the --help information below." $red
147 echo "PNDNAME set to '$PNDNAME'."
149 # Check if the selected folder actually exists
153 cecho "ERROR: '$FOLDER' doesnt exist or is not a folder." $red
156 echo "FOLDER set to '$FOLDER'."
158 # Check if the selected PXML file actually exists
162 cecho "ERROR: '$PXML' doesnt exist or is not a file." $red
165 if [ $PWML_ALREADY_EXISTING ];
167 echo "You have not explicitly specified a PXML to use, but an existing file was
168 fount. Will be using this one."
169 elif [ $PXML_GENERATED ];
171 echo "A PXML file was generated for you using '$GENPXML_PATH'. This file will
172 not be removed at the end of this script because you might want to review it, adjust
173 single entries and rerun the script to generate a pnd with a PXML file with all the
174 information you want to have listed."
176 echo "PXML set to '$PXML'."
179 # Print the other variables:
184 cecho "'$ICON' doesn't exist, will not append the selected icon to the pnd." $red
186 echo "ICON set to '$ICON'."
192 echo "Will use a squashfs for '$PNDNAME'."
196 # Validate the PXML file (if xmllint is available)
197 # Errors and problems in this section will be shown but are not fatal.
199 cecho "Trying to validate '$PXML' now. Will be using '$PXML_schema' to do so." $green
200 which xmllint &> /dev/null
204 cecho "WARNING: Could not find 'xmllint'. Validity check of '$PXML' is not possible!" $red
206 if [ ! -f "$PXML_schema" ];
209 cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your PXML file
210 please make sure to provide a schema using the --schema option." $red
212 xmllint --noout --schema $PXML_schema $PXML
213 if [ "$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
216 # Print some message at the end about the validation in case the user missed the output above
217 if [ $VALIDATED = "false" ]
219 cecho "WARNING: Could not successfully validate '$PXML'. Please check the output
220 above. This does not mean that your pnd will be broken. Either you are not following the strict
221 syntax required for validation or you don't have all files/programs required for validating." $red
223 cecho "Your file '$PXML' was validated successfully. The resulting pnd should
224 work nicely with libpnd." $green
228 # Make iso from folder
230 cecho "Creating an iso file based on '$FOLDER'." $green
233 if [ $(mksquashfs -version | awk 'BEGIN{r=0} $3>=4{r=1} END{print r}') -eq 0 ];
235 cecho "ERROR: Your squashfs version is older then version 4, pleas upgrade to 4.0 or later" $red
238 mksquashfs $FOLDER $PNDNAME.iso -nopad -no-recovery
240 mkisofs -o $PNDNAME.iso -R $FOLDER
246 cecho "Appending '$PXML' to the created iso file." $green
247 cat $PNDNAME.iso $PXML > $PNDNAME
248 rm $PNDNAME.iso #cleanup
251 # Append icon if specified and available
255 cecho "Appending the icon '$ICON' to the pnd." $green
256 mv $PNDNAME $PNDNAME.tmp
257 cat $PNDNAME.tmp $ICON > $PNDNAME # append icon
258 rm $PNDNAME.tmp #cleanup
266 cecho "Finished creating the pnd '$PNDNAME'." $green
268 cecho "There seems to have been a problem and '$PNDNAME' was not created. Please check
269 the output above for any error messages." $red
273 #if [ $PXML = "guess" ];then rm $FOLDER/PXML.xml; fi #cleanup