-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·82 lines (70 loc) · 2.09 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·82 lines (70 loc) · 2.09 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
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
source "$SCRIPT_DIR/lib/distro.sh"
source "$SCRIPT_DIR/lib/network.sh"
source "$SCRIPT_DIR/lib/build.sh"
APPLY=0
REQUESTED_TAG=""
while (($#)); do
case "$1" in
--apply) APPLY=1 ;;
--tag)
shift
(($#)) || die "--tag requires a value."
REQUESTED_TAG="$1"
;;
-h|--help)
printf 'Usage: ./update.sh [--apply] [--tag TAG]\n'
exit 0
;;
*) die "Unknown option: $1" ;;
esac
shift
done
require_linux
load_state
LATEST_TAG="$(list_upstream_tags | head -n1)"
[[ -n "$LATEST_TAG" ]] || die "No upstream Bridge release tags were found."
TARGET_TAG="${REQUESTED_TAG:-$LATEST_TAG}"
list_upstream_tags | grep -Fxq "$TARGET_TAG" || die "Unknown upstream tag: $TARGET_TAG"
printf 'Installed tag: %s\nTarget tag : %s\nNetwork mode : %s\nBind host : %s\n' \
"$BRIDGE_TAG" "$TARGET_TAG" "$NETWORK_MODE" "$BIND_HOST"
if [[ "$TARGET_TAG" == "$BRIDGE_TAG" ]]; then
log "The selected tag is already installed."
exit 0
fi
if (( ! APPLY )); then
printf '\nNo changes were made. Run sudo ./update.sh --apply to update.\n'
exit 0
fi
require_root
require_systemd
detect_distro
confirm_exact "UPDATE" "The selected tag will be built and replace the active Bridge binary."
OLD_TARGET="$(readlink -f "$ACTIVE_LINK")"
OLD_TAG="$BRIDGE_TAG"
OLD_VERSION="$BRIDGE_VERSION"
BRIDGE_TAG="$TARGET_TAG"
BRIDGE_VERSION="${BRIDGE_TAG#v}"
BRIDGE_VERSION="${BRIDGE_VERSION#br-}"
install_dependencies
prepare_source_tree "$BRIDGE_TAG"
ensure_go_toolchain
build_bridge
write_state
if systemctl is-enabled --quiet "$SERVICE_NAME"; then
systemctl restart "$SERVICE_NAME"
sleep 3
if ! systemctl is-active --quiet "$SERVICE_NAME"; then
warn "The updated service failed. Rolling back."
ln -sfn "$OLD_TARGET" "$ACTIVE_LINK"
BRIDGE_TAG="$OLD_TAG"
BRIDGE_VERSION="$OLD_VERSION"
write_state
systemctl restart "$SERVICE_NAME" || true
die "Update failed; the previous binary was restored."
fi
fi
log "Updated Proton Bridge to $BRIDGE_TAG."