readme, version checks, better url def

This commit is contained in:
shocknet-justin 2025-08-27 11:51:03 -04:00
parent 5b5c05906c
commit 1373f46ef3
4 changed files with 108 additions and 35 deletions

View file

@ -2,7 +2,7 @@
set -e
# Use user-space log file
LOG_FILE="$HOME/.lightning_pub/install.log"
LOG_FILE="$HOME/lightning_pub/install.log"
mkdir -p "$(dirname "$LOG_FILE")"
touch $LOG_FILE
@ -15,12 +15,15 @@ log() {
}
SCRIPT_VERSION="0.2.0"
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/script"
BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/script/scripts/"
REPO="shocknet/Lightning.Pub"
BRANCH="script"
BASE_URL="https://raw.githubusercontent.com/${REPO}/${BRANCH}"
REPO_URL="https://github.com/${REPO}/tarball/${BRANCH}"
SCRIPTS_URL="${BASE_URL}/scripts/"
cleanup() {
echo "Cleaning up temporary files..."
rm -f "$HOME/.lightning_pub/tmp"/*.sh 2>/dev/null || true
rm -f "$HOME/lightning_pub_tmp"/*.sh 2>/dev/null || true
}
trap cleanup EXIT
@ -48,11 +51,11 @@ modules=(
log "Script version $SCRIPT_VERSION"
# Create user-space temp directory
mkdir -p "$HOME/.lightning_pub/tmp"
mkdir -p "$HOME/lightning_pub_tmp"
for module in "${modules[@]}"; do
wget -q "${BASE_URL}/${module}.sh" -O "$HOME/.lightning_pub/tmp/${module}.sh" || log_error "Failed to download ${module}.sh" 1
source "$HOME/.lightning_pub/tmp/${module}.sh" || log_error "Failed to source ${module}.sh" 1
wget -q "${SCRIPTS_URL}${module}.sh" -O "$HOME/lightning_pub_tmp/${module}.sh" || log_error "Failed to download ${module}.sh" 1
source "$HOME/lightning_pub_tmp/${module}.sh" || log_error "Failed to source ${module}.sh" 1
done
detect_os_arch
@ -81,7 +84,22 @@ else
install_nodejs || log_error "Failed to install Node.js" 1
install_lightning_pub "$REPO_URL" || log_error "Failed to install Lightning.Pub" 1
pub_install_result=$(install_lightning_pub "$REPO_URL")
pub_install_status=$?
case $pub_install_status in
0)
log "Lightning.Pub installation/upgrade completed successfully."
pub_upgrade_status=100
;;
2)
log "Lightning.Pub is already up-to-date. No restart needed."
pub_upgrade_status=0
;;
*)
log_error "Lightning.Pub installation failed" $pub_install_status
;;
esac
log "Starting services..."
touch /tmp/pub_install_timestamp

View file

@ -33,6 +33,25 @@ install_lightning_pub() {
# Check if directory exists and is not empty to determine if it's an upgrade
if [ -d "$USER_HOME/lightning_pub" ] && [ "$(ls -A $USER_HOME/lightning_pub)" ]; then
log "Checking if Lightning.Pub update is needed..."
# Check if update is needed by comparing commit hashes
# Get latest commit hash from GitHub API
LATEST_COMMIT=$(wget -qO- "https://api.github.com/repos/${REPO}/commits/${BRANCH}" 2>/dev/null | grep -o '"sha":"[^"]*"' | cut -d'"' -f4 | head -c 40)
if [ -n "$LATEST_COMMIT" ]; then
# Check if we have a stored commit hash and compare
if [ -f "$USER_HOME/lightning_pub/.installed_commit" ]; then
CURRENT_COMMIT=$(cat "$USER_HOME/lightning_pub/.installed_commit" 2>/dev/null | head -c 40)
if [ "$CURRENT_COMMIT" = "$LATEST_COMMIT" ]; then
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} is already at the latest commit. No update needed."
rm -rf $USER_HOME/lightning_pub_temp
return 2 # Special exit code to indicate no changes
fi
fi
fi
log "Upgrading existing Lightning.Pub installation..."
upgrade_status=100 # Use 100 to indicate an upgrade
else
@ -99,5 +118,10 @@ install_lightning_pub() {
return 1
fi
# Store the commit hash for future update checks
if [ -n "$LATEST_COMMIT" ]; then
echo "$LATEST_COMMIT" > "$USER_HOME/lightning_pub/.installed_commit"
fi
return 0
}