File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
set -e
3
3
4
+ file_env () {
5
+ local var_name=" $1 "
6
+ local file_var_name=" $2 "
7
+
8
+ var_value=$( printenv " $var_name " ) || var_value=" "
9
+ file_path=$( printenv " $file_var_name " ) || file_path=" "
10
+
11
+ if [ -z " $var_value " ] && [ -z " $file_path " ]; then
12
+ echo " error: expected $var_name or $file_var_name env vars to be set"
13
+ exit 1
14
+
15
+ elif [ -n " $var_value " ] && [ -n " $file_path " ]; then
16
+ echo " both and $var_name $file_var_name env vars are set, expected only one of them"
17
+ exit 1
18
+
19
+ else
20
+ if [ -n " $file_path " ] && [ " $file_path " != " " ]; then
21
+ if [ -f " $file_path " ]; then
22
+ file_content=$( cat " $file_path " )
23
+ export " $var_name =$file_content "
24
+ else
25
+ echo " error: $var_name =$file_path : file '$file_path ' does not exist"
26
+ exit 1
27
+ fi
28
+ fi
29
+ fi
30
+ }
31
+
4
32
USERNAME=telegram-bot-api
5
33
GROUPNAME=telegram-bot-api
6
34
@@ -10,6 +38,9 @@ if [ -n "${1}" ]; then
10
38
exec " ${* } "
11
39
fi
12
40
41
+ file_env " TELEGRAM_API_ID" " TELEGRAM_API_ID_FILE"
42
+ file_env " TELEGRAM_API_HASH" " TELEGRAM_API_HASH_FILE"
43
+
13
44
DEFAULT_ARGS=" --dir=${TELEGRAM_WORK_DIR} --temp-dir=${TELEGRAM_TEMP_DIR} --username=${USERNAME} --groupname=${GROUPNAME} "
14
45
CUSTOM_ARGS=" "
15
46
51
82
COMMAND=" telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS} "
52
83
53
84
echo " $COMMAND "
85
+
54
86
# shellcheck disable=SC2086
55
87
exec $COMMAND
You can’t perform that action at this time.
0 commit comments