-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathCleanerInstaller.sh
More file actions
executable file
·135 lines (117 loc) · 4.18 KB
/
CleanerInstaller.sh
File metadata and controls
executable file
·135 lines (117 loc) · 4.18 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#Author Omar BOUYKOURNE updated by Anas AAMMARI to support linux
#42login obouykou, 42login aaammari
echo -en "\n By: "
echo -e "\033[33m𝒐𝒃𝒐𝒖𝒚𝒌𝒐𝒖\033[0m"
echo -e "\n report any issues to me in:"
echo -e " GitHub ~> \033[4;1;34mombhd\033[0m"
echo -e " 42 Slack ~> \033[4;1;34mobouykou\033[0m\n"
sleep 2
#update
git pull &>/dev/null
# Detect Operating System
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macOS"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "Linux"
else
echo "Unknown"
fi
}
OS=$(detect_os)
echo -e "\033[36m -- Detected Operating System: $OS --\033[0m\n"
# Set the appropriate cleaner script based on OS
case $OS in
"macOS")
CLEANER_SCRIPT="Cleaner_42.sh"
CLEANER_NAME="macOS Cleaner"
;;
"Linux")
CLEANER_SCRIPT="LinuxCleaner_42.sh"
CLEANER_NAME="Linux Cleaner"
;;
"Unknown")
echo -e "\033[31m -- Unsupported Operating System: $OS --\033[0m"
echo -e "\033[33m -- Please run this script on macOS or Linux --\033[0m"
exit 1
;;
*)
echo -e "\033[31m -- Unknown OS type detected! Exiting... --\033[0m"
exit 1
;;
esac
echo -e "\033[32m -- Installing $CLEANER_NAME ($CLEANER_SCRIPT) --\033[0m\n"
#get the shell configuration file name
shell_f=$(echo -n "$SHELL" | awk -F / '{print $3}')
shell_f="${HOME}/.${shell_f}rc"
#test if it is already installed
if grep "alias cclean='bash ~/$CLEANER_SCRIPT'" <"$shell_f" &>/dev/null && ls "$HOME"/$CLEANER_SCRIPT &>/dev/null; then
sleep 0.5
echo -e "\033[33m\n -- cclean Already installed --\n\033[0m"
sleep 0.5
echo -e "\033[36m -- Please, run this command now : [\033[33m source $shell_f\033[0m\033[36m ] Then run [\033[33m cclean \033[0m\033[36m]--\n\033[0m"
sleep 0.5
echo -e "\033[36m -- For updates, run [\033[33m cclean update \033[0m\033[36m] --\n\033[0m"
exit 0
fi
# Check if the appropriate cleaner script exists
if [ ! -f "./$CLEANER_SCRIPT" ]; then
echo -e "\033[31m\n -- Error: $CLEANER_SCRIPT not found in current directory! --\033[0m"
echo -e "\033[33m -- Please make sure you have the correct cleaner script for $OS --\033[0m"
exit 1
fi
#take confirmation
while true; do
echo "cclean program/command removes: "
sleep 0.2
echo " - the Trash contents."
sleep 0.2
echo " - 42 caches from Library and Home directories."
sleep 0.2
echo " - Chrome Caches."
sleep 0.2
echo " - VSCode Caches and its workspaces cache storage."
sleep 0.2
echo " - Social Media Apps Caches, like Slack and Discord."
sleep 0.2
echo " - FileSystems which are located in browsers profiles directories, such as Chrome and Chromium."
sleep 0.2
echo -en "\n\033[33mDo you really want to install this program ? \033[0m\0"
read -r yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo -e "\n\033[31mPlease answer yes or no !\033[0m\0\n" ;;
esac
done
#remove the old Cleaner and Cleaner42 if there are any, then copy the current one to Home dir
/bin/rm -rf ~/Cleaner_42.sh &>/dev/null
/bin/rm -rf ~/LinuxCleaner_42.sh &>/dev/null
/bin/rm -rf ~/Cleaner.sh &>/dev/null
# Copy the appropriate cleaner script to Home dir
cp -f ./$CLEANER_SCRIPT "$HOME"
# Remove old aliases from shell config
if [ -f "$shell_f" ]; then
# Create a temporary file without the old aliases
tmp_shell_f="/tmp/$(basename "$shell_f").tmp"
grep -v "alias cclean=" "$shell_f" > "$tmp_shell_f" 2>/dev/null
mv "$tmp_shell_f" "$shell_f" 2>/dev/null
fi
if ! grep "alias cclean='bash ~/$CLEANER_SCRIPT'" <"$shell_f" &>/dev/null; then
echo -e "\nalias cclean='bash ~/$CLEANER_SCRIPT'" >>"$shell_f"
fi
# Verify installation
if grep "alias cclean='bash ~/$CLEANER_SCRIPT'" <"$shell_f" &>/dev/null && ls "$HOME"/$CLEANER_SCRIPT &>/dev/null; then
sleep 0.5
echo -e "\n\033[32m -- cclean command has been successfully installed ! Enjoy :) --\n\033[0m"
sleep 0.5
echo -e "\033[36m -- Please, run this command now : [\033[33m source $shell_f\033[0m\033[36m ] Then run [\033[33m cclean \033[0m\033[36m]--\n\033[0m"
sleep 0.5
echo -e "\033[36m -- For updates, run [\033[33m cclean update \033[0m\033[36m] --\n\033[0m"
else
sleep 0.5
echo -e "\033[31m\n -- cclean command has NOT been installed ! :( --\n\033[0m"
exit 1
fi
exit 0