LibrePortal/scripts/function/run/reinstall_libreportal.sh
librelad e4872ab511 refactor(paths): single source of truth for a relocatable, split layout (phase 1)
Introduce scripts/source/paths.sh as the canonical path resolver for three
independently-relocatable roots:
  LP_SYSTEM_DIR      manager-owned control plane (configs/logs/install/db/ssl/ssh/migrate)
  LP_CONTAINERS_DIR  container-user-owned live app data
  LP_BACKUPS_DIR     container-user-owned backup repos (own mount-able)

Roots come from the environment when set (install bakes them; CLI/app inherit
from init.sh), else default to /libreportal-*. A transitional compat default
keeps EXISTING installs (legacy single /docker tree, by config marker) on /docker
until a deliberate reinstall, so deploying this never strands a running box.

- init.sh derives the same vars inline (self-contained for the bare /root/init.sh
  reinstall case); paths.sh mirrors it for the standalone task/check processors,
  which now self-locate their scripts dir and source it.
- Replace functional /docker literals with the derived vars across runtime,
  install, backup, crontab, crowdsec/restic, headscale, and reinstall paths;
  clean the inert '== /docker/containers/*' guard fallbacks to the variable form.
- backend: CONTAINERS_DIR now from LP_CONTAINERS_DIR (compose env, filled at
  generation via a new CONTAINERS_DIR_TAG), legacy-safe default for un-recreated
  containers.
- backup default path falls back to the backups root; exclude paths.sh from the
  sourced-file arrays (bootstrap file, sourced explicitly).

The CLI-wrapper heredoc + root helpers still reference /docker; those get baked
in phase 3. No layout/ownership change yet (phase 2).

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

86 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
runReinstall()
{
isHeader "Reinstalling LibrePortal"
# Check if this is a local installation
if [[ "$CFG_INSTALL_MODE" == "local" ]]; then
echo "NOTICE: Local installation detected - cannot reinstall from Git."
echo "To update a local installation, please update the files manually and rerun the init script."
echo ""
echo "Alternatively, you can switch to Git installation by:"
echo "1. Updating CFG_INSTALL_MODE to 'git' in config"
echo "2. Setting Git credentials"
echo "3. Running reinstall again"
else
gitCheckGitDetails;
# Reset git
local result=$(runAsManager rm -rf $script_dir)
checkSuccess "Deleting all Git files"
local result=$(createFolders "loud" $sudo_user_name "$script_dir")
checkSuccess "Create the directory if it doesn't exist"
# Validate non-empty input
validate_input() {
local input="$1"
local prompt="$2"
local error_message="${3:-Please enter a valid input.}"
while [[ -z "$input" ]]; do
read -p "$prompt" input
if [[ -z "$input" ]]; then
echo "$error_message"
fi
done
echo "$input"
}
# Git User
if [[ -z "$CFG_GIT_USER" ]] || [[ "$CFG_GIT_USER" == "changeme" ]]; then
CFG_GIT_USER=$(validate_input "" "Enter the Git username: " "Git username cannot be empty.")
updateConfigOption "CFG_GIT_USER" "$CFG_GIT_USER"
fi
# Git Token
if [[ -z "$CFG_GIT_KEY" ]] || [[ "$CFG_GIT_KEY" == "changeme" ]]; then
CFG_GIT_KEY=$(validate_input "" "Enter your Git token: " "Git token cannot be empty.")
updateConfigOption "CFG_GIT_KEY" "$CFG_GIT_KEY"
fi
# Git URL
if [[ -z "$CFG_GIT_URL" ]] || [[ "$CFG_GIT_URL" == "changeme" ]]; then
CFG_GIT_URL=$(validate_input "" "Enter the Git repository URL: " "Git URL cannot be empty.")
updateConfigOption "CFG_GIT_URL" "$CFG_GIT_URL"
fi
# Strip http:// or https:// and .git from GIT_URL.
CLEAN_GIT_URL=$(echo "$CFG_GIT_URL" | sed -E 's~^(https?://)?(.+?)\.git?$~\2~')
# 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
runSystem cp -f "$script_dir/init.sh" /root/
echo "SUCCESS: Git repository cloned via HTTPS into $script_dir."
echo ""
echo "SUCCESS: Reinstallation complete, you can now run the "libreportal run" command."
echo ""
else
# If HTTPS fails, try HTTP
if runAsManager git clone -q "$AUTH_HTTP_REPO_URL" "$script_dir" 2>/dev/null; then
runSystem cp -f "$script_dir/init.sh" /root/
echo "SUCCESS: Git repository cloned via HTTP into $script_dir."
echo ""
echo "SUCCESS: Reinstallation complete, you can now run the "libreportal run" command."
echo ""
else
isError " Authentication failed. Please check your credentials."
exit 1;
fi
fi
fi
}