-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdeleted.sh
More file actions
158 lines (137 loc) · 4.4 KB
/
deleted.sh
File metadata and controls
158 lines (137 loc) · 4.4 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
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
BASE_DIR="/srv/gml"
# Ensure the base directory exists
mkdir -p "$BASE_DIR"
# Function to display a spinner with support for nested tasks
show_spinner() {
local pid=$1
local text=$2
local level=${3:-0} # Default level is 0 if not provided
local spinstr='/-\|'
local delay=0.1
local indent=$(printf "%*s" $((level * 2)) "") # Indentation based on level
while kill -0 $pid 2>/dev/null; do
for char in $spinstr; do
printf "\r%s%s %c" "$indent" "$text" "$char"
sleep $delay
done
done
wait $pid
local result=$?
if [ $result -eq 0 ]; then
printf "\r%s%s \033[32m✓\033[0m\n" "$indent" "$text"
else
printf "\r%s%s \033[31m✗\033[0m\n" "$indent" "$text"
fi
return $result
}
# Disable additional notifications
disable_additional_notify() {
if [ -f /etc/needrestart/needrestart.conf ]; then
sed -i "s/#\$nrconf{restart} = 'i';/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf
fi
}
# Detect operating system
detect_os() {
step=$1
(
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
fi
) &
show_spinner $! "[Gml] Определение операционной системы $step"
return $?
}
# Prepare operating system
prepare_os() {
step=$1
(
disable_additional_notify
) &
show_spinner $! "[Gml] Подготовка операционной системы $step"
return $?
}
# Install a package
install_package() {
package=$1
(
if command -v apt-get >/dev/null; then
apt-get update >/dev/null 2>&1 && apt-get install -y "$package" >/dev/null 2>&1
elif command -v dnf >/dev/null; then
dnf install -y "$package" >/dev/null 2>&1
elif command -v yum >/dev/null; then
yum install -y "$package" >/dev/null 2>&1
elif command -v zypper >/dev/null; then
zypper install -y "$package" >/dev/null 2>&1
elif command -v pacman >/dev/null; then
pacman -Sy --noconfirm "$package" >/dev/null 2>&1
else
return 1
fi
) &
show_spinner $! "[System] Установка $package" 1
return $?
}
# Install Docker
install_docker() {
(
if ! command -v docker >/dev/null; then
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
apt-get remove -y $pkg >/dev/null 2>&1
done
apt-get update >/dev/null 2>&1
apt-get install -y ca-certificates curl >/dev/null 2>&1
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
tee /etc/apt/sources.list.d/docker.list >/dev/null
apt-get update >/dev/null 2>&1
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >/dev/null 2>&1
fi
) &
show_spinner $! "[Gml] Установка Docker" 1
return $?
}
# Install all required packages
install_packages() {
step=$1
(
install_docker
) &
show_spinner $! "[Gml] Установка пакетов $step"
return $?
}
# Startup function to run docker compose
startup() {
(
cd "$BASE_DIR" || exit
docker compose down -v
docker compose down --rmi all
mv "$BASE_DIR" "${BASE_DIR}_backup_$(date +%Y%m%d_%H%M%S)"
) &
show_spinner $! "[Gml] Запуск docker compose"
return $?
}
write_message() {
local server_ip=$(echo $SSH_CONNECTION | awk '{print $3}') # Извлекаем IP сервера
echo
echo
printf "\033[32m==================================================\033[0m\n"
printf "\033[32mПроект успешно Удален!\033[0m\n"
printf "\033[32m==================================================\033[0m\n"
}
# Main script execution
detect_os
prepare_os
install_packages
startup
write_message