LibrePortal/scripts/update/git/reset_git.sh
librelad ddea6b8a4d feat(update): route reset/reinstall recovery paths through the release fetch (phase D)
The git-era recovery commands now do the right thing in release mode instead of
attempting a clone:
- gitReset (libreportal reset / update reset) and runReinstall (CLI/system reset,
  missing-files recovery): a release branch re-fetches the verified tarball via
  lpFetchRelease, then refreshes /root/init.sh + ownership.
- the CLI wrapper's clone_and_install (libreportal reset): sources fetch.sh and
  re-fetches the release; falls back to directing the user to the install.sh
  bootstrap if the helper isn't present.

git/local behaviour unchanged. Wrapper still bakes cleanly (no placeholders left).

Phases A–D (release build, bootstrap installer, fetch abstraction, release-aware
install + update + recovery) are complete and locally verified. Remaining: phase E
(host install.sh + channels + tarballs on get.libreportal.org) and a real fresh
install on a throwaway box.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-25 18:16:35 +01:00

70 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
gitReset()
{
# Release mode: re-fetch the verified tarball instead of re-cloning.
if [[ "$CFG_INSTALL_MODE" == "release" ]]; then
if declare -f lpFetchRelease >/dev/null 2>&1 && lpFetchRelease; then
runSystem cp -f "$script_dir/init.sh" /root/ 2>/dev/null || true
runInstallOp chown -R "$sudo_user_name:$sudo_user_name" "$script_dir"
isSuccessful "Re-fetched the verified release."
else
isError "Release re-fetch failed — install unchanged."
fi
return
fi
# Check if this is a local installation
if [[ "$CFG_INSTALL_MODE" == "local" ]]; then
isNotice "Local installation detected - Git reset is not applicable."
echo "To reset a local installation, please manually restore files and rerun the init script."
else
gitCheckGitDetails;
gitMiscUpdate()
{
runSystem cp -f $script_dir/init.sh /root/
runInstallOp chown -R $sudo_user_name:$sudo_user_name "$script_dir"
}
local result=$(runAsManager rm -rf $script_dir)
checkSuccess "Deleting all Git files"
cd $docker_dir
# Strip http:// or https:// and .git for CLEAN_GIT_URL
CLEAN_GIT_URL=$(echo "$CFG_GIT_URL" | sed -E 's~^(https?://)?(.+?)\.git?$~\2~')
# Use authenticated clone if Git login is required
if [[ $CFG_INSTALL_MODE == "git" ]]; then
# Create authenticated URLs
AUTH_HTTPS_REPO_URL="https://${CFG_GIT_USER}:${CFG_GIT_KEY}@${CLEAN_GIT_URL}.git"
AUTH_HTTP_REPO_URL="http://${CFG_GIT_USER}:${CFG_GIT_KEY}@${CLEAN_GIT_URL}.git"
# Try HTTPS first
if runAsManager git clone -q "$AUTH_HTTPS_REPO_URL" "$script_dir" 2>/dev/null; then
isSuccessful "Git repository cloned via HTTPS into '$script_dir'."
else
# If HTTPS fails, try HTTP
if runAsManager git clone -q "$AUTH_HTTP_REPO_URL" "$script_dir" 2>/dev/null; then
isSuccessful "Git repository cloned via HTTP into '$script_dir'."
else
isError " Failed to clone repository via both HTTPS and HTTP."
exit 1
fi
fi
elif [[ $CFG_INSTALL_MODE == "local" ]]; then
if runAsManager git clone -q "https://${CLEAN_GIT_URL}.git" "$script_dir" 2>/dev/null; then
isSuccessful "Git repository cloned via HTTPS into '$script_dir'."
else
# If HTTPS fails, try HTTP
if runAsManager git clone -q "http://${CLEAN_GIT_URL}.git" "$script_dir" 2>/dev/null; then
isSuccessful "Git repository cloned via HTTP into '$script_dir'."
fi
fi
fi
gitMiscUpdate;
fi
}