summaryrefslogtreecommitdiffstats
path: root/source/compat32-tools/massconvert32.sh
blob: 9b1c174f85bbb7b7f608662f6e3847eeda660a71 (plain)
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/bin/bash
# $Id$
#
# Written 2009, 2010, 2011, 2012, 2013  Eric Hameleers, Eindhoven, NL
#
# Convert 32bit slackware packages 'en masse' into compatibility packages
# to be installed on slackware64 - providing the 32bit part of multilib.
# The string "-compat32" is added at the end of package name when a
# compatibility package gets created.  This allows it to be installed
# on slackware64 alongside the native 64bit versions.
# For example: the original 32bit package "bzip2" will be converted to a new
#              package with the name "bzip2-compat32"
#
# You also have to install multilib versions of glibc and gcc !

# Before we start
[ -x /bin/id ] && CMD_ID="/bin/id" || CMD_ID="/usr/bin/id"
if [ "$($CMD_ID -u)" != "0" ]; then
  echo "You need to be root to run $(basename $0)."
  exit 1
fi

# Should we be verbose?
VERBOSE=${VERBOSE:-1}

# Do we really convert the packages or only pretend to?
DRYRUN=0

# In case we need temporary storage:
TMP=${TMP:-/tmp}
mkdir -p $TMP
if [ ! -w "$TMP" ]; then
  echo "Can not write to temporary directory '$TMP'!"
  exit 3
fi

# Zero some other variables:
SLACK32ROOT=""
SLACK32URL=""
TARGET64ROOT=""

# Helpful instructions in case the user asks for it:
function show_help () {
  # Write the help text to output:
  cat <<EOF

Usage: $0 <-i 32bit_package_tree|-u 32bit_package_url>  [-d output_directory]

$(basename $0) converts an essential subset of 32-bit Slackware
packages into 'compatibility' packages for 64-bit Slackware.

Required parameter - one of these two::
  -i 32bit_package_tree        A 32bit Slackware package-tree. It should have
                               the a,ap,d,..,y directories immediately below.
  -u 32bit_package_url         The URL of a http or ftp server containing 32bit
                               Slackware packages. It should have the
                               a,ap,d,..,y directories immediately below.
Optional parameter::
  -d destination_directory     create packages in this directory.
                               By default, the new packages will be created
                               in your current directory.
  -n                           Dry-run (do not convert packages, just mention
                               their names).
  -q                           Only print output if packages are actually being
                               converted (useful for cron jobs).

Example of a useable Slackware URL:
  http://slackware.mirrors.tds.net/pub/slackware/slackware-14.0/slackware

EOF
}

# Parse the commandline parameters:
while [ ! -z "$1" ]; do
  case $1 in
    -d|--destdir)
      TARGET64ROOT="$(cd $(dirname "${2}"); pwd)/$(basename "${2}")"
      shift 2
      ;;
    -h|--help)
      show_help
      exit 0
      ;;
    -i|--inputdir)
      SLACK32ROOT="$(cd $(dirname "${2}"); pwd)/$(basename "${2}")"
      shift 2
      ;;
    -n|--dry-run)
      DRYRUN=1
      shift
      ;;
    -q|--quiet)
      VERBOSE=0
      shift
      ;;
    -u|--inputurl)
      SLACK32URL="${2}"
      shift 2
      ;;
    -*)
      echo "Unsupported parameter '$1'!"
      exit 1
      ;;
    *)
      # Do nothing
      shift
      ;;
  esac
done

# A function to determine if there are spaces in the pathname:
function contains_spaces () {
  local CHOPPED=$(echo "$1" | tr -d ' ')
  [ "x$CHOPPED" = "x$1" ] && return 1 || return 0
}

