-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkpkg
More file actions
executable file
·175 lines (142 loc) · 3.11 KB
/
mkpkg
File metadata and controls
executable file
·175 lines (142 loc) · 3.11 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
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
#!/bin/sh
help() {
echo \
"
mkpkg [options ...] [payload-dir] [pkg]
Small utility tool to make macos packages from any directory.
The package installs the files starting from the base location, conserving the file structure inside the payload directory.
does not use pkgutil/pkgbuild/productbuild/...
requirements:
xar
realpath
mkbom
lsbom
available options:
-h, --help
print the help and exit
-i, --id, --identifier [name]
set the identifier for the package
default: package name
-a, -auth [auth]
set the required auth level.
can be one of: none, root
default: none
-l, --location [path]
set the starting path from which the files will be installed, conserving the file structure inside the payload.
default: /
--preinstall [script]
provide a shell script which will be launched by the installer before installation.
should not be included in the payload.
--postinstall [script]
provide a shell script which will be launched by the installer after installation.
should not be included in the payload.
"
}
is_missing() {
case "$2" in
-* | "")
echo "$1: missing parameter"
exit 1
;;
esac
}
PARAMETERS=""
location="/"
auth="none"
while [ "$#" -gt 0 ]; do
case "$1" in
-h | --help)
help
exit 0
;;
-i | --id | --identifier)
is_missing "$1" "$2"
identifier=$2
shift 2
;;
-a | --auth)
is_missing "$1" "$2"
if [ $2 != "none" ] && [ $2 != "root" ]; then
echo "$1: $2: invalid parameter, please enter one of: root, none"
exit 1
fi
auth=$2
shift 2
;;
-l | --location)
is_missing "$1" "$2"
location=$2
shift 2
;;
--preinstall)
is_missing "$1" "$2"
preinstall="$(realpath $2)"
shift 2
;;
--postinstall)
is_missing "$1" "$2"
postinstall="$(realpath $2)"
shift 2
;;
-*)
echo "error: Unknown parameter '$1'"
exit 1
;;
*)
PARAMETERS+=" $1"
shift
;;
esac
done
set -- $PARAMETERS
if [ "$#" -lt 2 ]; then
help
exit 1
fi
files="$1"
if [ ! -d "$files" ]; then
echo "error: '$files' doesn't exit or is not a directory"
exit 1
fi
tmp="/tmp/$1_pkg_tmp"
name="$(basename $2)"
if [ -z $identifier ]; then
identifier=$name
fi
package="$(realpath $2)"
if [ -f "$package" ]; then
while true; do
echo "Warning: '$package' already exists. Do you wish to overwrite it? [y/n]: \c"
read yn
case $yn in
Y | y)
break;;
N | n)
exit;;
esac
done
fi
cd "$files"
weight=$(du -sk . | cut -f1 -w -)
rm -rf "$tmp"
mkdir "$tmp"
mkbom . "$tmp/Bom"
find ./ | cpio -o 2>/dev/null | gzip -c >"$tmp/Payload"
cd "$tmp"
if [ -n "$preinstall" ] || [ -n "$postinstall"]; then
mkdir scripts_dir
cp $preinstall $postinstall scripts_dir
cd scripts_dir
find ./* | cpio -o | gzip -c >"../Scripts"
cd ..
rm -rf scripts_dir
fi
nfiles=$(lsbom Bom | wc -l | cut -w -f2 -)
echo > PackageInfo \
"<pkg-info format-version=\"2\" identifier=\"$identifier\" auth=\"$auth\" version=\"1\" install-location=\"$location\">
<payload installKBytes=\"$weight\" numberOfFiles=\"$nfiles\"/>
</pkg-info>"
xar -j --no-compress "Payload" --no-compress "Scripts" -c * -f "$package"
rm -rf "$tmp"
echo "Made package '$name'"
exit 0