From: Jeremy Tan Date: Thu, 3 Oct 2013 03:34:55 +0000 (+0800) Subject: Make install script for server configs X-Git-Url: https://git.ucc.asn.au/?p=matches%2FMCTX3420.git;a=commitdiff_plain;h=2ca86f48743a695437aebd7ebe1304118e5bc4bf Make install script for server configs --- diff --git a/server-configs/gen_ssl_cert.sh b/server-configs/gen_ssl_cert.sh index 1342562..51abb2d 100644 --- a/server-configs/gen_ssl_cert.sh +++ b/server-configs/gen_ssl_cert.sh @@ -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 index 0000000..d904801 --- /dev/null +++ b/server-configs/install.sh @@ -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 + + diff --git a/server/run.sh b/server/run.sh index c2bd504..d4e6510 100755 --- a/server/run.sh +++ b/server/run.sh @@ -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