Skip to content

Commit

Permalink
Add seednode installer feature to use existing btcnode P2P/RPC config
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz committed Feb 6, 2020
1 parent bbc1db4 commit 41a8fed
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 40 deletions.
12 changes: 6 additions & 6 deletions seednode/bisq-seednode.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ JAVA_HOME=/usr/lib/jvm/openjdk-10.0.2
JAVA_OPTS="-Xms4096M -Xmx4096M -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.host=127.0.0.1 -Dcom.sun.management.jmxremote.port=6969 -Dcom.sun.management.jmxremote.rmi.port=6969 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

# bitcoin rpc credentials
BITCOIN_RPC_USERNAME=__BITCOIN_RPC_USER__
BITCOIN_RPC_PASSWORD=__BITCOIN_RPC_PASS__
BITCOIN_RPC_USER=__BITCOIN_RPC_USER__
BITCOIN_RPC_PASS=__BITCOIN_RPC_PASS__

# bitcoin p2p settings
BITCOIN_P2P_HOST=127.0.0.1
BITCOIN_P2P_PORT=8333
BITCOIN_P2P_HOST=__BITCOIN_P2P_HOST__
BITCOIN_P2P_PORT=__BITCOIN_P2P_PORT__

# bitcoind rpc ports
BITCOIN_RPC_HOST=127.0.0.1
BITCOIN_RPC_PORT=8332
BITCOIN_RPC_HOST=__BITCOIN_RPC_HOST__
BITCOIN_RPC_PORT=__BITCOIN_RPC_PORT__
BITCOIN_RPC_BLOCKNOTIFY_HOST=127.0.0.1
BITCOIN_RPC_BLOCKNOTIFY_PORT=5120

Expand Down
8 changes: 4 additions & 4 deletions seednode/bisq-seednode.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[Unit]
Description=Bisq Seed Node
After=bitcoin.service
Requires=bitcoin.service
BindsTo=bitcoin.service
#Requires=bitcoin.service
#BindsTo=bitcoin.service

[Service]
EnvironmentFile=/etc/default/bisq-seednode.env
Expand All @@ -22,8 +22,8 @@ ExecStart=__BISQ_HOME__/__BISQ_REPO_NAME__/bisq-seednode \
--rpcBlockNotificationPort=${BITCOIN_RPC_BLOCKNOTIFY_PORT} \
--rpcHost=${BITCOIN_RPC_HOST} \
--rpcPort=${BITCOIN_RPC_PORT} \
--rpcUser=${BITCOIN_RPC_USERNAME} \
--rpcPassword=${BITCOIN_RPC_PASSWORD} \
--rpcUser=${BITCOIN_RPC_USER} \
--rpcPassword=${BITCOIN_RPC_PASS} \
--dumpBlockchainData=${BISQ_DUMP_BLOCKCHAIN} \
--dumpStatistics=${BISQ_DUMP_STATISTICS} \

