-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.sh
More file actions
executable file
·307 lines (262 loc) · 8 KB
/
upgrade.sh
File metadata and controls
executable file
·307 lines (262 loc) · 8 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# Upgrade script for ui-apt-mirror
# Downloads and installs the latest version from https://ui-apt-mirror.dbashkatov.com/
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
WEBSITE_URL="https://ui-apt-mirror.dbashkatov.com"
TEMP_DIR="./tmp"
DIST_DIR="dist"
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to verify required commands are installed
require_cmd() {
local missing=()
for cmd in "$@"; do
if ! command -v "$cmd" >/dev/null 2>&1; then
missing+=("$cmd")
fi
done
if [ ${#missing[@]} -gt 0 ]; then
print_error "Missing required command(s): ${missing[*]}"
print_error "Install them and re-run this script."
case " ${missing[*]} " in
*" curl "*) print_error " curl: sudo apt-get install -y curl" ;;
esac
case " ${missing[*]} " in
*" tar "*) print_error " tar: sudo apt-get install -y tar" ;;
esac
exit 1
fi
}
# Function to detect system architecture
detect_architecture() {
local arch=$(uname -m)
case $arch in
x86_64)
echo "amd64"
;;
aarch64|arm64)
echo "arm64"
;;
*)
print_error "Unsupported architecture: $arch"
exit 1
;;
esac
}
# Function to check connectivity to the website
check_connectivity() {
print_status "Checking connectivity to $WEBSITE_URL..."
if curl -s --head --fail "$WEBSITE_URL" > /dev/null 2>&1; then
print_success "Connectivity check passed"
return 0
else
print_error "Cannot connect to $WEBSITE_URL"
print_error "Please check your internet connection and try again"
exit 1
fi
}
# Function to get user choice for architecture
get_architecture_choice() {
local current_arch=$(detect_architecture)
echo ""
echo "Current system architecture: $current_arch"
echo ""
echo "Choose download option:"
echo " 1. Download current architecture only ($current_arch)"
echo " 2. Download all architectures (amd64 + arm64)"
echo ""
while true; do
read -p "Enter your choice (1 or 2): " choice
case $choice in
1)
ARCH_CHOICE="current"
DOWNLOAD_ARCH=$current_arch
DOWNLOAD_URL="$WEBSITE_URL/downloads/ui-apt-mirror-$current_arch.tar"
print_success "Selected: Current architecture ($current_arch)"
break
;;
2)
ARCH_CHOICE="all"
DOWNLOAD_ARCH="all"
DOWNLOAD_URL="$WEBSITE_URL/downloads/ui-apt-mirror-all.tar"
print_success "Selected: All architectures"
break
;;
*)
print_error "Invalid choice. Please enter 1 or 2."
;;
esac
done
}
# Function to download the latest version
download_latest() {
print_status "Downloading latest version..."
print_status "URL: $DOWNLOAD_URL"
# Create temp directory
mkdir -p "$TEMP_DIR"
# Download the file
if curl -L -o "$TEMP_DIR/ui-apt-mirror.tar" "$DOWNLOAD_URL"; then
print_success "Download completed successfully"
else
print_error "Download failed"
rm -rf "$TEMP_DIR"
exit 1
fi
}
# Function to extract and install
extract_and_install() {
print_status "Extracting downloaded archive..."
# Extract to temp directory
if tar -xzf "$TEMP_DIR/ui-apt-mirror.tar" -C "$TEMP_DIR"; then
print_success "Archive extracted successfully"
else
print_error "Failed to extract archive"
rm -rf "$TEMP_DIR"
exit 1
fi
# Check if dist directory exists in extracted content
if [ ! -d "$TEMP_DIR/dist" ]; then
print_error "Invalid archive format: dist directory not found"
rm -rf "$TEMP_DIR"
exit 1
fi
# Create dist directory if it doesn't exist
mkdir -p "$DIST_DIR"
# Move image files to dist directory
print_status "Installing new image files..."
for image_file in "$TEMP_DIR"/dist/*.tar.gz; do
if [ -f "$image_file" ]; then
local filename=$(basename "$image_file")
print_status "Installing $filename..."
cp "$image_file" "$DIST_DIR/"
print_success "Installed $filename"
fi
done
# Check if any files were installed
if [ -z "$(ls -A "$DIST_DIR"/*.tar.gz 2>/dev/null)" ]; then
print_error "No image files found in the downloaded archive"
rm -rf "$TEMP_DIR"
exit 1
fi
print_success "Image files installed successfully"
# Copy additional project files
print_status "Installing additional project files..."
# List of files to copy
local files_to_copy=(
"setup.sh"
"start.sh"
"upgrade.sh"
"docker-compose.src.yml"
"README.md"
)
# Copy individual files
for file in "${files_to_copy[@]}"; do
if [ -f "$TEMP_DIR/$file" ]; then
print_status "Installing $file..."
cp "$TEMP_DIR/$file" "./"
print_success "Installed $file"
else
print_warning "File $file not found in downloaded archive"
fi
done
print_success "Additional project files installed successfully"
}
# Function to run setup
run_setup() {
print_status "Running setup script..."
if [ ! -f "./setup.sh" ]; then
print_error "setup.sh not found in current directory"
rm -rf "$TEMP_DIR"
exit 1
fi
print_status "Starting setup process..."
./setup.sh
}
# Function to cleanup
cleanup() {
print_status "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
print_success "Cleanup completed"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --help Show this help message"
echo ""
echo "This script will:"
echo " 1. Check connectivity to $WEBSITE_URL"
echo " 2. Ask user to choose architecture (current or all)"
echo " 3. Download the latest version"
echo " 4. Extract and install new image files"
echo " 5. Run setup.sh to deploy the upgrade"
echo " 6. Clean up temporary files"
echo ""
echo "Prerequisites:"
echo " - Internet connection"
echo " - curl for downloading"
echo " - tar for extraction"
echo " - setup.sh in current directory"
}
# Main execution
main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
print_status "Starting ui-apt-mirror upgrade process..."
# Verify required commands are installed
require_cmd curl tar
# Check connectivity
check_connectivity
# Get user choice for architecture
get_architecture_choice
# Download latest version
download_latest
# Extract and install
extract_and_install
# Run setup
run_setup
# Cleanup
cleanup
print_success "Upgrade completed successfully!"
echo ""
print_warning "docker-compose.yml was regenerated from docker-compose.src.yml."
print_warning "If you had custom changes, re-apply them now."
echo ""
print_status "The new version is now running. You can access it at:"
echo " - Main Repository: http://mirror.intra"
echo " - Admin Panel: http://admin.mirror.intra"
echo " - File Repository: http://files.mirror.intra"
}
# Run main function with all arguments
main "$@"