forked from swcombine/dev-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswc_setup.sh
More file actions
197 lines (175 loc) · 6.41 KB
/
swc_setup.sh
File metadata and controls
197 lines (175 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# SWC Dev VM Initial Configuration Script
# Installs necessary software and configures the VM to run a local instance of SWC
# Note: you will need the following:
# staging_prod.sql
# in order to complete this installation. It is not available in the repository currently
REAL_USER=$USER
BLUE="\e[34m"
RED="\e[31m"
GREEN="\e[32m"
NONE="\e[0m"
function do_install {
echo -n -e "Installing ${BLUE}$2${NONE}..."
sudo apt-get -y install $1 >/dev/null
if [ $? -ne 0 ]; then
echo -e "${RED}Failed!${NONE}";
exit 1;
else
echo -e "${GREEN}Successful.${NONE}";
fi
}
echo -e "Welcome to the ${BLUE}SWCombine VM Server${NONE} setup script";
if [ ! -e "staging_prod.sql" ]; then
echo -e "You are ${RED}missing${NONE} the required installation files. Please check that:";
echo -e "\tstaging_prod.sql";
echo -e "exist within the current directory and are readable";
exit 1;
fi
# First, install mysql, if need be
dpkg-query -W --showformat='${Status}' mysql-server | grep "ok installed" >/dev/null
if [ $? -ne 0 ]; then
echo -e "Please enter your ${BLUE}MySQL${NONE} root password (do not leave it blank):";
read -s MYSQL_PW;
echo "mysql-server-5.5 mysql-server/root_password password $MYSQL_PW" | sudo debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password $MYSQL_PW" | sudo debconf-set-selections
do_install "mysql-client mysql-server" "MySQL"
echo -e "[client]\nuser=root\npassword=$MYSQL_PW\n" > ~/.my.cnf
else
MYSQL_PW=`cat ~/.my.cnf | sed -n -e "s/password=\(.*\)/\1/p"`
echo -e "${BLUE}MySQL${NONE} already installed, skipping..."
fi
# Then install php5 and the mysql driver
do_install "php5 php5-mysql" "PHP 5"
# Make sure git is installed/updated
do_install "git" "git"
# Configure the SWC repository at /swcombine
while true; do
echo -e "Would you like to ${BLUE}download${NONE} the git repository or ${BLUE}use an existing${NONE} local copy?\n\t[1] Download\n\t[2] Use existing."
read dlgit
case $dlgit in
1 )
echo -e "Downloading git repository to ${BLUE}/swcombine${NONE}. When prompted, enter your git credentials (this will happen twice)";
sudo mkdir /swcombine;
sudo chown $REAL_USER /swcombine;
git clone http://svn.swcombine.com/git/swcombine.git /swcombine;
pushd /swcombine
git config credential.helper store
echo -e "Enter your developer username";
read gitname
git config user.name $gitname
git config user.email ${gitname}@swcombine.com
git fetch origin
popd
break;;
2 )
echo -n -e "Enter the location of the existing git repository checkout [${BLUE}/mnt/swcombine${NONE}]: "
read gitpath
if [ -d "$gitpath" ]; then
if [ "$gitpath" = "/swcombine" ]; then
echo -e "SWC already mounted correctly at ${BLUE}/swcombine${NONE}, skipping...";
else
echo -e "Creating symlink from ${BLUE}/swcombine${NONE} to ${BLUE}$gitpath${NONE}.";
ln -s /swcombine $gitpath;
fi;
else
echo -e "Supplied path ${BLUE}$gitpath${NONE} ${RED}does not exist${NONE}. Please check it and try again.";
exit 1;
fi;
break;;
* ) echo -e "${RED}Invalid selection${NONE}"
;;
esac
done
# Configure hooks repository in ~/hooks
pushd ~
git clone http://svn.swcombine.com/git/hooks.git
popd
# Configure apache to point to /swcombine and process php
echo -e "Configuring ${BLUE}Apache and PHP${NONE}"
if [ -e "/etc/apache2/sites-enabled/apache2-swc.conf" ]; then
echo -e "Configuration ${GREEN}detected${NONE}, skipping.";
else
sudo cp /swcombine/libs/apache2-swc.conf /etc/apache2/sites-enabled
sudo rm /etc/apache2/sites-enabled/000-default
sudo chmod 0777 /etc/php5/apache2/php.ini
echo "include_path = \".:/swcombine/libs\"" >> /etc/php5/apache2/php.ini
sudo service apache2 restart
echo -e "${GREEN}Successfully${NONE} configured apache and php";
fi
# Perform initial mysql configuration
CREATE_DB=0
while true; do
echo -e "Would you like to import the MySQL database, overwriting your current one (y/n)?"
echo -e "${BLUE}Note:${NONE} This step is required to set up path.php correctly the first time."
read importmysql
case $importmysql in
[yY] )
# Do actual DB import, makes use of ~/.my.cnf for auto-authentication
echo -e "Importing ${BLUE}MySQL${NONE} database.";
mysql < staging_prod.sql;
echo -e "\nImport ${GREEN}complete${NONE}.";
CREATE_DB=1
# Now, copy over path.php and fill in the actual mysql password chosen
pushd /swcombine/libs
cat path.template.php | sed -e "s/db\.pass', 'swc'/db.pass', '$MYSQL_PW'/" > path.php
popd
break;;
[nN] )
echo -e "${BLUE}Skipping${NONE} MySQL import.";
break;;
* )
echo -e "${RED}Invalid${NONE} selection."
;;
esac
done
cat ~/.my.cnf | sed -n -e "/database/p" | grep "database" > /dev/null
if [ $? -ne 0 && $CREATE_DB -ne 0 ]; then
echo -e "database=staging_prod\n" >> ~/.my.cnf
fi
# Install Nodejs for build environment
do_install "curl" "cURL"
curl -sL https://deb.nodesource.com/setup | sudo bash -
do_install "nodejs" "Node.js"
sudo npm install -g less
sudo npm install -g less-plugin-clean-css
# Configure build script stuff
pushd /swcombine/build
cp path.sh.template path.sh
if [ -z $SWC_ROOT ]; then
echo "export SWC_ROOT=/swcombine" >> ~/.bashrc
echo "export PATH=\"\$PATH:~/hooks/cmds" >> ~/.bashrc
fi
popd
# Configure cron jobs
echo -e "Configuring ${BLUE}cron jobs${NONE}"
sudo crontab -u root -l 2>/dev/null | grep "swcombine" > /dev/null
if [ $? -ne 0 ]; then
sudo crontab -u root -l | cat - /swcombine/libs/cron-swc.src | sudo crontab -u root -
echo -e "${GREEN}Added${NONE} SWC jobs to crontab"
else
echo -e "Cron jobs ${GREEN}already configured${NONE}."
fi
if [ ! -d /swcombine/logs ]; then
sudo mkdir /swcombine/logs
chmod 0777 /swcombine/logs
fi
# Install PHPUnit for running unit tests
echo -e "Configuring ${BLUE}PHPUnit${NONE}"
if [ -e "/usr/local/bin/phpunit" ]; then
echo -e "PHPUnit ${GREEN}already installed${NONE}, skipping.";
else
wget https://phar.phpunit.de/phpunit.phar;
chmod +x phpunit.phar;
sudo mv phpunit.phar /usr/local/bin/phpunit
echo -e "PHPUnit ${GREEN}installed${NONE} to ${BLUE}/usr/local/bin/phpunit${NONE}"
fi
# Configure some stuff in /tmp that we expect to exist, apparently
mkdir /tmp/feeds
touch /tmp/feeds/gns_flashnews.xml
sudo chown -R www-data:www-data /tmp/feeds
sudo chmod 0777 -R /tmp/feeds
# Run build once to ensure that the site will look decent when it is loaded
echo -e "Running ${BLUE}git swc build${NONE} to create initial stylesheets"
git swc build
echo -e "${BLUE}SWC VM server${NONE} setup ${GREEN}complete${NONE}."