-
Notifications
You must be signed in to change notification settings - Fork 1
/
makebundle
262 lines (218 loc) · 13.4 KB
/
makebundle
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
#!/bin/sh
# Proof-of-concept to make application bundles from existing packages
# installing only those packages that are not there or are outdated
# on the helloSytem ISO, as determined by a pristine package database
# from the helloSytem ISO
#### TODO:
#### Before investing much more time into this, consider rewriting it in Python
#### (port to /usr/local/bin/app)
#### because right now it fails on blanks in directory names and is cumbersome
#### to write and maintain in sh - and we have existing Python code for many
#### aspects including GUI
set -e
set -x
# FIXME: Run through shellcheck and fix
# https://github.com/koalaman/shellcheck/wiki/SC2044 and
# https://github.com/koalaman/shellcheck/wiki/SC2045
# Add jsm222 repository
mkdir -p /usr/local/etc/pkg/repos/
cat > /usr/local/etc/pkg/repos/helloDesktop.conf <<\EOF
helloDesktop: {
url: "pkg+http://build.schmitz.computer/packages/${ABI}-mozillapatched",
mirror_type: "srv",
enabled: yes,
signature_type: "pubkey",
pubkey: "/usr/local/etc/ssl/certs/jsm222.cert",
priority: 100
}
EOF
mkdir -p /usr/local/etc/ssl/certs/
cat > /usr/local/etc/ssl/certs/jsm222.cert <<\EOF
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA5gEt92AHUkYkZH2Q2nP3
2/Wu7gxbMEno5iqi1ea327lHmhJB18E0mW9dKYgxz74PbbTAmyaMdY4G1vn3cStp
jKVnrOCsNboaZ1L6riYFTjZX0pVAQYdtblCNjTf92X1kk8Yp1jy3baH8s19IKVWD
jX+2j33BOjRH3jbiLxdPu51wPItDUM4UU+mdrMH2+RgHjVX3ZkgRe/bYxMgrYBQg
roEwp0Pv9DbDQ0Vx3qIBJahQ7zfDCWZI1urr85/kM58KXYLt1YHW+vRd3scOm1IE
mRON0zVO2f8+obzy3lLNnZj/XIWxh+LNI4kmmdoHMksysYtrRz1bpcnsY8qOe4g3
X7q+i8k0JaaMwwD9YvKf6HyQ09rFt3WqV2AAOwR0835oHxCENJJFcoUCMCaKjNSF
OZyuYKKPqSm8BKj/QaoXBIF1fQJBJzrINYSUj4/M6TWKVTSO8H4s+eiqfD7FYJ3h
jSZ2ubydtTOef1Tk79OVoo8Ns7FqzCK7ffOvELxuY2OMDIKrw0sCfpkI9uM5Dfrr
rYXn4dwvZLwB+tnBbKBXIfjAvwqjHeWfzqgUHSk/Slqh7UEYL+BnLfHxLMVN0Omk
gFM24eVEKju1PHkBDHVAD+NGfq4g/hcbAbcrtjxDrs1ztdwjtCJmFNcEYFjz0DRc
q9cTv5oaRy9FQy0NdGwGuqUCAwEAAQ==
-----END PUBLIC KEY-----
EOF
pkg update
echo "pkg update ran outside of the chroot"
# Get the version that is going to be installed
PACKAGE_NAME=$(echo ${PACKAGE_NAMES} | cut -d " " -f 1)
VERSION=$(pkg search ${PACKAGE_NAME} | grep -e "^${PACKAGE_NAME}-[0-9]*\." | tail -n 1 | awk '{print $1}' | cut -d "-" -f 2-99 | cut -d "_" -f 1)
VERSION=$(echo "${VERSION}" | sed -e 's|esr-||g') # That is part of the application name already
APPLICATION_NAME="${APPLICATION_NAME} ${VERSION}"
rm -rf ./"${APPLICATION_NAME}".app || continue
# rm "${APPLICATION_NAME}".app.zip || continue
mkdir -p ./"${APPLICATION_NAME}".app/Resources/var/db/pkg ./"${APPLICATION_NAME}".app/Resources/etc
cp -r /var/db/pkg.pristine ./"${APPLICATION_NAME}".app/Resources/var/db/pkg
cp -r /etc/pkg ./"${APPLICATION_NAME}".app/Resources/etc
mkdir -p ./"${APPLICATION_NAME}".app/Resources/usr/share/keys # Needed?
cp -r /usr/share/keys/pkg ./"${APPLICATION_NAME}".app/Resources/usr/share/keys # Needed?
# FIXME: pkg: . wrong user or group ownership (expected 0/0 versus actual 1001/1001)
sudo chown -R root ./"${APPLICATION_NAME}".app/Resources/ # We would like to avoid this!
# cp -r /var/db/pkg /tmp/chrootpkg || exit 1
rm -rf /tmp/chrootpkg/ || true
mkdir -p /tmp/chrootpkg/
cp -r /var/db/pkg.pristine/local.sqlite /tmp/chrootpkg/local.sqlite || exit 1
sudo chown -R root /tmp/chrootpkg # We would like to avoid this!
sudo env PKG_DBDIR="$(readlink -f /tmp/chrootpkg)" pkg --rootdir "$(readlink -f ./"${APPLICATION_NAME}".app/Resources)" update
sudo env PKG_DBDIR="$(readlink -f /tmp/chrootpkg)" pkg --rootdir "$(readlink -f ./"${APPLICATION_NAME}".app/Resources)" install -y --no-scripts $PACKAGE_NAMES
# Does the right thing. But /tmp/chrootpkg is modified in this process, making it trash.
sudo chown -R "${USER}" ./"${APPLICATION_NAME}".app/Resources /tmp/chrootpkg
rm -rf /tmp/chrootpkg ./"${APPLICATION_NAME}".app/Resources/etc/FreeBSD.conf ./"${APPLICATION_NAME}".app/Resources/var/cache/pkg ./"${APPLICATION_NAME}".app/Resources/var/db/pkg
cat > ./"${APPLICATION_NAME}".app/"${APPLICATION_NAME}" <<\EOF
#!/bin/sh
EXECUTABLE=xxx
HERE="$(dirname "$(readlink -f "${0}")")"
VERSION=$(pkg show hello | head -n 1 | cut -d "-" -f 2 | cut -d "_" -f 1)
if [ "$VERSION" != "0.7.0" ] ; then
echo "helloSystem 0.7.0 is needed to run this application." >&2
exit 1
fi
export PATH="${HERE}/Resources/usr/local/sbin":"${HERE}/Resources/usr/local/bin":"${PATH}"
export XDG_DATA_DIRS="${HERE}/Resources/usr/local/share/:${XDG_DATA_DIRS}"
export QT_PLUGIN_PATH="${HERE}/Resources/usr/local/lib/qt5/plugins/:/usr/local/lib/qt5/plugins/"
cd "${HERE}/Resources/usr/local/"
if [ -z "${WHICH}"] ; then
# If there is a broken symlink, which doesn't find it
WHICH="${HERE}/Resources/usr/local/bin/${EXECUTABLE}"
fi
if file "${WHICH}" | grep -q "symbolic link to" ; then
TARGET=$(file "${WHICH}" | rev | cut -d " " -f 1 | rev)
exec "${HERE}/Resources/${TARGET}" "$@"
else
exec "${EXECUTABLE}" "$@"
fi
EOF
sed -i "" -e "s|xxx|${EXECUTABLE_NAME}|g" ./"${APPLICATION_NAME}".app/"${APPLICATION_NAME}"
chmod +x ./"${APPLICATION_NAME}".app/"${APPLICATION_NAME}"
set +e # Continue in the case of errors for now
# Patch rpath in binaries in bin/
for FILE in $(find "${APPLICATION_NAME}".app/Resources/usr/local/bin/ -type f); do
ORIG_RPATH=$(patchelf --print-rpath "${FILE}" 2>/dev/null)
if [ -n "${ORIG_RPATH}" ] ; then
MOD_RPATH=$(echo "${ORIG_RPATH}" | sed -e 's|/usr/local|\$ORIGIN/../|g')
echo patchelf --set-rpath "\$ORIGIN/../lib:${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
patchelf --set-rpath "\$ORIGIN/../lib:${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
fi
done
# Patch rpath in libraries in lib/
# FIXME: Use find -type f to prevent patching the same file multiple times
for FILE in $(ls "${APPLICATION_NAME}".app/Resources/usr/local/lib/*.so* 2>/dev/null); do
ORIG_RPATH=$(patchelf --print-rpath "${FILE}" 2>/dev/null)
if [ -n "${ORIG_RPATH}" ] ; then
MOD_RPATH=$(echo "${ORIG_RPATH}" | sed -e 's|/usr/local|\$ORIGIN/../|g')
echo patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
else
echo patchelf --set-rpath "\$ORIGIN" "${FILE}"
patchelf --set-rpath "\$ORIGIN" "${FILE}"
fi
done
# Patch rpath in libraries two levels under lib/
# FIXME: Use find -type f to prevent patching the same file multiple times
for FILE in $(ls "${APPLICATION_NAME}".app/Resources/usr/local/lib/*/*.so* 2>/dev/null); do
ORIG_RPATH=$(patchelf --print-rpath "${FILE}" 2>/dev/null)
if [ -n "${ORIG_RPATH}" ] ; then
MOD_RPATH=$(echo "${ORIG_RPATH}" | sed -e 's|/usr/local|\$ORIGIN/../../|g')
echo patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
else
echo patchelf --set-rpath "\$ORIGIN:\$ORIGIN/../"
patchelf --set-rpath "\$ORIGIN:\$ORIGIN/../" "${FILE}"
fi
done
# Patch rpath in libraries three levels under lib/ (e.g., Qt plugins)
# FIXME: Use find -type f to prevent patching the same file multiple times
for FILE in $(ls "${APPLICATION_NAME}".app/Resources/usr/local/lib/*/*/*.so* 2>/dev/null); do
ORIG_RPATH=$(patchelf --print-rpath "${FILE}" 2>/dev/null)
if [ -n "${ORIG_RPATH}" ] ; then
MOD_RPATH=$(echo "${ORIG_RPATH}" | sed -e 's|/usr/local|\$ORIGIN/../../../|g')
echo patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
patchelf --set-rpath "${MOD_RPATH}:${ORIG_RPATH}" "${FILE}"
else
echo patchelf --set-rpath "\$ORIGIN:\$ORIGIN/../:\$ORIGIN/../../"
patchelf --set-rpath "\$ORIGIN:\$ORIGIN/../::\$ORIGIN/../../" "${FILE}"
fi
done
# Patch rpath in Python libraries
find "${APPLICATION_NAME}".app/Resources/usr/local/lib/python*/site-packages/*/*/*.so -exec patchelf --set-rpath '$ORIGIN/../../../../' {} \;
find "${APPLICATION_NAME}".app/Resources/usr/local/lib/python*/site-packages/*/*.so -exec patchelf --set-rpath '$ORIGIN/../../../' {} \;
set -e # End: Continue in the case of errors for now
# TODO: Parse desktop file, get icon, place in correct location
# Show newly created bundle in Filer (fails when run as root)
# gdbus call --session --dest org.freedesktop.FileManager1 --object-path /org/freedesktop/FileManager1 --method org.freedesktop.FileManager1.ShowItems '["file:///'$(readlink -f "${APPLICATION_NAME}".app)'"]' ""
# Quick and dirty way to find icons. TODO: Parse desktop files?
# We already have parts of this code more properly in /usr/local/bin/app!
# At that location, there may be a broken symlink to /usr/local/share/...
if [ -e "${APPLICATION_NAME}".app/Resources/usr/local/share/pixmaps/"${EXECUTABLE}".png ] ; then
cp "${APPLICATION_NAME}".app/Resources/usr/local/share/pixmaps/"${EXECUTABLE}".png "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# Mozilla specific fixes (Firefox, Firefox ESR, Thunderbird)
find "${APPLICATION_NAME}".app/Resources/usr/ -name default128.png -exec cp {} "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png \; 2>&1 || true
# Firefox specific fixes: Bundle uBlock Origin and i-dont-care-about-cookies extensions
if [ "${PACKAGE_NAME}" == "firefox" ] || [ "${PACKAGE_NAME}" == "firefox-esr" ] ; then
mkdir -p cp "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/distribution/extensions/
URLA=$(wget -c "https://api.github.com/repos/gorhill/uBlock/releases" -O - | grep browser_download_url | grep 'firefox.signed.xpi"' | head -n 1 | cut -d '"' -f 4)
URLB=$(wget -q -c "https://addons.mozilla.org/en-US/firefox/addon/i-dont-care-about-cookies/" -O - | sed -e 's|\\u002F|/|g' | grep -o -e 'https[^\"]*xpi' | head -n 1)
wget -c -q "$URLA" -O "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/distribution/extensions/[email protected]
wget -c -q "$URLB" -O "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/distribution/extensions/[email protected]
# Patch libxul.so to accept newer versions of libicui and libicuuc; https://github.com/helloSystem/Applications/issues/4
SEARCH=$(patchelf --print-needed "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so" | grep libicui)
patchelf --remove-needed "${SEARCH}" "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so"
patchelf --add-needed "libicui18n.so" "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so"
SEARCH=$(patchelf --print-needed "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so" | grep libicuuc)
patchelf --remove-needed "${SEARCH}" "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so"
patchelf --add-needed "libicuuc.so" "${APPLICATION_NAME}".app/Resources/usr/local/lib/firefox/libxul.so"
fi
# Krita specific fixes
if [ "${PACKAGE_NAME}" == "krita" ] ; then
cp "${APPLICATION_NAME}".app/Resources/usr/local/share/icons/hicolor/128x128/apps/krita.png "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# Blender specific fixes
if [ -e "${APPLICATION_NAME}".app/Resources/usr/local/bin/blender ] ; then
( cd "${APPLICATION_NAME}".app/Resources/usr/local/bin ; ln -s ../share/blender/2.* . )
convert -fuzz 10% -transparent white -background transparent -resize 256x256 -gravity north -extent 256x256 "${APPLICATION_NAME}".app/Resources/usr/local/share/icons/hicolor/scalable/apps/blender.svg "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# Scribus specific fixes
# Unfortunately Scribus still has compiled in
# access("/usr/local/share/scribus/translations/scribus",R_OK) ERR#2 'No such file or directory'
# access("/usr/local/share/scribus/icons/",F_OK) ERR#2 'No such file or directory'
# DWANT_RELOCATABLE=1 in the scribus-devel Port Makefile could possibly remove the need for this
if [ "${PACKAGE_NAME}" == "scribus-devel" ] ; then
find "${APPLICATION_NAME}".app/Resources/usr/local -type f -exec sed -i '' -e 's|/usr/local|./././././|g' {} \;
cp "${APPLICATION_NAME}".app/Resources/usr/local/share/icons/hicolor/256x256/apps/scribus.png "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# LibreOffice specific fixes
if [ "${PACKAGE_NAME}" == "libreoffice" ] ; then
( cd "${APPLICATION_NAME}".app ; ln -s Resources/usr/local/lib . )
cp "${APPLICATION_NAME}".app/Resources/usr/local/share/icons/hicolor/256x256/apps/libreoffice-main.png "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# Inkscape specific fixes
if [ "${PACKAGE_NAME}" == "inkscape" ] ; then
convert -fuzz 10% -transparent white -background transparent -resize 256x256 -gravity north -extent 256x256 "${APPLICATION_NAME}".app/Resources/usr/local/share/inkscape/pixmaps/inkscape.svg "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
fi
# Chromium specific fixes
if [ "${PACKAGE_NAME}" == "chromium" ] ; then
sed -i '' -e 's|^exec /usr/local/share/chromium/chrome .*|exec "$(dirname "$(readlink -f "${0}")")"/../share/chromium/chrome ${1+"$@"}|g' "${APPLICATION_NAME}".app/Resources/usr/local/bin/chrome
cp "${APPLICATION_NAME}".app//Resources/usr/local/share/icons/hicolor/128x128/apps/chrome.png "${APPLICATION_NAME}".app/Resources/"${APPLICATION_NAME}".png
patchelf --set-rpath '$ORIGIN/../../lib' "${APPLICATION_NAME}".app/Resources/usr/local/share/chromium/chrome
fi
rm -rf ./"${APPLICATION_NAME}".app/Resources/usr/share/keys/pkg/
# Try to launch it
# launch "${APPLICATION_NAME}".app
sudo chown -R $USER "${APPLICATION_NAME}".app
# zip -r -y "${APPLICATION_NAME}".app.zip "${APPLICATION_NAME}".app
mkdir -p diskroot
mv "${APPLICATION_NAME}".app diskroot/
makefs -o label="${APPLICATION_NAME}" "${APPLICATION_NAME}".app.ufs diskroot/
mkuzip -A zstd -C 15 -d -s 262144 -o "${APPLICATION_NAME}".img "${APPLICATION_NAME}".app.ufs