diff --git a/ct/gotify.sh b/ct/gotify.sh index a4b7389997..1811d84ef2 100644 --- a/ct/gotify.sh +++ b/ct/gotify.sh @@ -29,23 +29,18 @@ function update_script() { fi RELEASE=$(curl -fsSL https://api.github.com/repos/gotify/server/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + if [[ "${RELEASE}" != "$(cat ~/.gotify 2>/dev/null)" ]] || [[ ! -f ~/.gotify ]]; then msg_info "Stopping ${APP}" systemctl stop gotify msg_ok "Stopped ${APP}" - msg_info "Updating ${APP} to ${RELEASE}" - cd /opt/gotify - curl -fsSL "https://github.com/gotify/server/releases/download/v${RELEASE}/gotify-linux-amd64.zip" -o $(basename "https://github.com/gotify/server/releases/download/v${RELEASE}/gotify-linux-amd64.zip") - $STD unzip -o gotify-linux-amd64.zip - rm -rf gotify-linux-amd64.zip - chmod +x gotify-linux-amd64 - echo "${RELEASE}" >/opt/${APP}_version.txt - msg_ok "Updated ${APP} to ${RELEASE}" + fetch_and_deploy_gh_release "gotify" "gotify/server" "prebuild" "latest" "/opt/gotify" "gotify-linux-amd64.zip" + chmod +x /opt/gotify/gotify-linux-amd64 msg_info "Starting ${APP}" systemctl start gotify msg_ok "Started ${APP}" + msg_ok "Updated Successfully" else msg_ok "No update required. ${APP} is already at ${RELEASE}" diff --git a/frontend/public/json/gotify.json b/frontend/public/json/gotify.json index 08cc46cab7..9765ba8d70 100644 --- a/frontend/public/json/gotify.json +++ b/frontend/public/json/gotify.json @@ -6,7 +6,7 @@ ], "date_created": "2024-05-02", "type": "ct", - "updateable": false, + "updateable": true, "privileged": false, "interface_port": 80, "documentation": "https://gotify.net/docs/index", diff --git a/install/gotify-install.sh b/install/gotify-install.sh index b87e38cf45..15fe235d2b 100644 --- a/install/gotify-install.sh +++ b/install/gotify-install.sh @@ -13,16 +13,8 @@ setting_up_container network_check update_os -msg_info "Installing Gotify" -RELEASE=$(curl -fsSL https://api.github.com/repos/gotify/server/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -mkdir -p /opt/gotify -cd /opt/gotify -curl -fsSL "https://github.com/gotify/server/releases/download/v${RELEASE}/gotify-linux-amd64.zip" -o "gotify-linux-amd64.zip" -$STD unzip gotify-linux-amd64.zip -rm -rf gotify-linux-amd64.zip -chmod +x gotify-linux-amd64 -echo "${RELEASE}" >/opt/${APPLICATION}_version.txt -msg_ok "Installed Gotify" +fetch_and_deploy_gh_release "gotify" "gotify/server" "prebuild" "latest" "/opt/gotify" "gotify-linux-amd64.zip" +chmod +x /opt/gotify/gotify-linux-amd64 msg_info "Creating Service" cat </etc/systemd/system/gotify.service diff --git a/misc/tools.func b/misc/tools.func index 65402fbe48..071a30cbb5 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -959,7 +959,7 @@ function fetch_and_deploy_gh_release() { $STD apt-get install -y unzip fi unzip -q "$tmpdir/$filename" -d "$unpack_tmp" - elif [[ "$filename" == *.tar.* ]]; then + elif [[ "$filename" == *.tar.* || "$filename" == *.tgz ]]; then tar -xf "$tmpdir/$filename" -C "$unpack_tmp" else msg_error "Unsupported archive format: $filename" @@ -969,23 +969,41 @@ function fetch_and_deploy_gh_release() { local top_dirs top_dirs=$(find "$unpack_tmp" -mindepth 1 -maxdepth 1 -type d | wc -l) - - if [[ "$top_dirs" -eq 1 ]]; then + local top_entries inner_dir + top_entries=$(find "$unpack_tmp" -mindepth 1 -maxdepth 1) + if [[ "$(echo "$top_entries" | wc -l)" -eq 1 && -d "$top_entries" ]]; then # Strip leading folder - local inner_dir - inner_dir=$(find "$unpack_tmp" -mindepth 1 -maxdepth 1 -type d) + inner_dir="$top_entries" shopt -s dotglob nullglob - cp -r "$inner_dir"/* "$target/" + if compgen -G "$inner_dir/*" >/dev/null; then + cp -r "$inner_dir"/* "$target/" || { + msg_error "Failed to copy contents from $inner_dir to $target" + rm -rf "$tmpdir" "$unpack_tmp" + return 1 + } + else + msg_error "Inner directory is empty: $inner_dir" + rm -rf "$tmpdir" "$unpack_tmp" + return 1 + fi shopt -u dotglob nullglob else # Copy all contents shopt -s dotglob nullglob - cp -r "$unpack_tmp"/* "$target/" + if compgen -G "$unpack_tmp/*" >/dev/null; then + cp -r "$unpack_tmp"/* "$target/" || { + msg_error "Failed to copy contents to $target" + rm -rf "$tmpdir" "$unpack_tmp" + return 1 + } + else + msg_error "Unpacked archive is empty" + rm -rf "$tmpdir" "$unpack_tmp" + return 1 + fi shopt -u dotglob nullglob fi - rm -rf "$unpack_tmp" - ### Singlefile Mode ### elif [[ "$mode" == "singlefile" ]]; then local pattern="${6%\"}"