mirror of
https://github.com/ben-grande/qusal.git
synced 2025-01-02 11:26:11 -05:00
011a71a36d
Editorconfig can only act based on file extension and path, not attributes, it remains a mean only for multiple collaborators to use the same configuration on their editor. When it is too restrictive, such as not considering the file syntax, use a lint tool for the specific file type instead of trusting editorconfig. Changes were made to increase readability.
47 lines
1.5 KiB
Bash
Executable File
47 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
#
|
|
# Creates a new rpcauth for the client qube if it does not exist. If bitcoind
|
|
# is running remotely, there is no way to set a new option with bitcoin-cli.
|
|
|
|
set -eu
|
|
|
|
bitcoin_conf="/home/user/.bitcoin/conf.d/rpcauth.conf"
|
|
bitcoin_pass="/home/user/.bitcoin/rpcclient.pass"
|
|
user="${QREXEC_REMOTE_DOMAIN}"
|
|
|
|
if ! systemctl is-active bitcoind >/dev/null 2>&1; then
|
|
echo "systemd service 'bitcoind' is not active" >&2
|
|
echo "cannot add credentials with remote RPC" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if test -r "${bitcoin_conf}"; then
|
|
if grep -qs "^\s*rpcauth=${user}:" "${bitcoin_conf}"; then
|
|
grep -m1 "^${user}:" "${bitcoin_pass}"
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
if ! command -v bitcoin-rpcauth >/dev/null; then
|
|
echo "command not found: bitcoin-rpcauth" >&2
|
|
exit 127
|
|
fi
|
|
|
|
full_auth="$(bitcoin-rpcauth "${user}" | sed -n '2p;4p')"
|
|
rpcauth="$(echo "${full_auth}" | head -1)"
|
|
user="$(echo "${rpcauth}" | cut -d "=" -f2 | cut -d ":" -f1)"
|
|
password="$(echo "${full_auth}" | tail -1)"
|
|
|
|
echo "${rpcauth}" | sudo -u user tee -a "${bitcoin_conf}" >/dev/null
|
|
echo "${user}:${password}" | sudo -u user tee -a "${bitcoin_pass}" >/dev/null
|
|
echo "${user}:${password}"
|
|
|
|
## Restart bitcoind to apply the configuration changes. Currently, there is no
|
|
## prevention of DDoS besides when the client already has an authentication
|
|
## configured, it is printed and returned before getting to this part.
|
|
systemctl restart bitcoind
|