Index

joshstock.in / 3d81656

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
5004 Jan 2020 14:064024ec7Update deploy bash script functionalityJosh Stockin1224N

Blob @ joshstock.in / installgitpager

text/x-shellscript1679 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/gitpager.service ]; then
27 echo "error: $SCRIPTPATH/gitpager.service is nonexistent"
28 exit 1
29fi
30echo "copying service file to systemd configuration folder"
31cp $SCRIPTPATH/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
49if [ ! -d $SCRIPTPATH/gitpager ]; then
50 echo "error: $SCRIPTPATH/gitpager is nonexistent"
51 exit 1
52fi
53echo "copying $SCRIPTPATH/gitpager/* to $GITPAGERPATH"
54cp -r $SCRIPTPATH/gitpager/* $GITPAGERPATH
55
56echo "installing node modules at $GITPAGERPATH"
57if [ -d /tmp/gitpager_node_modules/ ]; then
58 mv -v /tmp/gitpager_node_modules/ $GITPAGERPATH/node_modules/
59fi
60npm --prefix $GITPAGERPATH install $GITPAGERPATH
61
62echo "attempting to reload gitpager service"
63systemctl daemon-reload
64service gitpager restart
65
66echo "done"
67