adding bits to setupserver.sh script
[ga4php.git] / contrib / setupserver.sh
1 #!/bin/bash
2
3 ####################
4 # The purpose of this script is to setup a built ubuntu 10.04
5 # server as an auth server with next-to zero input from the user.
6 # This script will automagically download components
7 # from the ga4php site and install them locally on the machine
8 # it will also install all packages required for the system to work
9
10 print_usage() {
11         echo "Usage: $0 dedicated|shared"
12         echo "Dedicated means the website will be hosted as /"
13         echo "Shared means the website will be hosted as /ga"
14 }
15
16 if [ "x$1" = "x" ]
17 then
18         print_usage
19         exit 0
20 fi
21
22 if [ "$USER" != "root" ]
23 then
24         echo "This script must be run as root in order to function"
25         exit 0
26 fi
27
28 case "$1" in
29         "dedicated")
30                 echo "Installing as dedicated"
31         ;;
32         "shared")
33                 echo "Installing as shared"
34         ;;
35         *)
36         print_usage
37         exit 0
38 esac
39
40 # ok, we're ready to function, tell the user some stuff
41 echo "This script will now install packages required for the server to work"
42 echo "as well as install the auth server and start scripts into /opt/gaas and"
43 echo "/etc/init.d/. I will try to do this as quitely as possible"
44
45 read -p "are you sure [y/N]? " surity
46
47 if [ "x$surity" != "xy" ]
48 then
49         echo "Bailing, must hit y if you are sure"
50         exit 0
51 fi
52
53 # first install apt packages for apache and php
54 echo "Beginning install of apt-get packages"
55 apt-get install -y apache2 libapache2-mod-php5 php-soap php5-ldap php5-cli php5-adodb subversion qrencode > /dev/null 2>&1
56
57 if [ "$?" != "0" ]
58 then
59         echo "There was a problem during install of apt-get packages"
60         exit 1
61 fi
62
63 echo "Apt-get packages installed, getting auth server code"
64
65 # get the auth server code from svn
66 MYTMPDIR="/tmp/ga$RANDOM"
67 mkdir -p $MYTMPDIR
68 cd $MYTMPDIR
69 svn checkout http://ga4php.googlecode.com/svn/trunk/ ga4php > /dev/null 2>&1
70 if [ "$?" != "0" ]
71 then
72         echo "There was a problem downloading the authserver source code.. bailing"
73         exit 2
74 fi
75
76 echo "Code downloaded, beginning installation into /opt/gaas"
77
78 mkdir /opt/gaas
79 cp -r * /opt/gaas
80
81 echo "Createing service user"
82 useradd -d /opt/gaas -r gaas -m
83
84 chown -R gaas:gaas /opt/gaas
85 echo "Tightening up permissions"
86 chmod 700 /opt/gaas/authserver/authd
87 chmod 770 /opt/gaas/authserver/
88
89 echo "Users who wish to use the gaas system must now be added to the gaas group"