-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.sh
executable file
·54 lines (50 loc) · 1.25 KB
/
clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# Remove the environment
# import utility functions
. ./utils/utils.sh
delete_softlinks() {
# trap any error
trap "return 1" ERR
# remove all softlinks
for script in $(find ./scripts -name "*.sh"); do
# check that the script link exists
if [[ -L "$(cat ./utils/target-directory.txt)/$(basename "${script}" .sh)" ]]; then
sudo srm -drz "$(cat ./utils/target-directory.txt)/$(basename "${script}" .sh)"
fi
done
# remove target directory
rm ./utils/target-directory.txt
# remove the trap
trap - ERR
}
remove_permission() {
# trap any error
trap 'return 1' ERR
sudo find ./scripts -name "*.sh" -exec chmod a-x {} \;
# remove the trap
trap - ERR
}
echo 'bash-scripts uninstall'
# ask for super user
utils::ask_sudo
# check that the target directory is known
if [[ ! -f "./utils/target-directory.txt" ]]; then
utils::err 'Target directory ./utils/target-directory.txt not found.'
exit 1
fi
# error tracker
error=0
# delete softlinks
utils::exec_cmd 'delete_softlinks' 'Delete soft links'
((error|=$?))
# remove permission
utils::exec_cmd 'remove_permission' 'Remove permission'
((error|=$?))
# Done
if [[ "${error}" -eq 0 ]]; then
echo 'Uninstall finished!'
else
utils::err 'Unistallation imcomplete.'
exit 1
fi