|
1 | 1 | #!/bin/bash |
2 | | - |
3 | 2 | set -e |
4 | 3 |
|
5 | 4 | TARGET_DIR="/opt/custom_http_server" |
| 5 | +CONFIG_PATH="/etc/custom-http-server.conf" |
| 6 | +SERVICE_PATH="/etc/systemd/system/custom-http-server.service" |
6 | 7 |
|
7 | 8 | echo "Installing Custom HTTP Server..." |
8 | 9 |
|
9 | | -sudo mkdir -p $TARGET_DIR |
10 | | -sudo cp custom_http_server.py $TARGET_DIR/ |
11 | | -sudo cp custom-http-server.service /etc/systemd/system/ |
12 | | -sudo cp default-config.conf /etc/custom-http-server.conf |
| 10 | +# Detect OS |
| 11 | +OS_NAME="$(uname)" |
| 12 | + |
| 13 | +# macOS adjustments |
| 14 | +if [[ "$OS_NAME" == "Darwin" ]]; then |
| 15 | + TARGET_DIR="/usr/local/custom_http_server" |
| 16 | + CONFIG_PATH="/usr/local/etc/custom-http-server.conf" |
| 17 | +fi |
| 18 | + |
| 19 | +# Create target and config directories |
| 20 | +sudo mkdir -p "$TARGET_DIR" |
| 21 | +sudo mkdir -p "$(dirname "$CONFIG_PATH")" |
| 22 | + |
| 23 | +# Copy application and config files |
| 24 | +sudo cp custom_http_server.py "$TARGET_DIR/" |
| 25 | +sudo cp default-config.conf "$CONFIG_PATH" |
| 26 | + |
| 27 | +if [[ "$OS_NAME" == "Linux" ]]; then |
| 28 | + sudo cp custom-http-server.service "$SERVICE_PATH" |
| 29 | + sudo systemctl daemon-reload |
| 30 | + sudo systemctl enable custom-http-server |
| 31 | + sudo systemctl start custom-http-server |
| 32 | + |
| 33 | + echo "✅ Installed and started custom-http-server as a systemd service." |
| 34 | + echo "Edit $CONFIG_PATH to change path or port." |
| 35 | + echo "Logs: sudo journalctl -u custom-http-server -f" |
13 | 36 |
|
14 | | -sudo systemctl daemon-reload |
15 | | -sudo systemctl enable custom-http-server |
16 | | -sudo systemctl start custom-http-server |
| 37 | +elif [[ "$OS_NAME" == "Darwin" ]]; then |
| 38 | + echo "✅ Installed on macOS." |
| 39 | + echo "To run manually: python3 $TARGET_DIR/custom_http_server.py" |
| 40 | + echo "To make it a service, create a launchd plist manually." |
17 | 41 |
|
18 | | -echo "Installed and started custom-http-server." |
19 | | -echo "Edit /etc/custom-http-server.conf to change path or port." |
20 | | -echo "Logs: sudo journalctl -u custom-http-server -f" |
| 42 | +else |
| 43 | + echo "❌ Unsupported OS: $OS_NAME" |
| 44 | + exit 1 |
| 45 | +fi |
0 commit comments