#!/bin/sh # # Copyright 1993, 1994, 1995, 1996, 1997, # 1998, 1999 Patrick Volkerding, Moorhead, MN USA # Copyright 2001 Slackware Linux, Inc., Concord, CA USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Wed, 27 Apr 1994 00:06:50 -0700 (PDT) # Optimization by David Hinds. SOURCE_DIR=/var/log/mount ASK="tagfiles" if [ -L /bin/chmod -a -L /bin/chown ]; then # probably on the bootdisk using busybox TARGET_DIR=/mnt TMP=/mnt/var/log/setup/tmp if mount | grep "on /mnt" 1> /dev/null 2>&1 ; then # good true else # bad echo echo echo "You can't run pkgtool from the rootdisk until you've mounted your Linux" echo "partitions beneath /mnt. Here are some examples of this:" echo echo "If your root partition is /dev/hda1, and is using ext2fs, you would type:" echo "mount /dev/hda1 /mnt -t ext2" echo echo "Then, supposing your /usr partition is /dev/hda2, you must do this:" echo "mount /dev/hda2 /mnt/usr -t ext2" echo echo "Please mount your Linux partitions and then run pkgtool again." echo exit fi else TARGET_DIR=/ TMP=/var/log/setup/tmp fi if [ ! -d $TMP ]; then mkdir -p $TMP chmod 700 $TMP fi ADM_DIR=$TARGET_DIR/var/log LOG=$TMP/PKGTOOL.REMOVED # remove whitespace crunch() { while read FOO ; do echo $FOO done } package_name() { STRING=`basename $1 .tgz` # Check for old style package name with one segment: if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then echo $STRING else # has more than one dash delimited segment # Count number of segments: INDEX=1 while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do INDEX=`expr $INDEX + 1` done INDEX=`expr $INDEX - 1` # don't include the null value # If we don't have four segments, return the old-style (or out of spec) package name: if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then echo $STRING else # we have four or more segments, so we'll consider this a new-style name: NAME=`expr $INDEX - 3` NAME="`echo $STRING | cut -f 1-$NAME -d -`" echo $NAME # cruft for later #VER=`expr $INDEX - 2` #VER="`echo $STRING | cut -f $VER -d -`" #ARCH=`expr $INDEX - 1` #ARCH="`echo $STRING | cut -f $ARCH -d -`" #BUILD="`echo $STRING | cut -f $INDEX -d -`" fi fi } remove_packages() { for pkg_name in $* do if [ -r $ADM_DIR/packages/$pkg_name ]; then dialog --title "PACKAGE REMOVAL IN PROGRESS" --cr-wrap --infobox "nRemoving package $pkg_name.n n Since each file must be checked against the contents of every other installed package to avoid wiping out areas of overlap, this process can take quite some time. If you'd like to watch the progress, flip over to another virtual console and type:n n tail -f $TMP/PKGTOOL.REMOVEDn" 13 60 export ROOT=$TARGET_DIR removepkg $pkg_name >> $LOG 2> /dev/null else echo "No such package: $pkg_name. Can't remove." >> $LOG fi done } # Here, we read the list of arguments passed to the pkgtool script. if [ $# -gt 0 ]; then # there are arguments to the command while [ $# -gt 0 ]; do case "$1" in "-sets") DISK_SETS=`echo $2 | tr "[A-Z]" "[a-z]"` ; shift 2 ;; "-source_mounted") SOURCE_MOUNTED="always" ; shift 1 ;; "-ignore_tagfiles") ASK="never" ; shift 1 ;; "-tagfile") USETAG=$2 ; shift 2 ;; "-source_dir") SOURCE_DIR=$2 ; shift 2 ;; "-target_dir") TARGET_DIR=$2 ADM_DIR=$TARGET_DIR/var/log shift 2 ;; "-source_device") SOURCE_DEVICE=$2 ; shift 2 ;; esac done else # there were no arguments, so we'll get the needed information from the # user and then go on. CMD_START="true" rm -f $TMP/SeT* while [ 0 ]; do dialog --title "Slackware Package Tool (pkgtool version 9.0.0)" --menu "nWelcome to the Slackware package tool.n nWhich option would you like?n" 17 75 7 "Current" "Install packages from the current directory" "Other" "Install packages from some other directory" "Floppy" "Install packages from floppy disks" "Remove" "Remove packages that are currently installed" "View" "View the list of files contained in a package" "Setup" "Choose Slackware installation scripts to run again" "Exit" "Exit Pkgtool" 2> $TMP/reply if [ ! $? = 0 ]; then rm -f $TMP/reply dialog --clear exit fi REPLY="`cat $TMP/reply`" rm -f $TMP/reply if [ "$REPLY" = "Exit" ]; then dialog --clear exit fi if [ "$REPLY" = "Setup" ]; then echo 'dialog --title "SELECT SYSTEM SETUP SCRIPTS" --item-help --checklist "Please use the spacebar to select the setup scripts to run. Hit enter when you are done selecting to run the scripts." 17 70 9 ' > $TMP/setupscr for script in $ADM_DIR/setup/setup.* ; do BLURB=`grep '#BLURB' $script | cut -b8-` if [ "$BLURB" = "" ]; then BLURB="""" fi echo " "`basename $script | cut -f2- -d .`" $BLURB "no" $BLURB \" >> $TMP/setupscr done echo "2> $TMP/return" >> $TMP/setupscr . $TMP/setupscr if [ ! "`cat $TMP/return`" = "" ]; then # Run each script: for script in `cat $TMP/return` ; do scrpath=$ADM_DIR/setup/setup.`echo $script | tr -d "` rootdevice="`mount | head -1 | cut -f 1 -d ' '`" ( COLOR=on ; cd $TARGET_DIR ; . $scrpath / $rootdevice ) done fi rm -f $TMP/return $TMP/setupscr continue fi # end Setup if [ "$REPLY" = "View" ]; then DEFITEM="" export DEFITEM dialog --title "SCANNING" --infobox "Please wait while Pkgtool scans your system to determine which packages you have installed and prepares a list for you." 0 0 echo 'dialog $DEFITEM --item-help --menu "Please select the package you wish to view." 17 68 10 ' > $TMP/viewscr for name in `ls $ADM_DIR/packages` ; do pkg_name=`package_name $name` BLURB="`sed -n "/$pkg_name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" # Let's have some backward compatibility with the interim beta (for now): if [ "$BLURB" = "" ]; then BLURB="`sed -n "/$name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" fi echo " "$name" "$BLURB" "View information about package $name" \" >> $TMP/viewscr done echo "2> $TMP/return" >> $TMP/viewscr while [ 0 ]; do . $TMP/viewscr if [ ! "`cat $TMP/return`" = "" ]; then DEFITEM="--default-item `cat $TMP/return`" dialog --title "CONTENTS OF PACKAGE: `cat $TMP/return`" --no-shadow --textbox "$ADM_DIR/packages/`cat $TMP/return`" 0 0 2> /dev/null else break fi done rm -f $TMP/return $TMP/viewscr $TMP/tmpmsg # This will clean up after most defective packages: chmod 755 / chmod 1777 /tmp continue fi if [ "$REPLY" = "Remove" ]; then dialog --title "SCANNING" --infobox "Please wait while Pkgtool scans your system to determine which packages you have installed and prepares a list for you." 0 0 # end section cat << EOF > $TMP/rmscript dialog --title "SELECT PACKAGES TO REMOVE" --item-help --checklist "Please select the packages you wish to Remove. Use the spacebar to select packages to delete, and the UP/DOWN arrow keys to scroll up and down through the entire list." 20 75 11 \ EOF for name in `ls $ADM_DIR/packages` ; do pkg_name=`package_name $name` BLURB="`sed -n "/$pkg_name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" # Let's have some backward compatibility with the interim beta (for now): if [ "$BLURB" = "" ]; then BLURB="`sed -n "/$name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" fi echo " "$name" "$BLURB" off "Select/Unselect removing package $name" \" >> $TMP/rmscript done echo "2> $TMP/return" >> $TMP/rmscript if [ -L $LOG -o -r $LOG ]; then rm -f $LOG fi cat /dev/null > $LOG chmod 600 $LOG chmod 700 $TMP/rmscript export ADM_DIR; $TMP/rmscript remove_packages `cat $TMP/return | tr -d "