tore out guts that came from v002
[feisty_meow.git] / scripts / site_avenger / revamp_cakelampvm_v003.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 if [[ ! $(hostname) == *cakelampvm* ]]; then
13   echo "This script is only designed to be run on the cakelampvm host."
14   exit 1
15 fi
16
17 ##############
18
19 export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
20 export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
21
22 export NO_HELLO=right
23 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
24 # load dependencies for our script.
25 source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh"
26 source "$FEISTY_MEOW_SCRIPTS/security/password_functions.sh"
27
28 ##############
29
30 # it's a requirement to have sql root password, since we may need some sql db configuration.
31 load_password /etc/mysql/secret_password mysql_passwd
32 if [ -z "$mysql_passwd" ]; then
33   read_password "Please enter the MySQL root account password:" mysql_passwd
34 fi
35 if [ -z "$mysql_passwd" ]; then
36   echo "This script must have the sql root password to proceed."
37   exit 1
38 else
39   store_password /etc/mysql/secret_password "$mysql_passwd"
40 fi
41
42 ##############
43
44 sep
45
46 echo "Regenerating feisty meow loading dock."
47
48 regenerate
49 test_or_die "regenerating feisty meow configuration"
50 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
51 test_or_die "fix after reconfigured as sudo"
52
53 ##############
54
55 # set up some crucial users in the mysql db that we seem to have missed previously.
56
57 sep
58
59 echo "Adding users to the mysql database."
60
61 #hmmm: good application for hiding output unless error here.
62 mysql -u root -p"$mysql_passwd" &>/dev/null <<EOF
63   create user if not exists 'root'@'%' IDENTIFIED BY '$mysql_passwd';
64   grant all privileges on *.* TO 'root'@'%' with grant option;
65
66   create user if not exists 'wampcake'@'%' IDENTIFIED BY 'bakecamp';
67   grant all privileges on *.* TO 'wampcake'@'%' with grant option;
68
69   create user if not exists 'lampcake'@'%' IDENTIFIED BY 'bakecamp';
70   grant all privileges on *.* TO 'lampcake'@'%' with grant option;
71 EOF
72 test_or_die "configuring root, wampcake and lampcake users on mysql"
73
74 ##############
75
76 sep
77
78 echo "Making some important permission changes..."
79
80 ##############
81
82 # fix up the main web storage.
83 chown -R www-data:www-data /var/www 
84 test_or_die "chown www-data"
85 group_perm /var/www 
86 test_or_die "group_perm www-data"
87
88 ##############
89
90 # set up access on some important folders for the developer user.
91
92 # set the developer user as uber owner of many things with redeveloper alias.
93 # (must have run feisty meow "recustomize" command at some point to enable.)
94 redeveloper
95 test_or_die "running redeveloper to fix ownership"
96
97 ##############
98
99 # give the developer control over the apache and bind config files, as well
100 # as giving the user ownership of the local feisty meow repository.
101 chown -R developer:developer /etc/apache2 /etc/bind 
102 test_or_die "chown apache2 and bind to developer"
103 group_perm /etc/apache2 /etc/bind 
104 test_or_die "group perms on apache2 and bind"
105 chown -R developer:developer /opt/feistymeow.org 
106 test_or_die "chown feisty meow to developer"
107 group_perm /opt/feistymeow.org 
108 test_or_die "group perms on feisty meow"
109
110 ##############
111
112 echo "...done with permission changes."
113
114 ##############
115 #
116 # some slightly tricky bits start here.  we want to massage the vm into the
117 # best possible shape without needing to re-release it.
118 #
119 ##############
120 ##############
121
122 #thing 1
123
124 ##############
125
126 #thing 2
127
128 ##############
129 ##############
130
131 # sequel--tell them they're great and show the hello again also.
132
133 sep
134
135 regenerate
136 test_or_die "regenerating feisty meow scripts"
137 chown -R "$(logname)":"$(logname)" /home/$(logname)/.[a-zA-Z0-9]*
138 test_or_die "fix after regenerate as sudo"
139 echo "
140
141
142 Thanks for revamping your cakelampvm.  :-)
143
144 You may want to update your current shell's feisty meow environment by typing:
145   regenerate
146 "
147
148 ##############
149
150