#!/bin/sh # # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999 Patrick Volkerding, Moorhead, MN USA # Copyright 2001, 2004 Slackware Linux, Inc., Concord, CA USA # All rights reserved. # Copyright 2007, 2009, 2010, 2011, 2013, 2015 Patrick Volkerding, Sebeka, MN, USA # # 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. # # Sat Apr 25 21:18:53 UTC 2009 # Converted to use new pkgbase() function to remove pathname and # valid package extensions. # # Wed Oct 31 16:28:46 CDT 2007 # * Thanks to Gabriele Inghirami for a patch allowing this script to work # with much larger numbers of installed packages. # Wed, 27 Apr 1994 00:06:50 -0700 (PDT) # * Optimization by David Hinds. # Sun Oct 24 23:11:40 BST 2004 # * Further optimisations by Jim Hawkins # - dramatically improved the speed of the "View" option # Thu Nov 04 12:19:56 BST 2004 # * More optimisations by Jim Hawkins # - improved "Remove" speed in a similar manner to "View" # Wed Jan 12 16:53:48 GMT 2005 # * Fixed quoting bug thanks to Lasse Collin # Wed Jan 26 23:06:22 GMT 2005 # * Fix for non-standard package descriptions by Jim Hawkins export TEXTDOMAIN=slint if [ -f /tmp/.SlintInstallationLANG ]; then LANG=$( /dev/null 2>&1 ; then # good true else # bad gettext " You can't run pkgtool from the rootdisk until you've mounted your Linux \ partitions beneath /mnt. Here are some examples: If your root partition is /dev/sda1 you would type: mount /dev/sda1 /mnt Now you can find a list of all your partitions in /mnt/etc/fstab. Then, supposing your /usr partition is /dev/sda2, you must do this: mount /dev/sda2 /mnt/usr Please mount your Linux partitions and then run pkgtool again. " 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=$(pkgbase $1) # 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 $(cat $TMP/return | tr -d "\042") do if [ -r $ADM_DIR/packages/$pkg_name ]; then dialog --title "`gettext "PACKAGE REMOVAL IN PROGRESS"`" --cr-wrap --infobox \ "`eval_gettext " Removing package \\\$pkg_name. 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 would like to \ watch the progress, flip over to another virtual console and type: tail -f \\\$TMP/PKGTOOL.REMOVED"`" 13 80 export ROOT=$TARGET_DIR removepkg $pkg_name >> $LOG 2> /dev/null else echo "No such package: pkg_name. Can't remove." >> $LOG fi done } create_list_of_installed_packages() { FILES=$(ls $ADM_DIR/packages) ViewInfo="`gettext "View information about package"`" if [ -n "$FILES" ]; then cd $ADM_DIR/packages { grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \ | sed -n 'h;n;/\x00/{h;n;};x;s/ */ /g;s/ $//;s/[\"`$]/\\&/g s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "\3" "'"$ViewInfo"' \1" \\/;p' > $TMP/list_of_installed_packages \ fi } create_list_of_files_to_remove () { FILES=$(ls $ADM_DIR/packages) SelectUnselect="`gettext "Select\/Unselect removing package"`" if [ -n "$FILES" ]; then cd $ADM_DIR/packages { grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \ | sed -n 'h;n;/\x00/{h;n;};x;s/ */ /g;s/ $//;s/[\"`$]/\\&/g s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "\3" off "'"$SelectUnselect"' \1" \\/;p' > $TMP/temporary_list \ fi } # 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 -source_mounted | --source-mounted) SOURCE_MOUNTED="always" ; shift 1 ;; -source_dir | --source_dir) SOURCE_DIR=$2 ; shift 2 ;; -target_dir | --target_dir) TARGET_DIR=$2 ADM_DIR=$TARGET_DIR/var/log shift 2 ;; -source_device | --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 Version=14.2 dialog --visit-items --title "`eval_gettext "Slint Package Tool (pkgtool version \\\${Version})"`" \ --menu "`gettext " Welcome to the Slint package tool Which option would you like?"`" 0 0 0 \ "Current" "`gettext "Install packages from the current directory"`" \ "Other" "`gettext "Install packages from some other directory"`" \ "Remove" "`gettext "Remove packages that are currently installed"`" \ "View" "`gettext "View the list of files contained in a package"`" \ "Setup" "`gettext "Choose Slint installation scripts to run again"`" \ "Exit" "`gettext "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 -n 'dialog --visit-items --title "' > $TMP/setupscr gettext "SELECT SYSTEM SETUP SCRIPTS" >> $TMP/setupscr echo -n '" --item-help --checklist "' >> $TMP/setupscr gettext "Please use the spacebar to select the setup \ scripts to run. Hit enter when you are done selecting to run the scripts." >> $TMP/setupscr echo "\" 17 80 9 \\" >> $TMP/setupscr for script in $ADM_DIR/setup/setup.* ; do BLURB=$(grep '#BLURB' $script | cut -f2 -d '"') if [ "$BLURB" = "" ]; then BLURB="\"\"" fi BLURBl10n="$(eval_gettext "\$BLURB")" echo " \"$(basename $script | cut -f2- -d .)\" \"$BLURBl10n\" \"no\" \"$BLURBl10n\" \\" >> $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 # Let's execute the internationalized scripts in /usr/lib/config # instead if present and executables, as in SeTconfig - Didier Spaier if [ ! -x /usr/lib/config/setup.$(echo $script | tr -d \") ]; then scrpath=$ADM_DIR/setup/setup.$(echo $script | tr -d \") rootdevice="$(mount | head -n 1 | cut -f 1 -d ' ')" ( COLOR=on ; cd $TARGET_DIR ; . $scrpath / $rootdevice ) else rootdevice="$(mount | head -n 1 | cut -f 1 -d ' ')" ( COLOR=on ; cd $TARGET_DIR ; . /usr/lib/config/setup.$(echo $script | tr -d \") / $rootdevice ) fi done fi rm -f $TMP/return $TMP/setupscr continue fi # end Setup if [ "$REPLY" = "View" ]; then create_list_of_installed_packages 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 -n 'dialog --visit-items $DEFITEM --item-help --menu "' gettext "Please select the package you wish to view." echo '" 17 80 10 \ --file $TMP/list_of_installed_packages \' echo "2> $TMP/return" ) > $TMP/viewscr while [ 0 ]; do . $TMP/viewscr if [ ! "$(cat $TMP/return)" = "" ]; then DEFITEM="--default-item $(cat $TMP/return)" PkG=$(cat $TMP/return) dialog --title "`eval_gettext "CONTENTS OF PACKAGE: \\\$PkG"`" --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 $TMP/list_of_installed_packages # 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 ( create_list_of_files_to_remove #call the function to create a list of installed packages cat << EOF dialog --visit-items --title "` gettext "SELECT PACKAGES TO REMOVE"`" --item-help --checklist \ "`gettext "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 80 11 \ --file $TMP/temporary_list \\ EOF 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 if [ "$(cat $TMP/PKGTOOL.REMOVED)" = "" ]; then rm -f $TMP/PKGTOOL.REMOVED dialog --title "`gettext \"NO PACKAGES REMOVED\"`" --msgbox \ "`gettext \"Hit OK to return to the main menu.\"`" 5 80 else dialog --title "`gettext \"PACKAGE REMOVAL COMPLETE\"`" --msgbox \ "`eval_gettext \"The packages have been removed. A complete log of the \ files that were removed has been created in \\\$TMP/PKGTOOL.REMOVED.\"`" 0 0 fi rm -f $TMP/rmscript $TMP/return $TMP/tmpmsg $TMP/SeT* $TMP/temporary_list chmod 755 / chmod 1777 /tmp # No, return to the main menu: # exit elif [ "$REPLY" = "Other" ]; then dialog --title "`gettext "SELECT SOURCE DIRECTORY"`" --inputbox "`gettext "Please enter the name of the directory that you wish to \ install packages from:"`" 10 80 2> $TMP/pkgdir if [ $? = 1 ]; then rm -f $TMP/pkgdir $TMP/SeT* dialog --clear exit fi SOURCE_DIR="$(cat $TMP/pkgdir)" SOURCE_MOUNTED="always" DISK_SETS="disk" chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp rm -f $TMP/pkgdir if [ ! -d $SOURCE_DIR ]; then dialog --title "`gettext "DIRECTORY NOT FOUND"`" --msgbox "`eval_gettext "The directory you want to \ install from (\\\$SOURCE_DIR) \ does not seem to exist. Please check the directory and then try again."`" \ 10 80 dialog --clear exit fi break; else # installing from current directory SOURCE_MOUNTED="always" SOURCE_DIR="$PWD" DISK_SETS="disk" chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp break; fi done fi mount_the_source() { # is the source supposed to be mounted already? if [ "$SOURCE_MOUNTED" = "always" ]; then # The source should already be mounted, so we test it if [ ! -d $SOURCE_DIR ]; then # the directory is missing eval_gettext "Your source device cannot be accessed properly. Please be sure that it is mounted on \$SOURCE_DIR, \ and that the Slint disks are found in subdirectories \ of \$SOURCE_DIR like specified." > $TMP/tmpmsg dialog --title "`gettext "MOUNT ERROR"`" --msgbox "$(cat $TMP/tmpmsg)" 11 80 rm -f $TMP/tmpmsg exit 1; fi return 0; fi NumDisk=$1 dialog --visit-items --title "`gettext "INSERT DISK"`" --menu "`eval_gettext "Please insert disk \\\$NumDisk and \ press ENTER to continue."`" \ 11 80 3 \ "Continue" "`gettext "Continue with the installation"`" \ "Skip" "`gettext "Skip the current disk series"`" \ "Quit" "`gettext "Abort the installation process"`" 2> $TMP/reply if [ ! $? = 0 ]; then REPLY="Quit" else REPLY="$(cat $TMP/reply)" fi rm -f $TMP/reply if [ "$REPLY" = "Skip" ]; then return 1; fi if [ "$REPLY" = "Quit" ]; then dialog --title "`gettext "ABORTING"`" --msgbox "`gettext "Aborting software installation."`" 5 80 chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp exit 1; fi; # Old line: # mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR # New ones: (thanks to Andy Schwierskott!) go_on=y not_successfull_mounted=1 while [ "$go_on" = y -a "$not_successfull_mounted" = 1 ]; do mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR not_successfull_mounted=$? if [ "$not_successfull_mounted" = 1 ]; then mount_answer=x while [ "$mount_answer" != "y" -a "$mount_answer" != "q" ] ; do dialog --visit-items --title "`gettext "MOUNT PROBLEM "`" --menu "`gettext "Media was not successfully \ mounted! Do you want to \ retry, or quit?"`" 10 80 2 \ "Yes" "`gettext "Try to mount the disk again"`" \ "No" "`gettext "No, abort."`" 2> $TMP/mntans mount_answer="$(cat $TMP/mntans)" rm -f $TMP/mntans if [ "$mount_answer" = "Yes" ]; then mount_answer="y" else mount_answer="q" fi done go_on=$mount_answer fi done test $not_successfull_mounted = 0 } umount_the_source() { if [ ! "$SOURCE_MOUNTED" = "always" ]; then umount $SOURCE_DEVICE 1> /dev/null 2>&1 fi; } install_disk() { mount_the_source $1 if [ $? = 1 ]; then umount_the_source; return 1; fi CURRENT_DISK_NAME="$1" PACKAGE_DIR=$SOURCE_DIR if [ "$SOURCE_MOUNTED" = "always" -a ! "$DISK_SETS" = "disk" ]; then PACKAGE_DIR=$PACKAGE_DIR/$1 fi # If this directory is missing or contains no *.t?z files, bail. if [ ! -d $PACKAGE_DIR ]; then return 1 fi if ! ls $PACKAGE_DIR/*.t?z 1> /dev/null 2> /dev/null ; then return 1 fi # # look for tagfile for this series and copy into $TMP/tagfile # touch $TMP/tagfile # "$DISK_SETS" = "disk" # It's possible that the tagfile was specified on the command line. If that's # the case, then we'll just override whatever we figured out up above. # If there's a catalog file present, use it to check for missing files. # If not, forget about that and install whatever's there. # Install the packages: for PACKAGE_FILENAME in $PACKAGE_DIR/*.t?z; do if [ "$PACKAGE_FILENAME" = "$PACKAGE_DIR/*.t?z" ]; then continue; fi installpkg -root $TARGET_DIR -menu $PACKAGE_FILENAME ERROR=$? # Check for abort: if [ "$ERROR" = "99" ]; then umount_the_source; chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp exit 1; fi done OUTTAHERE="false" if [ -r $PACKAGE_DIR/install.end ]; then OUTTAHERE="true" fi umount_the_source; if [ "$OUTTAHERE" = "true" ]; then return 1; fi } # /* main() */ ;) install_disk single_disk; if [ -r $TMP/tagfile ]; then rm $TMP/tagfile fi dialog --clear chmod 755 $TARGET_DIR $TARGET_DIR/var $TARGET_DIR/usr chmod 1777 $TARGET_DIR/tmp