summaryrefslogtreecommitdiffstats
path: root/files/slackpkg
blob: caf8d1d1b9fcf957f6829baa507e73acde4ce324 (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
#!/bin/bash
#
# SlackPkg - An Automated packaging tool for Slackware Linux
# Copyright (C) 2003-2011 Roberto F. Batista, Evaldo Gardenali
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Project Page: https://slackpkg.org/
# Roberto F. Batista (aka PiterPunk) piterpunk@slackware.com
# Evaldo Gardenali (aka UdontKnow) evaldogardenali@fasternet.com.br
#

# Ensure that we're not at the epoch.  slackpkg breaks with GPG checks when
# the date is so far in the past:
if [ $( date +%s ) -le 1437841588 ]; then
cat <<"EOF"
Error: Your system date is wrong.  slackpkg requires that the date be correct
so that the package signatures can be verified.

The date may be incorrect because you have a system such as a Raspberry Pi that
does does not have an RTC (Real Time Clock), or that the correct date was unable
to be read from the RTC due to a driver bug, or a missing driver.

You may wish to set up NTP on your system:
http://docs.slackware.com/howtos:network_services:ntp

EOF
  exit 1
fi

#========================================================================
#
# LOAD CONFIGURATIONS
#

#
# CONF = configuration directory
# SOURCE = A mirror of Slackware. Source can be set by editing $CONF/mirrors
#
VERSION=@VERSION@
PATH=/bin:/usr/bin:/sbin:/usr/sbin
SLACKWARE_VERSION=$(cat /etc/slackware-version | cut -f2 -d\ )

[ -z "$ROOT" ] && CONF=${CONF:-/etc/slackpkg}
[ -n "$ROOT" ] && CONF=${CONF:-"${ROOT}/etc/slackpkg"}

SOURCE=$(sed -n '
  # Remove leading and trailing blanks
  s/^[[:blank:]]*//
  s/[[:blank:]]*$//
  # Only one token is allowed per line
  /[[:blank:]]/d
  # A single solidus should end the URI
  s,[/]*$,/,
  # Print the lines beginning with one of the URI schemes we look for
  \@^file://@p
  \@^cdrom://@p
  \@^local://@p
  \@^https\{0,1\}://@p
  \@^ftps\{0,1\}://@p' $CONF/mirrors)
PATH='' builtin source $CONF/slackpkg.conf
WORKDIR=${ROOT}/${WORKDIR}
ERROR=""

# Set temporary directory
#
mkdir -p ${ROOT}/tmp
TMPDIR=$(mktemp -p ${ROOT}/tmp -d slackpkg.XXXXXX 2>/dev/null)
if [ $? -ne 0 ]; then
  TMPDIR="${ROOT}/tmp/slackpkg.${RANDOM}"
  mkdir -p -m 700 $TMPDIR || TMPDIR="FAILED"
fi

#
# Load the slackpkg functions
#
. /usr/libexec/slackpkg/core-functions.sh

#========================================================================
#
# COMMAND LINE PARSING
#
if [ $# -eq 0 ]; then
  usage
fi

while [ -n "$1" ] ; do
  case $1 in
    -delall=on)
      DELALL=on
      shift
    ;;
    -delall=off)
      DELALL=off
      shift
    ;;
    -checkmd5=on)
      CHECKMD5=on
      shift
    ;;
    -checkmd5=off)
      CHECKMD5=off
      shift
    ;;
    -checkgpg=on)
      CHECKGPG=on
      shift
    ;;
    -checkgpg=off)
      CHECKGPG=off
      shift
    ;;
    -checksize=on)
      CHECKSIZE=on
      shift
    ;;
    -checksize=off)
      CHECKSIZE=off
      shift
    ;;
    -postinst=on)
      POSTINST=on
      shift
    ;;
    -postinst=off)
      POSTINST=off
      shift
    ;;
    -onoff=on)
      ONOFF=on
      shift
    ;;
    -onoff=off)
      ONOFF=off
      shift
    ;;
    -download_all=on)
      DOWNLOAD_ALL=on
      shift
    ;;
    -download_all=off)
      DOWNLOAD_ALL=off
      shift
    ;;
    -dialog=on)
      DIALOG=on
      shift
    ;;
    -dialog=off)
      DIALOG=off
      shift
    ;;
    -dialog_maxargs=*)
      DIALOG_MAXARGS=$(echo $1 | cut -f2 -d=)
      shift
    ;;
    -batch=on)
      BATCH=on
      shift
    ;;
    -batch=off)
      BATCH=off
      shift
    ;;
    -only_new_dotnew=on)
      ONLY_NEW_DOTNEW=on
      shift
    ;;
    -only_new_dotnew=off)
      ONLY_NEW_DOTNEW=off
      shift
    ;;
    -orig_backups=on)
      ORIG_BACKUPS=on
      shift
    ;;
    -orig_backups=off)
      ORIG_BACKUPS=off
      shift
    ;;
    -use_includes=on)
      USE_INCLUDES=on
      shift
    ;;
    -use_includes=off)
      USE_INCLUDES=off
      shift
    ;;
    -spinning=on)
      SPINNING=on
      shift
    ;;
    -spinning=off)
      SPINNING=off
      shift
    ;;
    -default_answer=y|-default_answer=yes)
      DEFAULT_ANSWER=y
      shift
    ;;
    -default_answer=n|-default_answer=no)
      DEFAULT_ANSWER=n
      shift
    ;;
    -mirror=*)
      SOURCE=$(echo $1 | cut -f2 -d=)
      shift
    ;;
    install|reinstall|upgrade|remove|download)
      CMD=$1
      shift
      if [ -n "$1" ]; then
        if echo $1 | egrep -q "^\.{0,2}/" ; then
          if [ -e $1 ]; then
            INPUTLIST=$(cat $1 | tr "\n" " ")
          else
            echo -e "The file $1 doesn't exist.\n"
            cleanup
          fi
        else
          #
          # Sanitize the argument. We have some problems with dots
          # and plus (.+)
          #
          #INPUTLIST="$(echo $@ | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g')"
          INPUTLIST="$@"
        fi
      elif [ "$CMD" != "blacklist" ]; then
        usage
      fi
      shift $#
    ;;
    blacklist)
      CMD=$1
      shift $#
    ;;
    update)
      CMD=$1
      shift
      if [ "$1" = "gpg" ]; then
        UPARG="$1"
        shift
      fi
    ;;
    install-new|upgrade-all|clean-system|new-config|check-updates|show-changelog|help)
      CMD=$1
      shift
      if [ -n "$1" ]; then
        echo -e "\n$CMD: Ignoring extra arguments: $@" >&2 >&1
        shift $#
      fi
    ;;
    generate-template|install-template|remove-template|search|file-search|info)
      CMD=$1
      shift
      if [ -n "$1" ]; then
        ARG=$1
        shift
      else
        usage
      fi

      if [ -n "$1" ]; then
        echo -e "\n$CMD: Ignoring extra arguments: $@" >&2 >&1
        shift $#
      fi
    ;;
    *)
  echo -e "\n$1: Unknown option.\n"
  usage
    ;;
  esac
