5 # This script is meant to ease generation of a pnd file. Please consult the output
6 # when running --help for a list of available parameters and an explaination of
9 # Required tools when running the script:
12 # mkisofs or mksquashfs (the latter when using the -c param!)
13 # xmllint (optional, only for validation of the PXML against the schema)
16 PXML_schema=$(dirname ${0})/PXML_schema.xsd
17 GENPXML_PATH=$(dirname ${0})/genpxml.sh
19 # useful functions ...
34 cecho "ERROR: Could not find the program '$1'. Please make sure
35 that it is available in your PATH since it is required to complete your request." $red
40 cecho () # Color-echo. Argument $1 = message, Argument $2 = color
42 local default_msg="No message passed." # Doesn't really need to be a local variable.
43 message=${1:-$default_msg} # Defaults to default message.
44 color=${2:-$black} # Defaults to black, if not specified.
45 echo -e "$color$message"
46 tput sgr0 # Reset to normal.
54 pnd_make.sh - A script to package "something" into a PND.
57 $(basename ${0}) {--directory|-d} <folder> {--pndname|-p} <file> [{--compress-squashfs|-c}]
58 [{--genpxml} <file>] [{--icon|-i} <file>] [{--pxml|-x} <file>]
59 [{--schema|-s} <file>] [{--help|-h}]
63 --compress-squashfs / -c Define whether or not the pnd should be compressed using
64 squashfs. If this parameter is selected, a compressed pnd
67 --compress-squashfs-xz Define whether or not the pnd should be compressed using
68 / -cx squashfs with xz compression. Note that older firmwares
69 will be unable to start such .pnd files.
71 --directory / -d Sets the folder that is to be used for the resulting pnd
72 to <folder>. This option is mandatory for the script to
75 --genpxml Sets the script used for generating a PXML file (if none
76 is available already) to <file>. Please make sure to either
77 provide a full path or prefix a script in the current folder
78 with './' so that the script can actually be executed. If
79 this variable is not specified, $GENPXML_PATH
82 --help / -h Displays this help text.
84 --icon / -i Sets the icon that will be appended in the pnd to <file>.
86 --pndname / -p Sets the output filename of the resulting pnd to <file>.
87 This option is mandatory for the script to function
90 --pxml / -x Sets the PXML file that is to be used to <file>. If you
91 neither provide a PXML file or set this entry to 'guess',
92 an existing 'PXML.xml' in your selected '--directory'
93 will be used, or the script $GENPXML_PATH
94 will be called to try to generate a basic PXML file for you.
96 --schema / -s Sets the schema file, that is to be used for validation,
97 to <file. If this is not defined, the script will try to
98 use the file '$PXML_schema'. If this fails,
101 If you select the option to create a compressed squashfs, a version >=4.0 of squashfs
102 is required to be available in your PATH.
107 # Parse command line parameters
108 while [ "${1}" != "" ]; do
109 if [ "${1}" = "--compress-squashfs" ] || [ "${1}" = "-c" ];
113 elif [ "${1}" = "--compress-squashfs-xz" ] || [ "${1}" = "-cx" ];
118 elif [ "${1}" = "--directory" ] || [ "${1}" = "-d" ];
122 elif [ "${1}" = "--genpxml" ];
126 elif [ "${1}" = "--help" ] || [ "${1}" = "-h" ];
130 elif [ "${1}" = "--icon" ] || [ "${1}" = "-i" ];
134 elif [ "${1}" = "--pndname" ] || [ "${1}" = "-p" ];
138 elif [ "${1}" = "--pxml" ] || [ "${1}" = "-x" ];
142 elif [ "${1}" = "--schema" ] || [ "${1}" = "-s" ]
147 cecho "ERROR: '$1' is not a known argument. Printing --help and aborting." $red
154 # Generate a PXML if the param is set to Guess or it is empty.
155 if [ ! $PXML ] || [ $PXML = "guess" ] && [ $PNDNAME ] && [ $FOLDER ];
157 if [ -f $FOLDER/PXML.xml ]; # use the already existing PXML.xml file if there is one...
159 PXML=$FOLDER/PXML.xml
160 PXML_ALREADY_EXISTING="true"
162 if [ -f $GENPXML_PATH ];
164 $GENPXML_PATH --src $FOLDER --dest $FOLDER --author $USER
165 if [ -f $FOLDER/PXML.xml ];
167 PXML_GENERATED="true"
169 cecho "ERROR: Generating a PXML file using '$GENPXML_PATH' failed.
170 Please generate a PXML file manually." $red
174 cecho "ERROR: Could not find '$GENPXML_PATH' for generating a PXML file." $red
181 # Probe if required variables were set
183 cecho "Checking if all required variables were set." $green
184 if [ ! $PNDNAME ] || [ ! $FOLDER ] || [ ! $PXML ];
187 cecho "ERROR: Not all required options were set! Please see the --help information below." $red
192 echo "PNDNAME set to '$PNDNAME'."
194 # Check if the selected folder actually exists
198 cecho "ERROR: '$FOLDER' doesn't exist or is not a folder." $red
201 echo "FOLDER set to '$FOLDER'."
203 # Check if the selected PXML file actually exists
207 cecho "ERROR: '$PXML' doesn't exist or is not a file." $red
210 if [ $PXML_ALREADY_EXISTING ];
212 echo "You have not explicitly specified a PXML to use, but an existing file was
213 found. Will be using this one."
214 elif [ $PXML_GENERATED ];
216 echo "A PXML file was generated for you using '$GENPXML_PATH'. This file will
217 not be removed at the end of this script because you might want to review it, adjust
218 single entries and rerun the script to generate a pnd with a PXML file with all the
219 information you want to have listed."
221 echo "PXML set to '$PXML'."
224 # Print the other variables:
229 cecho "WARNING: '$ICON' doesn't exist, will not append the selected icon to the pnd." $red
231 echo "ICON set to '$ICON'."
237 echo "Will use a squashfs for '$PNDNAME'."
241 # Validate the PXML file (if xmllint is available)
242 # Errors and problems in this section will be shown but are not fatal.
244 cecho "Trying to validate '$PXML' now. Will be using '$PXML_schema' to do so." $green
245 which xmllint &> /dev/null
249 cecho "WARNING: Could not find 'xmllint'. Validity check of '$PXML' is not possible!" $red
251 if [ ! -f "$PXML_schema" ];
254 cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your
255 PXML file please make sure to provide a schema using the --schema option." $red
257 xmllint --noout --schema $PXML_schema $PXML
258 if [ "$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
261 # Print some message at the end about the validation in case the user missed the output above
262 if [ $VALIDATED = "false" ]
264 cecho "WARNING: Could not successfully validate '$PXML'. Please check the output
265 above. This does not mean that your pnd will be broken. Either you are not following the strict
266 syntax required for validation or you don't have all files/programs required for validating." $red
268 cecho "Your file '$PXML' was validated successfully. The resulting pnd should
269 work nicely with libpnd." $green
273 # Make iso from folder
275 cecho "Creating an iso file based on '$FOLDER'." $green
278 check_for_tool mksquashfs
279 if [ $(mksquashfs -version | awk 'BEGIN{r=0} $3>=4{r=1} END{print r}') -eq 0 ];
281 cecho "ERROR: Your squashfs version is older then version 4, please upgrade to 4.0 or later" $red
286 mksquashfs $FOLDER $PNDNAME.iso -all-root -force-gid 0 -comp xz -Xbcj arm,armthumb
288 mksquashfs $FOLDER $PNDNAME.iso -all-root -force-gid 0
291 check_for_tool mkisofs
292 mkisofs -o $PNDNAME.iso -R $FOLDER
295 # Check that the iso file was actually created before continuing
296 if [ ! -f $PNDNAME.iso ];
298 cecho "ERROR: The temporary file '$PNDNAME.iso' could not be created.
299 Please check the output above for any errors and retry after fixing them. Aborting." $red
306 cecho "Appending '$PXML' to the created iso file." $green
307 cat $PNDNAME.iso $PXML > $PNDNAME
308 rm $PNDNAME.iso #cleanup
311 # Append icon if specified and available
315 cecho "Appending the icon '$ICON' to the pnd." $green
316 mv $PNDNAME $PNDNAME.tmp
317 cat $PNDNAME.tmp $ICON > $PNDNAME # append icon
318 rm $PNDNAME.tmp #cleanup
326 cecho "Successfully finished creating the pnd '$PNDNAME'." $green
328 cecho "There seems to have been a problem and '$PNDNAME' was not created. Please check
329 the output above for any error messages. A possible cause for this is that there was
330 not enough space available." $red
335 #if [ $PXML = "guess" ];then rm $FOLDER/PXML.xml; fi #cleanup