続きです。
#!/bin/sh
# pkg_delete
if [ ! -x /bin/mktemp ]; then
exit 1
elif [ ! -x /bin/tar ]; then
exit 1
elif [ ! -x /bin/gzip ]; then
exit 1
elif [ ! -x /bin/bzip2 ]; then
exit 1
elif [ ! -x /bin/rm ]; then
exit 1
elif [ ! -x /bin/rmdir ]; then
exit 1
fi
PROG=${0##*/}
if [ $# -lt 1 ]; then
echo "usage: ${PROG} <pkgname1> ... [pkgnameN]" >&2
exit 1
fi
DATDIR=${CYGWIN_SETUP_DAT:="/etc/setup_local"}
### START ###
for i in $@; do
PKGFILE=$i
if [ ! -f ${PKGFILE} ]; then
PKGFILE=${SAVEDIR}/$i
fi
if [ ! -f ${PKGFILE} ]; then
echo "${PROG}: not found PKG $i" >&2
else
DATFILE=${PKGFILE##*/}
DATFILE=${DATFILE%%.*}
DATFILE=${DATFILE%-[0-9]*}
DATFILE=${DATDIR}/${DATFILE}.lst
if [ -f ${DATFILE}.gz ]; then
echo "${PROG}: found DAT ${DATFILE}.gz" >&2
TMPF=`mktemp -t pkg_delete.XXXXXXXX`
gzip -dc ${DATFILE}.gz > ${TMPF}
rm -f ${DATFILE}.gz
else
echo "${PROG}: not found DAT ${DATFILE}.gz" >&2
echo "${PROG}: making list from ${PKGFILE}" >&2
TMPF=`mktemp -t pkg_delete.XXXXXXXX`
case ${PKGFILE} in
*.bz2) tar xvjf ${PKGFILE} -C /dev/null > ${TMPF} ;;
*.gz) tar xvzf ${PKGFILE} -C /dev/null > ${TMPF} ;;
*.tgz) tar xvzf ${PKGFILE} -C /dev/null > ${TMPF} ;;
*) echo "${PROG}: invalid package type ${PKGFILE}" >&2 ;;
esac
fi
while read line; do
FILE=`echo $line`
if [ -f /${FILE} ]; then
rm -f /${FILE} > /dev/null 2>&1
if [ $? -eq 0 ]; then echo "remove file: /${FILE}"; fi
fi
done < ${TMPF}
while read line; do
FILE=`echo $line`
if [ -d /${FILE} ]; then
rmdir /${FILE} > /dev/null 2>&1
if [ $? -eq 0 ]; then echo "remove dir: /${FILE}"; fi
fi
done < ${TMPF}
rm -f ${TMPF}
fi
done
exit 0
|