-
Notifications
You must be signed in to change notification settings - Fork 19
/
build8.sh
executable file
·274 lines (215 loc) · 8.09 KB
/
build8.sh
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
#!/bin/bash
#
# This is a script to build a deb of WordPerfect 7.0 for UNIX.
#
# Tavis Ormandy <taviso@gmail.com>, July 2022
#
set -x
set -e
umask 2
declare pkgname="${1:-wordperfect8_i386}"
declare libcver="5.3.12"
declare libmver="5.0.6"
declare prefix="/opt/wp80"
declare wpurl="https://archive.org/details/corel-wpunix-8/"
declare tmpfile="$(mktemp)"
declare topdir="${PWD}"
declare libcurl="https://archive.download.redhat.com/pub/redhat/linux/5.2/en/os/i386/RedHat/RPMS/libc-5.3.12-27.i386.rpm"
declare ldsourl="https://archive.download.redhat.com/pub/redhat/linux/5.2/en/os/i386/RedHat/RPMS/glibc-2.0.7-29.i386.rpm"
test -f "${topdir}/COREL_WPUNIX_1.iso" || {
echo "You need to download COREL_WPUNIX_1.iso from ${wpurl}"
exit 1
}
# Required tools.
echo Checking for required tools...
type patchelf
type wget
type objcopy
type rpm2cpio
type cpio
type awk
type install
type bsdtar
type cpp
# Setup directory structure.
mkdir -m0755 -p "${pkgname}/DEBIAN"
mkdir -m0755 -p "${pkgname}/${prefix}"
mkdir -m0755 -p "${pkgname}/usr/bin"
mkdir -m0755 -p build
# Make sure the directories have sane permissions.
find "${pkgname}" -type d -exec chmod 0755 {} \;
# Copy over the static files.
cp control "${pkgname}/DEBIAN/control"
cp wp8.sh "${pkgname}/usr/bin/wp"
chmod 0755 "${pkgname}/usr/bin/wp"
# Fetch any missing distfiles.
test -f "${libcurl##*/}" || wget "${libcurl}"
test -f "${ldsourl##*/}" || wget "${ldsourl}"
pushd build
# Extract libraries.
rpm2cpio < "../${ldsourl##*/}" | cpio -d -i '*/ld-*'
rpm2cpio < "../${libcurl##*/}" | cpio -d -i '*/lib[cm].*'
cp ../libcompat.so lib/
cp ../libwppatch.so lib/
mv usr/i486-linux-libc5/lib/* lib/
rm -rf usr
ln -fs libc.so.${libcver} lib/libc.so.5
ln -fs libm.so.${libmver} lib/libm.so.5
# Weaken the symbols we want to patch.
objcopy -W geteuid \
-W getuid \
-W getcwd \
-W _lxstat \
-W _fxstat \
-W _xstat \
-W _init \
-W times \
lib/libc.so.${libcver} lib/libc.so.${libcver}
# Extract original WP distribution.
bsdtar xf "${topdir}/COREL_WPUNIX_1.iso" linux/ solaris/ sco/ shared/
rm -rf linux/{dat,prn,trm,lng}
ln -sf ../solaris/{dat,prn,trm} linux/
ln -sf ../sco/lng linux/
ln -sf ../shared linux/
# These are only needed during install.
# This loader is too old to support DT_RPATH :)
patchelf --set-interpreter "${topdir}/build/lib/ld-linux.so.2" linux/ins/wpdecom
patchelf --set-interpreter "${topdir}/build/lib/ld-linux.so.2" linux/ins/wxar
patchelf --add-needed "${topdir}/build/lib/libcompat.so" linux/ins/wpdecom
patchelf --add-needed "${topdir}/build/lib/libcompat.so" linux/ins/wxar
patchelf --replace-needed "libm.so.5" "${topdir}/build/lib/libm.so.5" linux/ins/wpdecom
patchelf --replace-needed "libm.so.5" "${topdir}/build/lib/libm.so.5" linux/ins/wxar
patchelf --replace-needed "libc.so.5" "${topdir}/build/lib/libc.so.5" linux/ins/wpdecom
patchelf --replace-needed "libc.so.5" "${topdir}/build/lib/libc.so.5" linux/ins/wxar
chmod +x linux/ins/wxar linux/ins/wpdecom
# wxar works in the pwd, so this wrapper makes a tempdir.
function wxar()
{
local tmpdir="$(mktemp -d)"
local basedir="$(pwd)"
local mode="${1}"
local dest="${2}"
pushd "${tmpdir}" > /dev/null
"${basedir}/linux/ins/wxar" "${basedir}/${3}"
popd > /dev/null
mkdir -p --mode=0755 "${dest}"
install -D --mode="${mode}" "${tmpdir}"/* "${dest}"
rm -rf "${tmpdir}"
}
# Change function to return specified value.
# This is needed because the converter binaries have expired.
function patchfunc()
{
local val=(0xc390c031 0xc340c031)
if ! test -f "${1}"; then
return
fi
if ! nm "${1}" | grep -aF "T ${2}"; then
return
fi
# If this fails, that converters wont work, but it's a relatively harmless
# error.
if ! type gdb; then
return
fi
# If this fails then we may have broken the converters!
gdb --nx \
--write \
--batch-silent \
-ex "set * (int *) ${2} = ${val[$3]}" \
"${1}"
}
# Remove leftover rockridge junk
find -name YMTRANS.TBL -delete
# Decompress files
find linux -type f -exec linux/ins/wpdecom {} ${tmpfile} \; -exec cp ${tmpfile} {} \;
find solaris -type f -exec linux/ins/wpdecom {} ${tmpfile} \; -exec cp ${tmpfile} {} \;
find sco -type f -exec linux/ins/wpdecom {} ${tmpfile} \; -exec cp ${tmpfile} {} \;
egrep -hv '^#[ s]' shared/ship | cpp -Wno-endif-labels -DALL -Dlinux | egrep -v '^# ' > install.txt
# a means archive file
# b means backup (treat like copy)
# c means copy
awk '$4 ~ /^[bc].[bc]/ {
system(sprintf("install -D --mode=0%s linux/%s/%s root/%s/%s",$5,$3,$2,$6,$7));
}' install.txt
awk '$4 ~ /^[bc].a/ {
printf("0%s linux/%s/%s root/%s\n",$5,$3,$2,$6);
}' install.txt | while read mode src dst; do
wxar "${mode}" "${dst}" "${src}"
done
# I think its a bug in the ship manifest that these arent included in
# character mode.
install -D --mode=0755 linux/bin/wpexc root/shbin10/wpexc
install -D --mode=0755 linux/bin/cjpeg root/shbin10/cjpeg
install -D --mode=0755 linux/bin/djpeg root/shbin10/djpeg
# My updated xterm terminal definitions.
cp -f ../xterm.trs root/shlib10/xterm.trs
cp -f ../xterm.trs root/shlib10/xterm-256color.trs
cp -f ../xterm-nomouse.trs root/shlib10/xterm-nomouse.trs
# Add some sample macros.
cp -f ../macro/macros/*.wpm root/wpmacros/
# Add macro include files.
mkdir --mode=0755 root/wpmacros/include
cp -f ../macro/macros/*.h root/wpmacros/include/
# Ghostscript Printer Resources
cp -f ../gscript.all root/shlib10/gscript.all
# Add a CUA Keyboard Layout
cp -f ../cua.wpk root/wpmacros/
# Set default language.
printf "us\n" > root/shlib10/.def.lang
printf "us\n" > root/wplib/.def.lang
ln -fs wptplc.us root/wplib/wptpl.us
# This sets the language.
ln -rs root/wpmacros/us/* root/wpmacros/
ln -rs root/wpexpdocs/us/* root/wpexpdocs/
ln -rs root/wplearn/us/* root/wplearn/
# Cleanup some junk
rm -f root/install.ftp
rm -f root/install.wp
rm -f root/readme.ftp
# These dont seem useful.
rm -f root/shbin10/ptrinst
rm -f root/shbin10/wpxtool
rm -f root/shared/wpinstg
rm -f root/shared/mm
rm -f root/shared/ship
rm -f root/shlib10/readme.ftp
# Normalize permissions
find root/ -type f -perm /ugo+x -exec chmod 0755 {} \;
find root/ -type f -not -perm /ugo+x -exec chmod 0644 {} \;
find root/ -type d -exec chmod 0755 {} \;
find root/ -type f -perm -u+x -exec patchelf --set-interpreter "${prefix}/lib/ld-linux.so.2" {} \;
find root/ -type f -perm -u+x -exec patchelf --add-needed "${prefix}/lib/libcompat.so" {} \;
find root/ -type f -perm -u+x -exec patchelf --replace-needed libm.so.5 "${prefix}/lib/libm.so.5" {} \;
find root/ -type f -perm -u+x -exec patchelf --replace-needed libc.so.5 "${prefix}/lib/libc.so.5" {} \;
# Load our patch module into wp
patchelf --add-needed "${prefix}/lib/libwppatch.so" root/wpbin/wp
# Fix the tools we used during installation.
patchelf --replace-needed "${topdir}/build/lib/libm.so.5" "${prefix}/lib/libm.so.5" root/shared/wpdecompress root/shared/wxar
patchelf --replace-needed "${topdir}/build/lib/libc.so.5" "${prefix}/lib/libc.so.5" root/shared/wpdecompress root/shared/wxar
patchelf --remove-needed "${topdir}/build/lib/libcompat.so" root/shared/wpdecompress root/shared/wxar
# Copy over the runtime libraries
mv lib root
# Normalize those permissions
chmod -R 0755 root/lib
# Fix any expired converter programs.
for i in root/shbin10/fxwpf root/shbin10/in* root/shbin10/out*; do
patchfunc "${i}" CheckTime 1
patchfunc "${i}" SecureInFile 0
done
# Add any extra utility programs.
install -D --mode=0755 ../macro/mactool root/shbin10/mactool
install -D --mode=0755 ../util/grsutil root/shbin10/grsutil
# Remove any debugging symbols from our code.
strip root/shbin10/mactool
strip root/shbin10/grsutil
strip root/lib/libwppatch.so
# Install into prefix
mv root/* "${topdir}/${pkgname}/${prefix}/"
# Return to topdir
popd
# Install default configuration.
install -D --mode=0600 /dev/null ${pkgname}/${prefix}/shlib10/.wp8.lm
install -D --mode=0644 wp7c.set ${pkgname}/${prefix}/wplib/.wp8c.set
# Cleanup
rm -rf build "${tmpfile}"