diff --git a/Dockerfile b/Dockerfile index d84c732..d8ffbeb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:20-alpine -RUN apk add --no-cache jq=1.7.1-r0 && \ +RUN apk add --no-cache jq=1.7.1-r0 curl=8.8.0-r0 && \ npm install -g wikibase-cli@17.0.8 COPY --chmod=755 ./transferbot.sh /usr/bin/transferbot diff --git a/README.md b/README.md index edd52bf..924ff3c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ A Docker image providing a command that transfers entities from a source to a ta ``` docker run --rm ghcr.io/wbstack/transferbot \ + -e CALLBACK_ON_SUCCESS="echo 'this worked'" -e CALLBACK_ON_FAILURE="echo 'this failed'" \ https://source.wikibase.cloud https://target.wikibase.cloud Q1 P1 Q2 ``` @@ -36,6 +37,18 @@ The OAuth access token used for authenticating against the target wiki. The OAuth access secret used for authenticating against the target wiki. +## Running commands after the script has finished + +It's possible to provide commands that should be run when the script has finished. + +### `CALLBACK_ON_SUCCESS` (optional) + +If a value is set for this key, its content will be executed in case the script exits 0. + +### `CALLBACK_ON_FAILURE` (optional) + +If a value is set for this key, its content will be executed in case the script exits non-zero. + --- This work is distributed under the [BSD 3-Clause license](./LICENSE). diff --git a/transferbot.sh b/transferbot.sh index c19e07e..1048c5c 100644 --- a/transferbot.sh +++ b/transferbot.sh @@ -3,6 +3,17 @@ set -eu set -o pipefail +trap finish EXIT INT TERM + +finish () { + exit_code=$?; + if [ ! -z "${CALLBACK_ON_SUCCESS:-}" ] && [ "$exit_code" = 0 ]; then + sh -c "$CALLBACK_ON_SUCCESS" + elif [ ! -z "${CALLBACK_ON_FAILURE:-}" ] && [ "$exit_code" != 0 ]; then + sh -c "$CALLBACK_ON_FAILURE" + fi +} + source_wiki_origin="$1" shift target_wiki_origin="$1"