Newer
Older
DIRNAME=$(dirname "$0")
LIB_DIR="$(dirname "$0")/lib"
. "$LIB_DIR"/find_dep
. "$LIB_DIR"/find_module_paths
. "$LIB_DIR"/recursion
. "$LIB_DIR"/remove_module
fi
cat <<EOF
Usage: rm-module [OPTION ...] MODULE
Remove MODULE with dependency from system
Options:
-s --single remove only single module
-o --once confirm remove only once
-f --force don't ask, just do it!
-h --help display this usage message and exit
EOF
}
# Parse the command line.
ARGS=$(getopt --options shfo \
--long single,help,force,once \
--name "rm-module" -- "$@")
GETOPT_STATUS=$?
exit 6
fi
eval set -- "$ARGS"
while :; do
case "$1" in
-s|--single) SINGLE="yes" ;;
-o|--once) ONCE="yes" ;;
-f|--force) FORCE="yes" ;;
-h|--help) SHOWHELP="yes" ;;
--) shift; break ;;
*) echo "Error: internar error; getopt permitted \"$1\" unexpectedly"
exit 6
;;
esac
shift
done
if [ "$SHOWHELP" ]; then
usage
exit 0
fi
if [[ -z "$1" ]];then
usage
exit 1
fi
if [ $? == 1 ];then
echo "Error: can't find module $1"
exit 1
fi
MODULE=$(echo "$MODULE" | head -2 | tail -1 | tr -d ':' | rev | cut -d '/' -f 1,2 | rev | sed 's/.lua//')
if [ "$SINGLE" ]; then
if [[ -z $DEP ]]; then
echo -e "\r[\e[32mINDEPENDENT\e[0m] $MODULE"
if [[ -z "$FORCE" ]];then
echo -ne "\nRemove module $MODULE? [yes/NO]: "
read CONTINUE
if [ "$CONTINUE" != "yes" ]; then
exit 0
fi
fi
exit 0
else
echo -e "\r[\e[31m DEPENDENT \e[0m] $MODULE"
exit 1
fi
fi
echo -n "Building module tree..."
DEP=$(find_dep "$MODULE") #find all modules dependenton this one
for MOD in "$REMOVELIST"; do
DEP=$(echo "$DEP" | grep -v "$MOD") #erase modules which is on remove list
done
if [[ -z $DEP ]]; then
echo -e "\r[\e[32mINDEPENDENT\e[0m] $MODULE"
REMOVELIST+="$MODULE " #if module is independent add it to remove list
else
echo -e "\r[\e[31m DEPENDENT \e[0m] $MODULE"
fi
done
if [[ -z $REMOVELIST ]]; then
echo -e "\nNothing to remove, exiting..."
exit 0
fi
echo -e "\nRemove list:"
for MODULE in "$REMOVELIST"; do
find_module_paths "$MODULE"
for MODULE in "$REMOVELIST"; do
remove_module "$MODULE"
done
exit 0
fi
if [ "$ONCE" ]; then
echo -e "\n!!!\e[31m WARNING \e[0m!!! Modules will be permanently deleted! !!!\e[31m WARNING \e[0m!!!\n"
echo -n "Remove modules? [yes/NO]: "
read CONTINUE
if [ "$CONTINUE" != "yes" ]; then
exit 0
fi
fi
if [[ -z "$ONCE" ]]; then
echo -ne "\nRemove module $MODULE? [yes/NO]: "
read CONTINUE
if [ "$CONTINUE" != "yes" ]; then
continue
fi
fi