@@ -192,40 +192,34 @@ check_for_script_update() {
192192 echo -e " ${C_YELLOW} Skipping script update check: 'jq' command not found.${C_RESET} "
193193 return 0
194194 fi
195- echo -e " ${C_BOLD} --- Checking for script updates ---${C_RESET} "
195+ echo -e " ${C_BOLD} --- Checking for script updates ---${C_RESET} "
196196 local SCRIPT_API_URL=" https://api.github.com/repos/buildplan/restic-backup-script/releases/latest"
197197 local release_info
198- release_info=$( curl -sL " $SCRIPT_API_URL " )
198+ release_info=$( curl -sL -H " Cache-Control: no-cache " -H " Pragma: no-cache " " $SCRIPT_API_URL " )
199199 local remote_version
200200 remote_version=$( echo " $release_info " | jq -r ' .tag_name | sub("^v"; "")' )
201201 if [ -z " $remote_version " ] || [[ " $remote_version " == " $SCRIPT_VERSION " ]]; then
202202 echo -e " ${C_GREEN} ✅ Script is up to date (version $SCRIPT_VERSION ).${C_RESET} "
203203 return 0
204204 fi
205205 local release_notes
206- release_notes=$( echo " $release_info " | jq -r ' .body' )
206+ release_notes=$( echo " $release_info " | jq -r ' .body // "Could not retrieve release notes." ' )
207207 display_update_info " this script" " $SCRIPT_VERSION " " $remote_version " " $release_notes "
208-
209- read -p " Would you like to download and update now? (y/n): " confirm
210- if [[ " ${confirm,,} " != " y" && " ${confirm,,} " != " yes" ]]; then
208+ read -rp " Would you like to download and update now? (y/n): " confirm
209+ if [[ ! " $confirm " =~ ^[yY]$ ]]; then
211210 echo " Skipping update."
212211 return 0
213212 fi
214- local script_url checksum_url
215- script_url=$( echo " $release_info " | jq -r ' .assets[] | select(.name == "restic-backup.sh") | .browser_download_url' )
216- checksum_url=$( echo " $release_info " | jq -r ' .assets[] | select(.name == "restic-backup.sh.sha256") | .browser_download_url' )
217- if [ -z " $script_url " ] || [ -z " $checksum_url " ]; then
218- echo -e " ${C_RED} Could not find script/checksum download URLs in the latest release. Aborting update.${C_RESET} " >&2
219- return 1
220- fi
213+ local SCRIPT_URL=" https://raw.githubusercontent.com/buildplan/restic-backup-script/main/restic-backup.sh"
214+ local CHECKSUM_URL=" ${SCRIPT_URL} .sha256"
221215 local temp_script temp_checksum
222216 temp_script=$( mktemp)
223217 temp_checksum=$( mktemp)
224218 trap ' rm -f "$temp_script" "$temp_checksum"' RETURN
225- local curl_opts=(-sL --fail --retry 3 --retry-delay 2)
226- echo " Downloading script update..."
227- if ! curl " ${curl_opts[@]} " -o " $temp_script " " $script_url " ; then echo " Download failed" ; return 1; fi
228- if ! curl " ${curl_opts[@]} " -o " $temp_checksum " " $checksum_url " ; then echo " Download failed" ; return 1; fi
219+ local curl_opts=(-sL --fail --retry 3 --retry-delay 2 -H " Cache-Control: no-cache " -H " Pragma: no-cache " )
220+ echo " Downloading script update from raw file URL ..."
221+ if ! curl " ${curl_opts[@]} " -o " $temp_script " " $SCRIPT_URL " ; then echo " Download failed" ; return 1; fi
222+ if ! curl " ${curl_opts[@]} " -o " $temp_checksum " " $CHECKSUM_URL " ; then echo " Download failed" ; return 1; fi
229223 echo " Verifying downloaded file integrity..."
230224 local remote_hash
231225 remote_hash=$( awk ' {print $1}' " $temp_checksum " )
@@ -241,10 +235,6 @@ check_for_script_update() {
241235 return 1
242236 fi
243237 echo -e " ${C_GREEN} ✅ Checksum verified successfully.${C_RESET} "
244- if ! grep -q -E " ^#!/(usr/)?bin/(env )?bash" " $temp_script " ; then
245- echo -e " ${C_RED} Downloaded file does not appear to be a valid script. Aborting update.${C_RESET} " >&2
246- return 1
247- fi
248238 chmod +x " $temp_script "
249239 mv " $temp_script " " $0 "
250240 if [ -n " ${SUDO_USER:- } " ] && [[ " $SCRIPT_DIR " != /root* ]]; then
0 commit comments