# A function to get a package's URL in the repository:
function get_url_pkg () {
  local BP="$(basename $1)"
  local PS="$(dirname $1)"

  local DURL="$2"

  for FP in $(lftp -c 'open '${DURL}' ; cls -1 '${PS}/${BP}'-*.t?z' 2>/dev/null) ZALIEN ; do
    if [ "$(echo "$FP"|rev|cut -d- -f4-|cut -d/ -f1| rev)" = "$BP" ];
    then
      break
    fi
  done
  [ "$FP" != "ZALIEN" ] && echo "$DURL/$FP" || echo ""
}

# A function to retrieve the fullname of a package:
function get_pkgfullpath () {
  local IP="$1"
  local BP="$(basename $1)"
  local FP=""

  for FP in $(ls ${IP}-*.t?z 2>/dev/null) ZALIEN; do
    if [ "$(echo "$FP"|rev|cut -d- -f4-|cut -d/ -f1| rev)" = "$BP" ];
    then
      break
    fi
  done
  [ "$FP" != "ZALIEN" ] && echo "$FP" || echo ""
}

# A function to convert a package,
# downloading it first if needed, and taking patches into account:
function conv_pkg () {
  local BP="$1"
  local SERIES="$2"
  local PATCHLIST="$3"
 
  PKGPATH="$SERIES/$BP"
  REPOFOUND=""

  # First find out if the requested package exists in the repository:
  # Two repo location options: URL or local directory.
  if [ -n "$SLACK32URL" ]; then
    FULLURL=$(get_url_pkg $PKGPATH $SLACK32URL)
    if [ -n "$FULLURL" ]; then
      FULLPKG=$SLACK32ROOT/$SERIES/$(basename $FULLURL)
      REPOVERSION=$(basename $FULLURL |rev |cut -d- -f3 |rev)
      REPOBLD="$(basename $FULLURL |rev |cut -d- -f1 |cut -d. -f2- |rev)"
    else
      # Package could not be found on the remote server:
      FULLPKG=""
      REPOVERSION=""
      REPOBLD=""
    fi
  else
    FULLPKG=$(get_pkgfullpath $SLACK32ROOT/$PKGPATH)
    if [ -n "$FULLPKG" ]; then
      REPOVERSION="$(basename $FULLPKG |rev |cut -d- -f3 |rev)"
      REPOBLD="$(basename $FULLPKG |rev |cut -d- -f1 |cut -d. -f2- |rev)"
    else
      REPOVERSION=""
      REPOBLD=""
    fi
  fi

  if [ -n "$FULLPKG" ]; then
    # The requested original was found in the repository.
    REPOFOUND="yes"
    # Does the package we want have a patch available?
    echo "$PATCHLIST" | tr - _ | grep -wq $(echo $BP |tr - _)
    if [ $? -eq 0 ]; then
      [ $VERBOSE -eq 1 ] && echo "--- Using Slackware's patch package for $BP"
      PKGPATH="../patches/packages/$BP"
      if [ -n "$SLACK32URL" ]; then
        FULLURL=$(get_url_pkg $PKGPATH "$(dirname $SLACK32URL)/patches")
        if [ -n "$FULLURL" ]; then
          FULLPKG=$SLACK32ROOT/$SERIES/$(basename $FULLURL)
          REPOVERSION=$(basename $FULLURL |rev |cut -d- -f3 |rev)
          REPOBLD="$(basename $FULLURL |rev |cut -d- -f1 |cut -d. -f2- |rev)"
        else
          FULLPKG=""
          REPOVERSION=""
          REPOBLD=""
        fi
      else
        FULLPKG=$(get_pkgfullpath $SLACK32ROOT/$PKGPATH)
        if [ -n "$FULLPKG" ]; then
          REPOVERSION="$(basename $FULLPKG |rev |cut -d- -f3 |rev)"
          REPOBLD="$(basename $FULLPKG |rev |cut -d- -f1 |cut -d. -f2- |rev)"
        else
          REPOVERSION=""
          REPOBLD=""
        fi
      fi
    fi
  fi

  if [ -z "$FULLPKG" ]; then
    if [ -n "$REPOFOUND" ]; then
      [ $VERBOSE -eq 1 ] && echo "*** FAIL: patch-package for '$BP' was not found in repository (original package present, this means a repository mismatch)!"
    else
      [ $VERBOSE -eq 1 ] && echo "*** FAIL: package '$BP' was not found in repository!"
    fi
    return
  fi

  # Package (or patch) available - let's start!

  # Do we have a local converted package already?
  HAVE_COMPAT32="$(get_pkgfullpath $TARGET64ROOT/${SERIES}-compat32/$BP-compat32)"
  if [ -n "$HAVE_COMPAT32" ]; then
    COMPAT32VERSION="$(echo "$HAVE_COMPAT32" |rev|cut -d- -f3|rev)"
    COMPAT32BLD="$(echo "$HAVE_COMPAT32" |rev|cut -d- -f1|cut -d. -f2-|rev)"
    if [ "$COMPAT32VERSION" = "$REPOVERSION" -a "${COMPAT32BLD%compat32}" = "$REPOBLD" ]
    then
      [ $VERBOSE -eq 1 ] && echo "--- ${BP}-compat32 version '$COMPAT32VERSION' already available"
    else
      if [ $DRYRUN -eq 0 ]; then
        echo ">>> Deleting old version '$COMPAT32VERSION' of '${BP}-compat32'"
      else
        echo "${BP}: existing package needs update"
      fi
      FILE_TO_REMOVE=$HAVE_COMPAT32
      HAVE_COMPAT32=""
    fi
  else
    if [ $DRYRUN -eq 1 ]; then
      echo "${BP}: new package will be converted"
    fi
  fi

  # If we do not have the latest -compat32 package, then run the conversion:
  if [ ! -n "$HAVE_COMPAT32" -a $DRYRUN -eq 0 ]; then

    if [ -n "$SLACK32URL" ]; then
      # Download the Slackware package before converting it:
      ( mkdir -p $SLACK32ROOT/$SERIES
        cd $SLACK32ROOT/$SERIES
        lftp -c "open $(dirname $FULLURL) ; get $(basename $FULLURL)" 2>/dev/null
      )
    fi

    [ $VERBOSE -eq 1 ] && echo "--- $BP"
    # Convert the Slackware package into a -compat32 version:
    sh $CONV32 -i $FULLPKG -d $TARGET64ROOT/${SERIES}-compat32

    if [ -n "$FILE_TO_REMOVE" ]; then
      # This is where we delete an older version of the -compat32 package:
      rm $(echo $FILE_TO_REMOVE | rev | cut -d. -f2- | rev).*
      FILE_TO_REMOVE=""
    fi
  fi
}

