-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertpkg-compat64
executable file
·536 lines (471 loc) · 16.5 KB
/
convertpkg-compat64
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
#!/bin/sh
# $Id: convertpkg-compat64,v 1.29 2017/06/08 08:52:41 eha Exp eha $
# Copyright (c) 2009 Frederick Emmott <[email protected]>
# Copyright (c) 2009, 2010, 2011, 2012, 2013 Eric Hameleers, Eindhoven, NL
# Copyright (c) 2018 Ben Stern <[email protected]>
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED ``AS IS'' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
# USE OR PERFORMANCE OF THIS SOFTWARE.
# Contributions to the udev cleanup code by phenixia2003.
# Convert a 64-bit Slackware package (s390 or x86) to a compatibility package
# for a 32-bit multilib Slackware.
# Catch errors and display the offending line number:
set -e
trap 'echo "$0 FAILED at line ${LINENO}"' ERR
# Package-independent variables
PKGARCH=${PKGARCH:-$(uname -m)}
TAG=${TAG:-compat64} # tag to be used for the converted package
OUTPUT=${OUTPUT:-/tmp} # where the package gets created
TMP=${TMP:-/tmp} # location for temporary files
# $BUILD can also be overridden, though it in-turn is overridden if an output
# package name is specified on the command line.
# Blacklist of packages not to use this script on (these allegedly *have* to be
# compiled on a 32-bit box).
# Let's live dangerously.
#BLACKLIST=${BLACKLIST-'glibc.* kernel.* gcc.*'}
function show_help () {
# Write the help text to output:
cat <<EOF
Usage:
$0 <-i input_package_file_name> [-d output_directory]
[-s custom_slack_desc] [-e custom_package_extension]
or
$0 <input_package_file_name> [output_directory
[custom_slack_desc [custom_package_extension]]]
$(basename $0) is used to convert a 64-bit Slackware package
into a '64-bit compatibility' package, for installion on 32-bit Slackware.
Required parameters:
-i <input_package_file_name> 64-bit package to convert
Optional parameters:
-d <destination_directory> Create package in this directory
-e <extension> Use another valid extension instead of 'txz'
-s <output_slack_desc> Custom slack-desc file to use for new package
environment variables:
BUILD Build number for output package; currently same as input package;
<output_package_file_name> overrides this value
INSTALL If non-empty, this script will go ahead and install the created
package
OUTPUT Location to create the package; currently ${OUTPUT}
PKGARCH Target architecture; currently ${PKGARCH}
TAG Build tag, currently ${TAG}
TMP Location for temporary files; currently ${TMP}
EOF
}
# Zero some initial variables:
PKGEXT="txz"
PKGFILE=""
PKGPATH=""
SLACKDESC=""
# Parse the command-line parameters:
while [ ! -z "$1" ]; do
#echo "Looking at: $1"
case "$1" in
-d|--destdir)
OUTPUT="$(realpath -e $2)"
shift 2
;;
-e|--extension)
PKGEXT="${2}"
shift 2
;;
-h|--help)
show_help
exit 0
;;
-i|--inpkg)
PKGFILE="$(basename ${2})"
PKGPATH="$(realpath -m ${2})"
#echo "PKGFILE: $PKGFILE; PKGPATH: $PKGPATH"
shift 2
;;
-s|--slack-desc)
SLACKDESC="$(realpath ${2})"
shift 2
;;
-*)
echo "Unsupported parameter: ${1}!"
exit 1
;;
*)
if [ -z "$PKGFILE" ]; then
PKGFILE="$(basename ${1})"
PKGPATH="$(realpath -m ${1})"
elif [ -z "$OUTPUT" ]; then
OUTPUT="$(realpath -e ${1})"
elif [ -z "$SLACKDESC" ]; then
SLACKDESC="$(realpath ${1})"
elif [ -z "$PKGEXT" ]; then
PKGEXT="${1}"
else
echo "Extra argument: ${1}"
exit 2
fi
shift
;;
esac
done
# Bail out now if we did not get an input package:
if [ -z "$PKGFILE" -o ! -e "$PKGPATH" ]; then
echo "** Please supply a valid input package! **"
show_help
exit 3
fi
# If a destination_directory was specified, abort now if we can not create it.
# Since we've set -e, it's unlikely this will actually trigger, but whatever.
if [ -n "$OUTPUT" -a ! -d "$OUTPUT" ]; then
echo "Creating output directory '$OUTPUT'..."
mkdir -p $OUTPUT
if [ ! -w "$OUTPUT" ]; then
echo "Creating output directory '$OUTPUT' failed!"
exit 4
fi
fi
# Example: libXres-1.2.0-x86_64-1_slack14.2.txz
# Figure out initial variables.
# This seems like going around the barn an awful lot, but I fought read for too
# long and won't make this better now.
REVERSED=$(echo "$PKGFILE" | rev)
PKGNAM=$(echo "$REVERSED" | cut -f4- -d- | rev)
VERSION=$(echo "$REVERSED" | cut -f3 -d- | rev)
BUILD=${BUILD:-$(echo "$REVERSED" | cut -f1 -d- | cut -f2- -d. | rev)}
PKGARCH=${PKGARCH:-$(echo "$REVERSED" | cut -f2 -d- | rev)}
PKGEXT=${PKGEXT:-$(echo "$PKGFILE" | rev | cut -f1 -d. | rev)}
# Yes, $TAG is in here twice.
OUTPKG=${OUTPKG:-"${PKGNAM}-${TAG}-${VERSION}-${PKGARCH}-${BUILD}-${TAG}.${PKGEXT}"}
PKGNAM64="${PKGNAM}-compat64"
#echo " Got: ${PKGNAM}-${TAG}-${VERSION}-${PKGARCH}-${BUILD}-${TAG}.${PKGEXT}"
#echo "From: $PKGFILE"
if [ ! -z "${BLACKLIST}" ]; then
for regex in $BLACKLIST; do
if echo $PKGNAM | grep -Pq "$regex"; then
echo "Package $PKGNAM is blacklisted by '$regex', aborting."
exit 5
fi
done
fi
#echo "Converting package $PKGNAM (version $VERSION) to $OUTPKG ($PKGNAM64)"
PKG="$TMP/package-$PKGNAM64"
rm -rf "$PKG"
mkdir -p "$PKG" "$TMP"
cd "$PKG"
# Explode the package into ${PKG}. We will need to slightly modify an existing
# install/doinst.sh; it should still create symlinks and run other errands when
# the resulting package is installed, but should not mess with the files we are
# going to remove for the -compat64 package.
/sbin/explodepkg "$PKGPATH"
# Check if the user fed us a 32-bit package:
if [ -d usr/lib -o -d lib ]; then
echo "** This script converts 64-bit packages for Slackware32 multilib!"
echo "** It looks like you gave me a 32-bit package instead."
echo "** Are you certain you want to convert the package $(basename $PKGPATH) ?"
echo "** Press [Ctrl]-[C] now if you want to abort the script."
read JUNK
fi
if [ "$PKGNAM" = "udev" -o "$PKGNAM" = "eudev" ]; then
# These are part of the 32-bit package:
rm -rf lib/firmware
rm -rf lib/modprobe.d
rm -rf lib/udev
rm -rf run
fi
#if [ -f install/doinst.sh ]; then
# echo
# echo "Old contents of install/doinst.sh:"
# echo
# cat install/doinst.sh
# echo
#fi
# Strip doinst.sh from everything we can't use:
case "$PKGNAM" in
"gtk+2" | "gtk+3" | "gdk-pixbuf2" | "pango")
egrep -v '\( cd usr/(bin|doc)' install/doinst.sh > install/doinst.sh.2
cat install/doinst.sh.2 > install/doinst.sh
rm -f install/doinst.sh.2
if [ "$PKGNAM" = "gtk+2" ]; then
# Deal with the .new file in gtk+2 that does not get processed:
echo "config etc/gtk-2.0/im-multipress.conf.new" >> install/doinst.sh
fi
;;
"udev" | "eudev")
# Get rid of symlinks in sbin and lib directory, and all the other
# non-symlinking-stuff:
grep '( cd ' install/doinst.sh | egrep -v '\(cd (sbin|lib/udev)' \
> install/doinst.sh.2
cat install/doinst.sh.2 > install/doinst.sh
rm -f install/doinst.sh.2
;;
*)
if [ -f install/doinst.sh ]; then
# Check for a 'config()' section
if grep -q 'config()' install/doinst.sh; then
#echo "Found config section in install/doinst.sh"
cat << EOT > install/doinst.sh.1
config() {
NEW="\$1"
OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r \$OLD ]; then
mv \$NEW \$OLD
elif [ \`md5sum < "\${OLD}"\` = \`md5sum < "\${NEW}"\` ]; then
# toss the redundant copy
rm $NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
preserve_perms() {
NEW="\$1"
OLD="\$(dirname \${NEW})/\$(basename \${NEW} .new)"
if [ -e \${OLD} ]; then
cp -a \${OLD} \${NEW}.incoming
cat \${NEW} > \${NEW}.incoming
mv \${NEW}.incoming \${NEW}
fi
config \${NEW}
}
EOT
else
touch install/doinst.sh.1
fi
# Only keep lines that deal with symlinks in bin64 and lib64 directories,
# and the config/preserve_perms commands that apply outside of /etc/:
set +e
grep -v 'etc/ld.so.conf' install/doinst.sh |
egrep -v '(\.\./sbin64|(config|preserve_perms) etc)' | \
egrep '((usr/bin64|lib64)( |/)|^(config|preserve_perms) )' \
> install/doinst.sh.2 || :
cat install/doinst.sh.1 install/doinst.sh.2 | \
sed 's# usr/bin/# usr/bin64/#g' > install/doinst.sh
rm -f install/doinst.sh.1 install/doinst.sh.2
set -e
fi
;;
esac
#if [ -f install/doinst.sh ]; then
# echo
# echo "New contents of install/doinst.sh:"
# echo
# cat install/doinst.sh
# echo
#fi
# Post-cleanup-cleanup to catch sscript errors:
if [ "$PKGNAM" = "samba" ]; then
# Get rid of a useless (because taken care of in 32-bit package) block:
grep -v 'samba/private' install/doinst.sh > install/doinst.sh.2
cat install/doinst.sh.2 > install/doinst.sh
rm -f install/doinst.sh.2
fi
# The qt package installs several symlinks to /usr/bin which point to binaries
# in qt's lib directory. We have to strip those from the -compat64 package. If
# you want to build 64-bit software that needs these qt binaries, you will have
# to add /usr/lib/qt/bin/ to your $PATH We will remove a lot of stuff which we
# do not need in the compat64 package.
if [ "$PKGNAM" = "qt" -o "$PKGNAM" = "qt3" -o "$PKGNAM" = "qt5" ]; then
if [ -d usr/lib/qt ] ; then
for ITEM in q3porting.xml demos doc examples ; do
if [ -e "usr/lib/qt/$ITEM" ] ; then
rm -rf "usr/lib/qt/$ITEM"
fi
done
elif [ -d usr/lib/qt5 ] ; then
for ITEM in demos doc examples ; do
if [ -e "usr/lib/qt5/$ITEM" ] ; then
rm -rf "usr/lib/qt5/$ITEM"
fi
done
fi
egrep -v '(usr|opt/kde3)/bin' install/doinst.sh > install/doinst.sh.2
cat install/doinst.sh.2 > install/doinst.sh
rm -f install/doinst.sh.2
fi
for i in libexec bin lib sbin etc include; do
if [ -d $i ]; then
if [ -d ${i}64 ]; then
echo "Unexpected: both $i and ${i}64 exist in $PWD!"
exit 6
fi
mv $i ${i}64
if [ -f install/doinst.sh ]; then
echo "Trying to fix up install/doinst.sh for $i ..."
sed -i "s#${i}/#${i}64/#g" install/doinst.sh
fi
fi
if [ -d usr/$i ]; then
if [ -d usr/${i}64 ]; then
echo "Unexpected: both usr/$i and usr/${i}64 exist in $PWD!"
exit 7
fi
mv usr/$i usr/${i}64
if [ -f install/doinst.sh ]; then
echo "Trying to fix up install/doinst.sh for usr/$i ..."
sed -i "s#${i}/#${i}64/#g" install/doinst.sh
fi
fi
done
if [ -d usr/bin/64 ]; then
if [ ! -d usr/bin64 ]; then
mkdir usr/bin64
fi
cd usr/bin/64
for i in *; do
if [ -e "../bin64/$i" ]; then
echo "Unexpected: both usr/bin/64$i and usr/bin64/$i exist!"
exit 9
elif [ -e "$1" ]; then
mv "$1" ../bin64/
set +e
sed -i "s#usr/bin/64/$1#usr/bin64/$1#g" ../../../install/doinst.sh
set -e
fi
done
cd ../../..
fi
for i in include share; do
if [ -d "usr/${i}64" ]; then
cd "usr/${i}64"
find . -type f -exec diff -q {} "${ROOT}/usr/${i}/{}" \; -delete
cd ../..
fi
done
find usr -type d -empty -delete
if [ -f install/doinst.sh ]; then
set +e
for i in libexec bin lib sbin etc include; do
sed -i "s#cd usr/${i} #cd usr/${i}64 #g" install/doinst.sh
sed -i "s#cd ${i} #cd ${i}64 #g" install/doinst.sh
sed -i "s#/${i}/ #/${i}64/ #g" install/doinst.sh
done
set -e
fi
# Keep documentation we might be required to keep, or just be polite (or not).
if [ -d usr/doc -o -d usr/man -o -d usr/share/man ]; then
# find usr/doc -type f ! -iname 'Copyright*' -a ! -iname 'COPYING*' -a \
# ! -iname 'AUTHORS*' -a ! -iname 'LICENSE*' -a ! -iname 'GPL*' -a \
# ! -iname 'LGPL*' -a ! -iname 'THANKS*' -delete
# find usr/doc -type d -depth | xargs -d '\n' rmdir --ignore-fail-on-non-empty
# We already have docs, most likely, so nuke these, because they'll mess up
# our own docs.
rm -rf usr/doc usr/man usr/share/man usr/share/gtk-doc
if [ -f install/doinst.sh ]; then
egrep -wv 'usr/(doc|man|share/(man|gtk-doc))' install/doinst.sh > install/doinst.sh.2 || true
cat install/doinst.sh.2 > install/doinst.sh
rm install/doinst.sh.2
fi
fi
# for i in include man share; do
# if [ -d usr/${i} ]; then
# mv -vi usr/${i} usr/${i}64
# fi
# done
#set -x
#pwd
find . -type f | while read FILE; do
if [ -f "${ROOT}/${FILE}" ]; then
OLDDIR=`dirname "$FILE"`
case "$OLDDIR" in
*include*) NEWDIR=`echo "$OLDDIR" | sed 's#/include#/include64#'` ;;
*man*) NEWDIR=`echo "$OLDDIR" | sed 's#/man#/man64#'` ;;
*share*) NEWDIR=`echo "$OLDDIR" | sed 's#/share#/share64#'` ;;
*) NEWDIR="${OLDDIR}64" ;;
esac
FNAME=`basename "$FILE"`
if [ -f "${NEWDIR}/${FNAME}" ]; then
echo "${PWD}/${FILE} and ${PWD}/${NEWDIR}/${FNAME} both exist!"
exit 8
fi
if [ ! -d "$NEWDIR" ]; then
mkdir -p "$NEWDIR"
fi
if zdiff -q "$FILE" "${ROOT}/${FILE}" > /dev/null; then
if [ -z "$VERBOSE" ]; then
rm -f "$FILE"
else
echo -n "Duplicate File "
rm -pvf "$FILE" || true
fi
if [ -f install/doinst.sh ]; then
grep -v "$FILE" install/doinst.sh > install/doinst.sh.2 && \
cat install/doinst.sh.2 > install/doinst.sh &&
rm install/doinst.sh.2 || true
fi
else
echo
echo "WARNING: ${ROOT}/${FILE} and $PWD/$FILE are different!"
echo "Trying to fix up, but it's likely to cause comical results."
if [ ! -d "$NEWDIR" ]; then
mkdir -p "$NEWDIR"
fi
mv -v "$FILE" "${NEWDIR}/${FNAME}"
if [ -f install/doinst.sh ]; then
echo "Trying to fix up install/doinst.sh ..."
sed -i "s#${FILE}#${NEWDIR}/${FNAME}#g" install/doinst.sh
fi
fi
fi
done
#echo
# Nuke empty directories.
find . -type d -empty -delete
if [ ! -z "$SLACKDESC" ]; then
echo "Using externally provided slack-desc ($SLACKDESC)..."
cat "$SLACKDESC" > install/slack-desc
else
if [ ! -f install/slack-desc ]; then
# Non-standard package, missing slack-desc, so we use a template:
mkdir -p install
SPACES=`echo -n "$PKGNAM64" | awk '{ printf "%*s", length, "" }'`
cat <<EOT > install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
$SPACES|-----handy-ruler------------------------------------------------------|
$PKGNAM64: $PKGNAM64 (description of $PKGNAM64)
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64:
$PKGNAM64: This package contains 64-bit compatibility binaries.
EOT
fi
# Now, re-work the slack-desc:
# Fix the handy ruler:
SPCS=""; while [ ${#SPCS} -lt ${#PKGNAM64} ]; do SPCS=" $SPCS";done
sed -i -r "s/^ *\|-/${SPCS}\|-/" install/slack-desc
# Every line; foo: -> foo-compat64:
sed -i "s,$PKGNAM:,$PKGNAM64:," install/slack-desc
# First line: foo-compat64: foo (description of foo)
# -> foo-compat64: foo-compat64 (description of foo)
sed -i "s,$PKGNAM64: $PKGNAM ,$PKGNAM64: $PKGNAM64 ," install/slack-desc
# Last line: if empty, add 64-bit message
sed -i "\$s,^${PKGNAM64}: *$,${PKGNAM64}: This package contains 64-bit compatibility binaries.," install/slack-desc
fi
# If we ended up with an empty doinst.sh we should remove it now:
if [ ! -s install/doinst.sh ]; then
rm -f install/doinst.sh
fi
# Make the package (don't process the symlinks):
#echo "About to run: /sbin/makepkg --linkadd n --chown y $OUTPUT/$OUTPKG"
/sbin/makepkg --linkadd n --chown y "$OUTPUT"/"$OUTPKG"
echo "Package created as: $OUTPUT/$OUTPKG"
if [ ! -z "$INSTALL" ]; then
upgradepkg --install-new "$OUTPUT/$OUTPKG"
fi
cd
# Clean up - and be a little paranoid - we *are* running with root privileges
if [ -d "$PKG" -a "`dirname \"$PKG\"`" != "/" ]; then
rm -rf "$PKG"
fi