-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall
More file actions
229 lines (196 loc) · 7.3 KB
/
install
File metadata and controls
229 lines (196 loc) · 7.3 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
# Enable error handling
set -e
trap 'echo "Error occurred at line $LINENO. Exit code: $?" >&2' ERR
######################################################################
# 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! #
######################################################################
# INSTALLATION WITH TMUX SESSION PROTECTION
# This script automatically uses tmux to protect your installation session
# If your connection is lost, you can reconnect and run:
# tmux attach-session -t panel_install
# to resume the installation process
# set evironment variables in /etc/environment
if [[ -f /etc/environment ]]; then
echo "HOME_PAGE=https://sdk.tinycp.me" > /etc/environment
export $(grep -v '^#' /etc/environment | xargs)
else
echo "HOME_PAGE=https://sdk.tinycp.me" > /etc/environment
export $(grep -v '^#' /etc/environment | xargs)
fi
# Check if the script is run as root
if [[ "$(id -u)" != "0" ]]; then
echo "This script must be run as root. Please use 'sudo' or switch to the root user."
exit 1
fi
#check evironment variables
if [[ -z "${HOME_PAGE}" ]]; then
echo "HOME_PAGE variable is not set. creat issue github report bug with info os."
echo ${date +%Y-%m-%d %H:%M:%S}
echo $(cat /etc/os-release)
echo $(uname -a)
exit 1
fi
# Set Color
RED='\033[0;31m'
NC='\033[0m'
OS=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
SCRIPT_LINK="${HOME_PAGE}/${OS}"
OS_LIST="ubuntu debian"
RAM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
LOW_RAM='400000'
# Set Lang
ROOT_ERR="Ban can dang nhap SSH voi user root."
CANCEL_INSTALL="Huy cai dat..."
RAM_NOT_ENOUGH="Canh bao: Dung luong RAM qua thap de cai Script. (It nhat 512MB)"
WRONG_OS="Rat tiec he dieu hanh ban dang su dung khong duoc ho tro."
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
if [[ "$(id -u)" != "0" ]]; then
printf "${RED}%s${NC}\n" "${ROOT_ERR}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
if [[ ${RAM_TOTAL} -lt ${LOW_RAM} ]]; then
printf "${RED}%s${NC}\n" "${RAM_NOT_ENOUGH}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
## check service
if systemctl is-active --quiet apache2; then
printf "%s\n" "${RED}Apache process detected, exit...${NC}"
exit
fi
if systemctl is-active --quiet mysqld; then
printf "%s\n" "${RED}Mysql process detected, exit...${NC}"
exit
fi
if systemctl is-active --quiet mariadb; then
printf "%s\n" "${RED}Mysql process detected, exit...${NC}"
exit
fi
if systemctl is-active --quiet mysql; then
printf "%s\n" "${RED}Mysql process detected, exit...${NC}"
exit
fi
if systemctl is-active --quiet nginx; then
printf "%s\n" "${RED}Nginx process detected, exit...${NC}"
exit
fi
# kiểm tra hệ điều hành chỉ hỗ trợ ubuntu, debian không hỗ trợ centos, almalinux hay các hệ điều hành khác
OS_LIST=("ubuntu" "debian")
WRONG_OS="Rat tiec he dieu hanh ban dang su dung khong duoc ho tro."
if [[ "${OS}" == "debian" ]]; then
OS="debian"
elif
[[ "${OS}" == "ubuntu" ]]; then
OS="ubuntu"
else
OS="unknown"
printf "${RED}%s${NC}\n" "${WRONG_OS}"
fi
# Install and setup tmux for session protection
echo "Installing tmux for session protection..."
if [[ "${OS}" == "debian" || "${OS}" == "ubuntu" ]]; then
apt update -qq && apt install -y tmux
elif [[ "${OS}" == "centos" || "${OS}" == "almalinux" ]]; then
yum -y install tmux
fi
# Get the full path of the current script
SCRIPT_PATH="$(realpath "$0")"
#wellcome message
welcome() {
clear
echo "#############################################"
echo "# #"
echo "# Auto Install & Optimize LEMP #"
echo "# #"
echo "# Author: TinyPanel - HOSTVN Base #"
echo "# Website: tinycp.me #"
echo "# #"
echo "#############################################"
}
# Check if we're already in a tmux session
if [[ -z "$TMUX" ]]; then
echo "Starting tmux session for installation protection..."
echo "You will be automatically attached to the session to monitor progress."
echo "If connection is lost, reconnect and run: tmux attach-session -t panel_install"
echo "Script path: $SCRIPT_PATH"
echo "OS detected: $OS"
sleep 2
# Temporarily disable strict error handling for tmux operations
set +e
# Kill existing session if any
echo "Checking for existing tmux sessions..."
tmux list-sessions 2>/dev/null && echo "Found existing sessions" || echo "No existing sessions"
tmux kill-session -t panel_install 2>/dev/null && echo "Killed existing panel_install session" || echo "No panel_install session to kill"
# Create tmux session and automatically attach user to it
echo "Creating tmux session with command: TMUX_INSTALL=1 bash '$SCRIPT_PATH'"
if tmux new-session -s panel_install "TMUX_INSTALL=1 bash '$SCRIPT_PATH'"; then
echo "Tmux session completed"
else
echo "Tmux session failed, exit code: $?"
fi
# Re-enable error handling
set -e
exit 0
fi
# If we're here, we're in tmux or TMUX_INSTALL is set
if [[ "$TMUX_INSTALL" == "1" ]]; then
echo "=========================================="
echo "Installation running in protected tmux session"
echo "Session name: panel_install"
echo "TMUX variable: $TMUX"
echo "TMUX_INSTALL variable: $TMUX_INSTALL"
echo "OS detected: $OS"
echo "If disconnected, reconnect with: tmux attach-session -t panel_install"
echo "=========================================="
echo ""
elif [[ -n "$TMUX" ]]; then
echo "Running inside existing tmux session"
echo "TMUX variable: $TMUX"
echo "OS detected: $OS"
fi
# Call welcome function to show the banner
welcome
# Small pause to let user see the welcome message
echo "Starting installation process..."
echo "Checking OS compatibility..."
echo "OS detected: $OS"
echo "OS_LIST: ${OS_LIST[*]}"
sleep 3
# Debug OS check
if [[ " ${OS_LIST[*]} " == *" ${OS} "* ]]; then
echo "OS '$OS' is supported. Proceeding with installation..."
else
echo "OS '$OS' is NOT supported."
echo "Supported OS list: ${OS_LIST[*]}"
fi
if [[ " ${OS_LIST[*]} " == *" ${OS} "* ]]; then
if [[ "${OS}" == "centos" || "${OS}" == "almalinux" ]]; then
yum -y install dos2unix
else
apt -y install dos2unix
fi
curl -sO "${SCRIPT_LINK}"
dos2unix "${OS}"
chmod +x "${OS}"
bash "${OS}"
# Clean up tmux session after installation
if [[ -n "$TMUX" ]]; then
echo ""
echo "Installation completed successfully!"
echo "To exit tmux session, press Ctrl+B then D, or type 'exit'"
echo "To completely remove the tmux session: tmux kill-session -t panel_install"
fi
else
printf "${RED}%s${NC}\n" "${WRONG_OS}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi