| 1 |
#! /bin/bash |
| 2 |
# generates script doing what "make uninstall" would do |
| 3 |
# first parameter: the name of the uninstallation script, defaulting to uninstall.sh |
| 4 |
# second, optional parameter: the command to execute to uninstall, like "rpm -e armagetronad". |
| 5 |
|
| 6 |
#set -x |
| 7 |
|
| 8 |
UNINSTALL=$1 |
| 9 |
test "x${UNINSTALL}" = x && UNINSTALL=uninstall |
| 10 |
|
| 11 |
EXTERNAL_CMD=$2 |
| 12 |
|
| 13 |
test -z "`echo ${UNINSTALL} | grep '^/'`" && UNINSTALL="`pwd`/${UNINSTALL}" |
| 14 |
echo "Generating uninstallation script" ${UNINSTALL}... |
| 15 |
|
| 16 |
if test "$EXTERNAL_CMD" != "" && test "$EXTERNAL_CMD" != "yes"; then |
| 17 |
{ |
| 18 |
echo '#! /bin/sh' |
| 19 |
echo "$EXTERNAL_CMD" |
| 20 |
} > "${UNINSTALL}" |
| 21 |
else |
| 22 |
|
| 23 |
# start ${UNINSTALL} |
| 24 |
cat > "${UNINSTALL}" <<EOF |
| 25 |
#! /bin/sh |
| 26 |
# uninstalls ${PROGTITLE} |
| 27 |
|
| 28 |
# set default destdir to where the game was installed to |
| 29 |
test -z "\${DESTDIR}" && DESTDIR="${ROOTDIR}" |
| 30 |
export DESTDIR |
| 31 |
|
| 32 |
# uninstall system files |
| 33 |
"\${DESTDIR}${SCRIPTDIR}/sysinstall" uninstall "${PREFIX}" || exit 1 |
| 34 |
|
| 35 |
# automaticall generated from "make install" |
| 36 |
EOF |
| 37 |
|
| 38 |
|
| 39 |
# do an installation |
| 40 |
echo -n "Performing test installation..." |
| 41 |
DEST=$(pwd)/.foruninstall |
| 42 |
|
| 43 |
# test for recursion |
| 44 |
if echo ${DESTDIR} | grep "\.foruninstall$"; then |
| 45 |
echo "Recursion detected, aborting." |
| 46 |
exit 0 |
| 47 |
fi |
| 48 |
|
| 49 |
if ${MAKE} DESTDIR=${DEST} install > /dev/null; then |
| 50 |
echo "Success!" |
| 51 |
else |
| 52 |
echo "Failure :(" |
| 53 |
rm -rf $DEST |
| 54 |
exit -1 |
| 55 |
fi |
| 56 |
|
| 57 |
find "$DEST" -type d | sed -e "s,^${DEST},rmdir --ignore-fail-on-non-empty \\\$\{DESTDIR\}," > "${UNINSTALL}.dir0" |
| 58 |
find "$DEST" -type f | sed -e "s,^${DEST},rm -f \\\$\{DESTDIR\}," > "${UNINSTALL}.files" |
| 59 |
|
| 60 |
# less ${UNINSTALL}.dir0 |
| 61 |
|
| 62 |
# add all parent directories of those that are still game-specific |
| 63 |
grep "${PROGNAME}" "${UNINSTALL}.dir0" > "${UNINSTALL}.dir" |
| 64 |
while test -s "${UNINSTALL}.dir0"; do |
| 65 |
sed -e "s,/[^/]*\$,," < "${UNINSTALL}.dir0" | grep "${PROGNAME}" > "${UNINSTALL}.dir1" |
| 66 |
cat "${UNINSTALL}.dir1" >> "${UNINSTALL}.dir" |
| 67 |
mv "${UNINSTALL}.dir1" "${UNINSTALL}.dir0" |
| 68 |
done |
| 69 |
|
| 70 |
# compose uninstall script from file and directory list |
| 71 |
cat "${UNINSTALL}.files" >> "${UNINSTALL}" |
| 72 |
sort "${UNINSTALL}.dir" -ru >> "${UNINSTALL}" |
| 73 |
|
| 74 |
rm -rf "${DEST}" |
| 75 |
|
| 76 |
fi |
| 77 |
|
| 78 |
# clean up |
| 79 |
rm -f "${UNINSTALL}.dir" "${UNINSTALL}.dir0" "${UNINSTALL}.files" |
| 80 |
|
| 81 |
chmod 755 "${UNINSTALL}" |
| 82 |
|
| 83 |
# less "${UNINSTALL}" |
| 84 |
|
| 85 |
echo "done." |