This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
/
uninstall.sh
executable file
·124 lines (87 loc) · 4.29 KB
/
uninstall.sh
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
#!/bin/sh
# W
# R RW W.
# RW::::RW DR::R
# :RRRRRWWWWRt:::::::RRR::::::E jR
# R.::::::::::::::::::::::::::Ri jiR:::R
# R:::::::.RERRRRWWRERR,::::::Efi:::::::R GjRRR Rj
# R::::::.R R:::::::::::::;G RRj WWR RjRRRRj
# Rt::::WR RRWR R::::::::::::::::fWR::R; WRW RW R
# WWWWRR:::EWR E::W WRRW:::EWRRR::::::::: RRED WR RRW RR
# 'R:::::::RRR RR DWW R::::::::RW LRRR WR R
# RL:::::WRR GRWRR RR R::WRiGRWW RRR RRR R
# Ri:::WWD RWRRRWW WWR LR R W RR RRRR RR R
# RRRWWWWRE;,:::WW R:::RW RR:W RR ERE RR RRR RRR R
# RR:::::::::::RR tR:::WR Wf:R RW R R RRR RR R
# WR::::::::tRR WR::RW ER.R RRR R RRRR RR R
# WE:::::RR R:::RR :RW E RR RW; GRRR RR R
# R.::::,WR R:::GRW E::RR WiWW RRWR LRRWWRR
# WR::::::RRRRWRG::::::RREWDWRj::::RW ,WR::WR iRWWWWWRWW R
# LR:::::::::::::::::::::::::::::::::EWRR::::::RRRDi:::W RR R
# R:::::::::::::::::::::::::::::::::::::::::::::::::::tRW RRRWWWW
# RRRRRRRRRRR::::::::::::::::::::::::::::::::::::,:::DE RRWRWW,
# R::::::::::::: RW::::::::R::::::::::RRWRRR
# R::::::::::WR. ;R::::;R RWi:::::ER
# R::::::.RR Ri:iR RR:,R
# E::: RE RW Y
# ERRR
# G Zero-configuration Rack server for Mac OS X
# http://pow.cx/
#
# This is the uninstallation script for Pow.
# See the full annotated source: http://pow.cx/docs/
#
# Uninstall Pow by running this command:
# curl get.pow.cx/uninstall.sh | sh
# Set up the environment.
set -e
POW_ROOT="$HOME/Library/Application Support/Pow"
POW_CURRENT_PATH="$POW_ROOT/Current"
POW_VERSIONS_PATH="$POW_ROOT/Versions"
POWD_PLIST_PATH="$HOME/Library/LaunchAgents/cx.pow.powd.plist"
FIREWALL_PLIST_PATH="/Library/LaunchDaemons/cx.pow.firewall.plist"
POW_CONFIG_PATH="$HOME/.powconfig"
# Fail fast if Pow isn't present.
if [ ! -d "$POW_CURRENT_PATH" ] && [ ! -a "$POWD_PLIST_PATH" ] && [ ! -a "$FIREWALL_PLIST_PATH" ]; then
echo "error: can't find Pow" >&2
exit 1
fi
# Find the tty so we can prompt for confirmation even if we're being piped from curl.
TTY="/dev/$( ps -p$$ -o tty | tail -1 | awk '{print$1}' )"
# Make sure we really want to uninstall.
read -p "Sorry to see you go. Uninstall Pow [y/n]? " ANSWER < $TTY
[ $ANSWER == "y" ] || exit 1
echo "*** Uninstalling Pow..."
# Remove the Versions directory and the Current symlink.
rm -fr "$POW_VERSIONS_PATH"
rm -f "$POW_CURRENT_PATH"
# Unload cx.pow.powd from launchctl and remove the plist.
launchctl unload "$POWD_PLIST_PATH" 2>/dev/null || true
rm -f "$POWD_PLIST_PATH"
# Determine if the firewall uses ipfw or pf.
if grep ipfw "$FIREWALL_PLIST_PATH" >/dev/null; then
FIREWALL_TYPE=ipfw
elif grep pfctl "$FIREWALL_PLIST_PATH" >/dev/null; then
FIREWALL_TYPE=pf
fi
# If ipfw, extract the port numbers from the plist.
if [ "$FIREWALL_TYPE" = "ipfw" ]; then
ports=( $(ruby -e'puts $<.read.scan(/fwd .*?,([\d]+).*?dst-port ([\d]+)/)' "$FIREWALL_PLIST_PATH") )
HTTP_PORT="${ports[0]:-80}"
DST_PORT="${ports[1]:-20559}"
fi
# Try to find the ipfw rule and delete it.
if [ "$FIREWALL_TYPE" = "ipfw" ] && [ -x /sbin/ipfw ]; then
RULE=$(sudo ipfw show | (grep ",$HTTP_PORT .* dst-port $DST_PORT in" || true) | cut -f 1 -d " ")
[ -z "$RULE" ] || sudo ipfw del "$RULE"
fi
# If pf, just flush all rules from the Pow anchor.
if [ "$FIREWALL_TYPE" = "pf" ]; then
sudo pfctl -a "com.apple/250.PowFirewall" -F all 2>/dev/null || true
fi
# Unload the firewall plist and remove it.
sudo launchctl unload "$FIREWALL_PLIST_PATH" 2>/dev/null || true
sudo rm -f "$FIREWALL_PLIST_PATH"
# Remove /etc/resolver files that belong to us
grep -Rl 'generated by Pow' /etc/resolver/ | sudo xargs rm
echo "*** Uninstalled"