Files
jev-charms/opensem/hooks/paybox_system-relation-joined
2025-10-02 05:55:35 +02:00

63 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
. lib/common
set -e
test=$(relation-get test 2>/dev/null) || true
site=$(relation-get site) || {
err "The 'site' option is required."
exit 1
}
rank=$(relation-get rank) || {
err "The 'rank' option is required."
exit 1
}
id=$(relation-get id) || {
err "The 'id' option is required."
exit 1
}
hmac_key=$(relation-get hmac-key) || {
err "The 'hmac-key' option is required."
exit 1
}
[ -n "$test" ] && opensem:config-set PAYBOX_TEST "$test"
opensem:config-set PAYBOX_SITE "$site"
opensem:config-set PAYBOX_RANK "$rank"
opensem:config-set PAYBOX_ID "$id"
opensem:config-set PAYBOX_HMAC_KEY "$hmac_key"
paybox_url="http://www1.paybox.com/wp-content/uploads/2014/03/pubkey.pem"
paybox_pubkey_path="$SERVICE_DATASTORE/var/lib/opensem/paybox/pubkey.pem"
if ! [ -f "$paybox_pubkey_path" ]; then
mkdir -p "${paybox_pubkey_path%/*}"
if ! curl -sSL "$paybox_url" -o "$paybox_pubkey_path"; then
err "Failed to download Paybox public key from $paybox_url"
exit 1
fi
fi
## and create the mount point also:
paybox_mount_dir="$SERVICE_CONFIGSTORE/opt/apps/$SERVICE_NAME/storage/paybox"
if ! [ -d "$paybox_mount_dir" ]; then
mkdir -p "$paybox_mount_dir" || {
err "Could not create directory $paybox_mount_dir"
exit 1
}
fi
php_fpm_service=$(service:traverse "$SERVICE_NAME":php-fpm) || {
err "Could not find php-fpm service for $SERVICE_NAME"
exit 1
}
config-add "
services:
$php_fpm_service:
volumes:
- $SERVICE_DATASTORE/var/lib/opensem/paybox:/opt/apps/$SERVICE_NAME/storage/paybox:ro
"