1 | #!/usr/bin/env bash |
2 |
|
3 | SCRIPTPATH=$(dirname $(realpath -s $0)) |
4 |
|
5 | usage() { |
6 | echo "usage: sudo ./copynginx [prod | test]" |
7 | exit 1 |
8 | } |
9 | if [ "$EUID" -ne 0 ]; then |
10 | echo "error: must run as root" |
11 | usage |
12 | fi |
13 | if [ $# -eq 0 ]; then |
14 | usage |
15 | fi |
16 | if [ "$1" != "prod" ] && [ "$1" != "test" ]; then |
17 | usage |
18 | fi |
19 |
|
20 | if [ ! -f $SCRIPTPATH/nginx/nginx.conf ]; then |
21 | echo "error: $SCRIPTPATH/nginx/nginx.conf is nonexistent" |
22 | exit 1 |
23 | fi |
24 | echo -e "copying nginx.conf" |
25 | cp -v $SCRIPTPATH/nginx/nginx.conf /etc/nginx/nginx.conf |
26 |
|
27 | if [ -d /etc/nginx/joshstock.in/ ]; then |
28 | echo -e "clearing /etc/nginx/joshstock.in/" |
29 | rm -rv /etc/nginx/joshstock.in/* |
30 | else |
31 | echo -e "create new /etc/nginx/joshstock.in/" |
32 | mkdir -pv /etc/nginx/joshstock.in/ |
33 | fi |
34 |
|
35 | if [ ! -d $SCRIPTPATH/nginx/$1 ]; then |
36 | echo -e "error: $SCRIPTPATH/nginx/$1 is nonexistent" |
37 | exit 1 |
38 | fi |
39 | echo -e "copying $1 configuration" |
40 | cp -rv $SCRIPTPATH/nginx/$1/* /etc/nginx/joshstock.in/ |
41 |
|
42 | echo -e "attempting to reload nginx" |
43 | service nginx reload |
44 |
|
45 | echo -e "done" |
46 |
|