-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathubuntu
More file actions
200 lines (177 loc) · 7.87 KB
/
ubuntu
File metadata and controls
200 lines (177 loc) · 7.87 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
######################################################################
# Auto Install & Optimize LEMP Stack on Ubuntu #
# #
# Author: TinyActive - Base On HOSTVN.VN Scripts #
# Website: https://github.com/TinyActive/panel #
# #
# Please do not remove copyright. Thank! #
# Please do not copy under any circumstance for commercial reason! #
######################################################################
OS_VER=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
LIST_OS_VER_SUPPORT=('22.04' '24.04')
rm -rf ubuntu
DIR=$(pwd)
# Set link
SCRIPT_LINK="${HOME_PAGE}"
welcome(){
clear
printf "\033[1;36m╔════════════════════════════════════════════════════════╗\033[0m\n"
printf "\033[1;36m║ \033[1;33mTiny Panel\033[1;36m ║\033[0m\n"
printf "\033[1;36m║ \033[0;37mBase on HOSTVN.VN Scripts\033[1;36m ║\033[0m\n"
printf "\033[1;36m║ \033[0;37mAuto Install & Optimize LEMP Stack\033[1;36m ║\033[0m\n"
printf "\033[1;36m║ \033[0;37mContact: contact@manhtuong.net\033[1;36m ║\033[0m\n"
printf "\033[1;36m╚════════════════════════════════════════════════════════╝\033[0m\n"
echo
printf "\033[1;32m▶ Preparing installation...\033[0m\n"
sleep 3
}
###################
# Prepare Install #
###################
fixed_lock_frontend(){
killall apt apt-get
rm -rf /var/lib/apt/lists/lock
rm -rf /var/cache/apt/archives/*
rm -rf /var/lib/dpkg/*
}
# Remove unnecessary services
remove_old_service(){
# Remove packages in a single command
apt-get -y remove mysql* mariadb* php* apache2* postfix* rsyslog* nginx* fail2ban
# Remove directories in batches
rm -rf /etc/nginx/{nginx.conf,alias,rewrite,ssl,wordpress,apps,extra,redirect,rocket-nginx,web_apps.conf} \
/etc/{apache2,php,my.cnf,mysql,fail2ban} \
/var/{hostvn,lib/mysql} \
/run/mysqld \
/usr/{share/nginx,share/nginx_module/,lib/nginx/modules,bin/hostvn}
# Clean package cache
apt-get clean all
# Remove configuration entries in a single sed command for each file
sed -i '/TinyPanel\|tinycp/d' "$HOME/.bashrc"
sed -i '/filetransfer\|Prevent user access\|Disable X11\|Disable tunneling\|Disable port forwarding\|Disable network tunneling\|Force the connection/d' /etc/ssh/sshd_config
# Remove local script file if exists
[[ -f "$DIR/hostvn" ]] && rm -rf "$DIR/hostvn"
}
set_dns_server(){
check_dns=$(grep -rnw "/etc/resolv.conf" -e "1.1.1.1")
if [[ -z $check_dns ]]; then
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf > /dev/null
fi
}
create_source_list(){
# Backup existing sources.list
if [[ -f /etc/apt/sources.list ]]; then
mv /etc/apt/sources.list /etc/apt/sources.list."$(date +%Y-%m-%d)"
fi
# backup file /etc/apt/sources.list.d/ubuntu.sources nếu tồn tại
if [[ -f /etc/apt/sources.list.d/ubuntu.sources ]]; then
mv /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources."$(date +%Y-%m-%d)"
fi
# Set codename based on OS version
case "${OS_VER}" in
"22.04") codename="jammy" ;;
"24.04") codename="noble" ;; # Fixed: 24.04 uses "noble", not "lunar"
*) return 1 ;;
esac
# Create sources.list with the appropriate codename
cat > "/etc/apt/sources.list" << EOsource_list
deb http://archive.ubuntu.com/ubuntu/ ${codename} main restricted
deb http://archive.ubuntu.com/ubuntu/ ${codename}-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ ${codename} universe
deb http://archive.ubuntu.com/ubuntu/ ${codename}-updates universe
deb http://archive.ubuntu.com/ubuntu/ ${codename} multiverse
deb http://archive.ubuntu.com/ubuntu/ ${codename}-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ ${codename}-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu ${codename}-security main restricted
deb http://security.ubuntu.com/ubuntu ${codename}-security universe
deb http://security.ubuntu.com/ubuntu ${codename}-security multiverse
EOsource_list
apt update -y
}
install_requirement(){
apt-get update -y
apt-get upgrade -y
apt-get autoremove -y
apt-get install build-essential gcc g++ make flex bison openssl libssl-dev perl perl-base perl-modules libperl-dev cmake \
libperl4-corelibs-perl libwww-perl libaio1 libaio-dev gifsicle webp libde265-dev \
zlib1g zlib1g-dev libcap-dev cron bzip2 zip automake autoconf libtool cmake python libdb-dev libsasl2-dev \
libncurses5 libncurses5-dev libsystemd-dev bind9 dnsutils quota patch logrotate rsyslog libc6-dev libexpat1-dev \
libcrypt-openssl-rsa-perl libnuma-dev libnuma1 git dos2unix ipcalc unzip net-tools wget apache2-utils grc \
libjpeg-dev libpng-dev libtiff-dev libgif-dev libwebp-dev imagemagick libpcre3 libpcre3-dev uuid-dev \
gnupg2 ca-certificates lsb-release apache2-dev libxml2-dev libcurl4-openssl-dev liblmdb-dev libgeoip-dev pkgconf \
libpcre++-dev libyajl-dev apt-utils htop nano supervisor bc libmaxminddb-dev libbrotli-dev -y
service supervisor stop
systemctl disable supervisor
}
create_swap(){
swap="$(swapon -s)"
if [[ -z "${swap}" ]]; then
clear
while true
do
read -r -p "Ban co muon tao swap hay khong ? (y/n)" confirm_swap
echo
if [[ "${confirm_swap}" =~ ^([yY])$ || "${confirm_swap}" =~ ^([nN])$ ]]; then
break
else
printf "%s\n" "${RED}Lua chon cua ban khong chinh xac. Vui long nhap lai.${NC}"
fi
done
fi
if [[ "${confirm_swap}" =~ ^([yY])$ ]]; then
REGEX_NUMBER='^[0-9]+$'
while true
do
echo "Nhap vao dung luong swap muon tao. (VD: 1G nhap so 1, 2G nhap so 2)"
read -r -p "Nhap vao dung luong swap muon tao (Nhap 0 de huy tao swap): " swap_size
if [[ ${swap_size} =~ ${REGEX_NUMBER} ]]; then
break
else
clear
printf "%s\n" "${RED}Gia tri ban nhap khong dung. Vui long nhap lai.${NC}"
fi
done
if [ "${swap_size}" != 0 ]; then
fallocate -l "${swap_size}"G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
fi
fi
}
set_timezone(){
if [[ -f "/etc/localtime" && -f "/usr/share/zoneinfo/Asia/Ho_Chi_Minh" ]]; then
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
else
timedatectl set-timezone Asia/Ho_Chi_Minh
fi
}
#########################
#Dowload primary Script #
#########################
download_script(){
curl -sO "${SCRIPT_LINK}"/tinycp-ubuntu
dos2unix tinycp-ubuntu
chmod +x tinycp-ubuntu
bash tinycp-ubuntu
}
welcome
if [[ " ${LIST_OS_VER_SUPPORT[*]} " == *" ${OS_VER} "* ]]; then
#fixed_lock_frontend
remove_old_service
set_dns_server
create_source_list
install_requirement
create_swap
set_timezone
download_script
else
clear
printf "${RED}%s${NC}" "Ban dang su dung phien ban ${OS} ${OS_VER}."
printf "${RED}%s${NC}" "Hien tai Scripts chi ho tro Ubuntu 22.04 va 24.04, phien ban 24.04 la on dinh nhat, neu co the hay dung Ubuntu 24.04"
printf "${RED}%s${NC}" "Huy cai dat."
exit
fi