This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall.sh
93 lines (77 loc) · 2.54 KB
/
uninstall.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Check if running as root and exit if not
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
exit 1
fi
error_exit()
{
if [ "$?" != "0" ]; then
echo "$1"
exit 1
else echo -e "$success"
fi
}
error_warn()
{
if [ "$?" != "0" ]; then
echo "$1"
echo "Not exiting."
else echo -e "$success"
fi
}
# Set some colors
RED='\033[0;31m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
# Welcome message
echo ""
echo -e "${BLUE}Kali Linux Chroot Uninstaller${NC}"
echo -e "${PURPLE}by shibedrill (Discord: Shibe Drill#9730)${NC}"
echo "Please let me know if you encounter a bug! I'm happy to help."
echo "This script will automatically uninstall the chroot that was generated by the kali-chroot script."
echo -e "${RED}WARNING: This is permanent! Your chroot and any data inside will be removed forever."
echo -e "Do you wish to continue? (y/N)${NC}"
# Take user consent to continue
read CONSENT
if [ "$CONSENT" != "y" ]
then exit 1
fi
echo ""
sleep 1
# Find chroot path
# Breakdown since this next command is kinda weird:
# Path is equal to (whichever line contains "directory=", and then we remove "directory=". This gives us JUST the directory, in a readable format.)
CHROOTPATH=$(grep directory= /etc/schroot/chroot.d/kali.conf | sed 's/directory=//')
success="${RED}Chroot found: "$CHROOTPATH". Proceeding with removal in 3 seconds. Press Ctrl + C to cancel."
error_exit "Error while finding chroot path. Aborting!"
sleep 1
echo -e "3..."
sleep 1
echo -e "2..."
sleep 1
echo -e "1..."
sleep 1
echo -e "Uninstall is beginning.${NC}"
echo "Removing chroot dir..."
rm -r $CHROOTPATH
success="Directory removed."
error_exit "Error while removing directory. Aborting!"
echo "Removing config file..."
rm /etc/schroot/chroot.d/kali.conf
success="File removed."
error_warn "Error while removing config file."
echo "Removing alias..."
if [ -f /home/"$SUDO_USER"/.bash_aliases ] ; then
# Perform inverted grep on alias to remove it from alias file
grep -v "alias kali='xhost + && sudo schroot -c kali -u root -d /root && schroot -e --all-sessions && xhost -'" /home/"$SUDO_USER"/.bash_aliases > tmpfile && mv tmpfile /home/"$SUDO_USER"/.bash_aliases
success="Removed alias."
error_warn "Error while removing alias."
elif ! [ -f /home/"$SUDO_USER"/.bash_aliases ] ; then
echo "Bash alias file not found. Make sure to remove your 'kali' alias from wherever you put it."
fi
echo ""
sleep 1
echo -e "${PURPLE}Finished! Thank you for using kali-chroot!"
echo -e "If you had issues with your chroot, please let me know!$"