-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
90 lines (72 loc) · 2.21 KB
/
entrypoint.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
MY=(
[ROLE]=app
[RUN_AS]=www
[INIT_URL]="${INIT_URL:-}"
[INIT_POST]="${INIT_POST:-}"
[INIT_PKGS]="${INIT_PKGS:-}"
[CURL_OPTS]="${CURL_OPTS:-}"
[GIT_BRANCH]="${GIT_BRANCH:-}"
[KEEP_BOOTSTRAP_TOOLS]="${KEEP_BOOTSTRAP_TOOLS:-}"
[PRE_WWWCONFIG]="${PRE_WWWCONFIG:-}"
[POST_WWWCONFIG]="${POST_WWWCONFIG:-}"
[OWN_WWWCONFIG]="${OWN_WWWCONFIG:-}"
)
passthrough_unless "php-fpm" "$@"
declare -r curl=( curl -sL "${MY[CURL_OPTS]}" )
handle_smartly () {
local -r url="${1}"; shift
case "${url}" in
'')
log 'No INIT_URL given.'
return
;;
git://*|ssh://*|git+ssh://*|*.git)
if [[ -n "${MY[GIT_BRANCH]}" ]]; then
git clone --branch "${MY[GIT_BRANCH]}" --depth=1 "${url}" .
else
git clone --depth=1 "${url}" .
fi
return
;;
esac
local -r file="$(basename "${url}")"
local -r ext="${file#*.}"
log "${file} is a '${ext}' file."
case "${ext}" in
tar.gz) "${curl[@]}" "${url}" | tar xvzf - ;;
tar.bz2) "${curl[@]}" "${url}" | tar xvjf - ;;
sh) "${curl[@]}" "${url}" | bash ;;
*)
log "Don't know what to do with ${file} from ${url}. Aborting."
log "For complex deployment scenarios, try a .sh script as INIT_URL."
return 1
;;
esac
}
[[ -z "${MY[INIT_PKGS]}" ]] || apt-get install ${MY[INIT_PKGS]}
cd "${OUR[WEBDIR]}"
handle_smartly "${MY[INIT_URL]}"
if [[ -n "${MY[INIT_POST]}" ]]; then
if [[ $(dirname "${MY[INIT_POST]}") = '.' ]]; then
chmod +x "./${MY[INIT_POST]}"
fi
"${MY[INIT_POST]}"
fi
[[ -z "${MY[KEEP_BOOTSTRAP_TOOLS]}" ]] || apt-get purge curl
if have_global vhosts; then
if [[ -n "${MY[PRE_WWWCONFIG]}" ]]; then
echo "${MY[PRE_WWWCONFIG]}" > "${OUR[VHOSTS]}/default"
fi
{
if [[ -n "${MY[OWN_WWWCONFIG]}" ]]; then
echo "${MY[OWN_WWWCONFIG]}"
else
cat "${OUR[LOCAL_VHOSTS]}/default"
fi
} >> "${OUR[VHOSTS]}/default"
if [[ -n "${MY[POST_WWWCONFIG]}" ]]; then
echo "${MY[POST_WWWCONFIG]}" >> "${OUR[VHOSTS]}/default"
fi
reload_vhosts
fi
run "$@"