Fix here-document syntax issues in runtime config generation and Go module setup for mock API server
This commit is contained in:
		
							
								
								
									
										41
									
								
								start.sh
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								start.sh
									
									
									
									
									
								
							| @@ -1066,16 +1066,18 @@ else | |||||||
|     echo "==> ERROR: Museum server not found" |     echo "==> ERROR: Museum server not found" | ||||||
|     echo "==> Starting a mock server" |     echo "==> Starting a mock server" | ||||||
|      |      | ||||||
|     # Create a temporary directory for a simple Go server |     # Create a temporary directory for a simple Go server with correct permissions | ||||||
|     mkdir -p /tmp/mock-server |     mkdir -p /tmp/mock-server | ||||||
|     cd /tmp/mock-server |     cd /tmp/mock-server | ||||||
|      |      | ||||||
|     # Initialize a proper Go module |     # Create a simple Go module setup | ||||||
|     echo "==> Initializing Go module for mock API server" |     echo "==> Creating proper Go module structure" | ||||||
|     go mod init mock-server |     touch go.mod | ||||||
|  |     echo "module mock-server" > go.mod | ||||||
|      |      | ||||||
|     # Write the program to a file with proper quoting |     # Write main.go correctly | ||||||
|     cat > main.go << 'GOMOCK' |     echo "==> Writing main.go for mock API server" | ||||||
|  |     cat > main.go << EOF | ||||||
| package main | package main | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| @@ -1454,7 +1456,7 @@ func main() { | |||||||
|         logger.Fatalf("Server failed: %v", err) |         logger.Fatalf("Server failed: %v", err) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| GOMOCK | EOF | ||||||
|      |      | ||||||
|     # Completely unset Go module-related environment variables  |     # Completely unset Go module-related environment variables  | ||||||
|     echo "==> Unsetting module flags before building mock server" |     echo "==> Unsetting module flags before building mock server" | ||||||
| @@ -1463,24 +1465,23 @@ GOMOCK | |||||||
|     unset GOMODCACHE |     unset GOMODCACHE | ||||||
|     unset GOPATH |     unset GOPATH | ||||||
|      |      | ||||||
|     # Build and run the mock server in the background |     # Show directory content for debugging | ||||||
|     echo "==> Building and starting mock API server on port 8080" |     echo "==> Current directory contents:" | ||||||
|     ls -la |     ls -la | ||||||
|      |      | ||||||
|     # Show go.mod for debugging |     # Build and run the mock server in the background | ||||||
|     echo "==> Go module file contents:" |     echo "==> Building and starting mock API server on port 8080" | ||||||
|     cat go.mod |  | ||||||
|      |      | ||||||
|     # Build the mock server (explicitly in current directory) |     # Build without specifying the file (shorter command) | ||||||
|     if go build -o mock_server .; then |     if go build -v .; then | ||||||
|         echo "==> Successfully compiled mock API server" |         echo "==> Successfully compiled mock API server" | ||||||
|          |          | ||||||
|         # Create log directory if it doesn't exist |         # Create log directory if it doesn't exist | ||||||
|         mkdir -p /app/data/logs |         mkdir -p /app/data/logs | ||||||
|          |          | ||||||
|         # Start the server and log both to file and to console |         # Start the server and log both to file and to console | ||||||
|         chmod +x ./mock_server |         chmod +x ./mock-server | ||||||
|         nohup ./mock_server > /app/data/logs/mock_server.log 2>&1 & |         nohup ./mock-server > /app/data/logs/mock_server.log 2>&1 & | ||||||
|         SERVER_PID=$! |         SERVER_PID=$! | ||||||
|         echo "==> Mock API server started with PID $SERVER_PID" |         echo "==> Mock API server started with PID $SERVER_PID" | ||||||
|          |          | ||||||
| @@ -1877,7 +1878,7 @@ EOT | |||||||
|     # Create runtime-config.js files in writable locations |     # Create runtime-config.js files in writable locations | ||||||
|     echo "==> Creating runtime-config.js in writable location" |     echo "==> Creating runtime-config.js in writable location" | ||||||
|     mkdir -p /app/data/web |     mkdir -p /app/data/web | ||||||
|     cat > /app/data/web/runtime-config.js << 'EOT' |     cat << EOF > /app/data/web/runtime-config.js | ||||||
| // Runtime configuration for Ente | // Runtime configuration for Ente | ||||||
| window.ENTE_CONFIG = { | window.ENTE_CONFIG = { | ||||||
|     API_URL: '${API_ENDPOINT}', |     API_URL: '${API_ENDPOINT}', | ||||||
| @@ -1904,7 +1905,7 @@ EOT | |||||||
| console.log('Ente runtime config loaded from runtime-config.js'); | console.log('Ente runtime config loaded from runtime-config.js'); | ||||||
| console.log('API_URL:', window.ENTE_CONFIG.API_URL); | console.log('API_URL:', window.ENTE_CONFIG.API_URL); | ||||||
| console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL); | console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL); | ||||||
|     EOT | EOF | ||||||
|  |  | ||||||
|     # Update the variables in the runtime config |     # Update the variables in the runtime config | ||||||
|     sed -i "s|\${API_ENDPOINT}|${API_ENDPOINT}|g" /app/data/web/runtime-config.js |     sed -i "s|\${API_ENDPOINT}|${API_ENDPOINT}|g" /app/data/web/runtime-config.js | ||||||
| @@ -1954,7 +1955,7 @@ HTML | |||||||
|     done |     done | ||||||
|  |  | ||||||
|     # Modify the Caddyfile to serve our modified HTML files |     # Modify the Caddyfile to serve our modified HTML files | ||||||
|     cat > /app/data/caddy/Caddyfile <<EOT |     cat << EOF > /app/data/caddy/Caddyfile | ||||||
| # Global settings | # Global settings | ||||||
| { | { | ||||||
|     admin off |     admin off | ||||||
| @@ -2161,7 +2162,7 @@ HTML | |||||||
|         reverse_proxy 0.0.0.0:$PUBLIC_ALBUMS_PORT |         reverse_proxy 0.0.0.0:$PUBLIC_ALBUMS_PORT | ||||||
|     } |     } | ||||||
| } | } | ||||||
|     EOT | EOF | ||||||
|  |  | ||||||
|     echo "==> Created Caddy config with properly modified HTML files at /app/data/caddy/Caddyfile" |     echo "==> Created Caddy config with properly modified HTML files at /app/data/caddy/Caddyfile" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user