mac untested

This commit is contained in:
shocknet-justin 2025-11-26 00:30:24 -05:00
parent d319c1d4be
commit da5113ec05
8 changed files with 198 additions and 83 deletions

View file

@ -1,11 +0,0 @@
#!/bin/bash
check_homebrew() {
if ! command -v brew &> /dev/null; then
log "${PRIMARY_COLOR}Homebrew not found. Installing Homebrew...${RESET_COLOR}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || {
log "${PRIMARY_COLOR}Failed to install Homebrew.${RESET_COLOR}"
exit 1
}
fi
}

View file

@ -1,43 +0,0 @@
#!/bin/bash
create_launchd_plist() {
create_plist() {
local plist_path=$1
local label=$2
local program_args=$3
local working_dir=$4
if [ -f "$plist_path" ]; then
log "${PRIMARY_COLOR}${label} already exists. Skipping creation.${RESET_COLOR}"
else
cat <<EOF > "$plist_path"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${label}</string>
<key>ProgramArguments</key>
<array>
${program_args}
</array>
<key>WorkingDirectory</key>
<string>${working_dir}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
fi
}
USER_HOME=$(eval echo ~$(whoami))
NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${USER_HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
LAUNCH_AGENTS_DIR="${USER_HOME}/Library/LaunchAgents"
create_plist "${LAUNCH_AGENTS_DIR}/local.lnd.plist" "local.lnd" "<string>${USER_HOME}/lnd/lnd</string>" ""
create_plist "${LAUNCH_AGENTS_DIR}/local.lightning_pub.plist" "local.lightning_pub" "<string>/bin/bash</string><string>-c</string><string>source ${NVM_DIR}/nvm.sh && npm start</string>" "${USER_HOME}/lightning_pub"
log "${PRIMARY_COLOR}Created launchd plists. Please load them using launchctl.${RESET_COLOR}"
}

148
scripts/handle_macos.sh Normal file
View file

@ -0,0 +1,148 @@
#!/bin/bash
# macOS-specific installation handler
# Called from install.sh when OS=Mac
handle_macos() {
local REPO_URL="$1"
export INSTALL_DIR="$HOME/lightning_pub"
export LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents"
mkdir -p "$LAUNCH_AGENTS_DIR"
# Install Homebrew if needed
if ! command -v brew &> /dev/null; then
log "${PRIMARY_COLOR}Installing Homebrew...${RESET_COLOR}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || {
log_error "Failed to install Homebrew" 1
}
fi
# Install LND
log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..."
lnd_output=$(install_lnd)
install_result=$?
if [ $install_result -ne 0 ]; then
log_error "LND installation failed" $install_result
fi
lnd_status=$(echo "$lnd_output" | grep "LND_STATUS:" | cut -d':' -f2)
case $lnd_status in
0) log "LND fresh installation completed successfully." ;;
1) log "LND upgrade completed successfully." ;;
2) log "LND is already up-to-date. No action needed." ;;
*) log "WARNING: Unexpected status from install_lnd: $lnd_status" ;;
esac
# Install Node.js
install_nodejs || log_error "Failed to install Node.js" 1
# Install Lightning.Pub
install_lightning_pub "$REPO_URL" || pub_install_status=$?
case ${pub_install_status:-0} in
0)
log "Lightning.Pub fresh installation completed successfully."
pub_upgrade_status=0
;;
100)
log "Lightning.Pub upgrade completed successfully."
pub_upgrade_status=100
;;
2)
log "Lightning.Pub is already up-to-date. No action needed."
pub_upgrade_status=2
;;
*)
log_error "Lightning.Pub installation failed with exit code $pub_install_status" "$pub_install_status"
;;
esac
# Start services using launchd
if [ "$pub_upgrade_status" -eq 0 ] || [ "$pub_upgrade_status" -eq 100 ]; then
log "Starting services..."
if [ "$lnd_status" = "0" ] || [ "$lnd_status" = "1" ]; then
log "Note: LND may take several minutes to sync block headers depending on network conditions."
fi
create_launchd_plists
# Start/restart services
for svc in local.lnd local.lightning_pub; do
local plist="$LAUNCH_AGENTS_DIR/${svc}.plist"
if launchctl list 2>/dev/null | grep -q "$svc"; then
launchctl unload "$plist" 2>/dev/null || true
fi
launchctl load "$plist"
done
log "${SECONDARY_COLOR}LND${RESET_COLOR} and ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} services started."
TIMESTAMP_FILE=$(mktemp)
export TIMESTAMP_FILE
get_log_info || log_error "Failed to get log info" 1
fi
log "Installation process completed successfully"
if [ -d "$HOME/lightning_pub" ]; then
mv "$TMP_LOG_FILE" "$HOME/lightning_pub/install.log"
chmod 600 "$HOME/lightning_pub/install.log"
else
rm -f "$TMP_LOG_FILE"
fi
}
create_launchd_plists() {
local NVM_DIR="$HOME/.nvm"
# LND plist
if [ ! -f "$LAUNCH_AGENTS_DIR/local.lnd.plist" ]; then
cat > "$LAUNCH_AGENTS_DIR/local.lnd.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.lnd</string>
<key>ProgramArguments</key>
<array>
<string>$HOME/lnd/lnd</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
fi
# Lightning.Pub plist
if [ ! -f "$LAUNCH_AGENTS_DIR/local.lightning_pub.plist" ]; then
cat > "$LAUNCH_AGENTS_DIR/local.lightning_pub.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.lightning_pub</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>source $NVM_DIR/nvm.sh &amp;&amp; npm start</string>
</array>
<key>WorkingDirectory</key>
<string>$INSTALL_DIR</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
fi
}

