#!/bin/bash set -e USER="bitcoin" # Source debconf library . /usr/share/debconf/confmodule # Automatically added by dh_installsysusers/14.5 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} datum-gateway.conf fi # End automatically added section # Automatically added by dh_installtmpfiles/14.5 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "$(command -v systemd-tmpfiles)" ]; then systemd-tmpfiles ${DPKG_ROOT:+--root="$DPKG_ROOT"} --create datum-gateway.conf || true fi fi # End automatically added section # Automatically added by dh_installinit/14.5 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "$DPKG_ROOT/etc/init.d/datum-gateway" ]; then update-rc.d datum-gateway defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi if [ -z "$DPKG_ROOT" ]; then invoke-rc.d --skip-systemd-native datum-gateway $_dh_action || exit 1 fi fi fi # End automatically added section # Automatically added by dh_installsystemd/14.5 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'datum-gateway.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'datum-gateway.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'datum-gateway.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'datum-gateway.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/14.5 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "$DPKG_ROOT" ] && [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi deb-systemd-invoke $_dh_action 'datum-gateway.service' >/dev/null || true fi fi # End automatically added section update_conf_param () { local param="$1" local json="$2" db_get "datum-gateway/$param" || RET= if [ "$RET" ]; then runuser -u $USER -- jq --argjson PARAM "$RET" --arg JSON "$json" 'setpath($JSON | split("."); $PARAM)' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET } case "$1" in configure) if [ -z "$2" ]; then mkdir -p /etc/datum-gateway if [ ! -f /etc/datum-gateway/datum_gateway_config.json ]; then cp /usr/share/datum-gateway/datum_gateway_config.json /etc/datum-gateway/datum_gateway_config.json fi PASSWORD=$(pwgen -s 32 1) db_set datum-gateway/password "$PASSWORD" chown $USER:$USER /etc/datum-gateway/datum_gateway_config.json runuser -u $USER -- jq --arg PASSWORD "$PASSWORD" '.mining.pool_address = "" | .api.admin_password = $PASSWORD | .api.modify_conf = true' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json db_subst datum-gateway/password PASSWORD "$PASSWORD" db_fset datum-gateway/password seen false db_input high datum-gateway/password || true db_go fi if [ -f /etc/datum-gateway/datum_gateway_config.json ]; then db_get datum-gateway/bitcoin-address || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg BTCADDRESS "$RET" '.mining.pool_address = $BTCADDRESS' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json else db_input critical datum-gateway/bitcoin-address-blank || true db_go || true fi unset RET db_get datum-gateway/coinbase-tag-secondary || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg TAG "$RET" '.mining.coinbase_tag_secondary = $TAG' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json else runuser -u $USER -- jq '.mining.coinbase_tag_secondary = "DATUM User"' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET db_get datum-gateway/coinbase_tag_primary || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg TAG "$RET" '.mining.coinbase_tag_primary = $TAG' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json else runuser -u $USER -- jq '.mining.coinbase_tag_primary = "DATUM Gateway"' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET db_get datum-gateway/rpcurl || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg URL "$RET" '.bitcoind.rpcurl = $URL' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET db_get datum-gateway/rpccredorcookie || RET= if [ "$RET" = "cookie" ]; then db_get datum-gateway/cookiepath || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg PATH "$RET" '.bitcoind.rpccookiefile = $PATH | del(.bitcoind.rpcuser) | del(.bitcoind.rpcpassword)' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET else db_get datum-gateway/rpcuser || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg USER "$RET" '.bitcoind.rpcuser = $USER | del(.bitcoind.rpccookiefile)' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET db_get datum-gateway/rpcpassword || RET= if [ "$RET" ]; then runuser -u $USER -- jq --arg PASS "$RET" '.bitcoind.rpcpassword = $PASS | del(.bitcoind.rpccookiefile)' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET fi unset RET update_conf_param work_update_seconds bitcoind.work_update_seconds update_conf_param listen_port stratum.listen_port update_conf_param max_clients_per_thread stratum.max_clients_per_thread update_conf_param max_threads stratum.max_threads update_conf_param max_clients stratum.max_clients update_conf_param vardiff_min stratum.vardiff_min update_conf_param modify_conf api.modify_conf update_conf_param log_level_file logger.log_level_file update_conf_param pool_pass_workers datum.pool_pass_workers update_conf_param pool_pass_full_users datum.pool_pass_full_users update_conf_param pooled_mining_only datum.pooled_mining_only # couldn't use update_conf_param since listen_port already exist for the stratum port db_get datum-gateway/listen_port-api || RET= if [ "$RET" ]; then runuser -u $USER -- jq --argjson PARAM "$RET" --arg JSON "api.listen_port" 'setpath($JSON | split("."); $PARAM)' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET fi if [ -d /var/log/datum-gateway ]; then # begin-remove-after: released:forky dpkg-statoverride --remove /var/log/datum-gateway 2>/dev/null || true # end-remove-after db_get datum-gateway/log || RET= if [ "$RET" = "true" ]; then runuser -u $USER -- jq '.logger.log_to_file = true' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json runuser -u $USER -- jq '.logger.log_file = "/var/log/datum-gateway/datum.log"' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json elif [ "$RET" = "false" ]; then runuser -u $USER -- jq '.logger.log_to_file = false' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ && mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json fi unset RET fi invoke-rc.d datum-gateway restart || true db_stop ;; esac exit 0