making sure latest scripts are active
[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
28 ##############
29
30 echo "Making some important permission changes..."
31
32 # fix up the main web storage.
33 chown -R www-data:www-data /var/www 
34 test_or_die "chown www-data"
35 group_perm /var/www 
36 test_or_die "group_perm www-data"
37
38 ##############
39
40 # set up access on some important folders for the developer user.
41 chown -R developer:developer /home/developer
42 test_or_die "chown developer home"
43 harsh_perm /home/developer/.ssh
44 test_or_die "harsh_perm setting on developer .ssh"
45 chown -R developer:developer /etc/apache2 /etc/bind 
46 test_or_die "chown apache2 and bind to developer"
47 group_perm /etc/apache2 /etc/bind 
48 test_or_die "group perms on apache2 and bind"
49
50 ##############
51
52 # fix perms for fred user.
53 chown -R fred:fred /home/fred /home/archives/stuffing 
54 test_or_die "chown fred home"
55 harsh_perm /home/fred/.ssh
56 test_or_die "harsh_perm setting on fred .ssh"
57 chown -R fred:fred /opt/feistymeow.org 
58 test_or_die "chown feisty meow to fred"
59 group_perm /opt/feistymeow.org 
60 test_or_die "group perms on feisty meow"
61
62 echo "Done with important permission changes."
63
64 ##############
65 #
66 # some slightly tricky bits start here.  we want to massage the vm into the
67 # best possible shape without needing to re-release it.
68 #
69 ##############
70
71 echo "Updating developer welcome file."
72
73 # only update hello if they've still got the file there.  we don't want to
74 # keep forcing our hellos at people.
75 if [ -f "$HOME/hello.txt" ]; then
76   # copy the most recent hello file into place for the user.
77   \cp -f "$FEISTY_MEOW_APEX/production/sites/cakelampvm.com/hello.txt" "$HOME"
78   test_or_continue "copying hello file for user"
79 fi
80
81 ##############
82
83 # install a better editor app.
84
85 echo " The script is about to install the bluefish editor and some dependencies.
86 If the app is not already installed, then this process takes only about a
87 minute on a slower home DSL internet connection..."
88
89 apt-get install -y bluefish &> "/tmp/install_bluefish-$(logname).log"
90 test_or_continue "installing bluefish editor"
91
92 ##############
93
94 # deploy any site updates here to the VM's cakelampvm.com site.
95 #
96 # we want to upgrade the default apache site to the latest, since the new
97 # version mirrors the one on the internet (but with green checks instead
98 # of red X's) and since we also support https on the new default version.
99 # we can do this again later if needed, by upping the numbers on the apache
100 # site config files.  our original site was 000 and the new version is 001,
101 # which we've done as a prefix on the config for some reason.  makes the
102 # code below easy at least.
103 if [ -L /etc/apache2/sites-enabled/000-default.conf ]; then
104   # the old site is in place still, so let's update that.
105   echo "Updating default web sites to latest version."
106
107   a2enmod ssl
108   test_or_die "enabling SSL for secure websites"
109
110   a2dissite 000-default
111   test_or_die "disabling old apache site"
112
113   rm -f /etc/apache2/sites-available/000-default.conf 
114   test_or_die "removing old apache site"
115
116   # copy in our new 000 version (which  
117   cp $FEISTY_MEOW_APEX/production/sites/cakelampvm.com/rolling/default_page.001/* \
118       /etc/apache2/sites-available
119   test_or_die "installing new apache default sites"
120
121   # there should only be ours at this version level and with that prefix.
122   a2ensite 001-*
123   test_or_die "enabling new apache default sites"
124
125   restart_apache
126 fi
127
128 ##############
129
130 # clean out some old files that were not checked in in mapsdemo.
131 echo Doing some git repository maintenance in fred account.
132 #
133 # change over to fred folder
134 pushd /home/fred
135 test_or_die "changing dir to fred's home; what have you done with fred?"
136
137 pushd apps/mapsdemo/public
138 test_or_die "changing dir to mapsdemo app"
139
140 # gets rid of the old version of configs.
141 git stash 
142 if [ $? -eq 0 ]; then
143   # we actually stashed something, so deal with that.
144   git stash drop 
145   test_or_die "dropping mapsdemo stash"
146 fi
147
148 popd
149
150 rpuffer apps
151 test_or_die "puffing out apps directory"
152
153 popd
154 #...coolness
155
156 ##############
157
158 # sequel--tell them they're great and show the hello again also.
159
160 regenerate
161
162 echo "
163
164
165 Thanks for revamping your cakelampvm.  :-)
166 "
167
168 ##############
169
170