slightly tastier
[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 echo "Regenerating feisty meow loading dock."
24
25 reconfigure_feisty_meow
26 test_or_die "feisty meow reconfiguration"
27 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
28 test_or_die "fix after reconfigured as sudo"
29
30 ##############
31
32 echo "Making some important permission changes..."
33
34 # fix up the main web storage.
35 chown -R www-data:www-data /var/www 
36 test_or_die "chown www-data"
37 group_perm /var/www 
38 test_or_die "group_perm www-data"
39
40 ##############
41
42 # set up access on some important folders for the developer user.
43 chown -R developer:developer /home/developer /home/developer/.[a-zA-Z0-9]*
44 test_or_die "chown developer home"
45 harsh_perm /home/developer/.ssh
46 test_or_die "harsh_perm setting on developer .ssh"
47 chown -R developer:developer /etc/apache2 /etc/bind 
48 test_or_die "chown apache2 and bind to developer"
49 group_perm /etc/apache2 /etc/bind 
50 test_or_die "group perms on apache2 and bind"
51
52 ##############
53
54 # fix perms for fred user.
55 chown -R fred:fred /home/fred /home/archives/stuffing /home/fred/.[a-zA-Z0-9]*
56 test_or_die "chown fred home"
57 group_perm $HOME/apps
58 test_or_die "group perms on fred's apps"
59 harsh_perm /home/fred/.ssh
60 test_or_die "harsh_perm setting on fred .ssh"
61 chown -R fred:fred /opt/feistymeow.org 
62 test_or_die "chown feisty meow to fred"
63 group_perm /opt/feistymeow.org 
64 test_or_die "group perms on feisty meow"
65 group_perm /home/fred/apps/mapsdemo
66 test_or_die "group perms on mapsdemo app"
67
68 echo "Done with important permission changes."
69
70 ##############
71 #
72 # some slightly tricky bits start here.  we want to massage the vm into the
73 # best possible shape without needing to re-release it.
74 #
75 ##############
76
77 echo "Updating developer welcome file."
78
79 # only update hello if they've still got the file there.  we don't want to
80 # keep forcing our hellos at people.
81 if [ -f "$HOME/hello.txt" ]; then
82   # copy the most recent hello file into place for the user.
83   \cp -f "$FEISTY_MEOW_APEX/production/sites/cakelampvm.com/hello.txt" "$HOME"
84   test_or_continue "copying hello file for user"
85 fi
86
87 ##############
88
89 # install a better editor app.
90
91 echo "The script is about to install the bluefish editor and some dependencies.
92 If the app is not already installed, then this process takes only about a
93 minute on a slower home DSL internet connection..."
94
95 apt-get install -y bluefish &> "/tmp/install_bluefish-$(logname).log"
96 test_or_continue "installing bluefish editor"
97
98 ##############
99
100 # deploy any site updates here to the VM's cakelampvm.com site.
101 #
102 # we want to upgrade the default apache site to the latest, since the new
103 # version mirrors the one on the internet (but with green checks instead
104 # of red X's) and since we also support https on the new default version.
105 # we can do this again later if needed, by upping the numbers on the apache
106 # site config files.  our original site was 000 and the new version is 001,
107 # which we've done as a prefix on the config for some reason.  makes the
108 # code below easy at least.
109 if [ -L /etc/apache2/sites-enabled/000-default.conf ]; then
110   # the old site is in place still, so let's update that.
111   echo "Updating default web sites to latest version."
112
113   a2enmod ssl
114   test_or_die "enabling SSL for secure websites"
115
116   restart_apache
117   test_or_die "getting SSL loaded in apache"
118
119   a2dissite 000-default
120   test_or_die "disabling old apache site"
121
122   rm -f /etc/apache2/sites-available/000-default.conf 
123   test_or_die "removing old apache site"
124
125   # copy in our new 000 version (which  
126   cp $FEISTY_MEOW_APEX/production/sites/cakelampvm.com/rolling/default_page.001/* \
127       /etc/apache2/sites-available
128   test_or_die "installing new apache default sites"
129
130   # there should only be ours at this version level and with that prefix.
131   a2ensite 001-*
132   test_or_die "enabling new apache default sites"
133
134   restart_apache
135 fi
136
137 ##############
138
139 # fix up the apache site so that HSTS is disabled.  otherwise we can't view
140 # the https site for cakelampvm.com once the domain name switch has occurred.
141
142 # we operate only on our own specialized tls conf file.  hopefully no one has messed with it besides revamp.
143 # note the use of the character class :blank: below to match spaces or tabs.
144 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
145 if [ $? -ne 0 ]; then
146   echo the apache tls-enabling.conf file seems to have already been patched to disable strict transport security.  good.
147 else
148   restart_apache
149   echo successfully patched the apache tls-enabling.conf file to disable strict transport security.  awesome.
150 fi
151
152 ##############
153
154 # fix up bind so that we think of any address with cakelampvm.com on the end
155 # as being on the vm.  this is already true for some specific sites, but we
156 # want the wildcard enabled to ease the use of DNS for windows folks.
157
158 grep -q "\*[[:blank:]]*IN A[[:blank:]]*10.28.42.20" /etc/bind/cakelampvm.com.conf
159 if [ $? -eq 0 ]; then
160   # already present.
161   echo the bind settings for wildcard domains off of cakelampvm.com seems to already be present.  good deal.
162 else
163   echo "
164 ; our bind magic, a wildcard domain, for all other sites with cakelampvm.com
165 ; in the domain.  this forces any other sites besides the ones above to route
166 ; to the actual vm IP address, which currently is singular and very fixated.
167 *                               IN A            10.28.42.20
168                                 IN HINFO        "linux vm" "ubuntu"
169 " >> /etc/bind/cakelampvm.com.conf
170   restart_bind
171   echo "successfully added wildcard domains to the cakelampvm.com bind configuration, so we're still on track for greatness."
172 fi
173
174 ##############
175
176 # fix samba configuration for (ass-headed) default of read-only in user homes.
177 # why add a necessary feature if you're just going to cripple it by default?
178
179 search_replace a b
180 /etc/samba/smb.conf 
181 if [ $? -ne 0 ]; then
182   echo "the samba configuration has already been fixed for user homes, so that's fine."
183 else
184   restart_samba
185   echo successfully patched the samba configuration to enable writes on user home directories.  super cool.
186 fi
187
188 ##############
189 ##############
190
191 # sequel--tell them they're great and show the hello again also.
192
193 echo "
194
195
196 "
197 regenerate
198 test_or_die "regenerating feisty meow scripts"
199 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
200 test_or_die "fix after regenerate as sudo"
201 echo "
202
203
204 Thanks for revamping your cakelampvm.  :-)
205 "
206
207 ##############
208
209