home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / usr / lib / YaST / create_yast_tape < prev    next >
Text File  |  2000-03-30  |  3KB  |  125 lines

  1. #!/bin/bash
  2.  
  3. function check_list() {
  4.     set -f
  5.     for i in $2
  6.     do
  7.         NAME=`echo $1 | egrep -x -e "$i"`
  8.         if [ -n "$NAME" ]
  9.         then
  10.             echo $NAME
  11.             break;
  12.         fi
  13.     done
  14.     set +f
  15.     }
  16.  
  17. function Usage() {
  18.     echo `basename $0` understands the following options:
  19.     echo     "--tape=<Device>"
  20.     echo     "    Use <Device> as Tape instead of /dev/nrst0"
  21.     echo     "--verbose"
  22.     echo     "-v"
  23.     echo     "    Use verbose option for tar command"
  24.     echo     "--help"
  25.     echo     "    Print this message"
  26.     echo     "--exclude-disk=<List>"
  27.     echo     "    Exclude the disks in this list from having their partition"
  28.     echo     "    information written to tape"
  29.     echo     "    Wildcards work \"/dev/hd?\" excludes all IDE disks"
  30.     echo     "--include-disk=<List>"
  31.     echo     "    Write only the partition information of these disks to tape"
  32.     echo     "    Wildcards work \"/dev/hd*\" includes all IDE disks"
  33.     echo     "--dirlist=<List of Directories>"
  34.     echo     "    Save only these Directories to tape instead of everything"
  35.     echo     "--root=<Dir>"
  36.     echo     "    Change to <Dir> before saving the files to tape"
  37.     exit 1
  38.     }
  39.  
  40. TAPE=/dev/nst0
  41. CHDIR=/
  42. while [ "$#" -gt 0 ]
  43. do
  44.     case "$1" in
  45.     --tape=*)
  46.     TAPE=`echo $1 | sed s/^.*=//`
  47.     ;;
  48.     --root=*)
  49.     CHDIR=`echo $1 | sed s/^.*=//`
  50.     if [ -z "$DIRLIST" ]
  51.     then
  52.         DIRLIST=.
  53.     fi
  54.     ;;
  55.     --dirlist=*)
  56.     DIRLIST=`echo $1 | sed s/^.*=//`
  57.     ;;
  58.     --verbose|-v)
  59.     VERBOSE=-v
  60.     ;;
  61.     --exclude-disk=*)
  62.     EXCLUDE_DISK=`echo $1 | sed -e "s/^.*=//" -e "s/?/./g" -e "s/*/.*/g"`
  63.     if [ -n "$INCLUDE_DISK" ]
  64.     then
  65.         echo "not possible to use both --exclude-disk and --include-disk"
  66.         exit 1
  67.     fi
  68.     ;;
  69.     --include-disk=*)
  70.     INCLUDE_DISK=`echo $1 | sed -e "s/^.*=//" -e "s/?/./g" -e "s/*/.*/g"`
  71.     if [ -n "$EXCLUDE_DISK" ]
  72.     then
  73.         echo "not possible to use both --exclude-disk and --include-disk"
  74.         exit 1
  75.     fi
  76.     ;;
  77.     --help|-h|-?)
  78.     Usage
  79.     ;;
  80.     *)
  81.     echo unknown Option \"$1\"
  82.     Usage
  83.     ;;
  84.     esac
  85.     shift
  86. done
  87. if [ -z "$DIRLIST" ]
  88. then
  89.     DIRLIST=`mount | egrep -v " proc| autofs | iso9660| devpts| nfs" |
  90.              awk '{ print $3 }' | sed s:^/:./: | tr \\\n ' ' | sed "s: $::"`
  91. fi
  92. TMPDIR=/tmp/`basename $0`.$$
  93. rm -rf $TMPDIR
  94. mkdir -p $TMPDIR
  95. cd $TMPDIR
  96. echo Rewinding Tape "$TAPE"
  97. mt -f $TAPE rewind
  98. echo Saving partition information on Tape "$TAPE"
  99. /usr/lib/YaST/create_yast_partfiles
  100. for i in part.*
  101. do
  102.     DEVICE=`echo $i | sed -e "s:part.:/:" -e "s:\\.:/:"`
  103.     if [ -n "$INCLUDE_DISK" ] 
  104.     then
  105.     FILE=`check_list $DEVICE "$INCLUDE_DISK"`
  106.     [ -z "$FILE" ] && rm -f $i
  107.     elif [ -n "$EXCLUDE_DISK" ] 
  108.     then
  109.     FILE=`check_list $DEVICE "$EXCLUDE_DISK"`
  110.     [ -z "$FILE" ] || rm -f $i
  111.     fi
  112. done
  113. cd $CHDIR
  114. cat etc/fstab | grep -v ^# | awk '{print $2 }' | grep ^/ | sed s:^/:: \
  115.               | grep -v ^$ | (cpio -o >mpoints.cpio 2>/dev/null)
  116. cd -
  117. mv $CHDIR/mpoints.cpio .
  118. tar cf $TAPE part.* mpoints.cpio
  119. cd $CHDIR
  120. echo Saving Filesystems under  \"$DIRLIST\" on Tape "$TAPE"
  121. tar --numeric-owner -c -z -l $VERBOSE -f $TAPE $DIRLIST
  122. sleep 10
  123. mt -f $TAPE rewind
  124. rm -rf $TMPDIR
  125.