Make install script for server configs
authorJeremy Tan <[email protected]>
Thu, 3 Oct 2013 03:34:55 +0000 (11:34 +0800)
committerJeremy Tan <[email protected]>
Thu, 3 Oct 2013 03:34:55 +0000 (11:34 +0800)
server-configs/gen_ssl_cert.sh
server-configs/install.sh [new file with mode: 0644]
server/run.sh

index 1342562..51abb2d 100644 (file)
@@ -12,20 +12,25 @@ if [ "$(whoami)" != "root" ]; then
         exit 1
 fi
 
-echo 'Making the conf dir /usr/share/nginx/conf...'
-mkdir -p /usr/share/nginx/conf
+# Check for nginx dir
+nginx=/usr/share/nginx
+if [ ! -d "$nginx" ]; then
+       (echo "nginx folder not found at $nginx.") 1>&2
+       exit 1
+fi;
+
+echo 'Making the conf dir $nginx/conf...'
+mkdir -p $nginx/conf
 
 echo Generating the server private key...
-openssl genrsa -out /usr/share/nginx/conf/server.key 2048
+openssl genrsa -out $nginx/conf/server.key 2048
 
 echo Generating the CSR...
-openssl req -new -key /usr/share/nginx/conf/server.key \
--out /usr/share/nginx/conf/server.csr \
+openssl req -new -key $nginx/conf/server.key -out $nginx/conf/server.csr \
  -subj "/C=AU/ST=WA/L=Perth/O=UWA/OU=Mechatronics/CN=$1"
 
 echo Signing the certificate...
-openssl x509 -req -days 3650 -in /usr/share/nginx/conf/server.csr \
--signkey /usr/share/nginx/conf/server.key \
--out /usr/share/nginx/conf/server.crt
+openssl x509 -req -days 3650 -in $nginx/conf/server.csr \
+ -signkey $nginx/conf/server.key -out $nginx/conf/server.crt
 
 
diff --git a/server-configs/install.sh b/server-configs/install.sh
new file mode 100644 (file)
index 0000000..d904801
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Check running as root
+if [ "$(whoami)" != "root" ]; then
+        (echo "Run $0 as root.") 1>&2
+        exit 1
+fi
+
+nconf=/usr/share/nginx/conf
+# Generate the ssl cert, if necessary
+if [ ! -d "$nconf" ]; then
+       echo "ssl cert not found at $nconf, generating..."
+       ./gen_ssl_cert.sh $1
+       if [[ $? != 0 ]] ; then
+               (echo "gen_ssl_cert failed, exiting.") 1>&2
+               exit 1
+       fi;
+fi
+
+nginx=/etc/nginx
+# Check for nginx
+if [ ! -d "$nginx" ]; then
+       (echo "Install nginx.") 1>&2
+       exit 1
+fi
+
+# Copy nginx configs
+echo
+echo "Copying nginx configs..."
+cp -v nginx/fastcgi_params ./nginx/mime.types $nginx/
+rm -fv $nginx/sites-enabled/*
+cp -v nginx/sites-enabled/mctxconfig $nginx/sites-enabled
+
+echo
+echo "Restarting nginx..."
+/etc/init.d/nginx restart
+
+echo
+echo "Note: Check the document root for the nginx config is set correctly."
+
+# Copy syslog configs
+rsyslog=/etc/rsyslog.d
+lrotate=/etc/logrotate.d
+if [ -d "$rsyslog" ]; then
+       echo
+       echo "Copying rsyslog configs..."
+       cp -v rsyslog.d/30-mctxserv.conf $rsyslog/
+
+       echo
+       echo "Restarting rsyslog..."
+       /etc/init.d/rsyslog restart
+else
+       echo
+       (echo "Could not find rsyslog at $rsyslog. Skipping.") 1>&2
+fi
+
+if [ -d "$lrotate" ]; then
+       echo
+       echo "Copying logrotate configs..."
+       cp -v logrotate.d/mctxserv.conf $lrotate/
+else
+       echo
+       (echo "Could not find logrotate at $lrotate. Skipping.") 1>&2
+fi
+
+
index c2bd504..d4e6510 100755 (executable)
@@ -1,15 +1,18 @@
 #!/bin/bash
-# Use this to quickly test run the server in valgrind
-#spawn-fcgi -p9005 -n ./valgrind.sh
-# Use this to run the server normally
-#./stream &
+
+# Check existence of program
+if [ ! -e "server" ]; then
+        (echo "Rebuild server.") 1>&2;
+        exit 1
+fi
+
 
 if [[ "$(uname -m)" != *arm*  ]]; then
         echo Not running on the BBB
         # Use this to quickly test run the server in valgrind
         spawn-fcgi -p9005 -n ./valgrind.sh
         # Use this to run the server normally
-        #./stream &
+        #spawn-fcgi -p9005 -n ./server
         exit 0
 fi
 
@@ -19,12 +22,6 @@ if [ "$(whoami)" != "root" ]; then
         exit 1
 fi
 
-# Check existence of program
-if [ ! -e "server" ]; then
-        (echo "Rebuild server.") 1>&2;
-        exit 1
-fi
-
 # Rotate the logs
 echo Rotating the system logs
 logrotate -f /etc/logrotate.d/mctxserv.conf

UCC git Repository :: git.ucc.asn.au