mirror of
https://github.com/retspen/webvirtcloud
synced 2026-10-18 00:50:07 +00:00
refactor(install): harden bootstrap script and restore retspen upstream URLs
This commit is contained in:
parent
79c6bd4c62
commit
070e3baf75
3 changed files with 96 additions and 17 deletions
95
install.sh
Normal file → Executable file
95
install.sh
Normal file → Executable file
|
|
@ -1,24 +1,101 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# WebVirtCloud Installer Bootstrap Script
|
||||
# https://github.com/retspen/webvirtcloud
|
||||
#
|
||||
|
||||
# ensure running as root
|
||||
set -o pipefail
|
||||
|
||||
# Display help without requiring root privileges
|
||||
for arg in "$@"; do
|
||||
if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then
|
||||
echo "WebVirtCloud Installer Bootstrap"
|
||||
echo ""
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "OPTIONS:"
|
||||
echo " -v, --verbose Enable verbose installation output."
|
||||
echo " -h, --help Show this help message and exit."
|
||||
echo ""
|
||||
echo "Environment Variables:"
|
||||
echo " WEBVIRTCLOUD_SCRIPT_URL Custom URL to fetch webvirtcloud.sh installer"
|
||||
echo " APP_REPO_URL Custom WebVirtCloud git repository URL"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Ensure script runs with root privileges
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
#Debian doesnt have sudo if root has a password.
|
||||
if ! hash sudo 2>/dev/null; then
|
||||
exec su -c "$0" "$@"
|
||||
SCRIPT_PATH="$(cd "$(dirname "$0")" 2>/dev/null && pwd)/$(basename "$0")"
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
exec sudo "$SCRIPT_PATH" "$@"
|
||||
elif command -v su >/dev/null 2>&1; then
|
||||
exec su -c "$SCRIPT_PATH $*"
|
||||
else
|
||||
exec sudo "$0" "$@"
|
||||
echo "Error: Root privileges required, but neither 'sudo' nor 'su' was found." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# Locate existing webvirtcloud.sh or download it securely
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
TMP_DIR=""
|
||||
|
||||
cleanup() {
|
||||
if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then
|
||||
rm -rf "$TMP_DIR"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
download_installer() {
|
||||
local url="$1"
|
||||
local dest="$2"
|
||||
echo "* Downloading webvirtcloud installer from $url..."
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsSL --connect-timeout 15 --retry 3 -o "$dest" "$url"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q --timeout=15 --tries=3 -O "$dest" "$url"
|
||||
else
|
||||
echo "Error: Neither 'curl' nor 'wget' was found. Please install curl or wget." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -f "$SCRIPT_DIR/webvirtcloud.sh" ]; then
|
||||
INSTALLER="$SCRIPT_DIR/webvirtcloud.sh"
|
||||
elif [ -f "./webvirtcloud.sh" ]; then
|
||||
INSTALLER="./webvirtcloud.sh"
|
||||
else
|
||||
INSTALLER="./webvirtcloud.sh"
|
||||
wget -O "$INSTALLER" "${WEBVIRTCLOUD_SCRIPT_URL:-https://raw.githubusercontent.com/catborise/webvirtcloud/master/webvirtcloud.sh}"
|
||||
TMP_DIR="$(mktemp -d -t wvc-install.XXXXXX)"
|
||||
INSTALLER="$TMP_DIR/webvirtcloud.sh"
|
||||
UPSTREAM_URL="${WEBVIRTCLOUD_SCRIPT_URL:-https://raw.githubusercontent.com/retspen/webvirtcloud/master/webvirtcloud.sh}"
|
||||
download_installer "$UPSTREAM_URL" "$INSTALLER"
|
||||
fi
|
||||
|
||||
# Ensure installer is executable
|
||||
chmod 744 "$INSTALLER"
|
||||
"$INSTALLER" "$@" 2>&1 | tee -a /var/log/webvirtcloud-install.log
|
||||
|
||||
# Prepare log file location
|
||||
LOG_FILE="/var/log/webvirtcloud-install.log"
|
||||
mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null || true
|
||||
if ! touch "$LOG_FILE" 2>/dev/null; then
|
||||
LOG_FILE="/tmp/webvirtcloud-install.log"
|
||||
fi
|
||||
|
||||
echo "* Executing installer ($INSTALLER)..."
|
||||
echo "* Output is logged to $LOG_FILE"
|
||||
|
||||
# Execute installer and preserve exit status across pipe
|
||||
"$INSTALLER" "$@" 2>&1 | tee -a "$LOG_FILE"
|
||||
INSTALL_STATUS="${PIPESTATUS[0]}"
|
||||
|
||||
if [ "$INSTALL_STATUS" -ne 0 ]; then
|
||||
echo "" >&2
|
||||
echo "Error: WebVirtCloud installation failed with exit code $INSTALL_STATUS." >&2
|
||||
echo "See $LOG_FILE for details." >&2
|
||||
exit "$INSTALL_STATUS"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue