#!/bin/sh # TCEDIR="/etc/sysconfig/tcedir/" TRASH="/tmp/trash" EXTNAME=$1 CHANGES=0 if [ "`expr match "$EXTNAME" '.*\(.tcz$\)'`" != '.tcz' ]; then EXTNAME=$EXTNAME.'tcz'; fi if [ ! -d $TRASH ]; then mkdir $TRASH; fi if [ ! -d "$TRASH/$EXTNAME" ]; then mkdir "$TRASH/$EXTNAME"; fi TRASHSIZE=`du -d 1 -h $TRASH'/'$EXTNAME` TRASHSIZE=${TRASHSIZE%%/*} if [ $TRASHSIZE != '0' ]; then echo 'It will release '$TRASHSIZE'of disk space. Delete '$EXTNAME'? [Y/N]' read action if [ $action == 'Y' ] || [ $action == 'y' ]; then rm -r "$TRASH/$EXTNAME"; touch $TCEDIR'onboot.lst.new' while read line; do if [ "$line" != "$EXTNAME" ]; then echo $line >> $TCEDIR'onboot.lst.new'; fi done < $TCEDIR'onboot.lst' mv $TCEDIR'onboot.lst.new' $TCEDIR'onboot.lst' echo "$EXTNAME was deleted!"; else for file in "$TRASH/$EXTNAME/*"; do mv "$file" $TCEDIR'optional/'; echo "$file restored from trash" done echo "deleting $EXTNAME was canceled" fi exit 0 fi if [ ! -f $TCEDIR'optional/'$EXTNAME ]; then echo "$EXTNAME does not exist"; exit 1; fi function checkTCZ() { while read line; do if [ "$line" == "$1" ] && [ "$line" != "$EXTNAME" ]; then echo "$1 NOT removed: extension present in onboot.lst"; return 0; fi done < $TCEDIR'onboot.lst' for DEPFILE in `find $TCEDIR'optional' -name '*.dep'`; do if [ "$DEPFILE" == "$2" ]; then continue; fi while read line; do if [ "$line" == "$1" ]; then echo "$1 NOT removed: extension used in "${DEPFILE##/*/}; return 0; fi done < $DEPFILE done if [ -f $TCEDIR"optional/$1.dep" ]; then while read line; do if [ -z "$line" ]; then continue; fi checkTCZ $line $TCEDIR'optional/'$1'.dep' done < $TCEDIR'optional/'$1'.dep' fi DISK=`df | grep -E '/tmp/tcloop/'${1%.*}'$' | grep -o -E "^/dev/loop[0-9]{1,3}"` umount $DISK 2> /dev/null if [ $? -ne "0" ]; then echo "can not umount $DISK with $1. Service launched?" if [ $CHANGES -ne 0 ]; then for file in "$TRASH/$EXTNAME/*"; do mv "$file" $TCEDIR'optional/'; done; fi echo "deleting $EXTNAME was canceled" exit 1 else echo "$1 removed to $TRASH/$EXTNAME"; mv $TCEDIR'optional/'$1 $TRASH'/'$EXTNAME mv $TCEDIR'optional/'$1.'md5.txt' $TRASH'/'$EXTNAME if [ -f $TCEDIR'optional/'$1.'dep' ]; then cp $TCEDIR'optional/'$1.'dep' $TRASH'/'$EXTNAME; fi CHANGES=1 fi } checkTCZ $EXTNAME if [ $CHANGES -ne 0 ]; then $0 $EXTNAME; fi