-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
188 lines (169 loc) · 4.03 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
function _USAGE
{
cat << EOF
Usage :
${_SCRIPT_NAME} [OPTIONS]
Options :
-u website_url website url (ex: http://mydomain.ovh)
-d documentroot documentroot directory relative to home directory (ex: www)
-e entrypoint entrypoint (ex: app.py, index.js, config.ru)
-p publicdir publicdir directory relative to documentroot (ex: public)
-h show this message
Ex :
${_SCRIPT_NAME} -u http://mydomain.ovh -d www -e app.py -p public
EOF
exit 1
}
function _LOGS
{
local _LEVEL="${1}"
local _MESSAGE="${2}"
local _DATE="$(date --iso-8601=seconds)"
local _LOGS_MESSAGE="[${_DATE}] ${_LEVEL} ${_MESSAGE}"
echo -e "${_LOGS_MESSAGE}"
}
function _GET_OPTS
{
local _SHORT_OPTS="u:d:e:p:h";
local _OPTS=$(getopt \
-o "${_SHORT_OPTS}" \
-n "${_SCRIPT_NAME}" -- "${@}")
eval set -- "${_OPTS}"
while true ; do
case "${1}" in
-u)
_URL_OPT=${2}
shift 2
;;
-d)
_DOCUMENTROOT_OPT=${2}
shift 2
;;
-e)
_ENTRYPOINT_OPT=${2}
shift 2
;;
-p)
_PUBLICDIR_OPT=${2}
shift 2
;;
-h|--help)
_USAGE
shift
;;
--) shift ; break ;;
esac
done
}
function _CHECK_OPTS
{
if [ -z "${_DOCUMENTROOT_OPT}" ]
then
_LOGS "ERROR" "documentroot cannot be empty"
exit 1
fi
if [ -z "${_URL_OPT}" ]
then
_LOGS "ERROR" "website_url cannot be empty"
exit 1
fi
if [ -z "${_ENTRYPOINT_OPT}" ]
then
_LOGS "ERROR" "entrypoint cannot be empty"
exit 1
fi
if [ -z "${_PUBLICDIR_OPT}" ]
then
_LOGS "ERROR" "publicdir cannot be empty"
exit 1
fi
if [ -z "${HOME}" ]
then
_LOGS "ERROR" "home env var empty stopping"
exit 1
fi
}
function _LOAD_ENV
{
source /etc/ovhconfig.bashrc
passengerConfig
}
function _PRINT_ENV
{
cat << EOF
==============================================================
OVH_APP_ENGINE=${OVH_APP_ENGINE}
OVH_APP_ENGINE_VERSION=${OVH_APP_ENGINE_VERSION}
OVH_ENVIRONMENT=${OVH_ENVIRONMENT}
PATH=${PATH}
==============================================================
EOF
}
function _BUILDING
{
_LOGS "INFO" "Building runtime"
cd "${HOME}"/.powerworkflow
npm install
# npx eleventy --output="${HOME}"/.powerworkflow/ovhstaticfiles
}
function _REMOVING_OLD_DOCUMENTROOT
{
_LOGS "INFO" "Removing Document root"
rm -rf "${HOME:?}"/"${_DOCUMENTROOT_OPT}"
}
function _CREATING_DOCUMENTROOT
{
_LOGS "INFO" "Creating Document root"
mkdir -p "${HOME}"/"${_DOCUMENTROOT_OPT}"
}
function _MOVE_BUILD_FILES
{
_LOGS "INFO" "Moving build files to publicdir"
mkdir -p "${HOME}"/"${_DOCUMENTROOT_OPT}"/"${_PUBLICDIR_OPT}"
rm -rf "${HOME:?}"/"${_DOCUMENTROOT_OPT}"/"${_PUBLICDIR_OPT}"
mv "${HOME}"/.powerworkflow/ovhstaticfiles "${HOME}"/"${_DOCUMENTROOT_OPT}"/"${_PUBLICDIR_OPT}"
}
function _INSTALL_WEB_SERVER
{
cd "${HOME}"/"${_DOCUMENTROOT_OPT}"
npm install express
}
function _CREATING_ENTRYPOINT
{
_LOGS "INFO" "Creating entrypoint"
cat << EOF > "${HOME}"/"${_DOCUMENTROOT_OPT}"/"${_ENTRYPOINT_OPT}"
var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/${_PUBLICDIR_OPT}'));
app.listen();
EOF
}
function _RESTARTING
{
_LOGS "INFO" "Restarting server"
mkdir -p "${HOME}"/"${_DOCUMENTROOT_OPT}"/tmp
touch "${HOME}"/"${_DOCUMENTROOT_OPT}"/tmp/restart.txt
}
function _SLEEPING
{
_LOGS "INFO" "Wait for NFS files propagation"
sleep 30
}
### MAIN
set -e
set -o pipefail
_SCRIPT_NAME=$(basename "${0}")
_GET_OPTS "${@}"
_CHECK_OPTS
_LOAD_ENV
_PRINT_ENV
_BUILDING
_REMOVING_OLD_DOCUMENTROOT
_CREATING_DOCUMENTROOT
# _MOVE_BUILD_FILES
_INSTALL_WEB_SERVER
_CREATING_ENTRYPOINT
_RESTARTING
_SLEEPING
_LOGS "INFO" "job is done"