1 | #!/usr/bin/env bash |
2 |
|
3 | GITPAGERPATH=/srv/gitpager |
4 | SCRIPTPATH=$(dirname $(realpath -s $0)) |
5 |
|
6 | usage() { |
7 | echo "usage: sudo ./installgitpager [prod | test]" |
8 | exit 1 |
9 | } |
10 | if [ "$EUID" -ne 0 ]; then |
11 | echo "error: must run as root" |
12 | usage |
13 | fi |
14 | if [ $# -eq 0 ]; then |
15 | usage |
16 | fi |
17 | if [ "$1" != "prod" ] && [ "$1" != "test" ]; then |
18 | usage |
19 | fi |
20 | if [ "$1" == "prod" ]; then |
21 | NODE_ENV="production" |
22 | elif [ "$1" == "test" ]; then |
23 | NODE_ENV="development" |
24 | fi |
25 |
|
26 | if [ ! -f $SCRIPTPATH/gitpager.service ]; then |
27 | echo "error: $SCRIPTPATH/gitpager.service is nonexistent" |
28 | exit 1 |
29 | fi |
30 | echo "copying service file to systemd configuration folder" |
31 | cp $SCRIPTPATH/gitpager.service /etc/systemd/system/gitpager.service |
32 |
|
33 | echo "modifying service configuration file for node environment variable" |
34 | sed -i "s/\$env/$NODE_ENV/g" /etc/systemd/system/gitpager.service |
35 |
|
36 | if [ -d $GITPAGERPATH/node_modules/ ]; then |
37 | echo "preserving node_modules/ from old $GITPAGERPATH folder" |
38 | mv -v $GITPAGERPATH/node_modules/ /tmp/gitpager_node_modules/ |
39 | fi |
40 |
|
41 | if [ -d $GITPAGERPATH ]; then |
42 | echo "emptying old $GITPAGERPATH folder" |
43 | rm -r $GITPAGERPATH/* |
44 | else |
45 | echo "creating new $GITPAGERPATH folder" |
46 | mkdir -pv $GITPAGERPATH |
47 | fi |
48 |
|
49 | if [ ! -d $SCRIPTPATH/gitpager ]; then |
50 | echo "error: $SCRIPTPATH/gitpager is nonexistent" |
51 | exit 1 |
52 | fi |
53 | echo "copying $SCRIPTPATH/gitpager/* to $GITPAGERPATH" |
54 | cp -r $SCRIPTPATH/gitpager/* $GITPAGERPATH |
55 |
|
56 | echo "installing node modules at $GITPAGERPATH" |
57 | if [ -d /tmp/gitpager_node_modules/ ]; then |
58 | mv -v /tmp/gitpager_node_modules/ $GITPAGERPATH/node_modules/ |
59 | fi |
60 | npm --prefix $GITPAGERPATH install $GITPAGERPATH |
61 |
|
62 | echo "attempting to reload gitpager service" |
63 | systemctl daemon-reload |
64 | service gitpager restart |
65 |
|
66 | echo "done" |
67 |
|