This commit is contained in:
Justin (shocknet) 2024-07-23 13:36:14 -04:00
parent 86bbe4f1dc
commit 351b3e16fa
5 changed files with 80 additions and 65 deletions

View file

@ -29,10 +29,18 @@ get_log_info() {
exit 1 exit 1
fi fi
# Wait for wallet status in log file # Get the initial line count
initial_lines=$(wc -l < "$latest_unlocker_log")
# Wait for new wallet status in log file
while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do
latest_entry=$(grep -E "unlocker >> (macaroon not found, creating wallet|wallet is locked, unlocking|the wallet is already unlocked|created wallet with pub)" "$latest_unlocker_log" | tail -n 1) current_lines=$(wc -l < "$latest_unlocker_log")
[ -n "$latest_entry" ] && break if [ $current_lines -gt $initial_lines ]; then
latest_entry=$(tail -n $((current_lines - initial_lines)) "$latest_unlocker_log" | grep "unlocker >>" | tail -n 1)
if [ -n "$latest_entry" ]; then
break
fi
fi
sleep $WAIT_INTERVAL sleep $WAIT_INTERVAL
done done

View file

@ -1,6 +1,13 @@
#!/bin/bash #!/bin/bash
set -e set -e
# Function to log errors
log_error() {
log "ERROR: $1"
log "Exiting with status $2"
exit $2
}
BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/master/scripts/" BASE_URL="https://raw.githubusercontent.com/shocknet/Lightning.Pub/master/scripts/"
modules=( modules=(
@ -21,26 +28,37 @@ for module in "${modules[@]}"; do
source "/tmp/${module}.sh" source "/tmp/${module}.sh"
done done
# Upgrade flag
SKIP_PROMPT=false
for arg in "$@"; do
case $arg in
--yes)
SKIP_PROMPT=true
shift
;;
esac
done
detect_os_arch detect_os_arch
if [ "$OS" = "Mac" ]; then if [ "$OS" = "Mac" ]; then
handle_macos handle_macos
else else
install_lnd install_lnd || log_error "LND installation failed" $?
LND_UPGRADE=$? lnd_upgrade_status=$?
install_nodejs
PUB_UPGRADE_STATUS=$(install_lightning_pub) install_nodejs || log_error "NodeJS installation failed" $?
start_services $LND_UPGRADE $PUB_UPGRADE_STATUS
pub_output=$(install_lightning_pub)
install_result=$?
if [ $install_result -ne 0 ]; then
log_error "Lightning.Pub installation failed" $install_result
fi
# Extract the upgrade status from the output
pub_upgrade_status=$(echo "$pub_output" | grep "UPGRADE_STATUS:" | cut -d':' -f2)
if [ "$pub_upgrade_status" = "100" ]; then
log "Lightning.Pub upgrade completed successfully."
elif [ "$pub_upgrade_status" = "0" ]; then
log "Lightning.Pub fresh installation completed successfully."
else
log "WARNING: Unexpected return status from install_lightning_pub: $pub_upgrade_status"
log "Full output: $pub_output"
fi
start_services $lnd_upgrade_status $pub_upgrade_status
get_log_info get_log_info
log "Installation process completed successfully"
fi fi

View file

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
install_lightning_pub() { install_lightning_pub() {
local upgrade_status=0
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6) USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6)
USER_NAME=$SUDO_USER USER_NAME=$SUDO_USER
@ -12,69 +14,58 @@ install_lightning_pub() {
log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..." log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master" REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master"
sudo -u $USER_NAME wget $REPO_URL -O $USER_HOME/lightning_pub.tar.gz > /dev/null 2>&1 || { sudo -u $USER_NAME wget -q $REPO_URL -O $USER_HOME/lightning_pub.tar.gz > /dev/null 2>&1 || {
log "${PRIMARY_COLOR}Failed to download Lightning.Pub.${RESET_COLOR}" log "${PRIMARY_COLOR}Failed to download Lightning.Pub.${RESET_COLOR}"
exit 1 return 1
} }
sudo -u $USER_NAME mkdir -p $USER_HOME/lightning_pub_temp sudo -u $USER_NAME mkdir -p $USER_HOME/lightning_pub_temp
sudo -u $USER_NAME tar -xvzf $USER_HOME/lightning_pub.tar.gz -C $USER_HOME/lightning_pub_temp --strip-components=1 > /dev/null 2>&1 || { sudo -u $USER_NAME tar -xzf $USER_HOME/lightning_pub.tar.gz -C $USER_HOME/lightning_pub_temp --strip-components=1 > /dev/null 2>&1 || {
log "${PRIMARY_COLOR}Failed to extract Lightning.Pub.${RESET_COLOR}" log "${PRIMARY_COLOR}Failed to extract Lightning.Pub.${RESET_COLOR}"
exit 1 return 1
} }
rm $USER_HOME/lightning_pub.tar.gz rm $USER_HOME/lightning_pub.tar.gz
if ! command -v rsync &> /dev/null; then
log "${PRIMARY_COLOR}rsync not found, installing...${RESET_COLOR}"
if [ "$OS" = "Mac" ]; then
brew install rsync
elif [ "$OS" = "Linux" ]; then
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update > /dev/null 2>&1
sudo apt-get install -y rsync > /dev/null 2>&1
elif [ -x "$(command -v yum)" ]; then
sudo yum install -y rsync > /dev/null 2>&1
else
log "${PRIMARY_COLOR}Package manager not found. Please install rsync manually.${RESET_COLOR}"
exit 1
fi
else
log "${PRIMARY_COLOR}Package manager not found. Please install rsync manually.${RESET_COLOR}"
exit 1
fi
fi
if [ -d "$USER_HOME/lightning_pub" ]; then if [ -d "$USER_HOME/lightning_pub" ]; then
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} is already installed. Upgrading..." log "Upgrading existing Lightning.Pub installation..."
PUB_UPGRADE=true upgrade_status=100 # Use 100 to indicate an upgrade
else else
PUB_UPGRADE=false log "Performing fresh Lightning.Pub installation..."
upgrade_status=0
fi fi
# Merge if upgrade # Merge if upgrade
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' --exclude='.jwt_secret' --exclude='.wallet_secret' --exclude='admin.npub' --exclude='app.nprofile' --exclude='.admin_connect' --exclude='.admin_enroll' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1 if [ $upgrade_status -eq 100 ]; then
rm -rf lightning_pub_temp rsync -a --quiet --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' --exclude='.jwt_secret' --exclude='.wallet_secret' --exclude='admin.npub' --exclude='app.nprofile' --exclude='.admin_connect' --exclude='.admin_enroll' $USER_HOME/lightning_pub_temp/ $USER_HOME/lightning_pub/
else
mv $USER_HOME/lightning_pub_temp $USER_HOME/lightning_pub
fi
rm -rf $USER_HOME/lightning_pub_temp
# Load nvm and npm # Load nvm and npm
export NVM_DIR="${NVM_DIR}" export NVM_DIR="${NVM_DIR}"
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh" [ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
cd lightning_pub cd $USER_HOME/lightning_pub
log "${PRIMARY_COLOR}Installing${RESET_COLOR} npm dependencies..." log "${PRIMARY_COLOR}Installing${RESET_COLOR} npm dependencies..."
npm install > npm_install.log 2>&1 || { npm install > npm_install.log 2>&1
log "${PRIMARY_COLOR}Failed to install npm dependencies.${RESET_COLOR}" npm_exit_code=$?
exit 1
}
if [ "$PUB_UPGRADE" = true ]; then if [ $npm_exit_code -ne 0 ]; then
PUB_UPGRADE_STATUS=1 log "${PRIMARY_COLOR}Failed to install npm dependencies. Check npm_install.log for details.${RESET_COLOR}"
else return 1
PUB_UPGRADE_STATUS=0
fi fi
log "PUB_UPGRADE_STATUS set to $PUB_UPGRADE_STATUS" if [ ! -d "node_modules" ] || [ -z "$(ls -A node_modules)" ]; then
log "${PRIMARY_COLOR}npm install completed, but node_modules is empty or missing. Installation may have failed.${RESET_COLOR}"
return 1
fi
echo $PUB_UPGRADE_STATUS log "npm dependencies installed successfully."
# Echo a specific string followed by the upgrade status
echo "UPGRADE_STATUS:$upgrade_status"
return 0 # Always return 0 to indicate success
} }

