| 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 | echo "copying service file to systemd configuration folder" |
| 27 | cp $SCRIPTPATH/gitpager.service /etc/systemd/system/gitpager.service |
| 28 |
|
| 29 | echo "modifying service configuration file for node environment variable" |
| 30 | sed -i "s/\$env/$NODE_ENV/g" /etc/systemd/system/gitpager.service |
| 31 |
|
| 32 | echo "emptying and deleting old $GITPAGERPATH folder" |
| 33 | rm -r $GITPAGERPATH |
| 34 |
|
| 35 | echo "creating new $GITPAGERPATH folder" |
| 36 | mkdir -p $GITPAGERPATH |
| 37 |
|
| 38 | echo "copying $SCRIPTPATH/gitpager/* to $GITPAGERPATH" |
| 39 | cp -r $SCRIPTPATH/gitpager/* $GITPAGERPATH |
| 40 |
|
| 41 | echo "installing node modules at $GITPAGERPATH" |
| 42 | npm --prefix $GITPAGERPATH install $GITPAGERPATH |
| 43 |
|
| 44 | echo "attempting to reload gitpager service" |
| 45 | systemctl daemon-reload |
| 46 | service gitpager restart |
| 47 |
|
| 48 | echo "done" |
| 49 |
|