-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·167 lines (128 loc) · 3.68 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
#variables
VERSION="1.1.1"
SOURCE=$(dirname ${BASH_SOURCE[0]})
INITSCRIPT="$SOURCE/prerender.init"
SERVERSCRIPT=""
DEFAULT_NODE_PREFIX="/usr"
NODE_PREFIX=$DEFAULT_NODE_PREFIX
bold=`tput bold`
normal=`tput sgr0`
#parse options
SHOW_HELP=false
UNINSTALL=false
VERBOSE=false
for i in "$@"
do
case $i in
-h|--help)
SHOW_HELP=true
;;
-u|--uninstall)
UNINSTALL=true
;;
-v|--verbose)
VERBOSE=true
;;
-p=*|--node-prefix=*)
NODE_PREFIX="${i#*=}"
;;
-s=*|--server-script=*)
SERVERSCRIPT="${i#*=}"
;;
esac
done
banner() {
echo "" 1>&3 2>&4;
echo "» ${bold}Prerender-daemon installer v${VERSION}${normal} by Luciano Mammino"
echo "» http://loige.com"
echo "» https://github.com/lmammino/prerender-daemon"
echo ""
}
rootcheck() {
#should be run as sudo from here
if [ "$UID" -ne 0 ]; then
echo "${bold}WARNING: it seems that the installer has not be run as root${normal}. It may not work as intended."
read -p "${bold}Do you want to continue? (yn)${normal} [n]" yn
case $yn in
[Yy]* ) ;;
[Nn]* ) exit;;
* ) exit;;
esac
fi
}
#manage verbosity
exec 3>&1
exec 4>&2
if [ "$VERBOSE" = false ]; then
exec 1>/dev/null
exec 2>/dev/null
fi
# display help
if [ "$SHOW_HELP" = true ]; then
banner 1>&3 2>&4
cat 1>&3 2>&4 << EOF
Usage:
sudo ./install.sh [-h|--help] [-u|--uninstall]
Options:
-h|--help Display this help
-u|--uninstall Uninstall prerender
-v|--verbose Enable verbose output
(-p|--node-prefix)=VALUE specify a custom node prefix (default "${DEFAULT_NODE_PREFIX}")
(-s|--server-script)=VALUE specify a custom server script that will be used to replace the default launch script (eg. to provide a custom configuration)
Examples:
Install with default options:
sudo ./install.sh
Uninstall:
sudo ./install.sh --uninstall
Install with custom node prefix and using a custom server script:
sudo ./install.sh --node-prefix=usr/local --server-script=~/temp/my-custom-script.sh
EOF
exit 0;
fi
#uninstall
if [ "$UNINSTALL" = true ]; then
banner 1>&3 2>&4
rootcheck 1>&3 2>&4
echo " ${bold}Uninstalling prerender-daemon${normal}" 1>&3 2>&4
/etc/init.d/prerender stop
echo " ${bold}✓${normal} Daemon stopped" 1>&3 2>&4
rm /etc/init.d/prerender
update-rc.d prerender remove
echo " ${bold}✓${normal} Init script deleted" 1>&3 2>&4
rm -rf /var/run/prerender
echo " ${bold}✓${normal} PID folder deleted" 1>&3 2>&4
userdel prerender
echo " ${bold}✓${normal} prerender user deleted" 1>&3 2>&4
groupdel prerender
echo " ${bold}✓${normal} prerender user group deleted" 1>&3 2>&4
npm uninstall -g prerender
echo " ${bold}✓${normal} npm prerender uninstalled" 1>&3 2>&4
echo " Done." 1>&3 2>&4
exit 0;
fi
#install
banner 1>&3 2>&4
rootcheck 1>&3 2>&4
echo " ${bold}Installing prerender-daemon${normal}" 1>&3 2>&4
npm install --global prerender 1>&3 2>&4
echo " ${bold}✓${normal} npm prerender installed" 1>&3 2>&4
if [ -e "$SERVERSCRIPT" ]; then
DEFAULTSCRIPT="$NODE_PREFIX/lib/node_modules/prerender/server.js"
mv $DEFAULTSCRIPT "$DEFAULTSCRIPT.bak"
cp $SERVERSCRIPT $DEFAULTSCRIPT
chmod +x $DEFAULTSCRIPT;
echo " ${bold}✓${normal} Server script copied to ${DEFAULTSCRIPT}" 1>&3 2>&4
fi
useradd -r -s /bin/false prerender
echo " ${bold}✓${normal} prerender user and user group added" 1>&3 2>&4
mkdir -p /var/run/prerender
echo " ${bold}✓${normal} PID folder created" 1>&3 2>&4
cp $INITSCRIPT /etc/init.d/prerender
chmod +x /etc/init.d/prerender
update-rc.d prerender defaults
echo " ${bold}✓${normal} Init script installed" 1>&3 2>&4
/etc/init.d/prerender start
echo " ${bold}✓${normal} Daemon started" 1>&3 2>&4
echo " Done." 1>&3 2>&4
exit 0;