unified logname uses into fm_username
[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 recustomize
49 exit_on_error "regenerating feisty meow configuration"
50 chown -R "$(fm_username)":"$(fm_username)" /home/$(fm_username)/.[a-zA-Z0-9]*
51 exit_on_error "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 # note regarding v003 of the revamp script: i am leaving the mysql code
62 # alone for the moment; it's a good example of using our password, gathered
63 # above.  (a better example wouldn't pass the password on the command line
64 # but involving an "expect" script is out of scope currently.)  --fred
65
66 #hmmm: good example here for why we need the code that "hides output unless error".
67 mysql -u root -p"$mysql_passwd" &>/dev/null <<EOF
68   create user if not exists 'root'@'%' IDENTIFIED BY '$mysql_passwd';
69   grant all privileges on *.* TO 'root'@'%' with grant option;
70
71   create user if not exists 'wampcake'@'%' IDENTIFIED BY 'bakecamp';
72   grant all privileges on *.* TO 'wampcake'@'%' with grant option;
73
74   create user if not exists 'lampcake'@'%' IDENTIFIED BY 'bakecamp';
75   grant all privileges on *.* TO 'lampcake'@'%' with grant option;
76 EOF
77 exit_on_error "configuring root, wampcake and lampcake users on mysql"
78
79 ##############
80
81 sep
82
83 echo "Making some important permission changes..."
84
85 ##############
86
87 # fix up the main web storage.
88 chown -R www-data:www-data /var/www 
89 exit_on_error "chown www-data"
90 group_perm /var/www 
91 exit_on_error "group_perm www-data"
92
93 ##############
94
95 # set up access on some important folders for the developer user.
96
97 # set the developer user as uber owner of many things with redeveloper alias.
98 # (must have run feisty meow "recustomize" command at some point to enable.)
99 redeveloper
100 exit_on_error "running redeveloper to fix ownership"
101
102 ##############
103
104 # give the developer control over the apache and bind config files, as well
105 # as giving the user ownership of the local feisty meow repository.
106 chown -R developer:developer /etc/apache2 /etc/bind 
107 exit_on_error "chown apache2 and bind to developer"
108 group_perm /etc/apache2 /etc/bind 
109 exit_on_error "group perms on apache2 and bind"
110 chown -R developer:developer /opt/feistymeow.org 
111 exit_on_error "chown feisty meow to developer"
112 group_perm /opt/feistymeow.org 
113 exit_on_error "group perms on feisty meow"
114
115 ##############
116
117 echo "...done with permission changes."
118
119 ##############
120 #
121 # some slightly tricky bits start here.  we want to massage the vm into the
122 # best possible shape without needing to re-release it.
123 #
124 ##############
125 ##############
126
127 #thing 1
128
129 ##############
130
131 #thing 2
132
133 ##############
134 ##############
135
136 # sequel--tell them they're great and show the hello again also.
137
138 sep
139
140 recustomize
141 exit_on_error "recustomize-ing feisty meow scripts"
142 chown -R "$(fm_username)":"$(fm_username)" /home/$(fm_username)/.[a-zA-Z0-9]*
143 exit_on_error "fix after recustomize as sudo"
144 echo "
145
146
147 Thanks for revamping your cakelampvm.  :-)
148
149 You may want to update your current shell's feisty meow environment by typing:
150   recustomize
151 "
152
153 ##############
154
155