-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-psx-bios-package
executable file
·613 lines (528 loc) · 18 KB
/
make-psx-bios-package
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#!/bin/bash
#
# psx-bios-package - build a Debian package of psx-bios
#
# Copyright © 2014-2016 Frédéric Brière <fbriere@fbriere.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
VERSION=6
# List of all known ROM images. The version information comes from a string
# within the ROM itself (e.g. "System ROM Version 4.1 12/16/97 A"); the letter
# does not necessarily match the actual region where the models were released.
#
# Note that some models have included more than one ROM version over their
# lifetime.
#
# See http://redump.org/datfile/psx-bios/ for more information.
declare -A KNOWN_ROMS=(
# MD5 Hash Version Models
# -------------------------------- ------------------- -----------------------------------------------------------------
# PlayStation (MISSING: DTL-H1001H SCPH-5001 SCPH-5002)
['239665b1a3dade1b5a52c06338011044']="1.0 J 1994-09-22 SCPH-1000 DTL-H1000"
['849515939161e62f6b866f6853006780']="1.1 J 1995-01-22 SCPH-3000 DTL-H1000H"
['dc2b9bf8da62ec93e868cfd29f0d067d']="2.0 A 1995-05-07 DTL-H1001"
['54847e693405ffeb0359c6287434cbef']="2.0 E 1995-05-10 SCPH-1002 DTL-H1002"
['cba733ceeff5aef5c32254f1d617fa62']="2.1 J 1995-07-17 SCPH-3500"
['da27e8b6dab242d8f91a9b25d80c63b8']="2.1 A 1995-07-17 DTL-H1101"
['417b34706319da7cf001e76e40136c23']="2.1 E 1995-07-17 SCPH-1002 DTL-H1102"
['57a06303dfa9cf9351222dfcbb4a29d9']="2.2 J 1995-12-04 SCPH-5000 DTL-H1200 DTL-H3000"
# PlayStation Video CD (SCPH-5903)
# This image is basically a slightly modified 2.2/J (five bytes were
# changed), with another 512 KiB appended, making it 1 MiB in size.
# FIXME: This file will not be picked as it does not match $BIOS_SIZE
['81328b966e6dcf7ea1e32e55e1c104bb']="2.2 J(v) 1995-12-04 SCPH-5903"
['924e392ed05558ffdb115408c263dccf']="2.2 A 1995-12-04 SCPH-1001 SCPH-5003 DTL-H1201 DTL-H3001"
['e2110b8a2b97a8e0b857a45d32f7e187']="2.2 E 1995-12-04 SCPH-1002 DTL-H1202 DTL-H3002"
['ca5cfc321f916756e3f0effbfaeba13b']="2.2 D 1996-03-06 DTL-H1100"
['8dd7d5296a650fac7319bce665a6a53c']="3.0 J 1996-09-09 SCPH-5500"
['490f666e1afb15b7362b406ed1cea246']="3.0 A 1996-11-18 SCPH-5501 SCPH-5503 SCPH-7003"
['32736f17079d0b2b7024407c39bd3050']="3.0 E 1997-01-06 SCPH-5502 SCPH-5552"
['8e4c14f567745eff2f0408c8129f72a6']="4.0 J 1997-08-18 SCPH-7000 SCPH-7500 SCPH-9000"
# [?] Wikpedia lists the SCPH-7500 as 4.1 (1997-12-16)
['1e68c231d0896b7eadcad1d7d8e76129']="4.1 A 1997-12-16 SCPH-7001 SCPH-7501 SCPH-7503 SCPH-9001 SCPH-9003 SCPH-9903"
# 'Midnight Blue' PlayStation (SCPH-7000W)
# This image is identified as 4.1/A, but differs from the other
# 4.1/A models; it is also the only Japanese model (xxx0) to bear
# an "A" version, and is apparently not region-locked.
['b84be139db3ee6cbd075630aa20a6553']="4.1 A(w) 1997-11-14 SCPH-7000W"
['b9d9a0286c33dc6b7237bb13cd46fdee']="4.1 E 1997-12-16 SCPH-7002 SCPH-7502 SCPH-9002"
# [?] Wikipedia lists the SCPH-9003 as 4.2
# PSone (MISSING: SCPH-103)
['8abc1b549a4a80954addc48ef02c4521']="4.3 J 2000-03-11 SCPH-100"
['b10f5e0e3d9eb60e5159690680b1e774']="4.4 E 2000-03-24 SCPH-102"
['6e3735ff4c7dc899ee98981385f6f3d0']="4.5 A 2000-05-25 SCPH-101"
['de93caec13d1a141a40a79f5c86168d6']="4.5 E 2000-05-25 SCPH-102"
# [?] Wikipedia lists the SCPH-103 as 4.6
# PCI cards (MISSING: DTL-H2000 DTL-H2500 DTL-H2700)
#
# Copied from http://www.psxdev.net/forum/viewtopic.php?f=54&t=570
#['2118230527a9f51bd9216e32fa912842']=" ? ? 1994-07-27(?) DTL-H2000"
# Net Yaroze (MISSING: DTL-3000)
)
declare -A CORRUPT_ROMS=(
['eb201d2d98251a598af467d4347bb62f']='57a06303dfa9cf9351222dfcbb4a29d9'
['e56ec1b027e2fe8a49217d9678f7f6bb']='32736f17079d0b2b7024407c39bd3050'
)
BIOS_SIZE=524288
usage() {
cat <<EOF
Usage: $0 [ <options> ... ] { <file> | <directory> | <url> } [...]
Options:
--fullname <name> Full name in Maintainer field [$OPT_FULLNAME]
--email <email> Email address in Maintainer field [$OPT_EMAIL]
--package-append <string> Append to the package name [<bios-version> or "-multi"]
--revision-append <string> Append to the revision number [$OPT_REVISION_APPEND]
--compress-type <type> Compression type of resulting package [$OPT_COMPRESS_TYPE]
--compress-level <level> Compression level of resulting package [${OPT_COMPRESS_LEVEL:-<default>}]
--filename <filename> Filename to be used for the next BIOS image
--list-versions List all known BIOS versions
--list-models List all known models
--force Override safety checks
--help Show this help message
--version Show the version.
EOF
}
list_versions() {
local ROM_LINE VERSION LETTER DATE MODELS
for ROM_LINE in "${KNOWN_ROMS[@]}"; do
read VERSION LETTER DATE MODELS <<< "$ROM_LINE"
echo -e "$VERSION $LETTER \t$DATE\t$MODELS"
done | sort
}
list_models() {
local ROM_LINE VERSION LETTER DATE MODELS
for ROM_LINE in "${KNOWN_ROMS[@]}"; do
read VERSION LETTER DATE MODELS <<< "$ROM_LINE"
for MODEL in $MODELS; do
echo -e "$MODEL\tv$VERSION $LETTER \t$DATE"
done
done | sort
}
# Set default args early on -- they may be displayed in usage()
set_default_args() {
# (This is mostly copied from googleearth-package)
local SYS_MAILNAME="$(cat /etc/mailname 2>/dev/null)"
OPT_FULLNAME="${DEBFULLNAME:-${NAME:-$(getent passwd "$(whoami)" | cut -d ':' -f 5 | cut -d ',' -f 1)}}"
OPT_EMAIL="${DEBEMAIL:-${EMAIL:-$(whoami)@${SYS_MAILNAME:-$(hostname --fqdn)}}}"
OPT_REVISION_APPEND="+local"
# The resulting package will typically be installed right away, so
# there's no need to resort to the much slower xz compression type.
OPT_COMPRESS_TYPE=gzip
OPT_COMPRESS_LEVEL=
}
# Process command-line arguments, setting $OPT_* variables
parse_args() {
# Much easier than messing around with eval set --
declare -a -g OPT_SOURCES OPT_SOURCES_FILENAME
local ARG
while [ $# -gt 0 ]; do
ARG="$1"
shift
case "$ARG" in
--fullname)
OPT_FULLNAME="$1"
shift
;;
--email)
OPT_EMAIL="$1"
shift
;;
--revision-append)
OPT_REVISION_APPEND="$1"
shift
;;
--compress-type)
OPT_COMPRESS_TYPE="$1"
shift
case "$OPT_COMPRESS_TYPE" in
gzip|xz|bzip2|lzma|none) true ;;
*)
echo "Unknown compression type $OPT_COMPRESS_TYPE" >&2
if [ "$OPT_FORCE" = true ]; then
echo "Ignoring as requested by --force" >&2
else
exit 1
fi
;;
esac
;;
--compress-level)
OPT_COMPRESS_LEVEL="$1"
shift
;;
--filename)
OPT_FILENAME="$1"
if [ "$OPT_FILENAME" ]; then
if [ "$OPT_FILENAME" != "$(basename "$OPT_FILENAME")" ]; then
echo "--filename must not contain any directory" >&2
exit 1
fi
fi
shift
;;
--list-versions)
list_versions
exit 0
;;
--list-models)
list_models
exit 0
;;
--package-append)
# TODO: Sanitize argument (but leave any leading non-alnum char)
OPT_PKGNAME_APPEND="$1"
shift
;;
--force)
OPT_FORCE=true
;;
--ignore-bad-files)
OPT_IGNORE_BAD=true
;;
--help)
usage
exit 0
;;
--version)
echo "make-psx-bios-package version $VERSION"
exit 0
;;
--*)
echo "$0: unknown option $ARG" >&2
echo "Try '$0 --help' for more information." >&2
exit 1
;;
*)
OPT_SOURCES+=("$ARG")
OPT_SOURCES_FILENAME+=("$OPT_FILENAME")
unset OPT_FILENAME
;;
esac
done
if [ ${#OPT_SOURCES[@]} -eq 0 ]; then
usage >&2
exit 1
fi
}
# Inspired by googleearth-package
verify_sanity() {
if [ $(id --user) -eq 0 ]; then
echo 'Refusing to run as root; use --force to override.' >&2
return 1
fi
if [ -u . -o -g . ]; then
echo 'Refusing to build in a setuid/setgid directory; use --force to override.' >&2
return 1
fi
}
# Set up download() - download <url> <output-file>
if which wget > /dev/null; then
download() {
wget "$1" -O "$2" || return 1
}
elif which curl > /dev/null; then
download() {
curl "$1" -o "$2" || return 1
}
else
download() {
echo 'Either wget or curl is required to download the requested URL.' >&2
echo '(Or you can download it yourself and point to it.)' >&2
exit 1
}
fi
# Package names may only contain lower case letters, digits, "+", "-" and ".".
# (Some of these characters can be excluded via $2.)
# We also don't want filenames starting with a non-alnum character.
sanitize_name() {
echo "$1" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]+.-' | tr -d "$2" | sed 's/^[^[:alnum:]]\+//'
}
# Extract information from a ROM data line (some versions include
# parentheses, so 'eval' is not an option)
extract_version() {
echo "$1" | cut -d ' ' -f 1,2
}
extract_models() {
echo "$1" | cut -d ' ' -f 4-
}
# Check the MD5 of a file against known values, and output the ROM data line
get_rom() {
echo "${KNOWN_ROMS["$(md5sum "$1" | cut -d ' ' -f 1)"]}" |\
sed 's/\s\+/ /g'
}
get_rom_corrupt() {
local MD5="${CORRUPT_ROMS["$(md5sum "$1" | cut -d ' ' -f 1)"]}"
if [ "$MD5" ]; then
echo "${KNOWN_ROMS["$(echo "$MD5" | cut -d ' ' -f 1)"]}" |\
sed 's/\s\+/ /g'
fi
}
# Extract the contents of a (possible) archive
extract() {
local FILE="$1" DEST="$2"
# --test-label does not appear to work :(
if tar -t -f "$FILE" >/dev/null 2>&1; then
tar x -f "$FILE" -C "$DEST"
elif zipinfo -h "$FILE" >/dev/null 2>&1; then
unzip -q "$FILE" -d "$DEST"
else
return 1
fi
}
# Directory where we will find our misc. files
misc_dir() {
local SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
if [ "$SCRIPT_DIR" = "/usr/bin" ]; then
# We are running from an installed Debian package
echo "/usr/share/psx-bios-package"
elif [ -d "$SCRIPT_DIR/debian" -a -d "$SCRIPT_DIR/psx-bios" ]; then
# We appear to be running from the unpacked source
echo "$SCRIPT_DIR/psx-bios"
else
echo "$0: Unable to find misc. files directory" >&2
return 1
fi
}
# Process a single file, possibly as part of an archive, and print the ROM line
process_single_file() {
local WORK_DIR="$1" FILENAME="$2" DEST="$3"
local ROM="$(get_rom "$FILENAME")"
if [ ! "$ROM" ]; then
ROM="$(get_rom_corrupt "$FILENAME")"
if [ "$ROM" ]; then
echo "The BIOS image found in '$FILENAME' is a corrupted copy of version $(extract_version "$ROM")${OPT_IGNORE_BAD:+" (ignoring)"}" >&2
else
echo "Cannot determine BIOS version for $FILENAME${OPT_IGNORE_BAD:+" (ignoring)"}" >&2
fi
if [ "$OPT_IGNORE_BAD" ]; then
return 0
else
return 1
fi
fi
echo "$ROM"
DEST="$WORK_DIR/images/${DEST:-$(sanitize_name "$(extract_version "$ROM")" '.').bin}"
# FIXME: What should we do if $DEST already exists?
ln "$FILENAME" "$DEST" 2>/dev/null || cp "$FILENAME" "$DEST"
}
# Process a directory, and print the ROM line(s)
process_single_dir() {
local WORK_DIR="$1" DIRNAME="$2" DEST="$3"
while read FILENAME; do
process_single_file "$WORK_DIR" "$FILENAME" "$DEST" || exit
done < <(find "$DIRNAME" -type f -size ${BIOS_SIZE}c)
}
# Process a file, either a ROM image or an archive
process_file() {
local WORK_DIR="$1" FILENAME="$2" DEST="$3"
mkdir -p "$WORK_DIR/tmp"
if extract "$FILENAME" "$WORK_DIR/tmp"; then
if [ "$DEST" ]; then
# TODO: Maybe allow --filename if only one image is found
echo "--filename cannot be used with an archive file" >&2
exit 1
fi
process_single_dir "$WORK_DIR" "$WORK_DIR/tmp" "$DEST" \
>> "$WORK_DIR/roms" || exit
if [ ! -s "$WORK_DIR/roms" ]; then
echo "Could not find any images in $FILENAME" >&2
exit 1
fi
else
process_single_file "$WORK_DIR" "$FILENAME" "$DEST" \
>> "$WORK_DIR/roms" || exit
fi
rm -rf "$WORK_DIR/tmp"
readarray -t ROMS < "$WORK_DIR/roms"
}
# Process a directory
process_dir() {
local WORK_DIR="$1" DIRNAME="$2" DEST="$3"
if [ "$DEST" ]; then
# TODO: Maybe allow --filename if only one image is found
echo "--filename cannot be used with a directory" >&2
exit 1
fi
process_single_dir "$WORK_DIR" "$DIRNAME" "$DEST" \
>> "$WORK_DIR/roms" || exit
if [ ! -s "$WORK_DIR/roms" ]; then
echo "Could not find any images in $DIRNAME" >&2
exit 1
fi
readarray -t ROMS < "$WORK_DIR/roms"
}
# Download and process a URL
process_url() {
local WORK_DIR="$1" URL="$2" DEST="$3"
case "$URL" in
*.zip | *.ZIP)
if [ ! "$(which unzip)" -a "$OPT_FORCE" != true ]; then
echo "Not downloading <$URL>: unzip not available; use --force to override" >&2
return 1
fi
;;
esac
download "$URL" "$WORK_DIR/tmp.bin" \
&& process_file "$WORK_DIR" "$WORK_DIR/tmp.bin" "$DEST"
}
# Process either a file or URL
process() {
local WORK_DIR="$1" ARG="$2" DEST="$3"
case "$ARG" in
http://* | https://* | ftp://*)
process_url "$WORK_DIR" "$ARG" "$DEST"
;;
*)
if [ -f "$ARG" ]; then
process_file "$WORK_DIR" "$ARG" "$DEST"
elif [ -d "$ARG" ]; then
process_dir "$WORK_DIR" "$ARG" "$DEST"
else
echo "$0: $ARG: No such file or directory" >&2
return 1
fi
;;
esac
}
# Fill out a debian/control template
build_control() {
local SRC="$1" DEST="$2" SHARE="$3"
# debian/control substitution variables
local -A CONTROL_VARS=(
['local:Maintainer']="${OPT_FULLNAME} <${OPT_EMAIL}>"
['local:Package-Append']="${OPT_PKGNAME_APPEND}"
['local:Revision-Append']="${OPT_REVISION_APPEND}"
['local:Installed-Size']="$(du -k -s --apparent-size "$DEST" | cut -f1)"
)
if [ ${#ROMS[@]} -eq 1 ]; then
CONTROL_VARS['local:Version']="$(extract_version "${ROMS[0]}")"
fi
local CTRL_PROVIDES_MODELS CTRL_PROVIDES_VERSIONS
local -A CTRL_PROVIDES_MODELS_SEEN
for ROM in "${ROMS[@]}"; do
CTRL_PROVIDES_VERSIONS="${CTRL_PROVIDES_VERSIONS:+"${CTRL_PROVIDES_VERSIONS}, "}psx-bios-$(sanitize_name "$(extract_version "$ROM")" '-')"
for MODEL in $(extract_models "$ROM"); do
if [ -z "${CTRL_PROVIDES_MODELS_SEEN["$MODEL"]}" ]; then
CTRL_PROVIDES_MODELS="${CTRL_PROVIDES_MODELS:+"${CTRL_PROVIDES_MODELS}, "}psx-bios-$(sanitize_name "$MODEL" '-')"
CTRL_PROVIDES_MODELS_SEEN["$MODEL"]=true
fi
done
done
CONTROL_VARS['local:Provides-Versions']="$CTRL_PROVIDES_VERSIONS"
CONTROL_VARS['local:Provides-Models']="$CTRL_PROVIDES_MODELS"
if [ -e "$SHARE/../debian/changelog" ]; then
# This is very hackish, but we cannot rely on
# dpkg-parsechangelog to be available :(
CONTROL_VARS['local:Revision']="$(sed -n '1 s/.*(\(.*\)).*/\1/p' "$SHARE/../debian/changelog")"
fi
while IFS="" read CONTROL_LINE; do
for VARNAME in "${!CONTROL_VARS[@]}"; do
CONTROL_LINE="${CONTROL_LINE//"\${$VARNAME}"/"${CONTROL_VARS["$VARNAME"]}"}"
done
if [[ "$CONTROL_LINE" == *'${local:Model-List}'* ]]; then
for ROM in "${ROMS[@]}"; do
for MODEL in $(extract_models "$ROM"); do
echo "${CONTROL_LINE/'${local:Model-List}'/$MODEL}"
done
done | sort -u
else
echo "$CONTROL_LINE"
fi
done
}
# Build the filesystem tree for our binary package from an unpacked archive.
build_deb_tree() {
local SRC="$1" DEST="$2"
local ONLY_ROM
if [ ${#ROMS[@]} -eq 1 ]; then
ONLY_ROM="${ROMS[0]}"
fi
if [ -z "$OPT_PKGNAME_APPEND" ]; then
if [ "$ONLY_ROM" ]; then
OPT_PKGNAME_APPEND="-$(sanitize_name "$(extract_version "$ONLY_ROM")")"
else
OPT_PKGNAME_APPEND="-multi"
fi
fi
local PKGNAME="psx-bios${OPT_PKGNAME_APPEND}"
# Some additional files that we'll need
local SHARE="$(misc_dir)"
# We'll refer to this directory a lot
local DOC="$DEST/usr/share/doc/${PKGNAME}"
mkdir -p "$DEST/usr/share/psemu/bios"
ln "$SRC"/* "$DEST/usr/share/psemu/bios/"
# Documentation (under /usr/share/doc/psx-bios[-append])
mkdir -p "$DOC"
cp "$SHARE/copyright" "$DOC/"
if [ -e "$SHARE/../debian/changelog" ]; then
gzip -9 -c --no-name "$SHARE/../debian/changelog" > "$DOC/changelog.Debian.gz"
else
# Borrow the Debian changelog from psx-bios-package
cp /usr/share/doc/psx-bios-package/changelog.gz "$DOC/changelog.Debian.gz"
fi
# Finally, compress anything over 4 KiB (except copyright)
find "$DOC" -size +4k \! -name 'copyright' \! -name '*.gz' -print0 \
| xargs -0 --no-run-if-empty gzip -9 --no-name
# DEBIAN directory
mkdir -p "$DEST/DEBIAN"
# Fill out debian/control
local CONTROL_FILE
if [ "$ONLY_ROM" ]; then
CONTROL_FILE="$SHARE/control"
else
CONTROL_FILE="$SHARE/control.multi"
fi
build_control "$SRC" "$DEST" "$SHARE" < "$CONTROL_FILE" > "$DEST/DEBIAN/control"
# Generate md5sums (which must be relative to $DEST)
(cd "$DEST" && find . -type f \! -regex './\(DEBIAN\|etc\)/.*' -printf '%P\0' \
| LC_ALL=C sort --zero-terminated \
| xargs -0 md5sum) > "$DEST/DEBIAN/md5sums"
# Fix permissions
find "$DEST" -type f -print0 | xargs -0 chmod 644
find "$DEST" -type d -print0 | xargs -0 chmod 755
}
main() {
set_default_args
parse_args "$@"
[ "$OPT_FORCE" != true ] && verify_sanity
# Make sure the directory exists before going any further
misc_dir >/dev/null
# Temporary workspace
local WORK_DIR="$(mktemp --directory --tmpdir)"
trap "rm -rf '$WORK_DIR'" EXIT
local -a ROMS
mkdir -p "$WORK_DIR/images"
for SOURCE in "${OPT_SOURCES[@]}"; do
if ! process "$WORK_DIR" "$SOURCE" "${OPT_SOURCES_FILENAME[0]}"; then
echo "Cannot process $SOURCE" >&2
exit 1
fi
unset OPT_SOURCES_FILENAME[0]
OPT_SOURCES_FILENAME=( "${OPT_SOURCES_FILENAME[@]}" )
done
if ! ls "$WORK_DIR"/images/* >/dev/null 2>&1; then
echo "No images found" >&2
exit 1
fi
mkdir -p "$WORK_DIR/build"
build_deb_tree "$WORK_DIR/images" "$WORK_DIR/build"
fakeroot dpkg-deb --build \
-Z${OPT_COMPRESS_TYPE} \
${OPT_COMPRESS_LEVEL:+-z$OPT_COMPRESS_LEVEL} \
"$WORK_DIR/build" .
rm -rf "$WORK_DIR"
trap - EXIT
}
main "$@"