|
1 | 1 | #!/bin/bash |
2 | 2 | set -e |
3 | 3 |
|
4 | | -# Anyisland Universal Bootstrap |
5 | | -# This script prepares the system and hands off to the Anyisland binary. |
| 4 | +# Anyisland Universal Bootstrap & Tool Installer Hook |
| 5 | +# Prepares the host, bootstraps Anyisland, and optionally installs a target repository. |
6 | 6 |
|
7 | 7 | ISLAND_DIR="$HOME/.anyisland" |
8 | 8 | LOCAL_BIN="$HOME/.local/bin" |
9 | 9 | VERSION="latest" |
| 10 | +TARGET_REPO="${1:-$ANYISLAND_TARGET}" |
10 | 11 |
|
11 | | -echo "🏝️ Anyisland Bootstrap" |
| 12 | +if [ -n "$TARGET_REPO" ]; then |
| 13 | + echo "🏝️ Anyisland Universal Bootstrap (Installing: $TARGET_REPO)" |
| 14 | +else |
| 15 | + echo "🏝️ Anyisland Bootstrap" |
| 16 | +fi |
12 | 17 |
|
13 | 18 | # 1. Detect Platform |
14 | 19 | OS="$(uname -s | tr '[:upper:]' '[:lower:]')" |
|
25 | 30 | echo "📍 Platform: $OS-$ARCH" |
26 | 31 |
|
27 | 32 | # 2. Check if already installed and up-to-date |
| 33 | +ALREADY_INSTALLED=false |
28 | 34 | if command -v anyisland &> /dev/null; then |
29 | | - CURRENT_COMMIT=$(anyisland version | grep "Commit:" | awk '{print $2}' | cut -d'(' -f1 | xargs) |
| 35 | + CURRENT_COMMIT=$(anyisland version 2>/dev/null | grep "Commit:" | awk '{print $2}' | cut -d'(' -f1 | xargs || true) |
30 | 36 | REPO_URL="https://github.com/nathfavour/anyisland" |
31 | 37 |
|
32 | 38 | if command -v git &> /dev/null; then |
33 | | - REMOTE_COMMIT=$(git ls-remote "$REPO_URL" HEAD | awk '{print $1}') |
34 | | - if [ "$CURRENT_COMMIT" = "$REMOTE_COMMIT" ]; then |
| 39 | + REMOTE_COMMIT=$(git ls-remote "$REPO_URL" HEAD 2>/dev/null | awk '{print $1}' || true) |
| 40 | + if [ -n "$CURRENT_COMMIT" ] && [ "$CURRENT_COMMIT" = "$REMOTE_COMMIT" ]; then |
35 | 41 | echo "✅ Anyisland is already at the latest version ($CURRENT_COMMIT)." |
36 | | - exit 0 |
| 42 | + ALREADY_INSTALLED=true |
37 | 43 | fi |
| 44 | + else |
| 45 | + ALREADY_INSTALLED=true |
38 | 46 | fi |
39 | 47 | fi |
40 | 48 |
|
41 | | -# 3. Build/Download Binary |
42 | | -BUILD_SUCCESS=false |
| 49 | +# 3. Build/Download Binary if needed |
| 50 | +if [ "$ALREADY_INSTALLED" = false ]; then |
| 51 | + BUILD_SUCCESS=false |
43 | 52 |
|
44 | | -# Check if we can build from local source (meaning we are running `./install.sh` inside the repo) |
45 | | -if [ -d "cmd/anyisland" ] && command -v go &> /dev/null; then |
46 | | - echo "🔨 Building Anyisland from local source..." |
47 | | - if go build -o anyisland ./cmd/anyisland; then |
48 | | - BUILD_SUCCESS=true |
| 53 | + # Check if we can build from local source |
| 54 | + if [ -d "cmd/anyisland" ] && command -v go &> /dev/null; then |
| 55 | + echo "🔨 Building Anyisland from local source..." |
| 56 | + if go build -o anyisland ./cmd/anyisland 2>/dev/null; then |
| 57 | + BUILD_SUCCESS=true |
| 58 | + fi |
49 | 59 | fi |
50 | | -fi |
51 | 60 |
|
52 | | -if [ "$BUILD_SUCCESS" != "true" ]; then |
53 | | - echo "📥 Attempting to download pre-built binary for $OS-$ARCH..." |
54 | | - EXT="tar.gz" |
55 | | - if [ "$OS" = "windows" ]; then |
56 | | - EXT="zip" |
57 | | - fi |
58 | | - BINARY_NAME="anyisland_${OS}_${ARCH}.${EXT}" |
59 | | - DOWNLOAD_URL="https://github.com/nathfavour/anyisland/releases/download/v0.0.0/${BINARY_NAME}" |
60 | | - |
61 | | - if ! curl -fsSL "$DOWNLOAD_URL" -o anyisland_archive; then |
62 | | - echo "⚠️ v0.0.0 release not found. Falling back to latest release..." |
63 | | - DOWNLOAD_URL="https://github.com/nathfavour/anyisland/releases/latest/download/${BINARY_NAME}" |
64 | | - curl -fsSL "$DOWNLOAD_URL" -o anyisland_archive |
65 | | - fi |
66 | | - |
67 | | - if [ -f anyisland_archive ]; then |
68 | | - echo "✅ Downloaded pre-built binary archive." |
| 61 | + if [ "$BUILD_SUCCESS" != "true" ]; then |
| 62 | + echo "📥 Attempting to download pre-built binary for $OS-$ARCH..." |
| 63 | + EXT="tar.gz" |
69 | 64 | if [ "$OS" = "windows" ]; then |
70 | | - if command -v unzip &> /dev/null; then |
71 | | - unzip -o anyisland_archive anyisland.exe |
| 65 | + EXT="zip" |
| 66 | + fi |
| 67 | + BINARY_NAME="anyisland_${OS}_${ARCH}.${EXT}" |
| 68 | + DOWNLOAD_URL="https://github.com/nathfavour/anyisland/releases/latest/download/${BINARY_NAME}" |
| 69 | + |
| 70 | + if curl -fsSL "$DOWNLOAD_URL" -o anyisland_archive 2>/dev/null; then |
| 71 | + echo "✅ Downloaded pre-built binary archive." |
| 72 | + if [ "$OS" = "windows" ]; then |
| 73 | + if command -v unzip &> /dev/null; then |
| 74 | + unzip -o anyisland_archive anyisland.exe |
| 75 | + fi |
| 76 | + [ -f anyisland.exe ] && mv anyisland.exe anyisland |
72 | 77 | else |
73 | | - echo "⚠️ unzip command not found. Cannot extract archive." |
74 | | - rm -f anyisland_archive |
75 | | - exit 1 |
| 78 | + tar -xzf anyisland_archive anyisland 2>/dev/null || true |
76 | 79 | fi |
77 | | - mv anyisland.exe anyisland |
78 | | - else |
79 | | - tar -xzf anyisland_archive anyisland |
| 80 | + rm -f anyisland_archive |
| 81 | + [ -f anyisland ] && BUILD_SUCCESS=true |
80 | 82 | fi |
81 | | - rm -f anyisland_archive |
82 | | - BUILD_SUCCESS=true |
83 | | - else |
84 | | - echo "⚠️ Failed to download pre-built binary." |
85 | 83 | fi |
86 | | -fi |
87 | 84 |
|
88 | | -if [ "$BUILD_SUCCESS" != "true" ]; then |
89 | | - if command -v go &> /dev/null; then |
90 | | - echo "🔨 Go is installed. Attempting to compile from remote source..." |
91 | | - if GOBIN="$(pwd)" go install github.com/nathfavour/anyisland/cmd/anyisland@master; then |
92 | | - echo "✅ Built successfully from remote source." |
93 | | - BUILD_SUCCESS=true |
| 85 | + if [ "$BUILD_SUCCESS" != "true" ]; then |
| 86 | + if command -v go &> /dev/null; then |
| 87 | + echo "🔨 Go is installed. Attempting to compile from remote source..." |
| 88 | + if GOBIN="$(pwd)" go install github.com/nathfavour/anyisland/cmd/anyisland@master 2>/dev/null; then |
| 89 | + echo "✅ Built successfully from remote source." |
| 90 | + BUILD_SUCCESS=true |
| 91 | + fi |
94 | 92 | fi |
95 | 93 | fi |
96 | | -fi |
97 | 94 |
|
98 | | -if [ "$BUILD_SUCCESS" != "true" ]; then |
99 | | - echo "❌ Failed to download or build Anyisland binary. Exiting." |
100 | | - exit 1 |
101 | | -fi |
| 95 | + if [ "$BUILD_SUCCESS" != "true" ]; then |
| 96 | + echo "❌ Failed to download or build Anyisland binary. Exiting." |
| 97 | + exit 1 |
| 98 | + fi |
102 | 99 |
|
103 | | -# 4. Hand-off to Anyisland for self-installation |
104 | | -echo "🚚 Handing off to Anyisland for system integration..." |
105 | | -if [ -f "anyisland.exe" ]; then |
106 | | - mv anyisland.exe anyisland |
107 | | -fi |
108 | | -chmod +x anyisland |
109 | | -mkdir -p "$LOCAL_BIN" |
110 | | -mv anyisland "$LOCAL_BIN/" |
| 100 | + # 4. Hand-off to Anyisland for self-installation |
| 101 | + echo "🚚 Handing off to Anyisland for system integration..." |
| 102 | + if [ -f "anyisland.exe" ]; then |
| 103 | + mv anyisland.exe anyisland |
| 104 | + fi |
| 105 | + chmod +x anyisland 2>/dev/null || true |
| 106 | + mkdir -p "$LOCAL_BIN" |
| 107 | + mv anyisland "$LOCAL_BIN/" |
111 | 108 |
|
112 | | -"$LOCAL_BIN/anyisland" self-install |
| 109 | + "$LOCAL_BIN/anyisland" self-install |
| 110 | +fi |
113 | 111 |
|
114 | | -echo "" |
115 | | -echo "✅ Anyisland installation complete!" |
116 | | -echo "🚀 Run 'anyisland' to get started." |
117 | | -echo "👉 You may need to restart your shell to update your PATH." |
| 112 | +# 5. Handle Target Repo Hook if provided |
| 113 | +if [ -n "$TARGET_REPO" ]; then |
| 114 | + echo "📦 Installing target package: $TARGET_REPO via Anyisland..." |
| 115 | + ANYISLAND_BIN="$LOCAL_BIN/anyisland" |
| 116 | + if ! command -v anyisland &> /dev/null; then |
| 117 | + export PATH="$LOCAL_BIN:$PATH" |
| 118 | + fi |
| 119 | + "$ANYISLAND_BIN" install "$TARGET_REPO" |
| 120 | + echo "" |
| 121 | + echo "🎉 Successfully installed $TARGET_REPO!" |
| 122 | +else |
| 123 | + echo "" |
| 124 | + echo "✅ Anyisland installation complete!" |
| 125 | + echo "🚀 Run 'anyisland' to get started." |
| 126 | + echo "👉 You may need to restart your shell to update your PATH." |
| 127 | +fi |
0 commit comments