Repository navigation
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·105 lines (85 loc) · 2.32 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·105 lines (85 loc) · 2.32 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
#!/usr/bin/env bash
set -Eeuo pipefail
readonly LOG_FILE="/var/log/openship-control-update.log"
readonly STATE_FILE="/etc/openship-control/install.conf"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
log() { echo -e "$CYAN[INFO]$NC $*"; }
ok() { echo -e "$GREEN[ OK ]$NC $*"; }
warn() { echo -e "$YELLOW[WARN]$NC $*"; }
die() { echo -e "$RED[ERROR]$NC $*" >&2; exit 1; }
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
echo "Usage: sudo ./update.sh [--check]"
echo
echo "Options:"
echo " --check Check for OpenShip updates without applying"
echo " --help, -h Display this help message"
exit 0
fi
if [[ "$EUID" -ne 0 ]]; then
die "Run as root: sudo ./update.sh"
fi
mkdir -p "$(dirname "$LOG_FILE")"
touch "$LOG_FILE"
chmod 600 "$LOG_FILE"
exec > >(tee -a "$LOG_FILE") 2>&1
INSTALL_MODE="bare"
if [[ -f "$STATE_FILE" ]]; then
# shellcheck disable=SC1090
source "$STATE_FILE"
fi
echo
echo "============================================================"
echo " OpenShip Control Plane — Update"
echo "============================================================"
echo
command -v openship >/dev/null 2>&1 || die "OpenShip CLI is not installed."
log "Current OpenShip version:"
openship --version || true
echo
if [[ $# -ge 1 && "$1" == "--check" ]]; then
log "Checking for updates..."
openship update --check
exit $?
fi
if [[ $# -gt 0 ]]; then
die "Usage: sudo ./update.sh [--check]"
fi
echo
warn "OpenShip will update the CLI and bundled control plane server."
warn "The running OpenShip service will be restarted."
echo
read -r -p "Continue? [y/N]: " answer
case "$answer" in
y|Y|yes|YES) ;;
*) log "Update cancelled."; exit 0 ;;
esac
echo
log "Updating OpenShip..."
openship update
if [[ "${INSTALL_MODE}" == "bare" ]]; then
if systemctl is-active --quiet openship 2>/dev/null; then
log "Restarting OpenShip systemd service..."
systemctl restart openship
fi
fi
echo
log "Version after update:"
openship --version || true
echo
log "OpenShip status:"
openship status || true
echo
log "OpenShip doctor:"
if openship doctor; then
ok "OpenShip update and health check completed."
else
warn "OpenShip was updated, but doctor reported a problem."
warn "Run: sudo ./doctor.sh"
exit 2
fi
echo
echo "Log: $LOG_FILE"