@@ -48,7 +48,6 @@ print_hardlink_yml() {
4848EOF
4949}
5050
51-
5251print_s3import_yml () {
5352 cat << EOF
5453- id: s3import
@@ -103,7 +102,6 @@ print_s3import_yml() {
103102EOF
104103}
105104
106-
107105print_token_yml () {
108106 if [ " $1 " ]; then
109107 cat << EOF
@@ -118,40 +116,46 @@ EOF
118116 fi
119117}
120118
119+ exec_webhook () {
120+ # Validate WORKDIR
121+ if [ -z " $WEBHOOK_WORKDIR " ]; then
122+ echo " Must define the WEBHOOK_WORKDIR variable!" >&2
123+ exit 1
124+ fi
125+ WORKDIR=" $( realpath " $WEBHOOK_WORKDIR " 2> /dev/null) " || true
126+ if [ ! -d " $WORKDIR " ]; then
127+ echo " The WEBHOOK_WORKDIR '$WEBHOOK_WORKDIR ' is not a directory!" >&2
128+ exit 1
129+ fi
130+ # Get TOKENS, if the DU_TOKEN or HARDLINK_TOKEN is defined that is used, if not
131+ # if the COMMON_TOKEN that is used and in other case no token is checked (that
132+ # is the default)
133+ DU_TOKEN=" ${DU_TOKEN:- $COMMON_TOKEN } "
134+ HARDLINK_TOKEN=" ${HARDLINK_TOKEN:- $COMMON_TOKEN } "
135+ S3_TOKEN=" ${S3_TOKEN:- $COMMON_TOKEN } "
136+ # Create webhook configuration
137+ {
138+ print_du_yml
139+ print_token_yml " $DU_TOKEN "
140+ echo " "
141+ print_hardlink_yml
142+ print_token_yml " $HARDLINK_TOKEN "
143+ echo " "
144+ print_s3import_yml
145+ print_token_yml " $S3_TOKEN "
146+ }> " $WEBHOOK_YML "
147+ # Run the webhook command
148+ # shellcheck disable=SC2086
149+ exec webhook -hooks " $WEBHOOK_YML " $WEBHOOK_OPTS
150+ }
151+
121152# ----
122153# MAIN
123154# ----
124155
125- # Validate WORKDIR
126- if [ -z " $WEBHOOK_WORKDIR " ]; then
127- echo " Must define the WEBHOOK_WORKDIR variable!" >&2
128- exit 1
129- fi
130- WORKDIR=" $( realpath " $WEBHOOK_WORKDIR " 2> /dev/null) " || true
131- if [ ! -d " $WORKDIR " ]; then
132- echo " The WEBHOOK_WORKDIR '$WEBHOOK_WORKDIR ' is not a directory!" >&2
133- exit 1
134- fi
135-
136- # Get TOKENS, if the DU_TOKEN or HARDLINK_TOKEN is defined that is used, if not
137- # if the COMMON_TOKEN that is used and in other case no token is checked (that
138- # is the default)
139- DU_TOKEN=" ${DU_TOKEN:- $COMMON_TOKEN } "
140- HARDLINK_TOKEN=" ${HARDLINK_TOKEN:- $COMMON_TOKEN } "
141- S3_TOKEN=" ${S3_TOKEN:- $COMMON_TOKEN } "
142-
143- # Create webhook configuration
144- {
145- print_du_yml
146- print_token_yml " $DU_TOKEN "
147- echo " "
148- print_hardlink_yml
149- print_token_yml " $HARDLINK_TOKEN "
150- echo " "
151- print_s3import_yml
152- print_token_yml " $S3_TOKEN "
153- }> " $WEBHOOK_YML "
156+ case " $1 " in
157+ " server" ) exec_webhook ;;
158+ * ) exec " $@ " ;;
159+ esac
154160
155- # Run the webhook command
156- # shellcheck disable=SC2086
157- exec webhook -hooks " $WEBHOOK_YML " $WEBHOOK_OPTS
161+ # vim: ts=2:sw=2:et
0 commit comments