-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·79 lines (65 loc) · 2.07 KB
/
export.sh
File metadata and controls
executable file
·79 lines (65 loc) · 2.07 KB
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
#!/bin/bash
# SPDX-FileCopyrightText: © 2025 Ryan Carsten Schmidt <https://github.com/ryandesign>
# SPDX-License-Identifier: MIT
# Export files onto an HFS disk image.
set -uo pipefail
: "${SDK=/opt/local/libexec/Retro68/universal}"
: "${TMPDIR=/tmp}"
proj=memdump
dsk="$proj.dsk"
err() {
local msg="$1"
local code="${2-1}"
printf "%s: %s\n" "$(basename "$0")" "$msg" 1>&2
exit "$code"
}
[ "$(uname -s)" = "Darwin" ] || err "this script only works on macOS"
cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null || exit $?
cleanup() {
[ -n "${tmpfile-}" ] && rm -f "$tmpfile"
[ -n "${tmpfile2-}" ] && rm -f "$tmpfile2"
printf "Unmount %s\n" "$dsk"
humount
}
trap cleanup EXIT
if [ -f "$dsk" ]; then
printf "Mount %s\n" "$dsk"
hmount "$dsk" || exit $?
else
printf "Create %s\n" "$dsk"
dd if=/dev/zero of="$dsk" bs=1k count=800 status=none || exit $?
hformat -l "$proj" "$dsk" || exit $?
fi
export_file() {
local method="$1"
local infile="$2"
local type="$3"
local creator="$4"
local outfile
outfile=$(printf %s "$infile" | iconv -f utf-8 -t macroman)
printf "Export %s\n" "$infile"
tmpfile=$(mktemp "$TMPDIR/export.XXXXXXXX")
case $method in
rez)
tmpfile2=$(mktemp "$TMPDIR/export.XXXXXXXX")
iconv -f utf-8 -t macroman < "$infile.r" > "$tmpfile2" || return $?
Rez "$SDK/RIncludes/Types.r" "$tmpfile2" \
-d ALRT_RezTemplateVersion=0 \
-d DLOG_RezTemplateVersion=0 \
-o "$tmpfile" || return $?
rm -f "$tmpfile2"
tmpfile2=
;;
text)
tr '\n' '\r' < "$infile" \
| iconv -f utf-8 -t macroman > "$tmpfile" || return $?
;;
esac
SetFile -t "$type" -c "$creator" "$tmpfile" || return $?
macbinary encode --pipe "$tmpfile" | hcopy -m - ":$outfile" || return $?
rm -f "$tmpfile"
tmpfile=
}
export_file rez "$proj.π" PROJ KAHL || exit $?
export_file rez "$proj.π.rsrc" rsrc RSED || exit $?
export_file text "$proj.c" TEXT KAHL || exit $?