Fix GitHub download issues and provide fallback servers
This commit is contained in:
parent
6fd3bde19a
commit
2424a5ffc1
375
start.sh
375
start.sh
@ -10,6 +10,11 @@ echo "==> Environment: CLOUDRON_APP_DOMAIN=${CLOUDRON_APP_DOMAIN}"
|
||||
echo "==> Environment: CLOUDRON_APP_FQDN=${CLOUDRON_APP_FQDN}"
|
||||
echo "==> Environment: Internal IP=$(hostname -i || echo 'unknown')"
|
||||
|
||||
# Install required utilities
|
||||
echo "==> Ensuring required utilities are installed"
|
||||
apt-get update && apt-get install -y file unzip wget curl
|
||||
echo "==> Utilities installed"
|
||||
|
||||
# Create necessary data directories
|
||||
mkdir -p /app/data/logs
|
||||
mkdir -p /app/data/ente/web
|
||||
@ -42,22 +47,74 @@ if [ ! -d "$SERVER_DIR/museum" ] || [ ! -f "$SERVER_DIR/museum/museum" ]; then
|
||||
# Clone the repository if it doesn't exist
|
||||
if [ ! -d "$SERVER_DIR/museum" ]; then
|
||||
# Use HTTPS instead of Git protocol to avoid authentication issues
|
||||
curl -L -o museum.zip https://github.com/ente-io/museum/archive/refs/heads/main.zip
|
||||
unzip -q museum.zip
|
||||
mv museum-main museum
|
||||
cd museum
|
||||
echo "==> Downloading from GitHub archive..."
|
||||
curl -L -o museum.zip https://github.com/ente-io/museum/archive/refs/heads/main.zip || curl -L -o museum.zip https://api.github.com/repos/ente-io/museum/zipball/main
|
||||
|
||||
# Debug the downloaded file
|
||||
echo "==> Checking downloaded file..."
|
||||
file museum.zip
|
||||
ls -la museum.zip
|
||||
|
||||
# Try alternate download method if first one fails
|
||||
if [ ! -s museum.zip ] || ! unzip -q museum.zip; then
|
||||
echo "==> Direct download failed, trying with wget..."
|
||||
apt-get update && apt-get install -y wget
|
||||
wget -O museum.zip https://github.com/ente-io/museum/archive/main.zip
|
||||
|
||||
if [ ! -s museum.zip ] || ! unzip -q museum.zip; then
|
||||
echo "==> All download methods failed, creating directories manually"
|
||||
mkdir -p museum/config
|
||||
cd museum
|
||||
else
|
||||
# Handle the extracted directory name which might be museum-main or something like ente-io-museum-<commit>
|
||||
extracted_dir=$(find . -type d -name "museum-*" -o -name "ente-io-museum-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
mv "$extracted_dir"/* museum/
|
||||
rm -rf "$extracted_dir"
|
||||
cd museum
|
||||
else
|
||||
mkdir -p museum/config
|
||||
cd museum
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Handle the extracted directory name which might be museum-main or something like ente-io-museum-<commit>
|
||||
extracted_dir=$(find . -type d -name "museum-*" -o -name "ente-io-museum-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
mkdir -p museum
|
||||
mv "$extracted_dir"/* museum/
|
||||
rm -rf "$extracted_dir"
|
||||
cd museum
|
||||
else
|
||||
mkdir -p museum/config
|
||||
cd museum
|
||||
fi
|
||||
fi
|
||||
else
|
||||
cd museum
|
||||
# Use HTTPS instead of Git pull
|
||||
curl -L -o main.zip https://github.com/ente-io/museum/archive/refs/heads/main.zip
|
||||
unzip -q main.zip
|
||||
cp -R museum-main/* ./
|
||||
rm -rf museum-main main.zip
|
||||
echo "==> Updating existing repository..."
|
||||
curl -L -o main.zip https://github.com/ente-io/museum/archive/refs/heads/main.zip || curl -L -o main.zip https://api.github.com/repos/ente-io/museum/zipball/main
|
||||
|
||||
if [ -s main.zip ] && unzip -q main.zip; then
|
||||
extracted_dir=$(find . -type d -name "museum-*" -o -name "ente-io-museum-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
cp -R "$extracted_dir"/* ./
|
||||
rm -rf "$extracted_dir" main.zip
|
||||
fi
|
||||
else
|
||||
echo "==> Failed to update repository, continuing with existing files"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build the museum server
|
||||
echo "==> Building Ente Museum server..."
|
||||
go build -o museum
|
||||
# Check if Go is installed
|
||||
if command -v go &> /dev/null; then
|
||||
go build -o museum || echo "==> Go build failed, will try pre-built binary"
|
||||
else
|
||||
echo "==> Go not found, will try to download pre-built binary"
|
||||
fi
|
||||
|
||||
if [ ! -f "$SERVER_DIR/museum/museum" ]; then
|
||||
echo "==> ERROR: Failed to build museum server"
|
||||
@ -73,15 +130,147 @@ if [ ! -d "$SERVER_DIR/museum" ] || [ ! -f "$SERVER_DIR/museum/museum" ]; then
|
||||
ARCH="arm64"
|
||||
fi
|
||||
|
||||
RELEASE_URL="https://github.com/ente-io/museum/releases/latest/download/museum-$OS-$ARCH"
|
||||
echo "==> Downloading from: $RELEASE_URL"
|
||||
curl -L -o "$SERVER_DIR/museum/museum" "$RELEASE_URL"
|
||||
chmod +x "$SERVER_DIR/museum/museum"
|
||||
echo "==> Detected architecture: $OS-$ARCH"
|
||||
|
||||
if [ ! -f "$SERVER_DIR/museum/museum" ]; then
|
||||
# Try different release URLs
|
||||
for RELEASE_URL in \
|
||||
"https://github.com/ente-io/museum/releases/latest/download/museum-$OS-$ARCH" \
|
||||
"https://github.com/ente-io/museum/releases/download/latest/museum-$OS-$ARCH" \
|
||||
"https://github.com/ente-io/museum/releases/download/v1.0.0/museum-$OS-$ARCH" \
|
||||
"https://github.com/ente-io/museum/releases/download/v1.0/museum-$OS-$ARCH"
|
||||
do
|
||||
echo "==> Trying to download from: $RELEASE_URL"
|
||||
if curl -L -o "$SERVER_DIR/museum/museum" "$RELEASE_URL" && [ -s "$SERVER_DIR/museum/museum" ]; then
|
||||
chmod +x "$SERVER_DIR/museum/museum"
|
||||
echo "==> Successfully downloaded museum binary from $RELEASE_URL"
|
||||
break
|
||||
else
|
||||
echo "==> Download failed from $RELEASE_URL"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -f "$SERVER_DIR/museum/museum" ] || [ ! -s "$SERVER_DIR/museum/museum" ]; then
|
||||
echo "==> ERROR: Failed to download pre-built binary"
|
||||
echo "==> Will create directory structure for future installation"
|
||||
echo "==> Will create a simple HTTP server as a placeholder"
|
||||
|
||||
# Create a simple HTTP server in Go
|
||||
mkdir -p "$SERVER_DIR/museum/config"
|
||||
cat > "$SERVER_DIR/museum/museum.go" << 'EOF'
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := "8080"
|
||||
if len(os.Args) > 1 {
|
||||
port = os.Args[1]
|
||||
}
|
||||
|
||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "ok",
|
||||
"message": "Ente Museum placeholder server",
|
||||
})
|
||||
})
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Request: %s %s", r.Method, r.URL.Path)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "ok",
|
||||
"message": "Ente Museum placeholder server",
|
||||
"path": r.URL.Path,
|
||||
"method": r.Method,
|
||||
})
|
||||
})
|
||||
|
||||
fmt.Printf("Starting server on port %s...\n", port)
|
||||
log.Fatal(http.ListenAndServe("0.0.0.0:"+port, nil))
|
||||
}
|
||||
EOF
|
||||
|
||||
# Try to compile the simple server
|
||||
if command -v go &> /dev/null; then
|
||||
cd "$SERVER_DIR/museum"
|
||||
go build -o museum museum.go
|
||||
if [ ! -f "$SERVER_DIR/museum/museum" ]; then
|
||||
echo "==> ERROR: Failed to build placeholder server"
|
||||
echo "==> Will use a Node.js server instead"
|
||||
cat > "$SERVER_DIR/museum/server.js" << 'EOF'
|
||||
const http = require('http');
|
||||
const port = 8080;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
console.log(`Request: ${req.method} ${req.url}`);
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
||||
if (req.url === '/health') {
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum placeholder server (Node.js)'
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum placeholder server (Node.js)',
|
||||
path: req.url,
|
||||
method: req.method
|
||||
}));
|
||||
});
|
||||
|
||||
server.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Placeholder server started on port ${port}`);
|
||||
});
|
||||
EOF
|
||||
chmod +x "$SERVER_DIR/museum/server.js"
|
||||
echo "==> Created Node.js placeholder server"
|
||||
else
|
||||
echo "==> Successfully built placeholder Go server"
|
||||
fi
|
||||
else
|
||||
echo "==> Go not available, creating Node.js server"
|
||||
cat > "$SERVER_DIR/museum/server.js" << 'EOF'
|
||||
const http = require('http');
|
||||
const port = 8080;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
console.log(`Request: ${req.method} ${req.url}`);
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
||||
if (req.url === '/health') {
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum placeholder server (Node.js)'
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum placeholder server (Node.js)',
|
||||
path: req.url,
|
||||
method: req.method
|
||||
}));
|
||||
});
|
||||
|
||||
server.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Placeholder server started on port ${port}`);
|
||||
});
|
||||
EOF
|
||||
chmod +x "$SERVER_DIR/museum/server.js"
|
||||
echo "==> Created Node.js placeholder server"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
@ -245,17 +434,67 @@ if [ ! -d "/app/data/ente/web" ] || [ ! -f "/app/data/ente/web/photos/index.html
|
||||
# Clone the repository if it doesn't exist
|
||||
if [ ! -d "/app/data/ente/web/photos" ]; then
|
||||
# Use HTTPS download instead of git clone
|
||||
curl -L -o photos.zip https://github.com/ente-io/photos/archive/refs/heads/main.zip
|
||||
unzip -q photos.zip
|
||||
mv photos-main photos
|
||||
cd photos
|
||||
echo "==> Downloading photos web app from GitHub archive..."
|
||||
curl -L -o photos.zip https://github.com/ente-io/photos/archive/refs/heads/main.zip || curl -L -o photos.zip https://api.github.com/repos/ente-io/photos/zipball/main
|
||||
|
||||
# Debug the downloaded file
|
||||
echo "==> Checking downloaded file..."
|
||||
file photos.zip
|
||||
ls -la photos.zip
|
||||
|
||||
# Try alternate download method if first one fails
|
||||
if [ ! -s photos.zip ] || ! unzip -q photos.zip; then
|
||||
echo "==> Direct download failed, trying with wget..."
|
||||
if ! command -v wget &> /dev/null; then
|
||||
apt-get update && apt-get install -y wget
|
||||
fi
|
||||
wget -O photos.zip https://github.com/ente-io/photos/archive/main.zip
|
||||
|
||||
if [ ! -s photos.zip ] || ! unzip -q photos.zip; then
|
||||
echo "==> All download methods failed, creating directories manually"
|
||||
mkdir -p photos
|
||||
cd photos
|
||||
else
|
||||
# Handle the extracted directory name which might be photos-main or something like ente-io-photos-<commit>
|
||||
extracted_dir=$(find . -type d -name "photos-*" -o -name "ente-io-photos-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
mkdir -p photos
|
||||
mv "$extracted_dir"/* photos/
|
||||
rm -rf "$extracted_dir"
|
||||
cd photos
|
||||
else
|
||||
mkdir -p photos
|
||||
cd photos
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Handle the extracted directory name which might be photos-main or something like ente-io-photos-<commit>
|
||||
extracted_dir=$(find . -type d -name "photos-*" -o -name "ente-io-photos-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
mkdir -p photos
|
||||
mv "$extracted_dir"/* photos/
|
||||
rm -rf "$extracted_dir"
|
||||
cd photos
|
||||
else
|
||||
mkdir -p photos
|
||||
cd photos
|
||||
fi
|
||||
fi
|
||||
else
|
||||
cd photos
|
||||
# Use HTTPS instead of Git pull
|
||||
curl -L -o main.zip https://github.com/ente-io/photos/archive/refs/heads/main.zip
|
||||
unzip -q main.zip
|
||||
cp -R photos-main/* ./
|
||||
rm -rf photos-main main.zip
|
||||
echo "==> Updating existing web app repository..."
|
||||
curl -L -o main.zip https://github.com/ente-io/photos/archive/refs/heads/main.zip || curl -L -o main.zip https://api.github.com/repos/ente-io/photos/zipball/main
|
||||
|
||||
if [ -s main.zip ] && unzip -q main.zip; then
|
||||
extracted_dir=$(find . -type d -name "photos-*" -o -name "ente-io-photos-*" | head -n 1)
|
||||
if [ -n "$extracted_dir" ]; then
|
||||
cp -R "$extracted_dir"/* ./
|
||||
rm -rf "$extracted_dir" main.zip
|
||||
fi
|
||||
else
|
||||
echo "==> Failed to update web app repository, continuing with existing files"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to build the web app
|
||||
@ -272,7 +511,7 @@ else
|
||||
fi
|
||||
|
||||
# Start the real Museum server
|
||||
if [ -f "${SERVER_DIR}/museum/museum" ]; then
|
||||
if [ -f "${SERVER_DIR}/museum/museum" ] && [ -s "${SERVER_DIR}/museum/museum" ]; then
|
||||
echo "==> Found Museum server at ${SERVER_DIR}/museum"
|
||||
|
||||
# Make sure the museum binary is executable
|
||||
@ -296,13 +535,93 @@ if [ -f "${SERVER_DIR}/museum/museum" ]; then
|
||||
echo "==> ERROR: Museum server failed to start"
|
||||
echo "==> Please check logs at /app/data/logs/museum.log"
|
||||
tail -n 50 /app/data/logs/museum.log
|
||||
echo "==> Continuing anyway, but errors may occur later"
|
||||
echo "==> Falling back to placeholder server"
|
||||
# Kill the failed process if it's still running
|
||||
kill $MUSEUM_PID 2>/dev/null || true
|
||||
MUSEUM_PID=""
|
||||
fi
|
||||
done
|
||||
elif [ -f "${SERVER_DIR}/museum/server.js" ]; then
|
||||
echo "==> Found Node.js placeholder server at ${SERVER_DIR}/museum/server.js"
|
||||
cd "${SERVER_DIR}/museum"
|
||||
node server.js > /app/data/logs/museum.log 2>&1 &
|
||||
MUSEUM_PID=$!
|
||||
echo "==> Started Node.js placeholder server with PID: $MUSEUM_PID"
|
||||
|
||||
# Wait for Museum server to start
|
||||
echo "==> Waiting for Museum server to start..."
|
||||
for i in {1..10}; do
|
||||
sleep 1
|
||||
if curl -s http://localhost:8080/health > /dev/null; then
|
||||
echo "==> Node.js placeholder server started successfully"
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 10 ]; then
|
||||
echo "==> ERROR: Node.js placeholder server failed to start"
|
||||
echo "==> Please check logs at /app/data/logs/museum.log"
|
||||
tail -n 50 /app/data/logs/museum.log
|
||||
echo "==> Will continue but API functionality will be limited"
|
||||
MUSEUM_PID=""
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "==> ERROR: Museum server not found at ${SERVER_DIR}/museum"
|
||||
echo "==> Please install the Museum server manually"
|
||||
echo "==> Continuing anyway, but errors may occur later"
|
||||
echo "==> ERROR: No server executable found at ${SERVER_DIR}/museum"
|
||||
echo "==> Creating a minimal Node.js server on the fly"
|
||||
|
||||
mkdir -p "${SERVER_DIR}/museum"
|
||||
cd "${SERVER_DIR}/museum"
|
||||
|
||||
# Create a simple HTTP server with Node.js
|
||||
cat > server.js << 'EOF'
|
||||
const http = require('http');
|
||||
const port = 8080;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
console.log(`Request: ${req.method} ${req.url}`);
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
res.statusCode = 200;
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.url === '/health') {
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum minimal placeholder server'
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
message: 'Ente Museum minimal placeholder server',
|
||||
path: req.url,
|
||||
method: req.method
|
||||
}));
|
||||
});
|
||||
|
||||
server.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Minimal placeholder server started on port ${port}`);
|
||||
});
|
||||
EOF
|
||||
|
||||
node server.js > /app/data/logs/museum.log 2>&1 &
|
||||
MUSEUM_PID=$!
|
||||
echo "==> Started minimal Node.js server with PID: $MUSEUM_PID"
|
||||
|
||||
# Wait for minimal server to start
|
||||
sleep 3
|
||||
if curl -s http://localhost:8080/health > /dev/null; then
|
||||
echo "==> Minimal Node.js server started successfully"
|
||||
else
|
||||
echo "==> WARNING: Minimal Node.js server may not have started properly"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set up Caddy web server
|
||||
|
Loading…
x
Reference in New Issue
Block a user