This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsystools.sh
132 lines (101 loc) · 3.66 KB
/
systools.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
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
#!/bin/bash
function error() {
echo -e "\e[91m$1\e[39m"
}
function error-sleep() {
echo -e "\e[91m$1\e[39m"
echo "press [CTRL+C] to exit."
sleep $2
}
echo "this script will help you execute system maintenance tasks"
PS3='Please enter the number above for task you would like to perform (1 - 6): '
options=("autoremove" "autoclean" "fix broken install" "clear swap" "fix duplicates in sources.list" "back to main menu")
select opt in "${options[@]}"
do
case $opt in
"autoremove")
sudo apt autoremove -y || error-sleep "error occured!" 10
break
;;
"autoclean")
sudo apt autoclean || error-sleep "error occured!" 10
sudo apt clean || error "error occured!"
break
;;
"fix broken install")
sudo apt -f install || error-sleep "error occured!" 10
sudo dpkg --configure -a || error "error occured!"
break
;;
"clear swap")
while true; do
echo -e "$(tput setaf 3)$(tput bold)WARNING: clearing swap isn't recommended!$(tput sgr 0)"
read -p "Do you want to continue? [y/n]" answer
if [[ "$answer" == "y" ]]; then
echo "clearing swap..."
echo -ne '(0%)[## ](100%)\r'
sleep 0.1
echo -ne '(0%)[###### ](100%)\r'
sudo systemctl restart dphys-swapfile || error-sleep "Failed to clear swap!" 10
sleep 0.1
echo -ne '(0%)[############### ](100%)\r'
sleep 0.3
echo -ne '(0%)[######################## ](100%)\r'
sleep 0.1
echo -ne '(0%)[##########################](100%)\r'
sleep 0.8
clear -x
echo -e "$(tput bold)DONE!$(tput sgr 0)"
break
elif [[ "$answer" == "n" ]]; then
#echo "$DIRECTORY/main.sh --no-internet"
break
else
echo "invalid option '$answer'."
fi
done
break
;;
"fix duplicates in sources.list")
while true; do
echo -e "$(tput setaf 3)$(tput bold)WARNING: this option is experimental and isn't recommended! if your sources.list\ngets messed up because of this script, you can delete it\nand replace it with the backup this script creates at '/etc/apt/sources.list.bak'.$(tput sgr 0)"
read -p "Do you want to continue? [y/n]" answer
if [[ "$answer" == "y" ]]; then
echo "deleting duplicates in '/etc/apt/sources.list'..."
echo -ne '(0%)[# ](100%)\r'
sudo rm -f ~/sources.list /etc/apt/sources.list.bak
sleep 0.3
#the part that actually deletes the dupicates
awk '/^$/ {print; next} {if ($1 in a) next; a[$1]=$0; print}' /etc/apt/sources.list > ~/sources.list
echo -ne '(0%)[######### ](100%)\r'
sleep 0.2
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo -ne '(0%)[################### ](100%)\r'
sleep 0.1
sudo mv ~/sources.list /etc/apt/sources.list
echo -ne '(0%)[######################## ](100%)\r'
sleep 0.1
echo -ne '(0%)[######################### ](100%)\r'
sleep 0.1
echo -ne '(0%)[##########################](100%)\r'
sleep 0.7
echo -e "\n\n$(tput bold)DONE!$(tput sgr 0)"
echo "there is a backup of your previous sources.list in $(tput bold)/etc/apt/sources.list.bak$(tput sgr 0)"
sleep 10
break
elif [[ "$answer" == "n" ]]; then
sleep 0.001
break
else
echo "invalid option '$answer'."
fi
done
break
;;
"back to main menu")
sleep 0.0001
break
;;
*) echo "invalid option $REPLY";;
esac
done