Index

joshstock.in / c8cb357

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
7421 Jan 2020 21:033fb40dbFinish gitpager refactorJosh Stockin1620N

Blob @ joshstock.in / gitpager / installgitpager

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