-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·117 lines (97 loc) · 2.2 KB
/
run.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
#!/bin/sh
SKIP_CONFIRM=false
CROWI_DIR_PUBLIC=/app/crowi/public
usage() {
cat <<EOF
Usage: $0 [option]... <command>
Commands:
all do load-assets and then do serve
serve do npm start
load-assets download assets from URLs specified in env \$ASSETS_*
Options:
--yes, -y skip confirmations
--debug, -d print all executed commands (set -x)
--help, -h print this message
EOF
}
prompt_continue_or_exit1() {
if test "$SKIP_CONFIRM" = true
then
return
fi
read -r -p "Continue? [y/n]: "
if test "$REPLY" != y -a "$REPLY" != Y
then
exit 1
fi
}
check_command_exists_or_exit1() {
if ! command -v "$1" /dev/null 2>&1
then
echo "abort: command \"$1\" not found"
exit 1
fi
}
# Usage: download_if_env_exists <ENVIRONMENT_VARIABLE_NAME>
# Example: download_if_env_exists URL_FAVICON
download_if_env_exists() {
_key=\$"$1"
_val=$(eval "echo $_key")
if [ "$_val" ]
then
echo "load-assets: download $_key from $_val"
curl -LO "$_val"
else
echo "load-assets: skip $_key"
fi
}
do_serve() {
npm run start
}
do_load_assets() {
cd $CROWI_DIR_PUBLIC || exit 1
download_if_env_exists ASSETS_ICON_FAV_1
download_if_env_exists ASSETS_ICON_FAV_2
download_if_env_exists ASSETS_ICON_FAV_3
download_if_env_exists ASSETS_ICON_FAV_4
download_if_env_exists ASSETS_ICON_IOS_1
download_if_env_exists ASSETS_ICON_IOS_2
download_if_env_exists ASSETS_ICON_IOS_3
download_if_env_exists ASSETS_ICON_IOS_4
download_if_env_exists ASSETS_ICON_ANDROID_1
cd - || exit 1
}
if [ $# -eq 0 ] ; then
usage
exit 1
fi
while [ $# -gt 0 ];
do
case ${1} in
all)
do_load_assets
do_serve
;;
serve)
do_serve
;;
load-assets)
do_load_assets
;;
--yes|-y)
SKIP_CONFIRM=true
;;
--debug|-d)
set -x
;;
--help|-h)
usage
;;
*)
echo "$(basename "$0") invalid command or option '${1}'"
usage
exit 1
;;
esac
shift
done