电脑技术学习

Sun Solaris 安装包的反安装实现

dn001

  AWK=/bin/nawk

  GZIP=/bin/gzip

  MKDIR=/bin/mkdir

  CHMOD=/bin/chmod

  CHOWN=/bin/chown

  CP=/bin/cp

  MV=/bin/mv

  PKGMK=/bin/pkgmk

  PKGTRANS=/bin/pkgtrans

  # [Functions]

  #==================================================================

  function mk_dir

  {

  $MKDIR -p $PRO_DIR/$3

  $CHMOD $4 $PRO_DIR/$3

  $CHOWN $5:$6 $PRO_DIR/$3

  }

  function cp_file

  {

  $CP -p $3 $PRO_DIR/$3

  $CHMOD $4 $PRO_DIR/$3

  $CHOWN $5:$6 $PRO_DIR/$3

  }

  # [Main]

  #==================================================================

  if [ ${ID} != 0 ]

  then

  echo ""

  echo "Only Root User allow to run this script. Exit...."

  sleep 1

  echo ""

  exit 1

  fi

  echo ""

  echo "Please enter package name you want to create, then press Enter: "

  echo "Enter Package name: c"

  read pkgname

  PKG_NAME=$pkgname

  if [ ! -d $SYS_DIR/$PKG_NAME ]; then

  echo ""

  echo "This Package doesn@#t exist!!! Please check the name and try again!"

  echo ""

  exit 1

  fi

  if [ ! -d $PRO_DIR ]; then

  $MKDIR $PRO_DIR

  fi

  if [ ! -d $PKG_DIR ]; then

  $MKDIR $PKG_DIR

  fi

  # Producing part of Prototype file

  $GREP $PKG_NAME $CNT_FILE | $GREP -v ^#.* > $PRO_DIR/cnt_pkg

  $AWK @#{print $2,$3,$1,$4,$5,$6}@# $PRO_DIR/cnt_pkg > $PRO_DIR/Prototmp

  $GREP ^d $PRO_DIR/Prototmp > $PRO_DIR/Protodir

  $GREP ^f $PRO_DIR/Prototmp >> $PRO_DIR/Protofile

  rm -f $PRO_DIR/Prototmp

  rm -f $PRO_DIR/cnt_pkg

  # Producing pkginfo file

  cp $SYS_DIR/$PKG_NAME/pkginfo $PRO_DIR

  # Making Directory with permission

  i=0

  while IFS=@# @# read line

  do

  t[$i]=$line

  ((i=i+1))

  mk_dir $line

  done < $PRO_DIR/Protodir

  # Copying file to Spool directory

  i=0

  while IFS=@# @# read line

  do

  t[$i]=$line

  ((i=i+1))

  cp_file $line

  done < $PRO_DIR/Protofile

  # Producing Prototype file

  cat $PRO_DIR/Protodir > $PRO_DIR/Prototype

  cat $PRO_DIR/Protofile >> $PRO_DIR/Prototype

  (echo "i pkginfo"cat $PRO_DIR/Prototype ) > $PRO_DIR/Prototmp

  mv $PRO_DIR/Prototmp $PRO_DIR/Prototype

  rm -f $PRO_DIR/Protodir

  rm -f $PRO_DIR/Protofile

  # Now let@#s make the package

  $PKGMK -o -r $PRO_DIR -d $PRO_DIR -f $PRO_DIR/Prototype

  $PKGTRANS -s $PRO_DIR $PKG_DIR/$PKG_NAME-$VER-pkg $PKG_NAME

  $GZIP -f $PKG_DIR/$PKG_NAME-$VER-pkg

  rm -rf $PRO_DIR

标签: