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.conf ]; then |
21 | echo "error: $SCRIPTPATH/nginx.conf is nonexistent" |
22 | exit 1 |
23 | fi |
24 | echo -e "copying nginx.conf" |
25 | cp -v $SCRIPTPATH/nginx.conf /etc/nginx/nginx.conf |
26 |
|
27 | if [ -d /etc/nginx/conf.d/ ]; then |
28 | echo -e "clearing /etc/nginx/conf.d/" |
29 | rm -rv /etc/nginx/conf.d |
30 | fi |
31 |
|
32 | if [ -d /etc/nginx/sites-enabled/ ]; then |
33 | echo -e "clearing /etc/nginx/sites-enabled/" |
34 | rm -rv /etc/nginx/sites-enabled |
35 | fi |
36 |
|
37 | if [ -d /etc/nginx/env/ ]; then |
38 | echo -e "clearing /etc/nginx/env/" |
39 | rm -rv /etc/nginx/env |
40 | fi |
41 |
|
42 | if [ ! -d $SCRIPTPATH/$1 ]; then |
43 | echo -e "error: $SCRIPTPATH/$1 is nonexistent" |
44 | exit 1 |
45 | fi |
46 | echo -e "copying $1 configuration" |
47 | cp -rv $SCRIPTPATH/$1/* /etc/nginx |
48 |
|
49 | echo -e "attempting to reload nginx" |
50 | service nginx reload |
51 |
|
52 | echo -e "done" |
53 |
|