forked from hiddify/Hiddify-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·117 lines (99 loc) · 3.64 KB
/
update.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
117
#!/bin/bash
source /opt/hiddify-manager/common/utils.sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cd $(dirname -- "$0")
# Create necessary directories and define constants
LOG_DIR="log/system"
mkdir -p "$LOG_DIR"
LOCK_FILE="log/update.lock"
ERROR_LOCK_FILE="log/error.lock"
LOG_FILE="$LOG_DIR/update.log"
BACKTITLE="Welcome to Hiddify Panel Updater"
function cleanup() {
error "Script interrupted. Exiting..."
disable_ansii_modes
# reset
rm "$LOCK_FILE"
echo "1" >"$ERROR_LOCK_FILE"
exit 1
}
trap cleanup SIGINT
function main() {
local force=false
local manager_update=0
local panel_update=0
if [[ -n "$1" ]]; then
local package_mode=$1
force=true
else
local package_mode=$(get_package_mode)
fi
local current_config_version=$(get_installed_config_version)
local current_panel_version=$(get_installed_panel_version)
if [[ $package_mode == "release" ]] && [[ $current_config_version == *"dev"* || ! $current_panel_version == 10* || ! $current_panel_version == 9* ]]; then
bash common/downgrade.sh
return 0
fi
rm -rf sniproxy caddy
echo "Creating a backup ..."
./hiddify-panel/backup.sh
case "$package_mode" in
develop)
# Use the latest commit from GitHub
latest_panel=$(get_commit_version HiddifyPanel)
latest_manager=$(get_commit_version hiddify-manager)
;;
beta)
latest_panel=$(get_pre_release_version hiddifypanel)
latest_manager=$(get_pre_release_version hiddify-manager)
;;
release)
latest_panel=$(get_release_version hiddifypanel)
latest_manager=$(get_release_version hiddify-manager)
;;
esac
[[ "$latest_panel" != "$current_panel_version" ]] && panel_update=1
[[ "$latest_manager" != "$current_config_version" ]] && manager_update=1
echo "Latest panel version: $latest_panel Installed: $current_panel_version Lastest manager version: $latest_manager Installed: $current_config_version"
if [[ "$force" == "true" || $panel_update == 1 || $manager_update == 1 ]]; then
bash <(curl -sSL https://raw.githubusercontent.com/hiddify/hiddify-config/main/common/download.sh) "$package_mode" "$force" "--no-gui"
else
echo "Nothing to update"
fi
rm -f $LOCK_FILE
}
# Check if another installation is running
if [[ -f $LOCK_FILE && $(($(date +%s) - $(cat $LOCK_FILE))) -lt 120 ]]; then
echo "Another installation is running.... Please wait until it finishes or wait 5 minutes or execute 'rm -f $LOCK_FILE'"
exit 1
fi
# Create or update the lock file
date +%s >$LOCK_FILE
# Run the main function and log the output
if [[ " $@ " == *" --no-gui "* ]]; then
set -- "${@/--no-gui/}"
main "$@" 2>&1 | tee $LOG_FILE
disable_ansii_modes
else
# Get terminal dimensions with fallback values
width=$(tput cols 2>/dev/null || echo 20)
height=$(tput lines 2>/dev/null || echo 20)
width=$((width < 20 ? 20 : width))
height=$((height < 20 ? 20 : height))
# Calculate log dimensions
log_h=$((height - 10))
log_w=$((width - 6))
# Log the console size
echo "console size=$log_h $log_w" | tee $LOG_FILE
main "$@" 2>&1 | tee -a $LOG_FILE | dialog --colors --keep-tite --backtitle "$BACKTITLE" \
--title "Installing Hiddify" \
--begin 2 2 \
--tailboxbg $LOG_FILE $log_h $log_w \
--and-widget \
--begin $((log_h + 2)) 2 \
--gauge "Please wait..., We are going to Update Hiddify" 7 $log_w 0
disable_ansii_modes
msg_with_hiddify "The update has successfully completed."
reset
check_hiddify_panel $@ |& tee -a $log_file
fi