# Safety checks in case a URL was provided: 
if [ -n "$SLACK32URL" ]; then
  if [ -n "$SLACK32ROOT" ]; then
    echo "*** Options '-i' and '-u' can not be used together!"
    exit 1
  else
    # Define a 'temporary' root directory where we will download packages:
    SLACK32ROOT="${TMP}/alienBOB/slackware"
    if ! which lftp 1>/dev/null 2>&1 ; then
      echo  "No lftp binary detected! Need lftp for package downloading!"
      exit 1
    fi
  fi
fi

# The root directory of 32bit Slackware packages
# (should have the a,ap,d,..,y directories immediately below):
# Let's use a fallback directory in case none was specified:
SLACK32ROOT="${SLACK32ROOT:-"/home/ftp/pub/Linux/Slackware/slackware-current/slackware"}"

# The output directory for our converted packages; defaults to the current dir.
# Note that {a,ap,d,l,n,x}-compat32 directories will be created below this
# directory if they do not yet exist:
TARGET64ROOT="${TARGET64ROOT:-"$(pwd)"}"

# Abort if we got directories with spaces in them:
if contains_spaces "$SLACK32ROOT" ; then
  echo "Directories with spaces are unsupported: '$SLACK32ROOT'!"
  exit 1
fi
if contains_spaces "$TARGET64ROOT" ; then
  echo "Directories with spaces are unsupported: '$TARGET64ROOT'!"
  exit 1