Expand Down
92 changes: 62 additions & 30 deletions seednode/install_seednode_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@ BISQ_LATEST_RELEASE=$(curl -s https://api.github.com/repos/bisq-network/bisq/rel
BISQ_HOME=/bisq
BISQ_USER=bisq

# by default, this script will build and setup bitcoin fullnode
# if you want to use an existing bitcoin fullnode, see next section
BITCOIN_INSTALL=true
BITCOIN_REPO_URL=https://github.com/bitcoin/bitcoin
BITCOIN_REPO_NAME=bitcoin
BITCOIN_REPO_TAG=$(curl -s https://api.github.com/repos/bitcoin/bitcoin/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
BITCOIN_HOME=/bitcoin
BITCOIN_USER=bitcoin
BITCOIN_GROUP=bitcoin
BITCOIN_PKG="libevent-dev libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb-dev libssl-dev"
BITCOIN_P2P_HOST=127.0.0.1
BITCOIN_P2P_PORT=8333
BITCOIN_RPC_HOST=127.0.0.1
BITCOIN_RPC_PORT=8332

# set below settings to use existing bitcoin node
#BITCOIN_INSTALL=false
#BITCOIN_P2P_HOST=192.168.1.1
#BITCOIN_P2P_PORT=8333
#BITCOIN_RPC_HOST=192.168.1.1
#BITCOIN_RPC_PORT=8332
#BITCOIN_RPC_USER=foo
#BITCOIN_RPC_PASS=bar

TOR_PKG="tor"
TOR_USER=debian-tor
Expand Down Expand Up @@ -54,39 +70,43 @@ sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq
echo "[*] Installing Tor configuration"
sudo -H -i -u "${ROOT_USER}" install -c -m 644 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/torrc" "${TOR_HOME}/torrc"

echo "[*] Creating Bitcoin user with Tor access"
sudo -H -i -u "${ROOT_USER}" useradd -d "${BITCOIN_HOME}" -G "${TOR_GROUP}" "${BITCOIN_USER}"
if [ "${BITCOIN_INSTALL}" = true ];then

echo "[*] Installing Bitcoin build dependencies"
sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq -y ${BITCOIN_PKG}
echo "[*] Creating Bitcoin user with Tor access"
sudo -H -i -u "${ROOT_USER}" useradd -d "${BITCOIN_HOME}" -G "${TOR_GROUP}" "${BITCOIN_USER}"

echo "[*] Creating Bitcoin homedir"
sudo -H -i -u "${ROOT_USER}" mkdir "${BITCOIN_HOME}"
sudo -H -i -u "${ROOT_USER}" chown "${BITCOIN_USER}":"${BITCOIN_GROUP}" ${BITCOIN_HOME}
sudo -H -i -u "${BITCOIN_USER}" ln -s . .bitcoin
echo "[*] Installing Bitcoin build dependencies"
sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq -y ${BITCOIN_PKG}

echo "[*] Cloning Bitcoin repo"
sudo -H -i -u "${BITCOIN_USER}" git config --global advice.detachedHead false
sudo -H -i -u "${BITCOIN_USER}" git clone --branch "${BITCOIN_REPO_TAG}" "${BITCOIN_REPO_URL}" "${BITCOIN_HOME}/${BITCOIN_REPO_NAME}"
echo "[*] Creating Bitcoin homedir"
sudo -H -i -u "${ROOT_USER}" mkdir "${BITCOIN_HOME}"
sudo -H -i -u "${ROOT_USER}" chown "${BITCOIN_USER}":"${BITCOIN_GROUP}" ${BITCOIN_HOME}
sudo -H -i -u "${BITCOIN_USER}" ln -s . .bitcoin

echo "[*] Building Bitcoin from source"
sudo -H -i -u "${BITCOIN_USER}" sh -c "cd ${BITCOIN_REPO_NAME} && ./autogen.sh --quiet && ./configure --quiet --disable-wallet --with-incompatible-bdb && make -j9"
echo "[*] Cloning Bitcoin repo"
sudo -H -i -u "${BITCOIN_USER}" git config --global advice.detachedHead false
sudo -H -i -u "${BITCOIN_USER}" git clone --branch "${BITCOIN_REPO_TAG}" "${BITCOIN_REPO_URL}" "${BITCOIN_HOME}/${BITCOIN_REPO_NAME}"

echo "[*] Installing Bitcoin into OS"
sudo -H -i -u "${ROOT_USER}" sh -c "cd ${BITCOIN_HOME}/${BITCOIN_REPO_NAME} && make install >/dev/null"
echo "[*] Building Bitcoin from source"
sudo -H -i -u "${BITCOIN_USER}" sh -c "cd ${BITCOIN_REPO_NAME} && ./autogen.sh --quiet && ./configure --quiet --disable-wallet --with-incompatible-bdb && make -j9"

echo "[*] Installing Bitcoin configuration"
sudo -H -i -u "${ROOT_USER}" install -c -o "${BITCOIN_USER}" -g "${BITCOIN_GROUP}" -m 644 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/bitcoin.conf" "${BITCOIN_HOME}/bitcoin.conf"
sudo -H -i -u "${ROOT_USER}" install -c -o "${BITCOIN_USER}" -g "${BITCOIN_GROUP}" -m 755 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/blocknotify.sh" "${BITCOIN_HOME}/blocknotify.sh"
echo "[*] Installing Bitcoin into OS"
sudo -H -i -u "${ROOT_USER}" sh -c "cd ${BITCOIN_HOME}/${BITCOIN_REPO_NAME} && make install >/dev/null"

echo "[*] Generating Bitcoin RPC credentials"
BITCOIN_RPC_USER=$(head -150 /dev/urandom | md5sum | awk '{print $1}')
sudo sed -i -e "s/__BITCOIN_RPC_USER__/${BITCOIN_RPC_USER}/" "${BITCOIN_HOME}/bitcoin.conf"
BITCOIN_RPC_PASS=$(head -150 /dev/urandom | md5sum | awk '{print $1}')
sudo sed -i -e "s/__BITCOIN_RPC_PASS__/${BITCOIN_RPC_PASS}/" "${BITCOIN_HOME}/bitcoin.conf"
echo "[*] Installing Bitcoin configuration"
sudo -H -i -u "${ROOT_USER}" install -c -o "${BITCOIN_USER}" -g "${BITCOIN_GROUP}" -m 644 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/bitcoin.conf" "${BITCOIN_HOME}/bitcoin.conf"
sudo -H -i -u "${ROOT_USER}" install -c -o "${BITCOIN_USER}" -g "${BITCOIN_GROUP}" -m 755 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/blocknotify.sh" "${BITCOIN_HOME}/blocknotify.sh"

echo "[*] Installing Bitcoin init scripts"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/bitcoin.service" "${SYSTEMD_SERVICE_HOME}"
echo "[*] Generating Bitcoin RPC credentials"
BITCOIN_RPC_USER=$(head -150 /dev/urandom | md5sum | awk '{print $1}')
sudo sed -i -e "s/__BITCOIN_RPC_USER__/${BITCOIN_RPC_USER}/" "${BITCOIN_HOME}/bitcoin.conf"
BITCOIN_RPC_PASS=$(head -150 /dev/urandom | md5sum | awk '{print $1}')
sudo sed -i -e "s/__BITCOIN_RPC_PASS__/${BITCOIN_RPC_PASS}/" "${BITCOIN_HOME}/bitcoin.conf"

echo "[*] Installing Bitcoin init scripts"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${ROOT_HOME}/${BISQ_REPO_NAME}/seednode/bitcoin.service" "${SYSTEMD_SERVICE_HOME}"

fi

echo "[*] Creating Bisq user with Tor access"
sudo -H -i -u "${ROOT_USER}" useradd -d "${BISQ_HOME}" -G "${TOR_GROUP}" "${BISQ_USER}"
Expand All @@ -104,11 +124,19 @@ sudo -H -i -u "${ROOT_USER}" "${BISQ_HOME}/${BISQ_REPO_NAME}/scripts/install_jav

echo "[*] Installing Bisq init script"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/seednode/bisq-seednode.service" "${SYSTEMD_SERVICE_HOME}/bisq-seednode.service"
if [ "${BITCOIN_INSTALL}" = true ];then
sudo sed -i -e "s/#Requires=bitcoin.service/Requires=bitcoin.service/" "${SYSTEMD_SERVICE_HOME}/bisq-seednode.service"
sudo sed -i -e "s/#BindsTo=bitcoin.service/BindsTo=bitcoin.service/" "${SYSTEMD_SERVICE_HOME}/bisq-seednode.service"
fi
sudo sed -i -e "s/__BISQ_REPO_NAME__/${BISQ_REPO_NAME}/" "${SYSTEMD_SERVICE_HOME}/bisq-seednode.service"
sudo sed -i -e "s!__BISQ_HOME__!${BISQ_HOME}!" "${SYSTEMD_SERVICE_HOME}/bisq-seednode.service"

echo "[*] Installing Bisq environment file with Bitcoin RPC credentials"
sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/seednode/bisq-seednode.env" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_P2P_HOST__/${BITCOIN_P2P_HOST}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_P2P_PORT__/${BITCOIN_P2P_PORT}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_RPC_HOST__/${BITCOIN_RPC_HOST}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_RPC_PORT__/${BITCOIN_RPC_PORT}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_RPC_USER__/${BITCOIN_RPC_USER}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s/__BITCOIN_RPC_PASS__/${BITCOIN_RPC_PASS}/" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
sudo sed -i -e "s!__BISQ_HOME__!${BISQ_HOME}!" "${SYSTEMD_ENV_HOME}/bisq-seednode.env"
Expand All @@ -123,7 +151,9 @@ echo "[*] Updating systemd daemon configuration"
sudo -H -i -u "${ROOT_USER}" systemctl daemon-reload
sudo -H -i -u "${ROOT_USER}" systemctl enable tor.service
sudo -H -i -u "${ROOT_USER}" systemctl enable bisq-seednode.service
sudo -H -i -u "${ROOT_USER}" systemctl enable bitcoin.service
if [ "${BITCOIN_INSTALL}" = true ];then
sudo -H -i -u "${ROOT_USER}" systemctl enable bitcoin.service
fi

echo "[*] Preparing firewall"
sudo -H -i -u "${ROOT_USER}" ufw default deny incoming
Expand All @@ -132,10 +162,12 @@ sudo -H -i -u "${ROOT_USER}" ufw default allow outgoing
echo "[*] Starting Tor"
sudo -H -i -u "${ROOT_USER}" systemctl start tor

echo "[*] Starting Bitcoin"
sudo -H -i -u "${ROOT_USER}" systemctl start bitcoin
sudo -H -i -u "${ROOT_USER}" journalctl --no-pager --unit bitcoin
sudo -H -i -u "${ROOT_USER}" tail "${BITCOIN_HOME}/debug.log"
if [ "${BITCOIN_INSTALL}" = true ];then
echo "[*] Starting Bitcoin"
sudo -H -i -u "${ROOT_USER}" systemctl start bitcoin
sudo -H -i -u "${ROOT_USER}" journalctl --no-pager --unit bitcoin
sudo -H -i -u "${ROOT_USER}" tail "${BITCOIN_HOME}/debug.log"
fi

echo "[*] Adding notes to motd"
sudo -H -i -u "${ROOT_USER}" sh -c 'echo " " >> /etc/motd'
Expand Down

0 comments on commit 41a8fed

Please sign in to comment.