deploy
This commit is contained in:
parent
267a357ba2
commit
d44010bea9
1 changed files with 54 additions and 45 deletions
99
deploy.sh
99
deploy.sh
|
|
@ -5,6 +5,14 @@ PRIMARY_COLOR="\e[38;5;208m" # #f59322
|
||||||
SECONDARY_COLOR="\e[38;5;165m" # #c740c7
|
SECONDARY_COLOR="\e[38;5;165m" # #c740c7
|
||||||
RESET_COLOR="\e[0m"
|
RESET_COLOR="\e[0m"
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
LOG_FILE="/var/log/deploy.log"
|
||||||
|
|
||||||
|
# Log function
|
||||||
|
log() {
|
||||||
|
echo -e "$1" | tee -a $LOG_FILE
|
||||||
|
}
|
||||||
|
|
||||||
# Detect OS and architecture
|
# Detect OS and architecture
|
||||||
detect_os_arch() {
|
detect_os_arch() {
|
||||||
OS="$(uname -s)"
|
OS="$(uname -s)"
|
||||||
|
|
@ -33,7 +41,7 @@ detect_os_arch() {
|
||||||
|
|
||||||
# Install LND
|
# Install LND
|
||||||
install_lnd() {
|
install_lnd() {
|
||||||
echo -e "${PRIMARY_COLOR}Installing LND...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Installing LND...${RESET_COLOR}"
|
||||||
LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep 'tag_name' | cut -d\" -f4)
|
LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep 'tag_name' | cut -d\" -f4)
|
||||||
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz"
|
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz"
|
||||||
|
|
||||||
|
|
@ -41,51 +49,52 @@ install_lnd() {
|
||||||
if [ -d ~/lnd ]; then
|
if [ -d ~/lnd ]; then
|
||||||
CURRENT_VERSION=$(~/lnd/lnd --version | grep -oP 'version \K[^\s]+')
|
CURRENT_VERSION=$(~/lnd/lnd --version | grep -oP 'version \K[^\s]+')
|
||||||
if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then
|
if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then
|
||||||
echo -e "${SECONDARY_COLOR}LND is already up-to-date (version $CURRENT_VERSION).${RESET_COLOR}"
|
log "${SECONDARY_COLOR}LND is already up-to-date (version $CURRENT_VERSION).${RESET_COLOR}"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
if [ "$SKIP_PROMPT" != true ]; then
|
if [ "$SKIP_PROMPT" != true ]; then
|
||||||
read -p "LND version $CURRENT_VERSION is installed. Do you want to upgrade to version $LND_VERSION? (y/N): " response
|
read -p "LND version $CURRENT_VERSION is installed. Do you want to upgrade to version $LND_VERSION? (y/N): " response
|
||||||
case "$response" in
|
case "$response" in
|
||||||
[yY][eE][sS]|[yY])
|
[yY][eE][sS]|[yY])
|
||||||
echo -e "${PRIMARY_COLOR}Upgrading LND from version $CURRENT_VERSION to $LND_VERSION...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Upgrading LND from version $CURRENT_VERSION to $LND_VERSION...${RESET_COLOR}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "${SECONDARY_COLOR}Upgrade cancelled.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Upgrade cancelled.${RESET_COLOR}"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
echo -e "${PRIMARY_COLOR}Upgrading LND from version $CURRENT_VERSION to $LND_VERSION...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Upgrading LND from version $CURRENT_VERSION to $LND_VERSION...${RESET_COLOR}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo -e "${PRIMARY_COLOR}LND is not installed. Proceeding with installation...${RESET_COLOR}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wget $LND_URL -O lnd.tar.gz
|
log "${PRIMARY_COLOR}Downloading LND...${RESET_COLOR}"
|
||||||
|
wget --progress=dot:giga $LND_URL -O lnd.tar.gz 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\rDownloading: %s", $2)}'
|
||||||
|
echo -e "\n"
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to download LND binary. Please check the URL or your internet connection.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to download LND binary. Please check the URL or your internet connection.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if LND is already running and stop it if necessary
|
# Check if LND is already running and stop it if necessary
|
||||||
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
|
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
|
||||||
if systemctl is-active --quiet lnd; then
|
if systemctl is-active --quiet lnd; then
|
||||||
echo -e "${PRIMARY_COLOR}LND is currently running. Stopping LND service...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Stopping LND service...${RESET_COLOR}"
|
||||||
sudo systemctl stop lnd
|
sudo systemctl stop lnd
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to stop LND service. Please stop it manually and try again.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to stop LND service. Please stop it manually and try again.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "${SECONDARY_COLOR}systemctl not found. Please stop LND manually if it is running.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}systemctl not found. Please stop LND manually if it is running.${RESET_COLOR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tar -xvzf lnd.tar.gz > /dev/null
|
tar -xzf lnd.tar.gz -C ~/ > /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to extract LND binary.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to extract LND binary.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rm lnd.tar.gz
|
rm lnd.tar.gz
|
||||||
|
|
@ -96,7 +105,7 @@ install_lnd() {
|
||||||
|
|
||||||
# Check if lnd.conf already exists and avoid overwriting it
|
# Check if lnd.conf already exists and avoid overwriting it
|
||||||
if [ -f ~/.lnd/lnd.conf ]; then
|
if [ -f ~/.lnd/lnd.conf ]; then
|
||||||
echo -e "${SECONDARY_COLOR}lnd.conf already exists. Skipping creation of new lnd.conf file.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}lnd.conf already exists. Skipping creation of new lnd.conf file.${RESET_COLOR}"
|
||||||
else
|
else
|
||||||
cat <<EOF > ~/.lnd/lnd.conf
|
cat <<EOF > ~/.lnd/lnd.conf
|
||||||
bitcoin.mainnet=true
|
bitcoin.mainnet=true
|
||||||
|
|
@ -104,15 +113,15 @@ bitcoin.node=neutrino
|
||||||
neutrino.addpeer=neutrino.shock.network
|
neutrino.addpeer=neutrino.shock.network
|
||||||
feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
|
feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
|
||||||
EOF
|
EOF
|
||||||
echo -e "${PRIMARY_COLOR}Created new lnd.conf file.${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Created new lnd.conf file.${RESET_COLOR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${PRIMARY_COLOR}LND installation and configuration completed.${RESET_COLOR}"
|
log "${PRIMARY_COLOR}LND installation and configuration completed.${RESET_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install Node.js using nvm
|
# Function to install Node.js using nvm
|
||||||
install_nodejs() {
|
install_nodejs() {
|
||||||
echo -e "${PRIMARY_COLOR}Checking for Node.js...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Checking for Node.js...${RESET_COLOR}"
|
||||||
MINIMUM_VERSION="18.0.0"
|
MINIMUM_VERSION="18.0.0"
|
||||||
|
|
||||||
# Load nvm if it exists
|
# Load nvm if it exists
|
||||||
|
|
@ -120,61 +129,61 @@ install_nodejs() {
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
|
|
||||||
if ! command -v nvm &> /dev/null; then
|
if ! command -v nvm &> /dev/null; then
|
||||||
echo -e "${SECONDARY_COLOR}nvm not found, installing...${RESET_COLOR}"
|
log "${SECONDARY_COLOR}nvm not found, installing...${RESET_COLOR}"
|
||||||
NVM_VERSION=$(wget -qO- https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
|
NVM_VERSION=$(wget -qO- https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
|
||||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh | bash > /dev/null 2>&1
|
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh | bash > /dev/null 2>&1
|
||||||
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nvm install $MINIMUM_VERSION > /dev/null 2>&1
|
if command -v node &> /dev/null; then
|
||||||
nvm use $MINIMUM_VERSION > /dev/null 2>&1
|
NODE_VERSION=$(node -v)
|
||||||
nvm alias default $MINIMUM_VERSION > /dev/null 2>&1
|
if [ "$(printf '%s\n' "$MINIMUM_VERSION" "$NODE_VERSION" | sort -V | head -n1)" = "$MINIMUM_VERSION" ]; then
|
||||||
|
log "${SECONDARY_COLOR}Node.js is already installed and meets the minimum version requirement.${RESET_COLOR}"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
log "${PRIMARY_COLOR}Updating Node.js to the latest version...${RESET_COLOR}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "${PRIMARY_COLOR}Node.js is not installed. Installing the latest version...${RESET_COLOR}"
|
||||||
|
fi
|
||||||
|
|
||||||
NODE_VERSION=$(node -v | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
|
nvm install node
|
||||||
if [ -z "$NODE_VERSION" ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to install Node.js. Please check the installation process.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to install Node.js. Please check the nvm installation.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CURRENT_VERSION=$(printf '%s\n' "$MINIMUM_VERSION" "$NODE_VERSION" | sort -V | tail -n1)
|
log "${PRIMARY_COLOR}Node.js installation completed.${RESET_COLOR}"
|
||||||
if [ "$CURRENT_VERSION" != "$NODE_VERSION" ]; then
|
|
||||||
echo -e "${SECONDARY_COLOR}NodeJS version is less than required, installing LTS version...${RESET_COLOR}"
|
|
||||||
nvm install --lts > /dev/null 2>&1
|
|
||||||
nvm use --lts > /dev/null 2>&1
|
|
||||||
nvm alias default lts/* > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${PRIMARY_COLOR}Node.js installation completed.${RESET_COLOR}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download and extract Lightning.Pub
|
# Download and extract Lightning.Pub
|
||||||
install_lightning_pub() {
|
install_lightning_pub() {
|
||||||
echo -e "${PRIMARY_COLOR}Installing Lightning.Pub...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Installing Lightning.Pub...${RESET_COLOR}"
|
||||||
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master"
|
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master"
|
||||||
wget $REPO_URL -O lightning_pub.tar.gz > /dev/null 2>&1
|
wget $REPO_URL -O lightning_pub.tar.gz > /dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to download Lightning.Pub tarball. Please check the URL or your internet connection.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to download Lightning.Pub tarball. Please check the URL or your internet connection.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mkdir -p lightning_pub_temp
|
mkdir -p lightning_pub_temp
|
||||||
tar -xvzf lightning_pub.tar.gz -C lightning_pub_temp --strip-components=1 > /dev/null 2>&1
|
tar -xvzf lightning_pub.tar.gz -C lightning_pub_temp --strip-components=1 > /dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to extract Lightning.Pub tarball.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to extract Lightning.Pub tarball.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rm lightning_pub.tar.gz
|
rm lightning_pub.tar.gz
|
||||||
|
|
||||||
# Check if rsync is installed, install if not
|
# Check if rsync is installed, install if not
|
||||||
if ! command -v rsync &> /dev/null; then
|
if ! command -v rsync &> /dev/null; then
|
||||||
echo -e "${SECONDARY_COLOR}rsync not found, installing...${RESET_COLOR}"
|
log "${SECONDARY_COLOR}rsync not found, installing...${RESET_COLOR}"
|
||||||
if [ -x "$(command -v apt-get)" ]; then
|
if [ -x "$(command -v apt-get)" ]; then
|
||||||
sudo apt-get update > /dev/null 2>&1
|
sudo apt-get update > /dev/null 2>&1
|
||||||
sudo apt-get install -y rsync > /dev/null 2>&1
|
sudo apt-get install -y rsync > /dev/null 2>&1
|
||||||
elif [ -x "$(command -v yum)" ]; then
|
elif [ -x "$(command -v yum)" ]; then
|
||||||
sudo yum install -y rsync > /dev/null 2>&1
|
sudo yum install -y rsync > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
echo -e "${SECONDARY_COLOR}Package manager not found. Please install rsync manually.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Package manager not found. Please install rsync manually.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -183,7 +192,7 @@ install_lightning_pub() {
|
||||||
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1
|
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${SECONDARY_COLOR}Failed to merge Lightning.Pub files.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}Failed to merge Lightning.Pub files.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rm -rf lightning_pub_temp
|
rm -rf lightning_pub_temp
|
||||||
|
|
@ -195,22 +204,22 @@ install_lightning_pub() {
|
||||||
cd lightning_pub
|
cd lightning_pub
|
||||||
|
|
||||||
# Show a progress indicator while npm install is running
|
# Show a progress indicator while npm install is running
|
||||||
echo -e "${PRIMARY_COLOR}Installing npm dependencies...${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Installing npm dependencies...${RESET_COLOR}"
|
||||||
npm install > npm_install.log 2>&1 &
|
npm install > npm_install.log 2>&1 &
|
||||||
PID=$!
|
PID=$!
|
||||||
while kill -0 $PID 2> /dev/null; do
|
while kill -0 $PID 2> /dev/null; do
|
||||||
echo -e "${SECONDARY_COLOR}.${RESET_COLOR}"
|
log "${SECONDARY_COLOR}.${RESET_COLOR}"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
if wait $PID; then
|
if wait $PID; then
|
||||||
echo -e "${PRIMARY_COLOR} done.${RESET_COLOR}"
|
log "${PRIMARY_COLOR} done.${RESET_COLOR}"
|
||||||
else
|
else
|
||||||
echo -e "${SECONDARY_COLOR} failed. Check npm_install.log for details.${RESET_COLOR}"
|
log "${SECONDARY_COLOR} failed. Check npm_install.log for details.${RESET_COLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${PRIMARY_COLOR}Lightning.Pub installation completed.${RESET_COLOR}"
|
log "${PRIMARY_COLOR}Lightning.Pub installation completed.${RESET_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ceate start script
|
# Ceate start script
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue