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