fi

# Where the scripts are:
SRCDIR=$(cd $(dirname $(which $0)); pwd)

# The script that does the package conversion:
CONV32=$SRCDIR/convertpkg-compat32

# Bail out if the conversion script is not available/working:
if [ ! -f $CONV32 ]; then
  echo "Required script '$CONV32' is not present or not executable! Aborting..."
  exit 1
fi

# We can not proceed if there are no packages and we did not get an URL:
if [ -z "$SLACK32URL" ]; then
  if [ ! -d $SLACK32ROOT/a -o ! -d $SLACK32ROOT/ap -o ! -d $SLACK32ROOT/d -o ! -d $SLACK32ROOT/l -o ! -d $SLACK32ROOT/n -o ! -d $SLACK32ROOT/x -o ! -d $SLACK32ROOT/xap ]; then
    echo "Required package directories a,ap,d,l,n,x,xap below '$SLACK32ROOT' are not found! Aborting..."
    exit 1
  fi
fi

# If a destination_directory was specified, abort now if we can not create it:
if [ -n "$TARGET64ROOT" -a ! -d "$TARGET64ROOT" ]; then
  echo "Creating output directory '$TARGET64ROOT'..."
  mkdir -p $TARGET64ROOT
  if [ ! -w "$TARGET64ROOT" ]; then
    echo "Creation of output directory '$TARGET64ROOT' failed!"
    exit 3
  fi
fi

# Get a list of available patches
if [ -n "$SLACK32URL" ]; then
  PATCH_LIST=$(echo $(lftp -c "open $(dirname $SLACK32URL)/patches/packages/ ; cls *.t?z" 2>/dev/null | rev | cut -f4- -d- |rev))
else
  PATCH_LIST=$(echo $(cd $(dirname $SLACK32ROOT)/patches/packages/ 2>/dev/null ; ls -1 *.t?z 2>/dev/null | rev | cut -f4- -d- |rev))
fi

# This is the script's internal list of what I consider as the essential
# 32bit multilib package set for your Slackware64:

# The A/ series:
A_COMPAT32="
aaa_elflibs
attr
bzip2
cracklib
cups
cxxlibs
dbus
e2fsprogs
eudev
libgudev
lzlib
openssl-solibs
openssl10-solibs
pam
plzip
udev
util-linux
xz
"

# The AP/ series:
AP_COMPAT32="
cups
cups-filters
flac
lm_sensors
mariadb
mpg123
mysql
sqlite
"

# The D/ series:
D_COMPAT32="
libtool
llvm
opencl-headers
"

# The L/ series:
L_COMPAT32="
Mako
SDL2
alsa-lib
alsa-oss
alsa-plugins
atk
at-spi2-atk
at-spi2-core
audiofile
cairo
dbus-glib
elfutils
esound
expat
ffmpeg
fftw
fluidsynth
freetype
fribidi
gamin
gc
gdk-pixbuf2
giflib
glib2
gmp
gnome-keyring
gobject-introspection
graphite2
gtk+2
gtk+3
gst-plugins-base
gst-plugins-base0
gst-plugins-good
gst-plugins-good0
gst-plugins-libav
gstreamer
gstreamer0
hal
harfbuzz
icu4c
isl
jasper
json-c
json-glib
lame
lcms
lcms2
libaio
libarchive
libart_lgpl
libasyncns
libbluray
libcaca
libcap
libcdio
libcdio-paranoia
libclc
libcroco
libedit
libelf
libexif
libffi
libglade
libgphoto2
libidn
libidn2
libieee1284
libjpeg
libjpeg-turbo
libmng
libmpc
libnl3
libnotify
libogg
libpcap
libpng
librsvg
libsamplerate
libsndfile
libssh
libtasn1
libtermcap
libtheora
libtiff
libunistring
libunwind
libusb
libvorbis
libvpx
libwebp
libxkbcommon
libxml2
libxslt
lmdb
lzo
mozilla-nss
ncurses
ocl-icd
openal-soft
openjpeg
opus
orc
pango
pcre
pcre2
polkit
popt
pulseaudio
python-six
qt
qt5
readline
sbc
sdl
seamonkey-solibs
slang
speex
speexdsp
startup-notification
svgalib
talloc
tdb
tevent
v4l-utils
wavpack
zlib
zstd
"