View file

@ -11,7 +11,7 @@ log() {
echo -e "$(echo "$message" | sed 's/\\e\[[0-9;]*m//g')" >> "$TMP_LOG_FILE" echo -e "$(echo "$message" | sed 's/\\e\[[0-9;]*m//g')" >> "$TMP_LOG_FILE"
} }
SCRIPT_VERSION="0.2.2" SCRIPT_VERSION="0.3.0"
REPO="shocknet/Lightning.Pub" REPO="shocknet/Lightning.Pub"
BRANCH="master" BRANCH="master"
@ -36,6 +36,7 @@ modules=(
"install_nodejs" "install_nodejs"
"install_lightning_pub" "install_lightning_pub"
"start_services" "start_services"
"handle_macos"
"extract_nprofile" "extract_nprofile"
) )
@ -91,7 +92,7 @@ log "Detected OS: $OS"
log "Detected ARCH: $ARCH" log "Detected ARCH: $ARCH"
if [ "$OS" = "Mac" ]; then if [ "$OS" = "Mac" ]; then
log_error "macOS is not currently supported by this install script. Please use a Linux-based system." 1 handle_macos "$REPO_URL"
else else
# Explicit kickoff log for LND so the flow is clear in the install log # Explicit kickoff log for LND so the flow is clear in the install log
log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..." log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..."

View file

