LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 721|回复: 1

Dialog经典--Slackware软件包管理程序

[复制链接]
发表于 2003-9-3 13:43:26 | 显示全部楼层 |阅读模式
pkgtool

  1. #!/bin/sh
  2. #
  3. # Copyright 1993, 1994, 1995, 1996, 1997,
  4. #    1998, 1999  Patrick Volkerding,  Moorhead, MN  USA
  5. # Copyright 2001  Slackware Linux, Inc.,  Concord, CA  USA
  6. #    All rights reserved.
  7. #
  8. # Redistribution and use of this script, with or without modification, is
  9. # permitted provided that the following conditions are met:
  10. #
  11. # 1. Redistributions of this script must retain the above copyright
  12. #    notice, this list of conditions and the following disclaimer.
  13. #
  14. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  15. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  17. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  22. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  23. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. #

  25. # Wed, 27 Apr 1994 00:06:50 -0700 (PDT)
  26. # Optimization by David Hinds.

  27. SOURCE_DIR=/var/log/mount
  28. ASK="tagfiles"
  29. if [ -L /bin/chmod -a -L /bin/chown ]; then # probably on the bootdisk using busybox
  30. TARGET_DIR=/mnt
  31. TMP=/mnt/var/log/setup/tmp
  32. if mount | grep "on /mnt" 1> /dev/null 2>&1 ; then # good
  33.   true
  34. else # bad
  35.   echo
  36.   echo
  37.   echo "You can't run pkgtool from the rootdisk until you've mounted your Linux"
  38.   echo "partitions beneath /mnt. Here are some examples of this:"
  39.   echo
  40.   echo "If your root partition is /dev/hda1, and is using ext2fs, you would type:"
  41.   echo "mount /dev/hda1 /mnt -t ext2"
  42.   echo
  43.   echo "Then, supposing your /usr partition is /dev/hda2, you must do this:"
  44.   echo "mount /dev/hda2 /mnt/usr -t ext2"
  45.   echo
  46.   echo "Please mount your Linux partitions and then run pkgtool again."
  47.   echo
  48.   exit
  49. fi
  50. else
  51. TARGET_DIR=/
  52. TMP=/var/log/setup/tmp
  53. fi
  54. if [ ! -d $TMP ]; then
  55. mkdir -p $TMP
  56. chmod 700 $TMP
  57. fi
  58. ADM_DIR=$TARGET_DIR/var/log
  59. LOG=$TMP/PKGTOOL.REMOVED

  60. # remove whitespace
  61. crunch() {
  62.   while read FOO ; do
  63.     echo $FOO
  64.   done
  65. }

  66. package_name() {
  67.   STRING=`basename $1 .tgz`
  68.   # Check for old style package name with one segment:
  69.   if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then
  70.     echo $STRING
  71.   else # has more than one dash delimited segment
  72.     # Count number of segments:
  73.     INDEX=1
  74.     while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do
  75.       INDEX=`expr $INDEX + 1`
  76.     done
  77.     INDEX=`expr $INDEX - 1` # don't include the null value
  78.     # If we don't have four segments, return the old-style (or out of spec) package name:
  79.     if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then
  80.       echo $STRING
  81.     else # we have four or more segments, so we'll consider this a new-style name:
  82.       NAME=`expr $INDEX - 3`
  83.       NAME="`echo $STRING | cut -f 1-$NAME -d -`"
  84.       echo $NAME
  85.       # cruft for later ;)
  86.       #VER=`expr $INDEX - 2`
  87.       #VER="`echo $STRING | cut -f $VER -d -`"
  88.       #ARCH=`expr $INDEX - 1`
  89.       #ARCH="`echo $STRING | cut -f $ARCH -d -`"
  90.       #BUILD="`echo $STRING | cut -f $INDEX -d -`"
  91.     fi
  92.   fi
  93. }

  94. remove_packages() {
  95. for pkg_name in $*
  96. do
  97.   if [ -r $ADM_DIR/packages/$pkg_name ]; then
  98.    dialog --title "PACKAGE REMOVAL IN PROGRESS" --cr-wrap --infobox \
  99. "\nRemoving package $pkg_name.\n\
  100. \n\
  101. Since each file must be checked \
  102. against the contents of every other installed package to avoid wiping out \
  103. areas of overlap, this process can take quite some time. If you'd like to \
  104. watch the progress, flip over to another virtual console and type:\n\
  105. \n\
  106. tail -f $TMP/PKGTOOL.REMOVED\n" 13 60
  107.    export ROOT=$TARGET_DIR
  108.    removepkg $pkg_name >> $LOG 2> /dev/null
  109.   else
  110.    echo "No such package: $pkg_name. Can't remove." >> $LOG
  111.   fi
  112. done
  113. }

  114. # Here, we read the list of arguments passed to the pkgtool script.
  115. if [ $# -gt 0 ]; then # there are arguments to the command
  116. while [ $# -gt 0 ]; do
  117.   case "$1" in
  118.   "-sets")
  119.    DISK_SETS=`echo $2 | tr "[A-Z]" "[a-z]"` ; shift 2 ;;
  120.   "-source_mounted")
  121.    SOURCE_MOUNTED="always" ; shift 1 ;;
  122.   "-ignore_tagfiles")
  123.    ASK="never" ; shift 1 ;;
  124.   "-tagfile")
  125.    USETAG=$2 ; shift 2 ;;
  126.   "-source_dir")
  127.    SOURCE_DIR=$2 ; shift 2 ;;
  128.   "-target_dir")
  129.    TARGET_DIR=$2
  130.    ADM_DIR=$TARGET_DIR/var/log
  131.    shift 2 ;;
  132.   "-source_device")
  133.    SOURCE_DEVICE=$2 ; shift 2 ;;
  134.   esac
  135. done
  136. else  # there were no arguments, so we'll get the needed information from the
  137.       # user and then go on.
  138. CMD_START="true"
  139. rm -f $TMP/SeT*
  140. while [ 0 ]; do
  141.   dialog --title "Slackware Package Tool (pkgtool version 9.0.0)" \
  142. --menu "\nWelcome to the Slackware package tool.\n\
  143. \nWhich option would you like?\n" 17 75 7 \
  144. "Current" "Install packages from the current directory" \
  145. "Other" "Install packages from some other directory" \
  146. "Floppy" "Install packages from floppy disks" \
  147. "Remove" "Remove packages that are currently installed" \
  148. "View" "View the list of files contained in a package" \
  149. "Setup" "Choose Slackware installation scripts to run again" \
  150. "Exit" "Exit Pkgtool" 2> $TMP/reply
  151.   if [ ! $? = 0 ]; then
  152.    rm -f $TMP/reply
  153.    dialog --clear
  154.    exit
  155.   fi
  156.   REPLY="`cat $TMP/reply`"
  157.   rm -f $TMP/reply
  158.   if [ "$REPLY" = "Exit" ]; then
  159.    dialog --clear
  160.    exit
  161.   fi
  162.   if [ "$REPLY" = "Setup" ]; then
  163.     echo 'dialog --title "SELECT SYSTEM SETUP SCRIPTS" --item-help --checklist \
  164.     "Please use the spacebar to select the setup scripts to run.  Hit enter when you \
  165. are done selecting to run the scripts." 17 70 9 \' > $TMP/setupscr
  166.     for script in $ADM_DIR/setup/setup.* ; do
  167.       BLURB=`grep '#BLURB' $script | cut -b8-`
  168.       if [ "$BLURB" = "" ]; then
  169.         BLURB=""""
  170.       fi
  171.       echo " "`basename $script | cut -f2- -d .`" $BLURB "no" $BLURB \" >> $TMP/setupscr
  172.     done
  173.     echo "2> $TMP/return" >> $TMP/setupscr
  174.     . $TMP/setupscr
  175.     if [ ! "`cat $TMP/return`" = "" ]; then
  176.       # Run each script:
  177.       for script in `cat $TMP/return` ; do
  178.         scrpath=$ADM_DIR/setup/setup.`echo $script | tr -d "`
  179.         rootdevice="`mount | head -1 | cut -f 1 -d ' '`"
  180.         ( color=on ; cd $TARGET_DIR ; . $scrpath / $rootdevice )
  181.       done
  182.     fi
  183.     rm -f $TMP/return $TMP/setupscr
  184.     continue
  185.   fi # end Setup
  186.   if [ "$REPLY" = "View" ]; then
  187.    DEFITEM=""
  188.    export DEFITEM
  189.    dialog --title "SCANNING" --infobox "Please wait while \
  190. Pkgtool scans your system to determine which packages you have \
  191. installed and prepares a list for you." 0 0
  192.    echo 'dialog $DEFITEM --item-help --menu "Please select the package you wish to view." 17 68 10 \' > $TMP/viewscr
  193.    for name in `ls $ADM_DIR/packages` ; do
  194.     pkg_name=`package_name $name`
  195.     BLURB="`sed -n "/$pkg_name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`"
  196.     # Let's have some backward compatibility with the interim beta (for now):
  197.     if [ "$BLURB" = "" ]; then
  198.      BLURB="`sed -n "/$name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`"
  199.     fi
  200.     echo " "$name" "$BLURB" "View information about package $name" \" >> $TMP/viewscr
  201.    done
  202.    echo "2> $TMP/return" >> $TMP/viewscr
  203.    while [ 0 ]; do
  204.     . $TMP/viewscr
  205.     if [ ! "`cat $TMP/return`" = "" ]; then
  206.      DEFITEM="--default-item `cat $TMP/return`"
  207.      dialog --title "CONTENTS OF PACKAGE: `cat $TMP/return`" --no-shadow --textbox "$ADM_DIR/packages/`cat $TMP/return`" \
  208.      0 0 2> /dev/null
  209.     else
  210.      break
  211.     fi
  212.    done
  213.    rm -f $TMP/return $TMP/viewscr $TMP/tmpmsg
  214.    # This will clean up after most defective packages:
  215.    chmod 755 /
  216.    chmod 1777 /tmp
  217.    continue
  218.   fi  
  219.   if [ "$REPLY" = "Remove" ]; then
  220.    dialog --title "SCANNING" --infobox "Please wait while Pkgtool scans \
  221. your system to determine which packages you have installed and prepares \
  222. a list for you." 0 0
  223.    # end section
  224.    cat << EOF > $TMP/rmscript
  225. dialog --title "SELECT PACKAGES TO REMOVE" --item-help --checklist \
  226. "Please select the \
  227. packages you wish to Remove. Use the \
  228. spacebar to select packages to delete, and the UP/DOWN arrow keys to \
  229. scroll up and down through the entire list." 20 75 11 \\
  230. EOF
  231.    for name in `ls $ADM_DIR/packages` ; do
  232.     pkg_name=`package_name $name`
  233.     BLURB="`sed -n "/$pkg_name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`"
  234.     # Let's have some backward compatibility with the interim beta (for now):
  235.     if [ "$BLURB" = "" ]; then
  236.      BLURB="`sed -n "/$name:/{s/\"//g;p;q;}" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`"
  237.     fi
  238.     echo " "$name" "$BLURB" off "Select/Unselect removing package $name" \" >> $TMP/rmscript
  239.    done
  240.    echo "2> $TMP/return" >> $TMP/rmscript
  241.    if [ -L $LOG -o -r $LOG ]; then
  242.      rm -f $LOG
  243.    fi
  244.    cat /dev/null > $LOG
  245.    chmod 600 $LOG
  246.    chmod 700 $TMP/rmscript
  247.    export ADM_DIR;
  248.    $TMP/rmscript
  249.    remove_packages `cat $TMP/return | tr -d "\042"`
  250.    if [ "`cat $TMP/PKGTOOL.REMOVED`" = "" ]; then
  251.     rm -f $TMP/PKGTOOL.REMOVED
  252.     dialog --title "NO PACKAGES REMOVED" --msgbox "Hit OK to return \
  253. to the main menu." 5 40
  254.    else
  255.     dialog --title "PACKAGE REMOVAL COMPLETE" --msgbox "The packages have \
  256. been removed. A complete log of the files that were removed has been created \
  257. in $TMP: PKGTOOL.REMOVED." 0 0
  258.    fi
  259.    rm -f $TMP/rmscript $TMP/return $TMP/tmpmsg $TMP/SeT*
  260.    chmod 755 /
  261.    chmod 1777 /tmp
  262. # No, return to the main menu:
  263. #   exit
  264.   elif [ "$REPLY" = "Floppy" ]; then
  265.    dialog --title "SELECT FLOPPY DRIVE" --menu "Which floppy drive would \
  266. you like to install from?" \
  267. 11 70 4 \
  268. "/dev/fd0u1440" "1.44 MB first floppy drive" \
  269. "/dev/fd1u1440" "1.44 MB second floppy drive" \
  270. "/dev/fd0h1200" "1.2 MB first floppy drive" \
  271. "/dev/fd1h1200" "1.2 MB second floppy drive" 2> $TMP/wdrive
  272.    if [ $? = 1 ]; then
  273.     dialog --clear
  274.     exit
  275.    fi
  276.    SOURCE_DEVICE="`cat $TMP/wdrive`"
  277.    rm -f $TMP/wdrive
  278.    cat << EOF > $TMP/tmpmsg

  279. Enter the names of any disk sets you would like to install.
  280. Separate the sets with a space, like this: a b oi x

  281. To install packages from one disk, hit [enter] without typing
  282. anything.

  283. EOF
  284.    dialog --title "SOFTWARE SELECTION" --inputbox "`cat $TMP/tmpmsg`" 13 70 2> $TMP/sets
  285.    DISK_SETS="`cat $TMP/sets`"
  286.    rm -f $TMP/sets
  287.    if [ "$DISK_SETS" = "" ]; then
  288.     DISK_SETS="disk"
  289.    else
  290.     DISK_SETS=`echo $DISK_SETS | sed 's/ /#/g'`
  291.     DISK_SETS="#$DISK_SETS"
  292.    fi
  293.    break;
  294.   elif [ "$REPLY" = "Other" ]; then
  295.    dialog --title "SELECT SOURCE DIRECTORY" --inputbox "Please enter the name of the directory that you wish to \
  296. install packages from:" 10 50 2> $TMP/pkgdir
  297.    if [ $? = 1 ]; then
  298.     rm -f $TMP/pkgdir $TMP/SeT*
  299.     dialog --clear
  300.     exit
  301.    fi
  302.    SOURCE_DIR="`cat $TMP/pkgdir`"
  303.    SOURCE_MOUNTED="always"
  304.    DISK_SETS="disk"
  305.    chmod 755 $TARGET_DIR
  306.    chmod 1777 $TARGET_DIR/tmp
  307.    rm -f $TMP/pkgdir
  308.    if [ ! -d $SOURCE_DIR ]; then
  309.     dialog --title "DIRECTORY NOT FOUND" --msgbox "The directory you want to \
  310. install from ($SOURCE_DIR) \
  311. does not seem to exist. Please check the directory and then try again." \
  312. 10 50
  313.     dialog --clear
  314.     exit
  315.    fi
  316.    break;
  317.   else # installing from current directory
  318.    SOURCE_MOUNTED="always"
  319.    SOURCE_DIR="$PWD"
  320.    DISK_SETS="disk"
  321.    chmod 755 $TARGET_DIR
  322.    chmod 1777 $TARGET_DIR/tmp
  323.    break;
  324.   fi
  325. done
  326. fi
  327. if [ "$DISK_SETS" = "disk" ]; then
  328. ASK="always"
  329. fi

  330. mount_the_source() {
  331. # is the source supposed to be mounted already?
  332. if [ "$SOURCE_MOUNTED" = "always" ]; then
  333.   # The source should already be mounted, so we test it
  334.   if [ ! -d $SOURCE_DIR ]; then # the directory is missing
  335.    cat << EOF > $TMP/tmpmsg

  336. Your source device cannot be accessed properly.

  337. Please be sure that it is mounted on $SOURCE_DIR,
  338. and that the Slackware disks are found in subdirectories
  339. of $SOURCE_DIR like specified.

  340. EOF
  341.    dialog --title "MOUNT ERROR" --msgbox "`cat $TMP/tmpmsg`" 11 67
  342.    rm -f $TMP/tmpmsg
  343.    exit 1;
  344.   fi
  345.   return 0;
  346. fi
  347. dialog --title "INSERT DISK" --menu "Please insert disk $1 and \
  348. press ENTER to continue." \
  349. 11 50 3 \
  350. "Continue" "Continue with the installation" \
  351. "Skip" "Skip the current disk series" \
  352. "Quit" "Abort the installation process" 2> $TMP/reply
  353. if [ ! $? = 0 ]; then
  354.   REPLY="Quit"
  355. else
  356.   REPLY="`cat $TMP/reply`"
  357. fi
  358. rm -f $TMP/reply
  359. if [ "$REPLY" = "Skip" ]; then
  360.   return 1;
  361. fi
  362. if [ "$REPLY" = "Quit" ]; then
  363.    dialog --title "ABORTING" --msgbox "Aborting software installation." 5 50
  364.    chmod 755 $TARGET_DIR
  365.    chmod 1777 $TARGET_DIR/tmp
  366.    exit 1;
  367. fi;
  368. # Old line:
  369. # mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR
  370. # New ones: (thanks to Andy Schwierskott!)
  371. go_on=y
  372. not_successfull_mounted=1
  373. while [ "$go_on" = y -a "$not_successfull_mounted" = 1 ]; do
  374.   mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR
  375.   not_successfull_mounted=$?
  376.   if [ "$not_successfull_mounted" = 1 ]; then
  377.    mount_answer=x
  378.    while [ "$mount_answer" != "y" -a "$mount_answer" != "q" ] ; do
  379.     dialog --title "MOUNT PROBLEM" --menu "Media was not successfully \
  380. mounted! Do you want to \
  381. retry, or quit?" 10 60 2 \
  382. "Yes" "Try to mount the disk again" \
  383. "No" "No, abort." 2> $TMP/mntans
  384.     mount_answer="`cat $TMP/mntans`"
  385.     rm -f $TMP/mntans
  386.     if [ "$mount_answer" = "Yes" ]; then
  387.      mount_answer="y"
  388.     else
  389.      mount_answer="q"
  390.     fi
  391.    done
  392.    go_on=$mount_answer
  393.   fi
  394. done
  395. test $not_successfull_mounted = 0
  396. }

  397. umount_the_source() {
  398. if [ ! "$SOURCE_MOUNTED" = "always" ]; then
  399.   umount $SOURCE_DEVICE 1> /dev/null 2>&1
  400. fi;
  401. }

  402. install_disk() {
  403. mount_the_source $1
  404. if [ $? = 1 ]; then
  405.   umount_the_source;
  406.   return 1;
  407. fi
  408. CURRENT_DISK_NAME="$1"
  409. PACKAGE_DIR=$SOURCE_DIR
  410. if [ "$SOURCE_MOUNTED" = "always" -a ! "$DISK_SETS" = "disk" ]; then
  411.    PACKAGE_DIR=$PACKAGE_DIR/$1
  412. fi

  413. # If this directory is missing or contains no *.tgz files, bail.
  414. if [ ! -d $PACKAGE_DIR ]; then
  415.   return 1
  416. fi
  417. if ls $PACKAGE_DIR/*.tgz 1> /dev/null 2> /dev/null ; then
  418.   true
  419. else
  420.   return 1
  421. fi

  422. #
  423. # look for tagfile for this series and copy into $TMP/tagfile
  424. #
  425. touch $TMP/tagfile
  426. if [ ! "$DISK_SETS" = "disk" ]; then
  427.   if [ -r $TMP/SeTtagext ]; then
  428.    if [ -r $PACKAGE_DIR/tagfile`cat $TMP/SeTtagext` ]; then
  429.     cat $PACKAGE_DIR/tagfile`cat $TMP/SeTtagext` >> $TMP/tagfile
  430.    else
  431.     if [ -r $PACKAGE_DIR/tagfile ]; then
  432.      cat $PACKAGE_DIR/tagfile >> $TMP/tagfile
  433.     fi
  434.    fi

  435.   #
  436.   # Do we need to follow a custom path to the tagfiles?
  437.   #
  438.   elif [ -r $TMP/SeTtagpath ]; then
  439.    custom_path=`cat $TMP/SeTtagpath`
  440.    short_path=`basename $PACKAGE_DIR`

  441.    # If tagfile exists at the specified custom path, copy it over.
  442.    if [ -r $custom_path/$short_path/tagfile ]; then
  443.     cat $custom_path/$short_path/tagfile >> $TMP/tagfile

  444.    else # well, I guess we'll use the default one then.
  445.     if [ -r $PACKAGE_DIR/tagfile ]; then
  446.      cat $PACKAGE_DIR/tagfile >> $TMP/tagfile
  447.     fi
  448.    fi
  449.   #
  450.   # We seem to be testing for this too often... maybe this code should
  451.   # be optimized a little...
  452.   #
  453.   elif [ -r $PACKAGE_DIR/tagfile ]; then
  454.    cat $PACKAGE_DIR/tagfile >> $TMP/tagfile
  455.   fi

  456.   #
  457.   # Execute menus if in QUICK mode:
  458.   #
  459.   if [ -r $TMP/SeTQUICK -a -r $PACKAGE_DIR/maketag ]; then
  460.    if [ ! "$MAKETAG" = "" -a -r $PACKAGE_DIR/$MAKETAG ]; then # use alternate maketag
  461.     sh $PACKAGE_DIR/$MAKETAG
  462.    else   
  463.     sh $PACKAGE_DIR/maketag
  464.    fi
  465.    if [ -r $TMP/SeTnewtag ]; then
  466.     mv $TMP/SeTnewtag $TMP/tagfile
  467.    fi
  468.   fi

  469.   #
  470.   # Protect tagfile from hacker attack:
  471.   #
  472.   if [ -r $TMP/tagfile ]; then
  473.    chmod 600 $TMP/tagfile
  474.   fi

  475. fi #  ! "$DISK_SETS" = "disk"

  476. # It's possible that the tagfile was specified on the command line.  If that's
  477. # the case, then we'll just override whatever we figured out up above.
  478. if [ ! "$USETAG" = "" ]; then
  479.    cat $USETAG > $TMP/tagfile
  480. fi

  481. # If there's a catalog file present, use it to check for missing files.
  482. # If not, forget about that and install whatever's there.
  483. if [ "$1" = "single_disk" -o -r $PACKAGE_DIR/disk$1 -o -r $PACKAGE_DIR/package-list.txt ]; then
  484.   if [ -r $PACKAGE_DIR/package-list.txt ]; then
  485.    CATALOG_FILE=$PACKAGE_DIR/package-list.txt
  486.   else
  487.    CATALOG_FILE=`basename $PACKAGE_DIR/disk*`;
  488.   fi
  489.   if [ -r $PACKAGE_DIR/$CATALOG_FILE -a ! -d $PACKAGE_DIR/$CATALOG_FILE ]; then
  490.    if grep CONTENTS: $PACKAGE_DIR/$CATALOG_FILE 1> /dev/null 2>&1 ; then
  491.     # First we check for missing packages...
  492.     for PKGTEST in `grep "^CONTENTS:" $PACKAGE_DIR/$CATALOG_FILE | cut -f2- -d : 2> /dev/null` ; do
  493.      # This is not a perfect test.  (say emacs is missing but emacs-nox is not)
  494.      if ls $PACKAGE_DIR/$PKGTEST*.tgz 1> /dev/null 2> /dev/null ; then # found something like it
  495.       true
  496.      else
  497.       cat << EOF > $TMP/tmpmsg

  498. WARNING!!!

  499. While looking through your index file ($CATALOG_FILE),
  500. I noticed that you might be missing a package:

  501. $PKGTEST-\*-\*-\*.tgz

  502. that is supposed to be on this disk (disk $1). You may go
  503. on with the installation if you wish, but if this is a
  504. crucial file I'm making no promises that your machine will
  505. boot.

  506. EOF
  507.       dialog --title "FILE MISSING FROM YOUR DISK" --msgbox \
  508. "`cat $TMP/tmpmsg`" 17 67
  509.      fi
  510.     done # checking for missing packages
  511.     # Now we test for extra packages:
  512.     ALLOWED="`grep CONTENTS: $PACKAGE_DIR/$CATALOG_FILE | cut -b10- 2> /dev/null`"
  513.     for PACKAGE_FILENAME in $PACKAGE_DIR/*.tgz; do
  514.      BASE="`basename $PACKAGE_FILENAME .tgz`"
  515.      BASE="`package_name $BASE`"
  516.      if echo $ALLOWED | grep $BASE 1> /dev/null 2>&1 ; then
  517.       true
  518.      else
  519.       cat << EOF > $TMP/tmpmsg

  520. WARNING!!!

  521. While looking through your index file ($CATALOG_FILE),
  522. I noticed that you have this extra package:

  523. ($BASE.tgz)

  524. that I don't recognize. Please be sure this package is
  525. really supposed to be here, and is not left over from an
  526. old version of Slackware. Sometimes this can happen at the
  527. archive sites.

  528. EOF
  529.       dialog --title "EXTRA FILE FOUND ON YOUR DISK" \
  530. --msgbox "`cat $TMP/tmpmsg`" 17 67
  531.       rm -f $TMP/tmpmsg
  532.      fi
  533.     done
  534.    fi
  535.   fi
  536. fi # check for missing/extra packages

  537. # Install the packages:
  538. for PACKAGE_FILENAME in $PACKAGE_DIR/*.tgz; do
  539.   if [ "$PACKAGE_FILENAME" = "$PACKAGE_DIR/*.tgz" ]; then
  540.    continue;
  541.   fi
  542.   if [ "$ASK" = "never" ]; then # install the package
  543.    installpkg -root $TARGET_DIR -infobox -tagfile $TMP/tagfile $PACKAGE_FILENAME
  544.    ERROR=$?
  545.   elif [ "$ASK" = "tagfiles" ]; then
  546.    installpkg -root $TARGET_DIR -menu -tagfile $TMP/tagfile $PACKAGE_FILENAME
  547.    ERROR=$?
  548.   else # ASK should be = always here, and that's how we'll treat it
  549.    installpkg -root $TARGET_DIR -menu -ask -tagfile $TMP/tagfile $PACKAGE_FILENAME
  550.    ERROR=$?
  551.   fi
  552.   # Check for abort:
  553.   if [ "$ERROR" = "99" ]; then
  554.    umount_the_source;
  555.    chmod 755 $TARGET_DIR
  556.    chmod 1777 $TARGET_DIR/tmp
  557.    exit 1;
  558.    fi
  559. done
  560. OUTTAHERE="false"
  561. if [ -r $PACKAGE_DIR/install.end ]; then
  562.   OUTTAHERE="true"
  563. fi
  564. umount_the_source;
  565. if [ "$OUTTAHERE" = "true" ]; then
  566.   return 1;
  567. fi
  568. }

  569. install_disk_set() { # accepts one argument: the series name in lowercase.
  570. SERIES_NAME=$1
  571. CURRENT_DISK_NUMBER="1";
  572. while [ 0 ]; do
  573.   # Don't start numbering the directories until 2:
  574.   if [ $CURRENT_DISK_NUMBER = 1 ]; then
  575.     DISKTOINSTALL=$SERIES_NAME
  576.   else
  577.     DISKTOINSTALL=$SERIES_NAME$CURRENT_DISK_NUMBER
  578.   fi
  579.   install_disk $DISKTOINSTALL
  580.   if [ ! $? = 0 ]; then # install.end was found, or the user chose
  581.         # to quit installing packages.
  582.    return 0;
  583.   fi
  584.   CURRENT_DISK_NUMBER=`expr $CURRENT_DISK_NUMBER + 1`
  585. done;
  586. }

  587. # /* main() */ ;)
  588. if [ "$DISK_SETS" = "disk" ]; then
  589. install_disk single_disk;
  590. ASK="always"
  591. else
  592. touch $TMP/tagfile
  593. chmod 600 $TMP/tagfile
  594. if echo $DISK_SETS | grep "#a#" 1> /dev/null 2>&1; then
  595.   A_IS_NEEDED="true"
  596. else
  597.   A_IS_NEEDED="false"
  598. fi
  599. while [ 0 ];
  600. do
  601.   while [ 0 ]; # strip leading '#'s
  602.   do
  603.    if [ "`echo $DISK_SETS | cut -b1`" = "#" ]; then
  604.     DISK_SETS="`echo $DISK_SETS | cut -b2-`"
  605.    else
  606.     break;
  607.    fi
  608.   done
  609.   if [ "$A_IS_NEEDED" = "true" ]; then
  610.    cat << EOF > $TMP/tmpmsg

  611. --- Installing package series ==>a<==

  612. EOF
  613.    dialog --infobox "`cat $TMP/tmpmsg`" 5 45
  614.    sleep 1
  615.    rm -f $TMP/tmpmsg
  616.    install_disk_set a;
  617.    A_IS_NEEDED="false"
  618.   fi
  619.   count="1"
  620.   if [ "`echo $DISK_SETS | cut -b$count`" = "" ]; then
  621.    break; # we be done here :^)
  622.   else
  623.    count="2"
  624.    while [ 0 ]; do
  625.     if [ "`echo $DISK_SETS | cut -b$count`" = "" -o "`echo $DISK_SETS | cut -b$count`" = "#" ]; then
  626.      count="`expr $count - 1`"
  627.      break;
  628.     else
  629.      count="`expr $count + 1`"
  630.     fi
  631.    done
  632.   fi
  633.   diskset="`echo $DISK_SETS | cut -b1-$count`"
  634.   count="`expr $count + 1`"
  635.   DISK_SETS="`echo $DISK_SETS | cut -b$count-`"
  636.   if [ "$diskset" = "a" ]; then
  637.    continue; # we expect this to be done elsewhere
  638.   fi
  639.   cat << EOF > $TMP/tmpmsg

  640. Installing package series ==>$diskset<==

  641. EOF
  642.   dialog --infobox "`cat $TMP/tmpmsg`" 5 45
  643.   sleep 1
  644.   rm -f $TMP/tmpmsg
  645.   install_disk_set $diskset;
  646. done
  647. fi

  648. if [ "$DISK_SETS" = "disk" -o "$CMD_START" = "true" ]; then
  649. if [ -r $TMP/tagfile ]; then
  650.   rm $TMP/tagfile
  651. fi
  652. dialog --clear
  653. fi
  654. chmod 755 $TARGET_DIR $TARGET_DIR/var $TARGET_DIR/usr
  655. chmod 1777 $TARGET_DIR/tmp
复制代码


installpkg

  1. #!/bin/sh
  2. # Copyright 1994, 1998, 2000  Patrick Volkerding, Concord, CA, USA
  3. # Copyright 2001  Slackware Linux, Inc., Concord, CA, USA
  4. # All rights reserved.
  5. #
  6. # Redistribution and use of this script, with or without modification, is
  7. # permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of this script must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. #
  12. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  15. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  18. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  19. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  20. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  21. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. #
  23. # Sun Nov 26 12:38:25 CST 1995
  24. # Added patch from Glenn Moloney <glenn@physics.unimelb.edu.au> to allow
  25. # packages to be installed to directories other than /.
  26. #
  27. # Wed Mar 18 15:15:51 CST 1998
  28. # Changed $TMP directory to /var/log/setup/tmp, and chmod'ed it 700 to close
  29. # some security holes.

  30. # If installpkg encounters a problem, it will return a non-zero error code.
  31. # If it finds more than one problem (i.e. with a list of packages) you'll only
  32. # hear about the most recent one. :)
  33. # 1 = tar returned error code
  34. # 2 = failed 'gzip -l package'
  35. # 3 = does not end in .tgz
  36. # 4 = not a file
  37. # 99 = user abort from menu mode
  38. EXITSTATUS=0

  39. TAR=tar-1.13
  40. $TAR --help 1> /dev/null 2> /dev/null
  41. if [ ! $? = 0 ]; then
  42.   TAR=tar
  43. fi
  44. if [ ! "`LC_MESSAGES=C $TAR --version`" = "tar (GNU tar) 1.13

  45. Copyright (C) 1988, 92,93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
  46. This is free software; see the source for copying conditions.  There is NO
  47. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  48. Written by John Gilmore and Jay Fenlason." ]; then
  49.   echo "WARNING: pkgtools are unstable with tar > 1.13."
  50.   echo "         You should provide a "tar-1.13" in your \$PATH."
  51.   sleep 5
  52. fi

  53. usage() {
  54. cat << EOF
  55. Usage: installpkg [options] package_name

  56. Installpkg is used to install a .tgz package like this:
  57.    installpkg xf_bin.tgz

  58. options:      -warn (warn if files will be overwritten, but do not install)
  59.               -root /mnt (install someplace else, like /mnt)
  60.               -infobox (use dialog to draw an info box)
  61.               -menu (confirm package installation with a menu, unless
  62.                     the priority is [required] or ADD)
  63.               -ask (used with menu mode: always ask if a package should be
  64.                    installed regardless of what the package's priority is)
  65.               -priority ADD|REC|OPT|SKP  (provide a priority for the entire
  66.                     package list to use instead of the priority in the
  67.                     tagfile)
  68.               -tagfile /somedir/tagfile (specify a different file to use
  69.                     for package priorities.  The default is "tagfile" in
  70.                     the package's directory)

  71. EOF
  72. }

  73. # Eliminate whitespace function:
  74. crunch() {
  75.   while read FOO ; do
  76.     echo $FOO
  77.   done
  78. }

  79. package_name() {
  80.   STRING=`basename $1 .tgz`
  81.   # Check for old style package name with one segment:
  82.   if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then
  83.     echo $STRING
  84.   else # has more than one dash delimited segment
  85.     # Count number of segments:
  86.     INDEX=1
  87.     while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do
  88.       INDEX=`expr $INDEX + 1`
  89.     done
  90.     INDEX=`expr $INDEX - 1` # don't include the null value
  91.     # If we don't have four segments, return the old-style (or out of spec) package name:
  92.     if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then
  93.       echo $STRING
  94.     else # we have four or more segments, so we'll consider this a new-style name:
  95.       NAME=`expr $INDEX - 3`
  96.       NAME="`echo $STRING | cut -f 1-$NAME -d -`"
  97.       echo $NAME
  98.       # cruft for later ;)
  99.       #VER=`expr $INDEX - 2`
  100.       #VER="`echo $STRING | cut -f $VER -d -`"
  101.       #ARCH=`expr $INDEX - 1`
  102.       #ARCH="`echo $STRING | cut -f $ARCH -d -`"
  103.       #BUILD="`echo $STRING | cut -f $INDEX -d -`"
  104.     fi
  105.   fi
  106. }

  107. # Parse options:
  108. MODE=install # standard text-mode
  109. while [ 0 ]; do
  110.   if [ "$1" = "-warn" ]; then
  111.     MODE=warn
  112.     shift 1
  113.   elif [ "$1" = "-infobox" ]; then
  114.     MODE=infobox
  115.     shift 1
  116.   elif [ "$1" = "-menu" ]; then
  117.     MODE=menu
  118.     shift 1
  119.   elif [ "$1" = "-ask" ]; then
  120.     ALWAYSASK="yes"
  121.     shift 1
  122.   elif [ "$1" = "-tagfile" ]; then
  123.     if [ -r "$2" ]; then
  124.       USERTAGFILE="$2"
  125.     elif [ -r "`pwd`/$2" ]; then
  126.       USERTAGFILE="`pwd`/$2"
  127.     else
  128.       usage
  129.       exit
  130.     fi
  131.     shift 2
  132.   elif [ "$1" = "-priority" ]; then
  133.     if [ "$2" = "" ]; then
  134.       usage
  135.       exit
  136.     fi
  137.     USERPRIORITY="$2"
  138.     shift 2
  139.   elif [ "$1" = "-root" ]; then
  140.     if [ "$2" = "" ]; then
  141.       usage
  142.       exit
  143.     fi
  144.     ROOT="$2"
  145.     shift 2
  146.   else
  147.     break
  148.   fi
  149. done

  150. # Set the prefix for the package database directories (packages, scripts).
  151. ADM_DIR="$ROOT/var/log"
  152. # If the directories don't exist, "initialize" the package database:
  153. for PKGDBDIR in packages removed_packages removed_scripts scripts setup ; do
  154.   if [ ! -d $ADM_DIR/$PKGDBDIR ]; then
  155.     rm -rf $ADM_DIR/$PKGDBDIR # make sure it's not a symlink or something stupid
  156.     mkdir -p $ADM_DIR/$PKGDBDIR
  157.     chmod 755 $ADM_DIR/$PKGDBDIR
  158.   fi
  159. done

  160. # Make sure there's a proper temp directory:
  161. TMP=$ADM_DIR/setup/tmp
  162. # If the $TMP directory doesn't exist, create it:
  163. if [ ! -d $TMP ]; then
  164.   rm -rf $TMP # make sure it's not a symlink or something stupid
  165.   mkdir -p $TMP
  166.   chmod 700 $TMP # no need to leave it open
  167. fi

  168. # usage(), exit if called with no arguments:
  169. if [ $# = 0 ]; then
  170.   usage;
  171.   exit
  172. fi

  173. # If -warn mode was requested, produce the output and then exit:
  174. if [ "$MODE" = "warn" ]; then
  175.   while [ -f "$1" ]; do
  176.     echo "#### Scanning the contents of $1..."
  177.     mkdir -p $TMP/scan$$
  178.     ( cd $TMP/scan$$ ; $TAR xzf - install ) < $1 2> /dev/null
  179.     if [ -r $TMP/scan$$/install/doinst.sh ]; then
  180.       if cat $TMP/scan$$/install/doinst.sh | grep ' rm -rf ' 1>/dev/null 2>/dev/null ; then
  181.         cat $TMP/scan$$/install/doinst.sh | grep ' rm -rf ' > $TMP/scan$$/install/delete
  182.         echo "The following locations will be completely WIPED OUT to allow symbolic"
  183.         echo "links to be made. (We're talking 'rm -rf') These locations may be files,"
  184.         echo "or entire directories.  Be sure you've backed up anything at these"
  185.         echo "locations that you want to save before you install this package:"
  186.         cat $TMP/scan$$/install/delete | cut -f 3,7 -d ' ' | tr ' ' '/'
  187.       fi
  188.       if [ -d $TMP/scan$$ ]; then
  189.         ( cd $TMP/scan$$ ; rm -rf install ) 2> /dev/null
  190.         ( cd $TMP ; rmdir scan$$ ) 2> /dev/null
  191.       fi
  192.     fi
  193.     echo "The following files will be overwritten when installing this package."
  194.     echo "Be sure they aren't important before you install this package:"
  195.     ( $TAR tzvvf - ) < $1 | grep -v 'drwx'
  196.     echo
  197.     shift 1
  198.   done
  199.   exit
  200. fi

  201. # Main loop:
  202. for package in $* ; do

  203.   # If someone left off the .tgz, try to figure that out:
  204.   if [ ! -r "$package" -a -r "$package.tgz" ]; then
  205.     package=$package.tgz
  206.   fi

  207.   # "shortname" isn't really THAT short... it's just the full name without ".tgz"
  208.   shortname="`basename $package .tgz`"
  209.   packagedir="`dirname $package`"
  210.   # This is the base package name, used for grepping tagfiles and descriptions:
  211.   packagebase="`package_name $shortname`"

  212.   # Reject package if it does not end in '.tgz':
  213.   if [ ! -r "`dirname $package`/$shortname.tgz" ]; then
  214.     EXITSTATUS=3
  215.     if [ "$MODE" = "install" ]; then
  216.       echo "Cannot install $package: package does not end in .tgz"
  217.     fi
  218.     continue;
  219.   fi

  220.   # Determine package's priority:
  221.   unset PRIORITY
  222.   if [ "$USERPRIORITY" = "" ]; then
  223.     if [ "$USERTAGFILE" = "" ]; then
  224.       TAGFILE="`dirname $package`/tagfile"   
  225.     else
  226.       TAGFILE="$USERTAGFILE"
  227.     fi
  228.     if [ ! -r "$TAGFILE" ]; then
  229.       TAGFILE=/dev/null
  230.     fi
  231.     if grep "^$packagebase:" "$TAGFILE" | grep ADD > /dev/null 2> /dev/null ; then
  232.       PRIORITY="ADD"
  233.     elif grep "^$packagebase:" "$TAGFILE" | grep REC > /dev/null 2> /dev/null ; then
  234.       PRIORITY="REC"
  235.     elif grep "^$packagebase:" "$TAGFILE" | grep OPT > /dev/null 2> /dev/null ; then
  236.       PRIORITY="OPT"
  237.     elif grep "^$packagebase:" "$TAGFILE" | grep SKP > /dev/null 2> /dev/null ; then
  238.       PRIORITY="SKP"
  239.     fi
  240.   else
  241.     PRIORITY="$USERPRIORITY"
  242.   fi
  243.   if [ "$PRIORITY" = "ADD" ]; then
  244.     #PMSG="Priority: [required]"
  245.     PMSG="[required]"
  246.   elif [ "$PRIORITY" = "REC" ]; then
  247.     #PMSG="Priority: [recommended]"
  248.     PMSG="[recommended]"
  249.   elif [ "$PRIORITY" = "OPT" ]; then
  250.     #PMSG="Priority: [optional]"
  251.     PMSG="[optional]"
  252.   elif [ "$PRIORITY" = "SKP" ]; then
  253.     #PMSG="Priority: [skip]"
  254.     PMSG="[skip]"
  255.   else
  256.     #PMSG="Priority: [unknown]"
  257.     PMSG=""
  258.   fi

  259.   # Locate package description file:
  260.   DESCRIPTION="/dev/null"
  261.   # First check the usual locations outside the package, since this is faster:
  262.   for file in $packagedir/disk* $packagedir/package_descriptions $packagedir/$shortname.txt $packagedir/$packagebase.txt ; do
  263.     if grep "^$packagebase:" "$file" 1> /dev/null 2> /dev/null ; then
  264.       DESCRIPTION="$file"
  265.     elif grep "^$shortname:" "$file" 1> /dev/null 2> /dev/null ; then
  266.       DESCRIPTION="$file"
  267.     fi
  268.   done
  269.   # If we still don't have anything, look inside the package.  This requires a costly untar.
  270.   if [ "$DESCRIPTION" = "/dev/null" ]; then
  271.     mkdir -p $TMP/scan$$
  272.     ( cd $TMP/scan$$ ; $TAR xzf - install ) < $package 2> /dev/null
  273.     if grep "^$packagebase:" "$TMP/scan$$/install/slack-desc" 1> /dev/null 2> /dev/null ; then
  274.       DESCRIPTION="$TMP/scan$$/install/slack-desc"
  275.     elif grep "^$shortname:" "$TMP/scan$$/install/slack-desc" 1> /dev/null 2> /dev/null ; then
  276.       DESCRIPTION="$TMP/scan$$/install/slack-desc"
  277.     fi
  278.   fi

  279.   # Simple package integrity check:
  280.   if [ ! -f $package ]; then
  281.     EXITSTATUS=4
  282.     if [ "$MODE" = "install" ]; then
  283.       echo "Cannot install $package: package is not a regular file"
  284.     fi
  285.     continue;
  286.   fi
  287.   gzip -l $package 1> /dev/null 2> /dev/null
  288.   if [ ! "$?" = "0" ]; then
  289.     EXITSTATUS=2 # failed gzip -l
  290.     if [ "$MODE" = "install" ]; then
  291.       echo "Cannot install $package: package is corrupt (failed 'gzip -l $package')"
  292.     fi
  293.     continue;
  294.   fi

  295.   # Collect the package information into a temp file:
  296.   COMPRESSED=`gzip -l $package | grep -v uncompressed_name | crunch | cut -f 1 -d ' '`
  297.   UNCOMPRESSED=`gzip -l $package | grep -v uncompressed_name | crunch | cut -f 2 -d ' '`
  298.   COMPRESSED="`expr $COMPRESSED / 1024` K"
  299.   UNCOMPRESSED="`expr $UNCOMPRESSED / 1024` K"
  300. #  MD5SUM=`md5sum $package | cut -f 1 -d ' '`
  301.   cat $DESCRIPTION | grep "^$packagebase:" | cut -f 2- -d : | cut -b2- 1> $TMP/tmpmsg$$ 2> /dev/null
  302.   if [ "$shortname" != "$packagebase" ]; then
  303.     cat $DESCRIPTION | grep "^$shortname:" | cut -f 2- -d : | cut -b2- 1>> $TMP/tmpmsg$$ 2> /dev/null
  304.   fi
  305.   # Adjust the length here.  This allows a slack-desc to be any size up to 13 lines instead of fixed at 11.
  306.   LENGTH=`cat $TMP/tmpmsg$$ | wc -l`
  307.   while [ $LENGTH -lt 12 ]; do
  308.     echo >> $TMP/tmpmsg$$
  309.     LENGTH=`expr $LENGTH + 1`
  310.   done
  311.   echo "Size: Compressed: $COMPRESSED, uncompressed: $UNCOMPRESSED." >> $TMP/tmpmsg$$
  312.   # For recent versions of dialog it is necessary to add \n to the end of each line
  313.   # or it will remove repeating spaces and mess up our careful formatting:
  314.   cat << EOF > $TMP/controlns$$
  315. \n
  316. \n
  317. \n
  318. \n
  319. \n
  320. \n
  321. \n
  322. \n
  323. \n
  324. \n
  325. \n
  326. \n
  327. \n
  328. EOF
  329.   paste -d "" $TMP/tmpmsg$$ $TMP/controlns$$ > $TMP/pasted$$
  330.   rm -f $TMP/controlns$$
  331.   mv $TMP/pasted$$ $TMP/tmpmsg$$
  332.   # Emit information to the console:
  333.   if [ "$MODE" = "install" ]; then
  334.     if [ "$PMSG" = "" ]; then
  335.       echo "Installing package $shortname... "
  336.     else
  337.       echo "Installing package $shortname ($PMSG)... "
  338.     fi
  339.     echo "PACKAGE DESCRIPTION:"
  340.     cat $DESCRIPTION | grep "^$packagebase:" | uniq
  341.     if [ "$shortname" != "$packagebase" ]; then
  342.       cat $DESCRIPTION | grep "^$shortname:" | uniq
  343.     fi
  344.   elif [ "$MODE" = "infobox" -a ! "$PRIORITY" = "SKP" ]; then # install non-SKP infobox package
  345.     dialog --title "Installing package ==>$shortname<== $PMSG" --infobox "`cat $TMP/tmpmsg$$`" 0 0
  346.   elif [ "$MODE" = "menu" -a "$PRIORITY" = "ADD" -a ! "$ALWAYSASK" = "yes" ]; then # ADD overrides menu mode unless -ask was used
  347.     dialog --title "Installing package ==>$shortname<== $PMSG" --infobox "`cat $TMP/tmpmsg$$`" 0 0
  348.   elif [ "$MODE" = "menu" -a "$PRIORITY" = "SKP" -a ! "$ALWAYSASK" = "yes" ]; then # SKP overrides menu mode unless -ask used
  349.     rm -f $TMP/tmpmsg$$
  350.     continue # next package
  351.   elif [ "$MODE" = "infobox" -a "$PRIORITY" = "SKP" -a ! "$ALWAYSASK" = "yes" ]; then # SKP overrides infobox mode, too
  352.     rm -f $TMP/tmpmsg$$
  353.     continue
  354.   else # we must need a full menu:
  355.     dialog --title "Package Name: ==>$shortname<== $PMSG" --menu "`cat $TMP/tmpmsg$$`" 0 0 3 \
  356.     "Yes" "Install package $shortname" \
  357.     "No" "Do not install package $shortname" \
  358.     "Quit" "Abort software installation completely" 2> $TMP/reply$$
  359.     if [ ! $? = 0 ]; then
  360.       echo "No" > $TMP/reply$$
  361.     fi
  362.     REPLY="`cat $TMP/reply$$`"
  363.     rm -f $TMP/reply$$ $TMP/tmpmsg$$
  364.     if [ "$REPLY" = "Quit" ]; then
  365.       exit 99 # EXIT STATUS 99 = ABORT!
  366.     elif [ "$REPLY" = "No" ]; then
  367.       continue # skip the package
  368.     fi
  369.   fi

  370.   # Test tarball integrity, and make sure we're not installing files on top of existing symbolic links:
  371.   $TAR tzf $package 1> $TMP/tmplist$$ 2> /dev/null
  372.   TARERROR=$?
  373.   if [ ! "$TARERROR" = "0" ]; then
  374.     EXITSTATUS=1 # tar file corrupt
  375.     if [ "$MODE" = "install" ]; then
  376.       echo "Unable to install $package: tar archive is corrupt (tar returned error code $TARERROR)"
  377.     fi
  378.     rm -f $TMP/tmplist$$
  379.     continue
  380.   fi
  381.   cat $TMP/tmplist$$ | grep -v "/$" | while read file ; do
  382.     if [ -L "$ROOT/$file" ]; then
  383.       rm -f "$ROOT/$file"
  384.     fi
  385.   done
  386.   rm -f $TMP/tmplist$$

  387.   # Write the package file database entry and install the package:
  388.   echo "PACKAGE NAME:     $shortname" > $ADM_DIR/packages/$shortname
  389.   echo "COMPRESSED PACKAGE SIZE:     $COMPRESSED" >> $ADM_DIR/packages/$shortname
  390.   echo "UNCOMPRESSED PACKAGE SIZE:     $UNCOMPRESSED" >> $ADM_DIR/packages/$shortname
  391.   echo "PACKAGE LOCATION: $package" >> $ADM_DIR/packages/$shortname
  392. #  echo "PACKAGE MD5SUM: $MD5SUM" >> $ADM_DIR/packages/$shortname
  393.   echo "PACKAGE DESCRIPTION:" >> $ADM_DIR/packages/$shortname
  394.   cat $DESCRIPTION | grep "^$packagebase:" >> $ADM_DIR/packages/$shortname 2> /dev/null
  395.   if [ "$shortname" != "$packagebase" ]; then
  396.     cat $DESCRIPTION | grep "^$shortname:" >> $ADM_DIR/packages/$shortname 2> /dev/null
  397.   fi
  398.   echo "FILE LIST:" >> $ADM_DIR/packages/$shortname
  399.   ( cd $ROOT/ ; $TAR -xzlUpvf - ) < $package >> $TMP/$shortname 2> /dev/null
  400.   if [ "`cat $TMP/$shortname | grep '^./' | wc -l | tr -d ' '`" = "1" ]; then
  401.     # Good.  We have a package that meets the Slackware spec.
  402.     cat $TMP/$shortname >> $ADM_DIR/packages/$shortname
  403.   else
  404.     # Some dumb bunny built a package with something other than makepkg.  Bad!
  405.     # Oh well.  Bound to happen.  Par for the course.  Fix it and move on...
  406.     echo './' >> $ADM_DIR/packages/$shortname
  407.     cat $TMP/$shortname | grep -v '^./$' | cut -b3- >> $ADM_DIR/packages/$shortname
  408.   fi
  409.   rm -f $TMP/$shortname

  410.   if [ -x /sbin/ldconfig ]; then
  411.     /sbin/ldconfig
  412.   fi
  413.   if [ -f $ROOT/install/doinst.sh ]; then
  414.     if [ "$MODE" = "install" ]; then
  415.       echo "Executing install script for $shortname..."
  416.     fi
  417.     ( cd $ROOT/ ; sh install/doinst.sh -install; )
  418.   fi
  419.   # Clean up the mess...
  420.   if [ -d $ROOT/install ]; then
  421.     if [ -r $ROOT/install/doinst.sh ]; then
  422.       cp $ROOT/install/doinst.sh $ADM_DIR/scripts/$shortname
  423.       chmod 755 $ADM_DIR/scripts/$shortname
  424.     fi
  425.     # /install/doinst.sh and /install/slack-* are reserved locations for the package system.
  426.     ( cd $ROOT/install ; rm -f doinst.sh slack-* 1> /dev/null 2>&1 )
  427.     rmdir $ROOT/install 1> /dev/null 2>&1
  428.   fi
  429.   # If we used a scan directory, get rid of it:
  430.   if [ -d "$TMP/scan$$" ]; then
  431.     rm -rf "$TMP/scan$$"
  432.   fi
  433.   rm -f $TMP/tmpmsg$$ $TMP/reply$$
  434.   if [ "$MODE" = "install" ]; then
  435.     echo
  436.   fi
  437. done

  438. exit $EXITSTATUS
复制代码
发表于 2003-9-3 14:01:32 | 显示全部楼层
确实经典
我已经将您发布的脚本放在了[欣赏区],供兄弟们学习阅读!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表