View file

@ -47,7 +47,7 @@ EOF"
sudo systemctl enable lnd >/dev/null 2>&1 sudo systemctl enable lnd >/dev/null 2>&1
sudo systemctl enable lightning_pub >/dev/null 2>&1 sudo systemctl enable lightning_pub >/dev/null 2>&1
if [ "$LND_UPGRADE" = true ]; then if [ "$LND_UPGRADE" = "1" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..." log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
sudo systemctl restart lnd & sudo systemctl restart lnd &
lnd_pid=$! lnd_pid=$!
@ -74,7 +74,7 @@ EOF"
log "Giving ${SECONDARY_COLOR}LND${RESET_COLOR} a few seconds to start before starting ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..." log "Giving ${SECONDARY_COLOR}LND${RESET_COLOR} a few seconds to start before starting ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
sleep 10 sleep 10
if [ "$PUB_UPGRADE" = "1" ]; then if [ "$PUB_UPGRADE" = "100" ]; then
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..." log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
sudo systemctl restart lightning_pub & sudo systemctl restart lightning_pub &
lightning_pub_pid=$! lightning_pub_pid=$!

View file

@ -10,9 +10,7 @@ chmod 644 $LOG_FILE
log() { log() {
local message="$(date '+%Y-%m-%d %H:%M:%S') $1" local message="$(date '+%Y-%m-%d %H:%M:%S') $1"
if [ -t 1 ]; then
echo -e "$message" echo -e "$message"
fi
echo -e "$(echo $message | sed 's/\\e\[[0-9;]*m//g')" >> $LOG_FILE echo -e "$(echo $message | sed 's/\\e\[[0-9;]*m//g')" >> $LOG_FILE
} }