| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
USER="bitcoin" |
| 6 |
|
| 7 |
# Source debconf library |
| 8 |
. /usr/share/debconf/confmodule |
| 9 |
|
| 10 |
#DEBHELPER# |
| 11 |
|
| 12 |
update_conf_param () { |
| 13 |
local param="$1" |
| 14 |
local json="$2" |
| 15 |
db_get "datum-gateway/$param" || RET= |
| 16 |
if [ "$RET" ]; then |
| 17 |
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 \ |
| 18 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 19 |
fi |
| 20 |
unset RET |
| 21 |
} |
| 22 |
|
| 23 |
case "$1" in |
| 24 |
configure) |
| 25 |
|
| 26 |
if [ -z "$2" ]; then |
| 27 |
mkdir -p /etc/datum-gateway |
| 28 |
if [ ! -f /etc/datum-gateway/datum_gateway_config.json ]; then |
| 29 |
cp /usr/share/datum-gateway/datum_gateway_config.json /etc/datum-gateway/datum_gateway_config.json |
| 30 |
fi |
| 31 |
PASSWORD=$(pwgen -s 32 1) |
| 32 |
db_set datum-gateway/password "$PASSWORD" |
| 33 |
chown $USER:$USER /etc/datum-gateway/datum_gateway_config.json |
| 34 |
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 \ |
| 35 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 36 |
db_subst datum-gateway/password PASSWORD "$PASSWORD" |
| 37 |
db_fset datum-gateway/password seen false |
| 38 |
db_input high datum-gateway/password || true |
| 39 |
db_go |
| 40 |
fi |
| 41 |
|
| 42 |
if [ -f /etc/datum-gateway/datum_gateway_config.json ]; then |
| 43 |
db_get datum-gateway/bitcoin-address || RET= |
| 44 |
if [ "$RET" ]; then |
| 45 |
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 \ |
| 46 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 47 |
else |
| 48 |
db_input critical datum-gateway/bitcoin-address-blank || true |
| 49 |
db_go || true |
| 50 |
fi |
| 51 |
unset RET |
| 52 |
|
| 53 |
db_get datum-gateway/coinbase-tag-secondary || RET= |
| 54 |
if [ "$RET" ]; then |
| 55 |
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 \ |
| 56 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 57 |
else |
| 58 |
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 \ |
| 59 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 60 |
fi |
| 61 |
unset RET |
| 62 |
|
| 63 |
db_get datum-gateway/coinbase_tag_primary || RET= |
| 64 |
if [ "$RET" ]; then |
| 65 |
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 \ |
| 66 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 67 |
else |
| 68 |
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 \ |
| 69 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 70 |
fi |
| 71 |
unset RET |
| 72 |
|
| 73 |
db_get datum-gateway/rpcurl || RET= |
| 74 |
if [ "$RET" ]; then |
| 75 |
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 \ |
| 76 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 77 |
fi |
| 78 |
unset RET |
| 79 |
|
| 80 |
db_get datum-gateway/rpccredorcookie || RET= |
| 81 |
if [ "$RET" = "cookie" ]; then |
| 82 |
db_get datum-gateway/cookiepath || RET= |
| 83 |
if [ "$RET" ]; then |
| 84 |
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 \ |
| 85 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 86 |
fi |
| 87 |
unset RET |
| 88 |
else |
| 89 |
db_get datum-gateway/rpcuser || RET= |
| 90 |
if [ "$RET" ]; then |
| 91 |
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 \ |
| 92 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 93 |
fi |
| 94 |
unset RET |
| 95 |
|
| 96 |
db_get datum-gateway/rpcpassword || RET= |
| 97 |
if [ "$RET" ]; then |
| 98 |
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 \ |
| 99 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 100 |
fi |
| 101 |
unset RET |
| 102 |
fi |
| 103 |
unset RET |
| 104 |
|
| 105 |
update_conf_param work_update_seconds bitcoind.work_update_seconds |
| 106 |
update_conf_param listen_port stratum.listen_port |
| 107 |
update_conf_param max_clients_per_thread stratum.max_clients_per_thread |
| 108 |
update_conf_param max_threads stratum.max_threads |
| 109 |
update_conf_param max_clients stratum.max_clients |
| 110 |
update_conf_param vardiff_min stratum.vardiff_min |
| 111 |
update_conf_param modify_conf api.modify_conf |
| 112 |
update_conf_param log_level_file logger.log_level_file |
| 113 |
update_conf_param pool_pass_workers datum.pool_pass_workers |
| 114 |
update_conf_param pool_pass_full_users datum.pool_pass_full_users |
| 115 |
update_conf_param pooled_mining_only datum.pooled_mining_only |
| 116 |
|
| 117 |
# couldn't use update_conf_param since listen_port already exist for the stratum port |
| 118 |
db_get datum-gateway/listen_port-api || RET= |
| 119 |
if [ "$RET" ]; then |
| 120 |
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 \ |
| 121 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 122 |
fi |
| 123 |
unset RET |
| 124 |
fi |
| 125 |
|
| 126 |
if [ -d /var/log/datum-gateway ]; then |
| 127 |
# begin-remove-after: released:forky |
| 128 |
dpkg-statoverride --remove /var/log/datum-gateway 2>/dev/null || true |
| 129 |
# end-remove-after |
| 130 |
|
| 131 |
db_get datum-gateway/log || RET= |
| 132 |
if [ "$RET" = "true" ]; then |
| 133 |
runuser -u $USER -- jq '.logger.log_to_file = true' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ |
| 134 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 135 |
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 \ |
| 136 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 137 |
elif [ "$RET" = "false" ]; then |
| 138 |
runuser -u $USER -- jq '.logger.log_to_file = false' /etc/datum-gateway/datum_gateway_config.json > /etc/datum-gateway/datum_gateway_config.json.tmp \ |
| 139 |
&& mv /etc/datum-gateway/datum_gateway_config.json.tmp /etc/datum-gateway/datum_gateway_config.json |
| 140 |
fi |
| 141 |
unset RET |
| 142 |
fi |
| 143 |
|
| 144 |
invoke-rc.d datum-gateway restart || true |
| 145 |
|
| 146 |
db_stop |
| 147 |
;; |
| 148 |
esac |
| 149 |
|
| 150 |
exit 0 |