-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·127 lines (111 loc) · 7.16 KB
/
uninstall.sh
File metadata and controls
executable file
·127 lines (111 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# UniFi Controller on Firewalla Gold Pro - Macvlan Uninstall Script
# https://github.com/dagecko/unifi-firewalla-macvlan
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${RED}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ UniFi Controller Uninstaller for Firewalla (Macvlan Edition) ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
echo -e "${YELLOW}Warning: This will remove the UniFi Controller and ALL related data!${NC}"
echo ""
echo "The following will be deleted:"
echo " - Docker containers (unifi, unifi-db)"
echo " - Docker images"
echo " - /data/unifi (controller data)"
echo " - /data/unifi-db (database)"
echo " - /home/pi/.firewalla/run/docker/unifi/"
echo " - /home/pi/.firewalla/config/post_main.d/start_unifi.sh"
echo ""
read -p "Are you sure you want to continue? (yes/N): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo "Uninstall cancelled."
exit 0
fi
echo ""
echo -e "${YELLOW}Stopping containers...${NC}"
# Stop and remove containers
if [ -f /home/pi/.firewalla/run/docker/unifi/docker-compose.yaml ]; then
cd /home/pi/.firewalla/run/docker/unifi
sudo docker-compose down -v 2>/dev/null && echo -e "${GREEN}✓ Containers stopped${NC}" || echo -e "${YELLOW}⚠ No compose containers found${NC}"
fi
# Remove any remaining containers
sudo docker stop unifi 2>/dev/null && echo -e "${GREEN}✓ unifi container stopped${NC}" || true
sudo docker stop unifi-db 2>/dev/null && echo -e "${GREEN}✓ unifi-db container stopped${NC}" || true
sudo docker rm unifi 2>/dev/null && echo -e "${GREEN}✓ unifi container removed${NC}" || true
sudo docker rm unifi-db 2>/dev/null && echo -e "${GREEN}✓ unifi-db container removed${NC}" || true
echo ""
echo -e "${YELLOW}Removing Docker images...${NC}"
sudo docker rmi lscr.io/linuxserver/unifi-network-application:latest 2>/dev/null && echo -e "${GREEN}✓ UniFi image removed${NC}" || echo -e "${YELLOW}⚠ UniFi image not found${NC}"
sudo docker rmi mongo:4.4 2>/dev/null && echo -e "${GREEN}✓ MongoDB image removed${NC}" || echo -e "${YELLOW}⚠ MongoDB image not found${NC}"
echo ""
echo -e "${YELLOW}Removing Docker networks...${NC}"
sudo docker network rm unifi_unifi-internal 2>/dev/null && echo -e "${GREEN}✓ unifi_unifi-internal network removed${NC}" || echo -e "${YELLOW}⚠ unifi_unifi-internal network not found${NC}"
sudo docker network rm unifi_unifi-net 2>/dev/null && echo -e "${GREEN}✓ unifi_unifi-net network removed${NC}" || echo -e "${YELLOW}⚠ unifi_unifi-net network not found${NC}"
echo ""
echo -e "${YELLOW}Removing shim interface, routes, and policy rules...${NC}"
# Remove all routes using unifi-shim from main table
while read -r route; do
[ -n "$route" ] && sudo ip route del $route 2>/dev/null || true
done < <(ip route | grep "dev unifi-shim")
# Remove all routes using unifi-shim from lan_routable table
while read -r route; do
[ -n "$route" ] && sudo ip route del $route table lan_routable 2>/dev/null || true
done < <(ip route show table lan_routable | grep "dev unifi-shim")
# Remove policy routing rules for VLAN networks (priority 5002)
while read -r rule; do
RULE_NUM=$(echo "$rule" | awk '{print $1}' | tr -d ':')
[ -n "$RULE_NUM" ] && sudo ip rule del pref $RULE_NUM 2>/dev/null || true
done < <(ip rule list | grep "lookup lan_routable" | grep "5002:")
# Remove policy routing rules for container return traffic (priority 500)
while read -r rule; do
RULE_NUM=$(echo "$rule" | awk '{print $1}' | tr -d ':')
[ -n "$RULE_NUM" ] && sudo ip rule del pref $RULE_NUM 2>/dev/null || true
done < <(ip rule list | grep "lookup main" | grep "500:")
# Remove default route from lan_routable table if it was added for VLAN
# (Only remove if it's the exact route we added - check for eth0)
DEFAULT_VIA_ETH0=$(ip route show table lan_routable | grep "^default via .* dev eth0$")
if [ -n "$DEFAULT_VIA_ETH0" ]; then
sudo ip route del default table lan_routable 2>/dev/null && echo -e "${GREEN}✓ VLAN default route removed${NC}" || true
fi
sudo ip link delete unifi-shim 2>/dev/null && echo -e "${GREEN}✓ Shim interface, routes, and rules removed${NC}" || echo -e "${YELLOW}⚠ Shim interface not found${NC}"
echo ""
echo -e "${YELLOW}Removing data directories...${NC}"
if [ -d /data/unifi ] || [ -d /data/unifi-db ]; then
echo -e "${YELLOW}Note: This will delete all UniFi configuration and database!${NC}"
read -p "Delete all data? (yes/N): " DELETE_DATA
if [ "$DELETE_DATA" = "yes" ]; then
sudo rm -rf /data/unifi 2>/dev/null && echo -e "${GREEN}✓ /data/unifi removed${NC}" || true
sudo rm -rf /data/unifi-db 2>/dev/null && echo -e "${GREEN}✓ /data/unifi-db removed${NC}" || true
else
echo -e "${YELLOW}⚠ Data directories preserved${NC}"
fi
else
echo -e "${YELLOW}⚠ No data directories found${NC}"
fi
echo ""
echo -e "${YELLOW}Stopping and removing monitoring service...${NC}"
sudo systemctl stop unifi-monitor.service 2>/dev/null && echo -e "${GREEN}✓ Monitoring service stopped${NC}" || echo -e "${YELLOW}⚠ Monitoring service not running${NC}"
sudo systemctl disable unifi-monitor.service 2>/dev/null && echo -e "${GREEN}✓ Monitoring service disabled${NC}" || true
sudo rm -f /etc/systemd/system/unifi-monitor.service 2>/dev/null && echo -e "${GREEN}✓ Monitoring service file removed${NC}" || echo -e "${YELLOW}⚠ Service file not found${NC}"
sudo rm -f /home/pi/.firewalla/config/post_main.d/unifi-monitor.sh 2>/dev/null && echo -e "${GREEN}✓ Monitor script removed${NC}" || echo -e "${YELLOW}⚠ Monitor script not found${NC}"
sudo rm -f /var/log/unifi-monitor.log* 2>/dev/null && echo -e "${GREEN}✓ Monitor logs removed${NC}" || true
sudo systemctl daemon-reload
echo ""
echo -e "${YELLOW}Removing configuration files...${NC}"
sudo rm -rf /home/pi/.firewalla/run/docker/unifi 2>/dev/null && echo -e "${GREEN}✓ Docker config removed${NC}" || echo -e "${YELLOW}⚠ Docker config not found${NC}"
sudo rm -f /home/pi/.firewalla/config/post_main.d/start_unifi.sh 2>/dev/null && echo -e "${GREEN}✓ Startup script removed${NC}" || echo -e "${YELLOW}⚠ Startup script not found${NC}"
echo ""
echo -e "${YELLOW}Cleaning up Docker...${NC}"
sudo docker system prune -f 2>/dev/null && echo -e "${GREEN}✓ Docker cleanup complete${NC}"
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Uninstall Complete! ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo "All UniFi Controller components have been removed."
echo "You can reinstall at any time by running the install script."
echo ""