-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunsetup.sh
executable file
·163 lines (136 loc) · 2.74 KB
/
unsetup.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
# Run this script to remove the Werc environment on OpenBSD (after setup).
# ---- begin variables ----
# This section contains customizable variables, consider setting their values
# before running the script.
# The domain of your server.
# An invalid domain may result in an unsuccessful or incomplete installation.
domain='example.com'
# The root directory for httpd's chroot environment.
# The default value is usually fine and it should not be changed unless the
# change is backed by a valid reason. If unsure, do not change.
webdir='/var/www'
# ---- end variables ----
# ---- parts ----
preuninst() {
if [ $(uname) != "OpenBSD" ]
then
echo "$0: operating system is not OpenBSD" >&2
return 1
fi
if [ $(whoami) != "root" ]
then
echo "$0: not running as root" >&2
return 1
fi
# check webdir's value
echo "$webdir" | grep -E '^(/[^[:cntrl:]]+)+$' >/dev/null
if [ $? -eq 1 ]
then
echo "$0: invalid chroot directory" >&2
return 1
fi
}
rm9env() {
# remove hard links, copies, devices
rm -fr $webdir$p9pdir $webdir/{dev,tmp} $webdir/usr/{lib,libexec} $webdir/bin
rmdir $webdir/usr ; :
}
uninst() {
ls -1 $webdir/werc/ | grep -v '^sites$' | xargs -I {} rm -r $webdir/werc/{}
}
restore() {
# restore backups
test -f /etc/httpd.conf.bk && mv -v /etc/httpd.conf.bk /etc/httpd.conf
test -f /etc/fstab.bk && mv -v /etc/fstab.bk /etc/fstab
}
# remove packages
rmpkgs() {
while true
do
echo -n "remove the git package? (y/n) "
read yn
case $yn in
[Yy]* )
pkg_delete git
break
;;
[Nn]* )
break
;;
* )
continue
;;
esac
done
}
# disable services
services() {
while true
do
echo -n "disable the slowcgi and httpd services? (y/n) "
read yn
case $yn in
[Yy]* )
rcctl disable slowcgi httpd
break
;;
[Nn]* )
break
;;
* )
continue
;;
esac
done
}
# ---- end parts ----
all() {
if ! preuninst
then
echo "$0: could not complete pre-installation checks" >&2
exit 1
fi
if ! rm9env
then
echo "$0: could not remove the contents of $webdir" >&2
fi
if ! uninst
then
echo "$0: could not uninstall werc" >&2
exit 1
fi
if ! restore
then
echo "$0: could not restore backed up files" >&2
exit 1
fi
if ! rmpkgs
then
echo "$0: could not remove packages" >&2
exit 1
fi
if ! services
then
echo "$0: could not remove services" >&2
exit 1
fi
echo
echo "$0: the unsetup operation was successful"
echo "$0: the content of your site ($siteroot) has not been removed"
}
# default values if unset or empty
webdir=${webdir:-"/var/www"}
domain=${domain:-"example.com"}
# other useful variables
p9pdir='/plan9' # after chroot, full is $webdir$p9pdir
siteroot="$webdir/werc/sites/$domain"
if [ $# -ne 0 ]
then
for f
do
$f
done
else
all
fi