diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..8bb44342 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +# Function to detect OS and architecture +detect_os_arch() { + OS="$(uname -s)" + ARCH="$(uname -m)" + case "$OS" in + Linux*) OS=Linux;; + Darwin*) OS=Mac;; + CYGWIN*) OS=Cygwin;; + MINGW*) OS=MinGw;; + *) OS="UNKNOWN" + esac + case "$ARCH" in + x86_64) ARCH=amd64;; + armv7l) ARCH=armv7;; + arm64) ARCH=arm64;; + *) ARCH="UNKNOWN" + esac +} + +# Function to install LND +install_lnd() { + 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" + wget $LND_URL -O lnd.tar.gz + if [ $? -ne 0 ]; then + echo "Failed to download LND binary. Please check the URL or your internet connection." + exit 1 + fi + tar -xvzf lnd.tar.gz + if [ $? -ne 0 ]; then + echo "Failed to extract LND binary." + exit 1 + fi + rm lnd.tar.gz + mv lnd-* lnd + + # Create .lnd directory and lnd.conf file + mkdir -p ~/.lnd + cat < ~/.lnd/lnd.conf +bitcoin.mainnet=true +bitcoin.node=neutrino +neutrino.addpeer=neutrino.shock.network +feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json +noseedbackup=true +wallet-unlock-password-file=~/lnpass +wallet-unlock-allow-create=true +EOF +} + +# Function to install Node.js using nvm +install_nodejs() { + REQUIRED_VERSION="18.0.0" + if ! command -v nvm &> /dev/null; then + echo "nvm not found, installing..." + 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 + 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" + fi + + # Load 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" + + nvm install $REQUIRED_VERSION + nvm use $REQUIRED_VERSION + nvm alias default $REQUIRED_VERSION + + NODE_VERSION=$(node -v | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') + if [ -z "$NODE_VERSION" ]; then + echo "Failed to install Node.js. Please check the installation process." + exit 1 + fi + + CURRENT_VERSION=$(printf '%s\n' "$REQUIRED_VERSION" "$NODE_VERSION" | sort -V | tail -n1) + if [ "$CURRENT_VERSION" != "$NODE_VERSION" ]; then + echo "NodeJS version is less than required, aborting" + exit 1 + fi +} + +# Function to download and extract Lightning.Pub tarball +install_lightning_pub() { + REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master" + wget $REPO_URL -O lightning_pub.tar.gz + if [ $? -ne 0 ]; then + echo "Failed to download Lightning.Pub tarball. Please check the URL or your internet connection." + exit 1 + fi + mkdir lightning_pub + tar -xvzf lightning_pub.tar.gz -C lightning_pub --strip-components=1 + if [ $? -ne 0 ]; then + echo "Failed to extract Lightning.Pub tarball." + exit 1 + fi + rm lightning_pub.tar.gz + cd lightning_pub + npm install + if [ $? -ne 0 ]; then + echo "Failed to install npm dependencies." + exit 1 + fi +} + +# Function to create start script +create_start_script() { + cat < start.sh +#!/bin/bash +~/lnd/lnd & +LND_PID=\$! +sleep 10 +npm start & +NODE_PID=\$! +wait \$LND_PID +wait \$NODE_PID +EOF + chmod +x start.sh + echo "systemctl not available. Created start.sh. Please use this script to start the services manually." +} + +# Function to display animated "starting..." log +display_starting_animation() { + echo -n "Starting services" + for i in {1..3}; do + sleep 1 + echo -n "." + done + echo +} + +# Function to start services +start_services() { + ~/lnd/lnd & + LND_PID=$! + sleep 10 + npm start & + NODE_PID=$! + + if [[ "$OS" == "Linux" ]]; then + if [ -x "$(command -v systemctl)" ]; then + sudo bash -c "cat > /etc/systemd/system/lnd.service < /etc/systemd/system/lightning_pub.service <