Skip to content

Commit 627dbf1

Browse files
authored
Update uninstall.sh
1 parent 3db7c53 commit 627dbf1

File tree

1 file changed

+28
-92
lines changed

1 file changed

+28
-92
lines changed

custom-http-server/uninstall.sh

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,53 @@
11
#!/bin/bash
22
set -e
33

4-
# Default values
5-
DEFAULT_TARGET_DIR="/usr/local/custom_http_server"
6-
DEFAULT_CONFIG_PATH="/usr/local/etc/custom-http-server.conf"
7-
DEFAULT_PORT=""
8-
DEFAULT_PATH=""
9-
10-
# Parse macOS arguments
114
OS_NAME="$(uname)"
12-
if [[ "$OS_NAME" == "Darwin" ]]; then
13-
while [[ $# -gt 0 ]]; do
14-
case "$1" in
15-
-path)
16-
DEFAULT_PATH="$2"
17-
shift 2
18-
;;
19-
-port)
20-
DEFAULT_PORT="$2"
21-
shift 2
22-
;;
23-
24-
*)
25-
echo "❌ Unknown argument: $1"
26-
exit 1
27-
;;
28-
esac
29-
done
30-
31-
if [[ -z "$DEFAULT_PATH" && -z "$DEFAULT_PORT" ]]; then
32-
echo "❌ Error: At least one of -path or -port must be specified."
33-
exit 1
34-
fi
355

36-
fi
6+
if [[ "$OS_NAME" == "Linux" ]]; then
7+
echo "Stopping custom-http-server service on Linux..."
8+
sudo systemctl stop custom-http-server || true
379

38-
# Set platform-specific values
39-
TARGET_DIR="/opt/custom_http_server"
40-
CONFIG_PATH="/etc/custom-http-server.conf"
41-
SERVICE_PATH="/etc/systemd/system/custom-http-server.service"
10+
echo "Disabling the service..."
11+
sudo systemctl disable custom-http-server || true
4212

43-
if [[ "$OS_NAME" == "Darwin" ]]; then
44-
TARGET_DIR="$DEFAULT_TARGET_DIR"
45-
CONFIG_PATH="$DEFAULT_CONFIG_PATH"
46-
fi
13+
echo "Killing any running Python server process..."
14+
sudo pkill -f "/opt/custom-http-server/custom_http_server.py" || true
4715

48-
echo "Installing Custom HTTP Server..."
16+
echo "Removing systemd service file..."
17+
sudo rm -f /etc/systemd/system/custom-http-server.service
4918

50-
# Create target and config directories
51-
sudo mkdir -p "$TARGET_DIR"
52-
sudo mkdir -p "$(dirname "$CONFIG_PATH")"
19+
echo "Removing config file..."
20+
sudo rm -f /etc/custom-http-server.conf
5321

54-
# Copy application and config files
55-
sudo cp custom_http_server.py "$TARGET_DIR/"
56-
sudo cp default-config.conf "$CONFIG_PATH"
22+
echo "Removing installed files from /opt/custom-http-server..."
23+
sudo rm -rf /opt/custom-http-server
5724

58-
if [[ "$OS_NAME" == "Linux" ]]; then
59-
echo "✅ Installing on Linux."
60-
sudo cp custom-http-server.service "$SERVICE_PATH"
25+
echo "Reloading systemd daemon..."
6126
sudo systemctl daemon-reload
62-
sudo systemctl enable custom-http-server
63-
sudo systemctl start custom-http-server
6427

65-
echo "✅ Installed and started custom-http-server as a systemd service."
66-
echo "Edit $CONFIG_PATH to change path or port."
67-
echo "Logs: sudo journalctl -u custom-http-server -f"
28+
echo "Uninstall complete on Linux."
6829

6930
elif [[ "$OS_NAME" == "Darwin" ]]; then
70-
echo "✅ Installing on macOS."
71-
echo "Note: macOS does not support automatic install/uninstall like Linux (systemd)."
72-
echo "⚠️ To run manually:"
73-
echo " python3 $TARGET_DIR/custom_http_server.py --path /Users/<your-username> --port <your-port>"
74-
echo "Replace <your-username> with your actual macOS username."
75-
echo "Choose a port that's not already in use (e.g., 8080, 8888, 3000, etc.)."
76-
echo "To make it a background service, create a launchd plist manually."
77-
78-
# Fallback to config value if port was not passed
79-
if [[ -z "$DEFAULT_PORT" ]]; then
80-
echo "Reading port from config: $CONFIG_PATH"
81-
DEFAULT_PORT=$(grep '^SERVE_PORT=' "$CONFIG_PATH" | cut -d= -f2)
82-
fi
31+
echo "Stopping custom-http-server(com.custom_http_server.python) service on macOS..."
8332

84-
# Fallback to config value if path was not passed
85-
if [[ -z "$DEFAULT_PATH" ]]; then
86-
echo "Reading path from config: $CONFIG_PATH"
87-
TEMP_PATH=$(grep '^SERVE_PATH=' "$CONFIG_PATH" | cut -d= -f2)
88-
89-
# Skip using /root if on macOS
90-
if [[ "$OS_NAME" == "Darwin" && "$TEMP_PATH" == "/root" ]]; then
91-
echo "⚠️ Ignoring '/root' path on macOS. Please specify --path manually."
92-
else
93-
DEFAULT_PATH="$TEMP_PATH"
94-
fi
95-
fi
33+
PLIST="$HOME/Library/LaunchAgents/com.custom_http_server.plist"
9634

97-
98-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
99-
if [[ ! -x "$SCRIPT_DIR/macos-launchd-setup.sh" ]]; then
100-
echo "❌ Error: macos-launchd-setup.sh is missing or not executable."
101-
ls -l "$SCRIPT_DIR/macos-launchd-setup.sh"
102-
exit 1
35+
if [[ -f "$PLIST" ]]; then
36+
launchctl unload "$PLIST" 2>/dev/null || true
37+
echo "Unloaded service: $PLIST"
10338
fi
10439

105-
chmod +x "$SCRIPT_DIR/macos-launchd-setup.sh"
106-
# bash "$SCRIPT_DIR/macos-launchd-setup.sh" -path "$DEFAULT_PATH" -port "$DEFAULT_PORT"
107-
LAUNCHD_ARGS=()
108-
[[ -n "$DEFAULT_PATH" ]] && LAUNCHD_ARGS+=("-path" "$DEFAULT_PATH")
109-
[[ -n "$DEFAULT_PORT" ]] && LAUNCHD_ARGS+=("-port" "$DEFAULT_PORT")
40+
if [[ -f "$PLIST" ]]; then
41+
rm "$PLIST"
42+
echo "Removed plist: $PLIST"
43+
fi
11044

111-
bash "$SCRIPT_DIR/macos-launchd-setup.sh" "${LAUNCHD_ARGS[@]}"
45+
echo "Verifying removal..."
46+
launchctl list | grep custom_http_server || echo "Service fully removed."
11247

48+
echo "Uninstall complete on macOS."
11349

11450
else
115-
echo "Unsupported OS: $OS_NAME"
51+
echo "Unsupported OS: $OS_NAME"
11652
exit 1
11753
fi

0 commit comments

Comments
 (0)