deploy
This commit is contained in:
parent
86bbe4f1dc
commit
351b3e16fa
5 changed files with 80 additions and 65 deletions
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue