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