-
Notifications
You must be signed in to change notification settings - Fork 24
/
install.bash
executable file
·128 lines (113 loc) · 3.35 KB
/
install.bash
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
#!/bin/bash
# RMS Setup Script
#
# Author: Russell Toris - [email protected]
DB="rms"
USER="rms"
echo " ____ __ __ ____ "
echo "| _ \| \/ / ___| "
echo "| |_) | |\/| \___ \ "
echo "| _ <| | | |___) |"
echo "|_| \_\_| |_|____/ "
echo
echo
echo "Robot Management System Setup"
echo "Author: Russell Toris - [email protected]"
echo
# check the directory we are working in
DIR=`pwd`
if [[ $DIR != *install ]]
then
echo "ERROR: Please run this script in the 'install' directory."
exit;
fi
echo
echo "WARNING: This is an automated setup script."
echo "It will create a fresh install of the RMS."
echo "Any older versions of RMS will be deleted."
echo
# confirmation prompt
while true; do
read -p "Continue with installation? [Y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer with 'y' or 'n'";;
esac
done
## Update and install the LAMP server
echo
echo "Setting up LAMP and PEAR..."
echo -e "\tupdating sources..."
sudo apt-get update >> /dev/null
echo -e "\tinstalling LAMP..."
sudo apt-get install lamp-server^ php-pear php5-mcrypt -yy
echo -e "\tenabling Apache mod-rewrite..."
sudo a2enmod rewrite >> /dev/null
echo -e "\tenabling PHP mcrypt..."
sudo php5enmod mcrypt >> /dev/null 2>&1
sudo service apache2 restart > /dev/null 2>&1
## Setup CakePHP
echo
echo "Setting up CakePHP..."
echo -e "\tadding CakePHP channel to PEAR..."
sudo pear channel-discover pear.cakephp.org >> /dev/null
echo -e "\tinstalling CakePHP via PEAR..."
sudo pear install -Z cakephp/CakePHP-2.5.8
## Install the app
echo
echo "Linking RMS to Apache..."
echo -e "\tinstalling site configuration..."
sudo cp rms.conf /etc/apache2/sites-available/
echo -e "\tdisabling default Apache site(s)..."
sudo a2dissite 000-default.conf 000-default rms.conf > /dev/null 2>&1
echo -e "\tlinking RMS folder to Apache..."
sudo rm -f /var/www/rms
sudo ln -s $DIR/../app/ /var/www/rms
echo -e "\trestarting Apache..."
sudo a2ensite rms.conf > /dev/null
sudo /etc/init.d/apache2 restart > /dev/null 2>&1
## Create a tmp folder
echo
echo "Setting up site tmp folder..."
sudo rm -rf ../app/tmp
mkdir ../app/tmp
sudo chown -R www-data ../app/tmp
## Setup the SQL server
echo
echo "Setting MySQL server (use SQL root password)..."
echo -e "\tgenerating random password..."
PASS=`date +%s | sha256sum | base64 | head -c 16 ;`
echo -e "\tcreating RMS database and local MySQL user..."
mysql -u root -v -e "DROP DATABASE IF EXISTS $DB; \
GRANT USAGE ON *.* TO '$USER'@'localhost'; \
DROP USER '$USER'@'localhost'; \
CREATE DATABASE IF NOT EXISTS $DB; \
GRANT ALL PRIVILEGES ON $DB.* TO '$USER'@'localhost' IDENTIFIED BY '$PASS';\G " -p >> /dev/null
echo -e "\tinstalling the RMS database..."
mysql -D $DB -u $USER -p$PASS < rms.sql
## Setup the CakePHP configuration
echo
echo "Setting CakePHP configuration file(s)..."
CONFIG="<?php\n
// auto generated by RMS setup\n
class DATABASE_CONFIG {\n\n
\tpublic \$default = array(\n
\t\t'datasource' => 'Database/Mysql',\n
\t\t'persistent' => false,\n
\t\t'host' => 'localhost',\n
\t\t'login' => '$USER',\n
\t\t'password' => '$PASS',\n
\t\t'database' => '$DB',\n
\t\t'encoding' => 'utf8'\n
\t);\n
}"
rm -f ../app/Config/database.php
echo -e $CONFIG | sed "s/^[ ]*//" >> ../app/Config/database.php
## Install the cron job
echo
echo "Installing cron job(s)..."
echo "0,30 * * * * cd /var/www/rms && Console/cake reminder" | sudo crontab -u www-data -
echo
echo "Setup complete!"
echo