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}" = "-s" ]
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 if [ ! $PXML ] || [ $PXML = "guess" ] && [ $PNDNAME ] && [ $FOLDER ];
148 if [ -f $FOLDER/PXML.xml ]; # use the already existing PXML.xml file if there is one...
150 PXML=$FOLDER/PXML.xml
151 PXML_ALREADY_EXISTING="true"
153 if [ -f $GENPXML_PATH ];
155 $GENPXML_PATH --src $FOLDER --dest $FOLDER --author $USER
156 if [ -f $FOLDER/PXML.xml ];
158 PXML_GENERATED="true"
160 cecho "ERROR: Generating a PXML file using '$GENPXML_PATH' failed.
161 Please generate a PXML file manually." $red
165 cecho "ERROR: Could not find '$GENPXML_PATH' for generating a PXML file." $red
172 # Probe if required variables were set
174 cecho "Checking if all required variables were set." $green
175 if [ ! $PNDNAME ] || [ ! $FOLDER ] || [ ! $PXML ];
178 cecho "ERROR: Not all required options were set! Please see the --help information below." $red
183 echo "PNDNAME set to '$PNDNAME'."
185 # Check if the selected folder actually exists
189 cecho "ERROR: '$FOLDER' doesn't exist or is not a folder." $red
192 echo "FOLDER set to '$FOLDER'."
194 # Check if the selected PXML file actually exists
198 cecho "ERROR: '$PXML' doesn't exist or is not a file." $red
201 if [ $PXML_ALREADY_EXISTING ];
203 echo "You have not explicitly specified a PXML to use, but an existing file was
204 found. Will be using this one."
205 elif [ $PXML_GENERATED ];
207 echo "A PXML file was generated for you using '$GENPXML_PATH'. This file will
208 not be removed at the end of this script because you might want to review it, adjust
209 single entries and rerun the script to generate a pnd with a PXML file with all the
210 information you want to have listed."
212 echo "PXML set to '$PXML'."
215 # Print the other variables:
220 cecho "WARNING: '$ICON' doesn't exist, will not append the selected icon to the pnd." $red
222 echo "ICON set to '$ICON'."
228 echo "Will use a squashfs for '$PNDNAME'."
232 # Validate the PXML file (if xmllint is available)
233 # Errors and problems in this section will be shown but are not fatal.
235 cecho "Trying to validate '$PXML' now. Will be using '$PXML_schema' to do so." $green
236 which xmllint &> /dev/null
240 cecho "WARNING: Could not find 'xmllint'. Validity check of '$PXML' is not possible!" $red
242 if [ ! -f "$PXML_schema" ];
245 cecho "WARNING: Could not find '$PXML_schema'. If you want to validate your
246 PXML file please make sure to provide a schema using the --schema option." $red
248 xmllint --noout --schema $PXML_schema $PXML
249 if [ "$?" -ne "0" ]; then VALIDATED=false; else VALIDATED=true; fi
252 # Print some message at the end about the validation in case the user missed the output above
253 if [ $VALIDATED = "false" ]
255 cecho "WARNING: Could not successfully validate '$PXML'. Please check the output
256 above. This does not mean that your pnd will be broken. Either you are not following the strict
257 syntax required for validation or you don't have all files/programs required for validating." $red
259 cecho "Your file '$PXML' was validated successfully. The resulting pnd should
260 work nicely with libpnd." $green
264 # Make iso from folder
266 cecho "Creating an iso file based on '$FOLDER'." $green
269 check_for_tool mksquashfs
270 if [ $(mksquashfs -version | awk 'BEGIN{r=0} $3>=4{r=1} END{print r}') -eq 0 ];
272 cecho "ERROR: Your squashfs version is older then version 4, please upgrade to 4.0 or later" $red
275 mksquashfs $FOLDER $PNDNAME.iso # -nopad -no-recovery
277 check_for_tool mkisofs
278 mkisofs -o $PNDNAME.iso -R $FOLDER
281 # Check that the iso file was actually created before continuing
282 if [ ! -f $PNDNAME.iso ];
284 cecho "ERROR: The temporary file '$PNDNAME.iso' could not be created.
285 Please check the output above for any errors and retry after fixing them. Aborting." $red
292 cecho "Appending '$PXML' to the created iso file." $green
293 cat $PNDNAME.iso $PXML > $PNDNAME
294 rm $PNDNAME.iso #cleanup
297 # Append icon if specified and available
301 cecho "Appending the icon '$ICON' to the pnd." $green
302 mv $PNDNAME $PNDNAME.tmp
303 cat $PNDNAME.tmp $ICON > $PNDNAME # append icon
304 rm $PNDNAME.tmp #cleanup
312 cecho "Successfully finished creating the pnd '$PNDNAME'." $green
314 cecho "There seems to have been a problem and '$PNDNAME' was not created. Please check
315 the output above for any error messages. A possible cause for this is that there was
316 not enough space available." $red
321 #if [ $PXML = "guess" ];then rm $FOLDER/PXML.xml; fi #cleanup