Skip to content

Commit 0f4a200

Browse files
committed
Fix installer pipe execution and upgrade extraction failures
- Installer now works when piped via curl | bash - detects pipe execution and saves to temp file before re-executing - Fix upgrade command marker mismatch: __SHIPNODE_PAYLOAD__ → __ARCHIVE_BELOW__ - Fix upgrade extraction paths to account for shipnode/ subdirectory in archive
1 parent d162b2f commit 0f4a200

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

build-dist.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ cat > "$DIST_DIR/$INSTALLER_NAME" << 'EOF'
5959
6060
set -e
6161
62+
# Detect pipe execution and save to temp file
63+
if [ ! -f "$0" ] || [ "$(basename "$0")" = "bash" ] || [ "$(basename "$0")" = "sh" ]; then
64+
SELF_TEMP=$(mktemp)
65+
cat > "$SELF_TEMP"
66+
bash "$SELF_TEMP" "$@"
67+
EXIT_CODE=$?
68+
rm -f "$SELF_TEMP"
69+
exit $EXIT_CODE
70+
fi
71+
6272
# Colors
6373
RED='\033[0;31m'
6474
GREEN='\033[0;32m'
@@ -85,19 +95,20 @@ done
8595
# Extract embedded archive
8696
echo -e "${BLUE}→${NC} Extracting ShipNode..."
8797
88-
# Get absolute path of this script before changing directory (portable for Linux and macOS)
89-
if command -v realpath &> /dev/null; then
90-
SCRIPT_PATH="$(realpath "$0")"
98+
# Get absolute path of this script (after pipe detection, $0 is always a real file)
99+
if command -v readlink &> /dev/null && readlink -f "$0" &> /dev/null; then
100+
# Linux: use readlink -f
101+
SCRIPT_PATH="$(readlink -f "$0")"
91102
elif [[ "$OSTYPE" == "darwin"* ]]; then
92-
# macOS: construct absolute path manually since readlink -f doesn't exist
103+
# macOS: readlink -f doesn't exist, construct absolute path manually
93104
if [ -L "$0" ]; then
94105
SCRIPT_PATH="$(cd "$(dirname "$0")" && cd "$(dirname "$(readlink "$0")")" && pwd)/$(basename "$(readlink "$0")")"
95106
else
96107
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
97108
fi
98109
else
99-
# Linux: use readlink -f
100-
SCRIPT_PATH="$(readlink -f "$0")"
110+
# Fallback
111+
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
101112
fi
102113
103114
# Create temp directory

lib/commands/upgrade.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ cmd_upgrade() {
5555
# Extract the installer (it's a self-extracting script)
5656
info "Extracting installer..."
5757

58-
# The installer has a base64 payload after __SHIPNODE_PAYLOAD__ marker
58+
# The installer has a base64 payload after __ARCHIVE_BELOW__ marker
5959
# Extract and decode it
60-
local payload_marker="__SHIPNODE_PAYLOAD__"
60+
local payload_marker="__ARCHIVE_BELOW__"
6161
local payload_start
6262
payload_start=$(grep -n "^${payload_marker}$" "$temp_dir/shipnode-installer.sh" | head -n1 | cut -d: -f1)
6363

@@ -73,22 +73,22 @@ cmd_upgrade() {
7373
error "Failed to extract installer payload"
7474
fi
7575

76-
# Verify extraction
77-
if [ ! -f "$temp_dir/shipnode" ] || [ ! -d "$temp_dir/lib" ]; then
76+
# Verify extraction (tar extracts into shipnode/ subdirectory)
77+
if [ ! -f "$temp_dir/shipnode/shipnode" ] || [ ! -d "$temp_dir/shipnode/lib" ]; then
7878
rm -rf "$temp_dir"
7979
error "Extracted files are incomplete"
8080
fi
8181

8282
# Install to SHIPNODE_DIR (overwrite existing installation)
8383
info "Installing to $SHIPNODE_DIR..."
8484

85-
# Copy files
86-
cp -r "$temp_dir/shipnode" "$SHIPNODE_DIR/" || {
85+
# Copy files from the extracted shipnode/ subdirectory
86+
cp -r "$temp_dir/shipnode/shipnode" "$SHIPNODE_DIR/" || {
8787
rm -rf "$temp_dir"
8888
error "Failed to copy shipnode entry point"
8989
}
9090

91-
cp -r "$temp_dir/lib" "$SHIPNODE_DIR/" || {
91+
cp -r "$temp_dir/shipnode/lib" "$SHIPNODE_DIR/" || {
9292
rm -rf "$temp_dir"
9393
error "Failed to copy lib directory"
9494
}

0 commit comments

Comments
 (0)