|
| 1 | +# This script is meant to be sourced. |
| 2 | +# It's not for directly running. |
| 3 | + |
| 4 | +# shellcheck shell=bash |
| 5 | + |
| 6 | +printf "${STY_RED}" |
| 7 | +printf "===CAUTION===\n" |
| 8 | +printf "This script will try to revert changes made by \"./setup install\".\n" |
| 9 | +printf "However:\n" |
| 10 | +printf "1. It is far from enough to precisely revert all changes.\n" |
| 11 | +printf "2. It has not been fully tested, use at your own risk.\n" |
| 12 | +printf "${STY_RST}" |
| 13 | +pause |
| 14 | +############################################################################################################################## |
| 15 | + |
| 16 | +# Undo Step 3 |
| 17 | +printf "${STY_CYAN}Undo install step 3...\n${STY_RST}" |
| 18 | + |
| 19 | +function view_listfile(){ |
| 20 | + local listfile="$1" |
| 21 | + if command -v less >/dev/null; then |
| 22 | + less "$listfile" |
| 23 | + else |
| 24 | + cat "$listfile" |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +function edit_listfile(){ |
| 29 | + local listfile="$1" |
| 30 | + for ed in "$EDITOR" nano vim nvim vi; do |
| 31 | + if command -v $ed >/dev/null; then |
| 32 | + x $ed "$listfile" |
| 33 | + return |
| 34 | + fi |
| 35 | + done |
| 36 | + printf "Failed to find an available editor, please manually edit \"$listfile\".\n" |
| 37 | +} |
| 38 | + |
| 39 | +function delete_targets(){ |
| 40 | + local listfile="$1" |
| 41 | + local targets=() |
| 42 | + readarray -t targets < "$listfile" |
| 43 | + for path in "${targets[@]}"; do |
| 44 | + if [[ ! -e "$path" ]]; then |
| 45 | + printf "${STY_YELLOW}Target \"$path\" inexists, skipping...${STY_RST}\n" |
| 46 | + continue |
| 47 | + elif [[ "$path" == "$HOME"* ]]; then |
| 48 | + x rm -- "$path" |
| 49 | + else |
| 50 | + while true; do |
| 51 | + printf "WARNING: Target \"$path\" is not under \$HOME. Still delete it?\ny=Yes, delete it;\nn=No, skip this one\n" |
| 52 | + read -n1 -p "> " ans < /dev/tty |
| 53 | + echo |
| 54 | + case "$ans" in |
| 55 | + y|Y) |
| 56 | + x rm -- "$path" |
| 57 | + break 1 |
| 58 | + ;; |
| 59 | + n|N) |
| 60 | + break 1 |
| 61 | + ;; |
| 62 | + *) |
| 63 | + ;; |
| 64 | + esac |
| 65 | + done |
| 66 | + fi |
| 67 | + done |
| 68 | +} |
| 69 | + |
| 70 | +function deletion_prompt(){ |
| 71 | + local listfile="$1" |
| 72 | + while true; do |
| 73 | + printf "Every target which path as a line inside the list \"$listfile\" will be deleted permanently.\n" |
| 74 | + printf "Please choose:\nv=View the list\ne=Edit the list\nq=Quit\ny=Perform deletion now\n" |
| 75 | + read -n1 -p "> " choice |
| 76 | + echo |
| 77 | + case "$choice" in |
| 78 | + q|Q) |
| 79 | + printf "Quiting...\n" |
| 80 | + break |
| 81 | + ;; |
| 82 | + y|Y) |
| 83 | + delete_targets "$listfile" |
| 84 | + break |
| 85 | + ;; |
| 86 | + v|V) |
| 87 | + view_listfile "$listfile" |
| 88 | + ;; |
| 89 | + e|E) |
| 90 | + edit_listfile "$listfile" |
| 91 | + ;; |
| 92 | + *) |
| 93 | + ;; |
| 94 | + esac |
| 95 | + done |
| 96 | +} |
| 97 | + |
| 98 | +deletion_prompt "${INSTALLED_LISTFILE}" |
| 99 | + |
| 100 | +empty_dir_listfile=$(mktemp) |
| 101 | +scan_paths=(${XDG_CONFIG_HOME} "${XDG_DATA_HOME}"/konsole) |
| 102 | +for dir in "${scan_paths[@]}"; do |
| 103 | + find "$dir" -type d -empty -print >> $empty_dir_listfile |
| 104 | +done |
| 105 | +x dedup_and_sort_listfile "$empty_dir_listfile" "$empty_dir_listfile" |
| 106 | +deletion_prompt "$empty_dir_listfile" |
| 107 | + |
| 108 | +############################################################################################################################## |
| 109 | + |
| 110 | +printf "${STY_CYAN}Undo install step 2...\n${STY_RST}" |
| 111 | +user=$(whoami) |
| 112 | +warn_undo_break_system(){ |
| 113 | + printf "${STY_YELLOW}WARNING: The command below could break your system functionality. If you are unsure about it, just skip the command.${STY_RST}\n" |
| 114 | +} |
| 115 | +warn_undo_break_system |
| 116 | +v sudo gpasswd -d "$user" video |
| 117 | +warn_undo_break_system |
| 118 | +v sudo gpasswd -d "$user" i2c |
| 119 | +warn_undo_break_system |
| 120 | +v sudo gpasswd -d "$user" input |
| 121 | +warn_undo_break_system |
| 122 | +v sudo rm /etc/modules-load.d/i2c-dev.conf |
| 123 | + |
| 124 | +############################################################################################################################## |
| 125 | + |
| 126 | +printf "${STY_CYAN}Undo install step 1...\n${STY_RST}" |
| 127 | + |
| 128 | +if test -f sdata/dist-$OS_GROUP_ID/uninstall-deps.sh; then |
| 129 | + source sdata/dist-$OS_GROUP_ID/uninstall-deps.sh |
| 130 | +else |
| 131 | + printf "${STY_YELLOW}Automatic depedencies uninstallation is not yet avaible for your distro. Skipping...${STY_RST}\n" |
| 132 | +fi |
| 133 | + |
| 134 | +printf "${STY_CYAN}Uninstall script finished.\n${STY_RST}" |
| 135 | +printf "${STY_CYAN}Hint: If you had agreed to backup when you ran \"./setup install\", you should be able to find it under \"$BACKUP_DIR\".\n${STY_RST}" |
0 commit comments