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 --directory / -d Sets the folder that is to be used for the resulting pnd
68 to <folder>. This option is mandatory for the script to
71 --genpxml Sets the script used for generating a PXML file (if none
72 is available already) to <file>. Please make sure to either
73 provide a full path or prefix a script in the current folder
74 with './' so that the script can actually be executed. If
75 this variable is not specified, $GENPXML_PATH
78 --help / -h Displays this help text.
80 --icon / -i Sets the icon that will be appended in the pnd to <file>.
82 --pndname / -p Sets the output filename of the resulting pnd to <file>.
83 This option is mandatory for the script to function
86 --pxml / -x Sets the PXML file that is to be used to <file>. If you
87 neither provide a PXML file or set this entry to 'guess',
88 an existing 'PXML.xml' in your selected '--directory'
89 will be used, or the script $GENPXML_PATH
90 will be called to try to generate a basic PXML file for you.
92 --schema / -s Sets the schema file, that is to be used for validation,
93 to <file. If this is not defined, the script will try to
94 use the file '$PXML_schema'. If this fails,
97 If you select the option to create a compressed squashfs, a version >=4.0 of squashfs
98 is required to be available in your PATH.
103 # Parse command line parameters
104 while [ "${1}" != "" ]; do
105 if [ "${1}" = "--compress-squashfs" ] || [ "${1}" = "-c" ];
109 elif [ "${1}" = "--directory" ] || [ "${1}" = "-d" ];
113 elif [ "${1}" = "--genpxml" ];
117 elif [ "${1}" = "--help" ] || [ "${1}" = "-h" ];
121 elif [ "${1}" = "--icon" ] || [ "${1}" = "-i" ];
125 elif [ "${1}" = "--pndname" ] || [ "${1}" = "-p" ];
129 elif [ "${1}" = "--pxml" ] || [ "${1}" = "-x" ];
133 elif [ "${1}" = "--schema" ] || [ "${1}" = "-f" ]
138 cecho "ERROR: '$1' is not a known argument. Printing --help and aborting." $red
145 # Generate a PXML if the param is set to Guess or it is empty.
146 #TODO: make sure this does still work nicely with the latest genpxml that sebt3 is working on!
147 if [ ! $PXML ] || [ $PXML = "guess" ] && [ $PNDNAME ] && [ $FOLDER ];
149 if [ -f $FOLDER/PXML.xml ]; # use the already existing PXML.xml file if there is one...
151 PXML=$FOLDER/PXML.xml
152 PWML_ALREADY_EXISTING="true"
154 if [ -f $GENPXML_PATH ];
156 PXMLtxt=$($GENPXML_PATH $FOLDER $ICON)
159 cecho "ERROR: Generating a PXML file using '$GENPXML_PATH' failed.
160 Please generate a PXML file manually." $red
163 PXML=$FOLDER/PXML.xml
164 echo "$PXMLtxt" > $FOLDER/PXML.xml
165 PXML_GENERATED="true"
168 cecho "ERROR: Could not find '$GENPXML_PATH' for generating a PXML file." $red
175 # Probe if required variables were set
177 cecho "Checking if all required variables were set." $green
178 if [ ! $PNDNAME ] || [ ! $FOLDER ] || [ ! $PXML ];
181 cecho "ERROR: Not all required options were set! Please see the --help information below." $red
186 echo "PNDNAME set to '$PNDNAME'."
188 # Check if the selected folder actually exists
192 cecho "ERROR: '$FOLDER' doesn't exist or is not a folder." $red
195 echo "FOLDER set to '$FOLDER'."
197 # Check if the selected PXML file actually exists
201 cecho "ERROR: '$PXML' doesn't exist or is not a file." $red
204 if [ $PWML_ALREADY_EXISTING ];
206 echo "You have not explicitly specified a PXML to use, but an existing file was
207 found. Will be using this one."
208 elif [ $PXML_GENERATED ];
210 echo "A PXML file was generated for you using '$GENPXML_PATH'. This file will
211 not be removed at the end of this script because you might want to review it, adjust
212 single entries and rerun the script to generate a pnd with a PXML file with all the
213 information you want to have listed."
215 echo "PXML set to '$PXML'."
218 # Print the other variables:
223 cecho "WARNING: '$ICON' doesn't exist, will not append the selected icon to the pnd." $red
225 echo "ICON set to '$ICON'."
231 echo "Will use a squashfs for '$PNDNAME'."
235 # Validate the PXML file (if xmllint is available)
236 # Errors and problems in this section will be shown but are not fatal.
238 cecho "Trying to validate '$PXML' now. Will be using '$PXML_schema' to do so." $green
239 which xmllint &> /dev/null
243 cecho "WARNING: Could not find 'xmllint'. Validity check of '$PXML' is not possible!" $red
245 if [ ! -f "$PXML_schema" ];
248 cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your
249 PXML file please make sure to provide a schema using the --schema option." $red
251 xmllint --noout --schema $PXML_schema $PXML
252 if [ "$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
255 # Print some message at the end about the validation in case the user missed the output above
256 if [ $VALIDATED = "false" ]
258 cecho "WARNING: Could not successfully validate '$PXML'. Please check the output
259 above. This does not mean that your pnd will be broken. Either you are not following the strict
260 syntax required for validation or you don't have all files/programs required for validating." $red
262 cecho "Your file '$PXML' was validated successfully. The resulting pnd should
263 work nicely with libpnd." $green
267 # Make iso from folder
269 cecho "Creating an iso file based on '$FOLDER'." $green
272 check_for_tool mksquashfs
273 if [ $(mksquashfs -version | awk 'BEGIN{r=0} $3>=4{r=1} END{print r}') -eq 0 ];
275 cecho "ERROR: Your squashfs version is older then version 4, please upgrade to 4.0 or later" $red
278 mksquashfs $FOLDER $PNDNAME.iso -nopad -no-recovery
280 check_for_tool mkisofs
281 mkisofs -o $PNDNAME.iso -R $FOLDER
284 # Check that the iso file was actually created before continuing
285 if [ ! -f $PNDNAME.iso ];
287 cecho "ERROR: The temporary file '$PNDNAME.iso' could not be created.
288 Please check the output above for any errors and retry after fixing them. Aborting." $red
295 cecho "Appending '$PXML' to the created iso file." $green
296 cat $PNDNAME.iso $PXML > $PNDNAME
297 rm $PNDNAME.iso #cleanup
300 # Append icon if specified and available
304 cecho "Appending the icon '$ICON' to the pnd." $green
305 mv $PNDNAME $PNDNAME.tmp
306 cat $PNDNAME.tmp $ICON > $PNDNAME # append icon
307 rm $PNDNAME.tmp #cleanup
315 cecho "Successfully finished creating the pnd '$PNDNAME'." $green
317 cecho "There seems to have been a problem and '$PNDNAME' was not created. Please check
318 the output above for any error messages. A possible cause for this is that there was
319 not enough space available." $red
324 #if [ $PXML = "guess" ];then rm $FOLDER/PXML.xml; fi #cleanup