@ -9,15 +9,17 @@ install_lnd() {
USER_NAME=$(whoami) USER_NAME=$(whoami)
log "Checking latest LND version..." log "Checking latest LND version..."
LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') local api_response=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest)
LND_VERSION=$(json_value "tag_name" "$api_response")
log "Latest LND version: $LND_VERSION" log "Latest LND version: $LND_VERSION"
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz" local LND_OS="$OS"; [ "$OS" = "Mac" ] && LND_OS="darwin"
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${LND_OS}-${ARCH}-${LND_VERSION}.tar.gz"
# Check if LND is already installed # Check if LND is already installed
if [ -d "$USER_HOME/lnd" ]; then if [ -d "$USER_HOME/lnd" ]; then
log "LND directory found. Checking current version..." log "LND directory found. Checking current version..."
CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+') CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | awk '/version/ {print $3}')
log "Current LND version: $CURRENT_VERSION" log "Current LND version: $CURRENT_VERSION"
if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then
@ -60,12 +62,13 @@ install_lnd() {
log "${PRIMARY_COLOR}Stopping${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} user service..." log "${PRIMARY_COLOR}Stopping${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} user service..."
systemctl --user stop lnd systemctl --user stop lnd
fi fi
else elif [ "$OS" = "Mac" ] && launchctl list 2>/dev/null | grep -q "local.lnd"; then
log "${PRIMARY_COLOR}Please stop ${SECONDARY_COLOR}LND${RESET_COLOR} manually if it is running.${RESET_COLOR}" log "${PRIMARY_COLOR}Stopping${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} launchd service..."
launchctl unload "$USER_HOME/Library/LaunchAgents/local.lnd.plist" 2>/dev/null || true
fi fi
log "Extracting LND..." log "Extracting LND..."
LND_TMP_DIR=$(mktemp -d -p "$USER_HOME") LND_TMP_DIR=$(mktemp_in "$USER_HOME")
tar -xzf "$USER_HOME/lnd.tar.gz" -C "$LND_TMP_DIR" --strip-components=1 > /dev/null || { tar -xzf "$USER_HOME/lnd.tar.gz" -C "$LND_TMP_DIR" --strip-components=1 > /dev/null || {
log "${PRIMARY_COLOR}Failed to extract LND.${RESET_COLOR}" log "${PRIMARY_COLOR}Failed to extract LND.${RESET_COLOR}"
@ -106,7 +109,7 @@ install_lnd() {
# Port conflict resolution. # Port conflict resolution.
local lnd_port=9735 local lnd_port=9735
if ! is_port_available $lnd_port; then if [ "$OS" = "Linux" ] && ! is_port_available $lnd_port; then
# The port is occupied. We should intervene if our service is either in a failed state # The port is occupied. We should intervene if our service is either in a failed state
# or not active at all (which covers fresh installs and failure loops). # or not active at all (which covers fresh installs and failure loops).
if systemctl --user -q is-failed lnd.service 2>/dev/null || ! systemctl --user -q is-active lnd.service 2>/dev/null; then if systemctl --user -q is-failed lnd.service 2>/dev/null || ! systemctl --user -q is-active lnd.service 2>/dev/null; then
@ -114,7 +117,7 @@ install_lnd() {
lnd_port_new=$(find_available_port $lnd_port) lnd_port_new=$(find_available_port $lnd_port)
log "Configuring LND to use new port $lnd_port_new." log "Configuring LND to use new port $lnd_port_new."
sed -i '/^listen=/d' $USER_HOME/.lnd/lnd.conf sed_i '/^listen=/d' $USER_HOME/.lnd/lnd.conf
echo "listen=0.0.0.0:$lnd_port_new" >> $USER_HOME/.lnd/lnd.conf echo "listen=0.0.0.0:$lnd_port_new" >> $USER_HOME/.lnd/lnd.conf
log "LND configuration updated. The service will be restarted by the installer." log "LND configuration updated. The service will be restarted by the installer."
else else

View file

@ -13,7 +13,8 @@ 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
NVM_VERSION=$(wget -qO- https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') local nvm_api=$(wget -qO- https://api.github.com/repos/nvm-sh/nvm/releases/latest)
NVM_VERSION=$(json_value "tag_name" "$nvm_api")
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="${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"

View file

@ -1,17 +0,0 @@
#!/bin/bash
start_services_mac() {
create_launchd_plist
launchctl load "${LAUNCH_AGENTS_DIR}/local.lnd.plist"
launchctl load "${LAUNCH_AGENTS_DIR}/local.lightning_pub.plist"
log "${SECONDARY_COLOR}LND${RESET_COLOR} and ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} services started using launchd."
}
handle_macos() {
check_homebrew
install_rsync_mac
install_nodejs
install_lightning_pub
create_launchd_plist
start_services_mac
}

View file

@ -29,10 +29,43 @@ detect_os_arch() {
} }
check_deps() { check_deps() {
for cmd in wget grep stat tar sha256sum; do for cmd in wget grep stat tar; do
if ! command -v $cmd &> /dev/null; then if ! command -v $cmd &> /dev/null; then
log "Missing system dependency: $cmd. Install $cmd via your package manager and retry." log "Missing system dependency: $cmd. Install $cmd via your package manager and retry."
exit 1 exit 1
fi fi
done done
if ! command -v sha256sum &> /dev/null && ! command -v shasum &> /dev/null; then
log "Missing system dependency: sha256sum or shasum."
exit 1
fi
}
# Cross-platform sed in-place
sed_i() {
if [ "$OS" = "Mac" ]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
# Cross-platform mktemp with parent directory
mktemp_in() {
local parent="$1"
if [ "$OS" = "Mac" ]; then
mktemp -d "${parent}/tmp.XXXXXX"
else
mktemp -d -p "$parent"
fi
}
# Extract JSON value (cross-platform)
json_value() {
local key="$1"
if [ "$OS" = "Mac" ]; then
echo "$2" | awk -F"\"${key}\"[[:space:]]*:[[:space:]]*\"" '{print $2}' | awk -F'"' '{print $1}' | head -1
else
echo "$2" | grep -oP "\"${key}\": \"\\K[^\"]+"
fi
} }