deploy
This commit is contained in:
parent
86bbe4f1dc
commit
351b3e16fa
5 changed files with 80 additions and 65 deletions
|
|
@ -29,10 +29,18 @@ get_log_info() {
|
|||
exit 1
|
||||
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
|
||||
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)
|
||||
[ -n "$latest_entry" ] && break
|
||||
current_lines=$(wc -l < "$latest_unlocker_log")
|
||||
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
|
||||
done
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
#!/bin/bash
|
||||
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/"
|
||||
|
||||
modules=(
|
||||
|
|
@ -21,26 +28,37 @@ for module in "${modules[@]}"; do
|
|||
source "/tmp/${module}.sh"
|
||||
done
|
||||
|
||||
# Upgrade flag
|
||||
SKIP_PROMPT=false
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--yes)
|
||||
SKIP_PROMPT=true
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
detect_os_arch
|
||||
|
||||
if [ "$OS" = "Mac" ]; then
|
||||
handle_macos
|
||||
else
|
||||
install_lnd
|
||||
LND_UPGRADE=$?
|
||||
install_nodejs
|
||||
PUB_UPGRADE_STATUS=$(install_lightning_pub)
|
||||
start_services $LND_UPGRADE $PUB_UPGRADE_STATUS
|
||||
install_lnd || log_error "LND installation failed" $?
|
||||
lnd_upgrade_status=$?
|
||||
|
||||
install_nodejs || log_error "NodeJS installation failed" $?
|
||||
|
||||
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
|
||||
|
||||
log "Installation process completed successfully"
|
||||
fi
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
install_lightning_pub() {
|
||||
local upgrade_status=0
|
||||
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6)
|
||||
USER_NAME=$SUDO_USER
|
||||
|
|
@ -12,69 +14,58 @@ install_lightning_pub() {
|
|||
log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
|
||||
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}"
|
||||
exit 1
|
||||
return 1
|
||||
}
|
||||
|
||||
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}"
|
||||
exit 1
|
||||
return 1
|
||||
}
|
||||
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
|
||||
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} is already installed. Upgrading..."
|
||||
PUB_UPGRADE=true
|
||||
log "Upgrading existing Lightning.Pub installation..."
|
||||
upgrade_status=100 # Use 100 to indicate an upgrade
|
||||
else
|
||||
PUB_UPGRADE=false
|
||||
log "Performing fresh Lightning.Pub installation..."
|
||||
upgrade_status=0
|
||||
fi
|
||||
|
||||
# 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
|
||||
rm -rf lightning_pub_temp
|
||||
if [ $upgrade_status -eq 100 ]; then
|
||||
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
|
||||
export NVM_DIR="${NVM_DIR}"
|
||||
[ -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..."
|
||||
|
||||
npm install > npm_install.log 2>&1 || {
|
||||
log "${PRIMARY_COLOR}Failed to install npm dependencies.${RESET_COLOR}"
|
||||
exit 1
|
||||
}
|
||||
npm install > npm_install.log 2>&1
|
||||
npm_exit_code=$?
|
||||
|
||||
if [ "$PUB_UPGRADE" = true ]; then
|
||||
PUB_UPGRADE_STATUS=1
|
||||
else
|
||||
PUB_UPGRADE_STATUS=0
|
||||
if [ $npm_exit_code -ne 0 ]; then
|
||||
log "${PRIMARY_COLOR}Failed to install npm dependencies. Check npm_install.log for details.${RESET_COLOR}"
|
||||
return 1
|
||||
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
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ EOF"
|
|||
sudo systemctl enable lnd >/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..."
|
||||
sudo systemctl restart lnd &
|
||||
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}..."
|
||||
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..."
|
||||
sudo systemctl restart lightning_pub &
|
||||
lightning_pub_pid=$!
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ chmod 644 $LOG_FILE
|
|||
|
||||
log() {
|
||||
local message="$(date '+%Y-%m-%d %H:%M:%S') $1"
|
||||
if [ -t 1 ]; then
|
||||
echo -e "$message"
|
||||
fi
|
||||
echo -e "$message"
|
||||
echo -e "$(echo $message | sed 's/\\e\[[0-9;]*m//g')" >> $LOG_FILE
|
||||
}
|
||||
|
||||
|
|
@ -37,4 +35,4 @@ detect_os_arch() {
|
|||
else
|
||||
SYSTEMCTL_AVAILABLE=false
|
||||
fi
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue