@@ -9,16 +9,24 @@ OLD_PULSE_DIR="/opt/pulse-proxmox"
9
9
PULSE_USER=" pulse"
10
10
SERVICE_NAME=" pulse-monitor.service"
11
11
REPO_BASE_URL=" https://github.com/rcourtman/Pulse"
12
+ SCRIPT_NAME=" install-pulse.sh"
13
+ SCRIPT_RAW_URL=" https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-pulse.sh"
14
+ CURRENT_SCRIPT_COMMIT_SHA=" 4348a3d"
12
15
13
16
MODE_UPDATE=" "
14
17
INSTALL_MODE=" "
15
18
SPECIFIED_VERSION_TAG=" "
16
19
TARGET_TAG=" "
20
+ INSTALLER_WAS_REEXECUTED=false
17
21
18
22
# Parse command line arguments
19
23
while [[ " $# " -gt 0 ]]; do
20
24
case $1 in
21
25
--update) MODE_UPDATE=" true" ; shift ;;
26
+ --installer-reexecuted)
27
+ INSTALLER_WAS_REEXECUTED=true
28
+ shift
29
+ ;;
22
30
--version)
23
31
if [[ -n " $2 " ]] && [[ " $2 " != --* ]]; then
24
32
SPECIFIED_VERSION_TAG=" $2 "
@@ -59,38 +67,130 @@ check_root() {
59
67
60
68
# Self-update check
61
69
self_update_check () {
62
- # Skip if running from pipe or no curl available
63
- if [ ! -t 0 ] || ! command -v curl & > /dev/null ; then
70
+ # Skip if running from pipe, in update mode, or already reexecuted
71
+ if [ ! -t 0 ] || [ -n " $MODE_UPDATE " ] || [ " $INSTALLER_WAS_REEXECUTED " = " true " ] ; then
64
72
return 0
65
73
fi
66
74
67
- print_info " Checking for installer updates..."
75
+ if ! command -v curl & > /dev/null; then
76
+ print_warning " curl not found, skipping installer update check"
77
+ return 0
78
+ fi
79
+
80
+ # Install jq if needed for robust SHA checking
81
+ if ! command -v jq & > /dev/null; then
82
+ print_info " Installing jq for installer update check..."
83
+ if command -v apt-get & > /dev/null; then
84
+ apt-get update -qq > /dev/null 2>&1
85
+ if apt-get install -y -qq jq > /dev/null 2>&1 ; then
86
+ print_success " jq installed"
87
+ else
88
+ print_warning " Could not install jq, falling back to simple update check"
89
+ # Fall back to simple diff check
90
+ simple_update_check
91
+ return $?
92
+ fi
93
+ else
94
+ print_warning " Could not install jq, falling back to simple update check"
95
+ simple_update_check
96
+ return $?
97
+ fi
98
+ fi
99
+
100
+ print_info " Checking for installer updates (GitHub API)..."
68
101
69
- local current_script=" $0 "
102
+ local owner=" rcourtman"
103
+ local repo=" Pulse"
104
+ local script_path=" scripts/install-pulse.sh"
105
+ local branch=" main"
106
+ local api_url=" https://api.github.com/repos/${owner} /${repo} /commits?path=${script_path} &sha=${branch} &per_page=1"
107
+
108
+ local latest_sha
109
+ latest_sha=$( curl -sL -H " Accept: application/vnd.github.v3+json" " $api_url " | jq -r ' if type=="array" and length > 0 then .[0].sha else empty end' )
110
+
111
+ if [ -z " $latest_sha " ] || [ " $latest_sha " = " null" ]; then
112
+ print_warning " Could not check for updates via API"
113
+ return 0
114
+ fi
115
+
116
+ local current_sha=" $CURRENT_SCRIPT_COMMIT_SHA "
117
+ if [ -z " $current_sha " ]; then
118
+ print_warning " Current version unknown, skipping update check"
119
+ return 0
120
+ fi
121
+
122
+ if [ " $latest_sha " != " $current_sha " ]; then
123
+ print_warning " New installer version available (${latest_sha: 0: 7} )"
124
+ read -p " Update installer and restart? [Y/n]: " confirm
125
+
126
+ if [[ ! " $confirm " =~ ^[Nn]$ ]]; then
127
+ print_info " Downloading new installer..."
128
+ local temp_script=" /tmp/${SCRIPT_NAME} .tmp"
129
+
130
+ if ! curl -sL " $SCRIPT_RAW_URL " -o " $temp_script " ; then
131
+ print_error " Failed to download new installer"
132
+ rm -f " $temp_script "
133
+ return 1
134
+ fi
135
+
136
+ # Update the SHA in the downloaded script
137
+ local updated_script=" ${temp_script} .updated"
138
+ local sha_updated=false
139
+
140
+ while IFS= read -r line || [[ -n " $line " ]]; do
141
+ if [[ " $line " == CURRENT_SCRIPT_COMMIT_SHA= * ]]; then
142
+ echo " CURRENT_SCRIPT_COMMIT_SHA=\" ${latest_sha: 0: 7} \" " >> " $updated_script "
143
+ sha_updated=true
144
+ else
145
+ echo " $line " >> " $updated_script "
146
+ fi
147
+ done < " $temp_script "
148
+
149
+ if [ " $sha_updated " = false ]; then
150
+ print_error " Failed to update version in new installer"
151
+ rm -f " $temp_script " " $updated_script "
152
+ return 1
153
+ fi
154
+
155
+ # Replace current script
156
+ if ! mv " $updated_script " " $0 " ; then
157
+ print_error " Failed to update installer"
158
+ rm -f " $temp_script " " $updated_script "
159
+ return 1
160
+ fi
161
+
162
+ chmod +x " $0 "
163
+ rm -f " $temp_script "
164
+
165
+ print_success " Installer updated to ${latest_sha: 0: 7} "
166
+ print_info " Restarting..."
167
+ exec " $0 " --installer-reexecuted " $@ "
168
+ fi
169
+ else
170
+ print_success " Installer is up to date"
171
+ fi
172
+ }
173
+
174
+ # Simple fallback update check using diff
175
+ simple_update_check () {
70
176
local temp_script=" /tmp/install-pulse-new.sh"
71
- local script_url=" https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-pulse.sh"
72
-
73
- # Download latest version
74
- if curl -sL " $script_url " -o " $temp_script " 2> /dev/null; then
75
- # Compare with current script
76
- if ! diff -q " $current_script " " $temp_script " > /dev/null 2>&1 ; then
77
- print_warning " A newer version of the installer is available"
78
- read -p " Update installer and restart? [Y/n]: " update_confirm
177
+
178
+ if curl -sL " $SCRIPT_RAW_URL " -o " $temp_script " 2> /dev/null; then
179
+ if ! diff -q " $0 " " $temp_script " > /dev/null 2>&1 ; then
180
+ print_warning " New installer version might be available"
181
+ read -p " Update installer and restart? [Y/n]: " confirm
79
182
80
- if [[ ! " $update_confirm " =~ ^[Nn]$ ]]; then
81
- print_info " Updating installer..."
82
- cp " $temp_script " " $current_script "
83
- chmod +x " $current_script "
183
+ if [[ ! " $confirm " =~ ^[Nn]$ ]]; then
184
+ cp " $temp_script " " $0 "
185
+ chmod +x " $0 "
84
186
rm -f " $temp_script "
85
-
86
- print_success " Installer updated, restarting..."
87
- exec " $current_script " " $@ "
187
+ print_success " Installer updated"
188
+ exec " $0 " " $@ "
88
189
fi
89
- else
90
- print_success " Installer is up to date"
91
190
fi
92
191
rm -f " $temp_script "
93
192
fi
193
+ return 0
94
194
}
95
195
96
196
# Print welcome banner
0 commit comments