# The N/ series:
N_COMPAT32="
curl
cyrus-sasl
gnutls
libgcrypt
libgpg-error
libtirpc
nettle
openldap-client
openssl
p11-kit
samba
"

# The X/ series:
X_COMPAT32="
fontconfig
freeglut
glew
glu
intel-vaapi-driver
libFS
libICE
libSM
libX11
libXScrnSaver
libXTrap
libXau
libXaw
libXcomposite
libXcursor
libXdamage
libXdmcp
libXevie
libXext
libXfixes
libXfont
libXfont2
libXfontcache
libXft
libXi
libXinerama
libXmu
libXp
libXpm
libXprintUtil
libXrandr
libXrender
libXres
libXt
libXtst
libXv
libXvMC
libXxf86dga
libXxf86misc
libXxf86vm
libdmx
libdrm
libepoxy
libfontenc
libglvnd
libinput
libpciaccess
libpthread-stubs
libva
libva-intel-driver
libvdpau
libwacom
libxcb
libxshmfence
mesa
pixman
vulkan-sdk
xcb-util
xorgproto
"

# The XAP/ series:
XAP_COMPAT32="
sane
"

# Create target directories if they do not exist:
for TDIR in a-compat32 ap-compat32 d-compat32 l-compat32 n-compat32 x-compat32 xap-compat32 ; do
  mkdir -p $TARGET64ROOT/$TDIR
  if [ ! -w $TARGET64ROOT/$TDIR ]; then
    echo "Directory '$TARGET64ROOT/$TDIR' is not writable! Aborting..."
    exit 1
  fi
done

# Convert the 32bit packages from A AP D L N and X series, checking for patches:
[ $VERBOSE -eq 1 ] && echo "*** Starting the conversion process:"

[ $VERBOSE -eq 1 ] && echo "*** 'A' series:"
for INPKG in $A_COMPAT32 ; do
  conv_pkg $INPKG a "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'AP' series:"
for INPKG in $AP_COMPAT32 ; do
  conv_pkg $INPKG ap "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'D' series:"
for INPKG in $D_COMPAT32 ; do
  conv_pkg $INPKG d "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'L' series:"
for INPKG in $L_COMPAT32 ; do
  conv_pkg $INPKG l "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'N' series:"
for INPKG in $N_COMPAT32 ; do
  conv_pkg $INPKG n "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'X' series:"
for INPKG in $X_COMPAT32 ; do
  conv_pkg $INPKG x "$PATCH_LIST"
done

[ $VERBOSE -eq 1 ] && echo "*** 'XAP' series:"
for INPKG in $XAP_COMPAT32 ; do
  conv_pkg $INPKG xap "$PATCH_LIST"
done

# Mention downloaded packages if we used a URL as source:
if [ $VERBOSE -eq 1 -a $DRYRUN -eq 0 -a  -n "$SLACK32URL" ]; then
  echo "WARNING: packages which were downloaded from '$SLACK32URL'"
  echo "have been left in directory '$SLACK32ROOT'."
  echo "It is safe to remove these now."
  echo ""
fi

[ $VERBOSE -eq 1 ] && echo "*** Conversion done!"