done

#========================================================================
#
# SYSTEM SETUP
#
system_setup

#========================================================================
#
# SYNTAX CHECKING
#
system_checkup

#========================================================================
#
# READ EXTRA FUNCTIONS
#

# If you want a new function or need a rewrite of an existing
# feature, you can put your new function in a shell script under
# /usr/libexec/slackpkg/functions.d/
#
# Remember - the new function scripts need to be executable
#
for i in /usr/libexec/slackpkg/functions.d/*.sh; do
  if [ -x $i ]; then
    . $i
  fi
done

#========================================================================
#
# MAIN PROGRAM
#

#
# A *BIG* case with all slackpkg commands -:)
#
case "$CMD" in
  help)
    full_usage
    ;;
  check-updates)
    # output to stdout if no change, or stderr if changes. Will cause
    # cron jobs to notify system admin
    if checkchangelog 1>/dev/null 2>/dev/null ; then
      echo "Slackpkg: No updated packages since last check."
    else
      echo "Slackpkg: Updated packages are available since last check." >&2
      PENDING_UPDATES=1
    fi
    ;;
  show-changelog)
    # display changelog and exit
    if [ -e ${WORKDIR}/ChangeLog.txt ]; then
      $MORECMD ${WORKDIR}/ChangeLog.txt
    else
      echo "ChangeLog.txt file not found. Aborting"
    fi
    POSTINST=off
    ;;
  update)
    # If you are using "slackpkg update gpg" OR the system
    # doesn't have Slackware GPG key, download and install
    # the key
    #
    if [ "$UPARG" = "gpg" ] || [ "$GPGFIRSTTIME" = "0" ]; then
      #
      # Creates .gnupg directory if doesn't exist
      # without this dir, gpg got an error.
      #
      if ! [ -e ~/.gnupg ]; then
        mkdir ~/.gnupg
      fi
      getfile ${SOURCE}GPG-KEY $TMPDIR/gpgkey
      gpg --yes --batch --delete-key "$SLACKKEY" &>/dev/null
      gpg --import $TMPDIR/gpgkey &>/dev/null && \
      echo -e "\t\t\tSlackware Linux Project's GPG key added"
      if [ "$UPARG" = "gpg" ]; then
        cleanup
      fi
    fi
    echo "Updating the package lists..."
    updatefilelists
  ;;
  install)
    makelist $INPUTLIST
    if [ -n "$LIST" ]; then
      showlist "$LIST" $CMD
      install_pkg
    else
      echo -e "No packages match the pattern for install. Try:"
      echo -e "\n\t$0 reinstall|upgrade $2\n"
      POSTINST=off
    fi
  ;;
  reinstall)
    makelist $INPUTLIST
    if [ -n "$LIST" ]; then
      showlist "$LIST" $CMD
      install_pkg
    else
      echo -e "No packages match the pattern for reinstall. Try:"
      echo -e "\n\t$0 install|upgrade $2\n"
      POSTINST=off
    fi
  ;;
  upgrade)
    sanity_check
    makelist $INPUTLIST
    if [ -n "$LIST" ]; then
      showlist "$LIST" $CMD
      upgrade_pkg
    else
      echo -e "No packages match the pattern for upgrade. Try:"
      echo -e "\n\t$0 install|reinstall $2\n"
      POSTINST=off
    fi
  ;;
  download)
    makelist $INPUTLIST
    DELALL="off"
    if ! [ "$LIST" = "" ]; then
      showlist "$LIST" $CMD
      for i in $SHOWLIST; do
        getpkg $i true
      done
    else
      echo -e "No packages match the pattern for download."
      POSTINST=off
    fi
  ;;
  remove)
    makelist $INPUTLIST
    if [ "$LIST" = "" ]; then
      echo -e "The file(s) $INPUTLIST can't be removed - package not installed.\n"
      cleanup
    fi
    showlist "$LIST" $CMD
    remove_pkg
  ;;
  clean-system)
    makelist $INPUTLIST
    if [ -n "$LIST" ]; then
      showlist "$LIST" remove
      remove_pkg
    else
      echo -e "No packages match the pattern for clean-system\n"
      POSTINST=off
    fi
  ;;
  upgrade-all)
    sanity_check
    makelist $INPUTLIST
    if ! [ -n "${LIST}" ]; then
      echo -e "No packages match the pattern for upgrade. Try:"
      echo -e "\n\t$0 install|reinstall $2\n"
      POSTINST=off
    else
      showlist "$LIST" upgrade
      if [ "$DOWNLOAD_ALL" = "on" ]; then
        OLDDEL="$DELALL"
        DELALL="off"
        for i in $SHOWLIST; do
          getpkg $i true
        done
        DELALL="$OLDDEL"
      fi
      FOUND=""
      FOUND=$(echo $SHOWLIST | tr -s ' ' "\n" | grep "slackpkg-[0-9]")
      if [ "$FOUND" != "" ]; then
        getpkg $FOUND upgradepkg Upgrading
        echo -e "slackpkg was upgraded - you will need start the upgrade process again...\n"
        cleanup
        exit 0
      fi
      for i in pkgtools aaa_glibc-solibs glibc-solibs aaa_libraries aaa_elflibs readline sed; do
        FOUND=""
        FOUND=$(echo $SHOWLIST | tr -s ' ' "\n" | grep "${i}-[0-9]")
        if [ "$FOUND" != "" ]; then
          getpkg $FOUND upgradepkg Upgrading
        fi
      done
      upgrade_pkg
    fi
  ;;
  install-new)
    makelist ${INPUTLIST}
    if ! [ -n "${LIST}" ]; then
      echo -e "No packages match the pattern for install. Try:"
      echo -e "\n\t$0 upgrade|reinstall $2\n"
      POSTINST=off
    else
      showlist "$LIST" install
      install_pkg
    fi
  ;;
  blacklist)
    echo -e "Edit /etc/slackpkg/blacklist to add or remove packages."
    echo -e ""
    echo -e "Packages in blacklist:\n"
    grep -v "^#" $CONF/blacklist | $MORECMD
    echo -e ""
  ;;
  file-search)
    PATTERN=$(echo $ARG | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g' -e 's/ /\|/g')
    makelist $PATTERN

    if [ "$LIST" = "" ]; then
      echo -e "No packages contains \"$PATTERN\" file."
    else
      echo -e "The list below shows the packages that contains \"$PATTERN\" file.\n"
      searchlist "$LIST"
      echo -e "\nYou can search specific packages using \"slackpkg search package\".\n"
    fi
  ;;
  search)
    PATTERN=$(echo $ARG | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g' -e 's/ /\|/g')
    makelist $PATTERN

    if [ "$LIST" = "" ]; then
      echo -e "No package name matches the pattern."
    else
      echo -e "The list below shows all packages with name matching \"$PATTERN\".\n"
      searchlist "$LIST"
      echo -e "\nYou can search specific files using \"slackpkg file-search file\".\n"
    fi
  ;;
  info)
    PATTERN=$(echo $ARG | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g')
    NAME=$(cutpkg $PATTERN)
    awk -F: "/PACKAGE NAME:.* ${NAME}-[^-]+-(${ARCH}|fw|noarch)-[^-]+/,/^$/ {
      found=1
      if (\$1 ~ /"$NAME"/) {
        print \$PATTERN
      } else {
        print \$0
      }
    }
    END {
      if ( found != 1 ) {
        print \"No packages found! Try:\n\n\tslackpkg search $PATTERN\n\nand choose one (and ONLY one package).\n\"
      }
    }" ${WORKDIR}/PACKAGES.TXT 2>/dev/null
  ;;
  new-config)
    POSTINST=on
  ;;
  generate-template)
    TEMPLATE=$ARG.template
    if [ -e $TEMPLATEDIR/$TEMPLATE ]; then
      echo -e "\
\"$TEMPLATE\" already exists!\n\
\nDo you want to overwrite $TEMPLATE (y/N)? \c"
      answer
      if [ "$ANSWER" = "Y" -o "$ANSWER" = "y" ]; then
        rm $TEMPLATEDIR/$TEMPLATE
        echo
      else
        cleanup
      fi
    fi
    generate_template $ARG
  ;;
  install-template)
    TEMPLATE=$ARG.template
    if [ -e $TEMPLATEDIR/$TEMPLATE ]; then
      ( cd $TEMPLATEDIR
        parse_template $TEMPLATE
      )
      INPUTLIST=$(cat ${TMPDIR}/${TEMPLATE}.tmp | tr "\n" " ")
    else
      echo -e "$ARG template not found!"
      cleanup
    fi

    makelist $INPUTLIST
    if [ -n "$LIST" ]; then
      showlist "$LIST" $CMD
      install_pkg
    else
      echo -e "All packages from $ARG template are already installed"
      POSTINST=off
    fi
  ;;
  remove-template)
    TEMPLATE=$ARG.template
    if [ -e $TEMPLATEDIR/$TEMPLATE ]; then
      ( cd $TEMPLATEDIR
        parse_template $TEMPLATE
      )
      INPUTLIST=$(cat ${TMPDIR}/${TEMPLATE}.tmp | tr "\n" " ")
    else
      echo -e "$ARG template not found!"
      cleanup
    fi

    makelist $INPUTLIST
    if [ "$LIST" = "" ]; then
      echo -e "The template $ARG can't be removed - it isn't installed.\n"
      cleanup
    fi
    showlist "$LIST" $CMD
    remove_pkg
  ;;
  *)
    usage
  ;;
esac

#
# Executes the post-install. This is the default
# Before runs post-install, check if the slackpkg option is
# remove, search, update, info or clean-system.
# That options don't change configurations files and, if
# someone remove the kernel, i hope he knows what is doing.
#
for i in check-updates remove search file-search update info blacklist \
   clean-system download generate-template remove-template; do
  if [ "$CMD" = "$i" ]; then
    POSTINST=off
  fi
done

if [ "$POSTINST" != "off" ]; then
  lookkernel
  looknew
fi

cleanup