disable echo during password entry
[feisty_meow.git] / scripts / site_avenger / revamp_cakelampvm.sh
1 #!/bin/bash
2
3 # fixes the cakelampvm permissions according to the way.
4
5 ##############
6
7 if [[ $EUID != 0 ]]; then
8   echo "This script must be run as root or sudo."
9   exit 1
10 fi
11
12 ##############
13
14 export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
15 export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )"
16
17 export NO_HELLO=right
18 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
19 source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh"
20
21 ##############
22
23 # new requirement is to get the sql root password, since we need to do some sql db configuration.
24 echo -n "Please enter the MySQL root account password: "
25 # turn off echo but remember former setting.
26 stty_orig=`stty -g`
27 stty -echo
28 read mysql_passwd
29 # turn echo back on.
30 stty $stty_orig
31 if [ -z "$mysql_passwd" ]; then
32   echo "This script must have the sql root password to proceed."
33   exit 1
34 fi
35
36 ##############
37
38 sep
39
40 echo "Regenerating feisty meow loading dock."
41
42 reconfigure_feisty_meow
43 test_or_die "feisty meow reconfiguration"
44 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
45 test_or_die "fix after reconfigured as sudo"
46
47 ##############
48
49 # set up some crucial users in the mysql db that we seem to have missed previously.
50
51 sep
52
53 echo "Adding users to the mysql database."
54
55 mysql -u root -p"$mysql_passwd" <<EOF
56   create user if not exists 'root'@'%' IDENTIFIED BY '$mysql_passwd';
57   grant all privileges on *.* TO 'root'@'%' with grant option;
58
59   create user if not exists 'wampcake'@'%' IDENTIFIED BY 'bakecamp';
60   grant all privileges on *.* TO 'wampcake'@'%' with grant option;
61
62   create user if not exists 'lampcake'@'%' IDENTIFIED BY 'bakecamp';
63   grant all privileges on *.* TO 'lampcake'@'%' with grant option;
64 EOF
65 test_or_die "configuring root, wampcake and lampcake users on mysql"
66
67 ##############
68
69 echo "Making some important permission changes..."
70
71 # fix up the main web storage.
72 chown -R www-data:www-data /var/www 
73 test_or_die "chown www-data"
74 group_perm /var/www 
75 test_or_die "group_perm www-data"
76
77 ##############
78
79 # set up access on some important folders for the developer user.
80 chown -R developer:developer /home/developer /home/developer/.[a-zA-Z0-9]*
81 test_or_die "chown developer home"
82 harsh_perm /home/developer/.ssh
83 test_or_die "harsh_perm setting on developer .ssh"
84 chown -R developer:developer /etc/apache2 /etc/bind 
85 test_or_die "chown apache2 and bind to developer"
86 group_perm /etc/apache2 /etc/bind 
87 test_or_die "group perms on apache2 and bind"
88
89 ##############
90
91 # fix perms for fred user.
92 chown -R fred:fred /home/fred /home/archives/stuffing /home/fred/.[a-zA-Z0-9]*
93 test_or_die "chown fred home"
94 group_perm $HOME/apps
95 test_or_die "group perms on fred's apps"
96 harsh_perm /home/fred/.ssh
97 test_or_die "harsh_perm setting on fred .ssh"
98 chown -R fred:fred /opt/feistymeow.org 
99 test_or_die "chown feisty meow to fred"
100 group_perm /opt/feistymeow.org 
101 test_or_die "group perms on feisty meow"
102 group_perm /home/fred/apps/mapsdemo
103 test_or_die "group perms on mapsdemo app"
104
105 echo "Done with important permission changes."
106
107 ##############
108 #
109 # some slightly tricky bits start here.  we want to massage the vm into the
110 # best possible shape without needing to re-release it.
111 #
112 ##############
113
114 sep
115
116 echo "Updating developer welcome file."
117
118 # only update hello if they've still got the file there.  we don't want to
119 # keep forcing our hellos at people.
120 if [ -f "$HOME/hello.txt" ]; then
121   # copy the most recent hello file into place for the user.
122   \cp -f "$FEISTY_MEOW_APEX/production/sites/cakelampvm.com/hello.txt" "$HOME"
123   test_or_continue "copying hello file for user"
124 fi
125
126 ##############
127
128 # install a better editor app.
129
130 sep
131
132 echo "The script is about to install the bluefish editor and some dependencies.
133 If the app is not already installed, then this process takes only about a
134 minute on a slower home DSL internet connection..."
135
136 apt-get install -y bluefish &> "/tmp/install_bluefish-$(logname).log"
137 test_or_continue "installing bluefish editor"
138
139 ##############
140
141 # deploy any site updates here to the VM's cakelampvm.com site.
142 #
143 # we want to upgrade the default apache site to the latest, since the new
144 # version mirrors the one on the internet (but with green checks instead
145 # of red X's) and since we also support https on the new default version.
146 # we can do this again later if needed, by upping the numbers on the apache
147 # site config files.  our original site was 000 and the new version is 001,
148 # which we've done as a prefix on the config for some reason.  makes the
149 # code below easy at least.
150 if [ -L /etc/apache2/sites-enabled/000-default.conf ]; then
151
152   sep
153
154   # the old site is in place still, so let's update that.
155   echo "Updating default web sites to latest version."
156
157   a2enmod ssl
158   test_or_die "enabling SSL for secure websites"
159
160   restart_apache
161   test_or_die "getting SSL loaded in apache"
162
163   a2dissite 000-default
164   test_or_die "disabling old apache site"
165
166   rm -f /etc/apache2/sites-available/000-default.conf 
167   test_or_die "removing old apache site"
168
169   # copy in our new version of the default page.
170 #hmmm: would be nice if this worked without mods for any new version, besides just 001.  see apache env var file below for example implem.
171   \cp -f $FEISTY_MEOW_APEX/production/sites/cakelampvm.com/rolling/default_page.001/* \
172       /etc/apache2/sites-available
173   test_or_die "installing new apache default sites"
174
175   # there should only be ours at this version level and with that prefix.
176   a2ensite 001-*
177   test_or_die "enabling new apache default sites"
178
179   restart_apache
180 fi
181
182 ##############
183
184 # fix up the apache site so that HSTS is disabled.  otherwise we can't view
185 # the https site for cakelampvm.com once the domain name switch has occurred.
186
187 sep
188
189 # we operate only on our own specialized tls conf file.  hopefully no one has messed with it besides revamp.
190 # note the use of the character class :blank: below to match spaces or tabs.
191 search_replace "^[[:blank:]]*Header always set Strict-Transport-Security.*" "# not good for cakelampvm.com -- Header always set Strict-Transport-Security \"max-age=63072000; includeSubdomains;\"" /etc/apache2/conf-library/tls-enabling.conf
192 if [ $? -ne 0 ]; then
193   echo the apache tls-enabling.conf file seems to have already been patched to disable strict transport security. 
194 else
195   restart_apache
196   echo successfully patched the apache tls-enabling.conf file to disable strict transport security. 
197 fi
198
199 ##############
200
201 # fix up bind so that we think of any address with cakelampvm.com on the end
202 # as being on the vm.  this is already true for some specific sites, but we
203 # want the wildcard enabled to ease the use of DNS for windows folks.
204
205 sep
206
207 grep -q "\*[[:blank:]]*IN A[[:blank:]]*10.28.42.20" /etc/bind/cakelampvm.com.conf
208 if [ $? -eq 0 ]; then
209   # already present.
210   echo the bind settings for wildcard domains off of cakelampvm.com seems to already be present. 
211 else
212   echo "
213
214
215 ;;;;;;
216
217 ; our bind magic, a wildcard domain, for all other sites with cakelampvm.com
218 ; in the domain.  this forces any other sites besides the ones above to route
219 ; to the actual vm IP address, which currently is singular and very fixated.
220 *                               IN A            10.28.42.20
221                                 IN HINFO        "linux vm" "ubuntu"
222
223 ;;;;;;
224
225
226
227 " >> /etc/bind/cakelampvm.com.conf
228   restart_bind
229   echo "successfully added wildcard domains to the cakelampvm.com bind configuration."
230 fi
231
232 ##############
233
234 # fix samba configuration for (ass-headed) default of read-only in user homes.
235 # why cripple a necessary feature by default?
236
237 sep
238
239 pattern="[#;][[:blank:]]*read only = yes"
240 replacement="read only = no"
241
242 # we just always do the replacement now, after realizing the sentinel pattern
243 # was acutally already in the file...  too much subtlety can get one into trouble.
244 sed -i "0,/$pattern/{s/$pattern/$replacement/}" /etc/samba/smb.conf
245 test_or_die "patching samba configuration to enable write acccess on user home dirs"
246 # sweet, looks like that worked...
247 restart_samba
248 echo successfully patched the samba configuration to enable writes on user home directories. 
249
250 ##############
251
252 # add the latest version of the cakelampvm environment variables for apache.
253
254 sep
255
256 # drop existing file, if already configured.  ignore errors.
257 a2disconf env_vars_cakelampvm &>/dev/null
258
259 # plug in the new version, just stomping anything there.
260 # note: we only expect to have one version of the env_vars dir at a time in place in feisty...
261 \cp -f $FEISTY_MEOW_APEX/production/sites/cakelampvm.com/rolling/env_vars.*/env_vars_cakelampvm.conf /etc/apache2/conf-available
262 test_or_die "copying environment variables file into place"
263
264 # enable the new version of the config file.
265 a2enconf env_vars_cakelampvm
266 test_or_die "enabling the new cakelampvm environment config for apache"
267
268 echo Successfully configured the apache2 environment variables needed for cakelampvm.
269
270 ##############
271 ##############
272
273 # sequel--tell them they're great and show the hello again also.
274
275 sep
276
277 regenerate
278 test_or_die "regenerating feisty meow scripts"
279 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
280 test_or_die "fix after regenerate as sudo"
281 echo "
282
283
284 Thanks for revamping your cakelampvm.  :-)
285 "
286
287 ##############
288
289