Skip to content

Commit 1895305

Browse files
committed
Rework uninstall
1 parent 9fd83a2 commit 1895305

File tree

7 files changed

+153
-92
lines changed

7 files changed

+153
-92
lines changed

sdata/dist-arch/uninstall-deps.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This script is meant to be sourced.
2+
# It's not for directly running.
3+
4+
for i in illogical-impulse-{quickshell-git,audio,backlight,basic,bibata-modern-classic-bin,fonts-themes,hyprland,kde,microtex-git,oneui4-icons-git,portal,python,screencapture,toolkit,widgets} plasma-browser-integration; do
5+
v yay -Rns $i
6+
done

sdata/lib/environment-variables.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
44
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
55
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
66
XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
7-
BACKUP_DIR=${BACKUP_DIR:-$HOME/ii-original-dots-backup}
8-
INSTALLED_LISTFILE=${INSTALLED_LISTFILE:-$XDG_CONFIG_HOME/illogical-impulse/installed_listfile}
9-
107

118
STY_RED='\e[31m'
129
STY_GREEN='\e[32m'
@@ -23,8 +20,11 @@ STY_BLINK='\e[5m'
2320
STY_INVERT='\e[7m'
2421
STY_RST='\e[00m'
2522

26-
2723
# Used by register_temp_file()
2824
declare -a TEMP_FILES_TO_CLEANUP=()
2925

30-
FIRSTRUN_FILE="${XDG_CACHE_HOME}/.ii-qs-installed"
26+
# Used by install script
27+
BACKUP_DIR="${BACKUP_DIR:-$HOME/ii-original-dots-backup}"
28+
DOTS_CORE_CONFDIR="${XDG_CONFIG_HOME}/illogical-impulse"
29+
INSTALLED_LISTFILE="${DOTS_CORE_CONFDIR}/installed_listfile"
30+
FIRSTRUN_FILE="${DOTS_CORE_CONFDIR}/installed_true"

sdata/subcmd-exp-uninstall/0.run.sh

Lines changed: 0 additions & 80 deletions
This file was deleted.

sdata/subcmd-install/3.files-legacy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ case "${SKIP_MISCCONF}" in
120120
elif [ -f "dots/.config/$i" ];then install_file "dots/.config/$i" "$XDG_CONFIG_HOME/$i"
121121
fi
122122
done
123-
install_dir "dots/.local/share/konsole" "${XDG_DATA_HOME:-$HOME/.local/share}"/konsole
123+
install_dir "dots/.local/share/konsole" "${XDG_DATA_HOME}"/konsole
124124
;;
125125
esac
126126

sdata/subcmd-uninstall/0.run.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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}"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Handle args for subcmd: exp-uninstall
1+
# Handle args for subcmd: uninstall
22
# shellcheck shell=bash
33

44
showhelp(){
5-
echo -e "Syntax: $0 exp-uninstall [OPTIONS]...
5+
echo -e "Syntax: $0 uninstall [OPTIONS]...
66
7-
Experimental unintallation.
7+
Unintall dots.
88
99
Options:
1010
-h, --help Show this help message

setup

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ showhelp_global(){
1515
printf "${STY_CYAN}NOTE:
1616
The old \"./install.sh\" is now \"./setup install\"
1717
The old \"./update.sh\" is now \"./setup exp-update\"
18-
The old \"./uninstall.sh\" is now \"./setup exp-uninstall\"${STY_RST}
18+
The old \"./uninstall.sh\" is now \"./setup uninstall\"${STY_RST}
1919
2020
[$0]: Handle setup for illogical-impulse.
2121
@@ -30,7 +30,7 @@ Subcommands:
3030
install-files Run the install step \"3. Copying config files\"
3131
resetfirstrun Reset firstrun state.
3232
33-
exp-uninstall (Experimental) Uninstall illogical-impulse.
33+
uninstall Uninstall illogical-impulse.
3434
exp-update (Experimental) Update illogical-impulse without fully reinstall.
3535
exp-update-old (Experimental) exp-update but use behaves like old version.
3636
@@ -48,7 +48,7 @@ case $1 in
4848
# Global help
4949
""|help|--help|-h)showhelp_global;exit;;
5050
# Correct subcommand
51-
install|exp-uninstall|exp-update|exp-update-old|resetfirstrun|checkdeps|virtmon)
51+
install|uninstall|exp-update|exp-update-old|resetfirstrun|checkdeps|virtmon)
5252
SUBCMD_NAME=$1
5353
SUBCMD_DIR=./sdata/subcmd-$1
5454
shift;;

0 commit comments

Comments
 (0)