forked from hawshemi/Linux-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux-optimizer.sh
116 lines (101 loc) · 2.81 KB
/
linux-optimizer.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
#!/bin/bash
clear
# Green, Yellow & Red Messages.
green_msg() {
tput setaf 2
echo "[*] ----- $1"
tput sgr0
}
yellow_msg() {
tput setaf 3
echo "[*] ----- $1"
tput sgr0
}
red_msg() {
tput setaf 1
echo "[*] ----- $1"
tput sgr0
}
# Intro
echo
green_msg '================================================================='
green_msg 'This script will automatically Optimize your Linux Server.'
green_msg 'Tested on: Ubuntu 16+, Debian 11+, CentOS 8+, Fedora 37+'
green_msg 'Root access is required.'
green_msg 'Source is @ https://github.com/DanielNoohi/linux-optimizer'
green_msg '================================================================='
echo
# Root
check_if_running_as_root() {
# If you want to run as another user, please modify $EUID to be owned by this user
if [[ "$EUID" -ne '0' ]]; then
echo
red_msg 'Error: You must run this script as root!'
echo
sleep 0.5
exit 1
fi
}
# Check Root
check_if_running_as_root
sleep 0.5
# OS Detection
if [[ $(grep -oP '(?<=^NAME=").*(?=")' /etc/os-release) == "Ubuntu" ]]; then
OS="ubuntu"
echo
sleep 0.5
yellow_msg "OS: Ubuntu"
echo
sleep 1
elif [[ $(grep -oP '(?<=^NAME=").*(?=")' /etc/os-release) == "Debian GNU/Linux" ]]; then
OS="debian"
echo
sleep 0.5
yellow_msg "OS: Debian"
echo
sleep 1
elif [[ $(grep -oP '(?<=^NAME=").*(?=")' /etc/os-release) == "CentOS Stream" ]]; then
OS="centos"
echo
sleep 0.5
yellow_msg "OS: Centos"
echo
sleep 1
elif [[ $(grep -oP '(?<=^NAME=").*(?=")' /etc/os-release) == "Fedora Linux" ]]; then
OS="fedora"
echo
sleep 0.5
yellow_msg "OS: Fedora"
echo
sleep 1
else
echo
sleep 0.5
red_msg "Unknwon OS, Create an issue here: https://github.com/DanielNoohi/Linux-Optimizer"
OS="unknown"
echo
sleep 2
fi
# Run Script based on Distros
case $OS in
ubuntu)
# Ubuntu
wget "https://raw.githubusercontent.com/DanielNoohi/Linux-Optimizer/main/scripts/ubuntu-optimizer.sh" -q -O ubuntu-optimizer.sh && chmod +x ubuntu-optimizer.sh && bash ubuntu-optimizer.sh
;;
debian)
# Debian
wget "https://raw.githubusercontent.com/DanielNoohi/Linux-Optimizer/main/scripts/debian-optimizer.sh" -q -O debian-optimizer.sh && chmod +x debian-optimizer.sh && bash debian-optimizer.sh
;;
centos)
# CentOS
wget "https://raw.githubusercontent.com/DanielNoohi/Linux-Optimizer/main/scripts/centos-optimizer.sh" -q -O centos-optimizer.sh && chmod +x centos-optimizer.sh && bash centos-optimizer.sh
;;
fedora)
# Fedora
wget "https://raw.githubusercontent.com/DanielNoohi/Linux-Optimizer/main/scripts/fedora-optimizer.sh" -q -O fedora-optimizer.sh && chmod +x fedora-optimizer.sh && bash fedora-optimizer.sh
;;
unknown)
# Unknown
exit
;;
esac