More WIP on new installation scripts

This commit is contained in:
wiz 2020-10-23 13:35:20 +09:00
parent ea0572384b
commit ccd740befb
No known key found for this signature in database
GPG Key ID: A394E332255A6173
8 changed files with 290 additions and 39 deletions

View File

@ -786,7 +786,7 @@ osSudo "${ROOT_USER}" chown "${BITCOIN_USER}:${BITCOIN_GROUP}" "${BITCOIN_ELECTR
echo "[*] Cloning Bitcoin Electrs repo from ${BITCOIN_ELECTRS_REPO_URL}"
osSudo "${BITCOIN_USER}" git config --global advice.detachedHead false
osSudo "${BITCOIN_USER}" git clone --branch "${ELECTRS_REPO_BRANCH}" "${ELECTRS_REPO_URL}" "${MEMPOOL_HOME}/${MEMPOOL_REPO_NAME}"
osSudo "${BITCOIN_USER}" git clone --branch "${ELECTRS_REPO_BRANCH}" "${ELECTRS_REPO_URL}" "${BITCOIN_HOME}/${ELECTRS_REPO_NAME}"
echo "[*] Installing Rust from rustup.rs"
osSudo "${BITCOIN_USER}" sh -c "cd ${BITCOIN_ELECTRS_HOME} && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"

172
production/bitcoind.freebsd Normal file
View File

@ -0,0 +1,172 @@
#!/bin/sh
# $FreeBSD: branches/2020Q2/net-p2p/bitcoin/files/bitcoind.in 488524 2018-12-27 09:53:37Z ale $
# PROVIDE: bitcoind
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable :
# bitcoind_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable bitcoind
# bitcoind_user (str) Set to "bitcoin" by default.
# bitcoind_group (str) Set to "bitcoin" by default.
# bitcoind_conf (str) Set to "/usr/local/etc/bitcoind.conf" by default.
# bitcoind_data_dir (str) Set to "/var/db/bitcoin" by default.
# bitcoindlimits_enable (bool) Set to "NO" by default.
# Set it to "YES" to enable bitcoindlimits
# bitcoindlimits_args Set to "-e -U ${bitcoind_user}" by default
. /etc/rc.subr
name="bitcoind"
rcvar=bitcoind_enable
start_precmd="bitcoind_precmd"
start_cmd="bitcoind_start"
restart_precmd="bitcoind_checkconfig"
reload_precmd="bitcoind_checkconfig"
configtest_cmd="bitcoind_checkconfig"
status_cmd="bitcoind_status"
stop_cmd="bitcoind_stop"
stop_postcmd="bitcoind_wait"
command="/usr/local/bin/bitcoind"
daemon_command="/usr/sbin/daemon"
pidfile="/var/run/${name}.pid"
extra_commands="configtest"
: ${bitcoind_enable:="NO"}
: ${bitcoindlimits_enable:="NO"}
load_rc_config ${name}
: ${bitcoind_user:="bitcoin"}
: ${bitcoind_group:="bitcoin"}
: ${bitcoind_data_dir:="/var/db/bitcoin"}
: ${bitcoind_config_file:="/usr/local/etc/bitcoin.conf"}
: ${bitcoindlimits_args:="-e -U ${bitcoind_user}"}
# set up dependant variables
procname="${command}"
#pidfile="${bitcoind_data_dir}/bitcoind.pid"
required_files="${bitcoind_config_file}"
bitcoind_checkconfig()
{
echo "Performing sanity check on bitcoind configuration:"
if [ ! -d "${bitcoind_data_dir}" ]
then
echo "Missing data directory: ${bitcoind_data_dir}"
exit 1
fi
chown -R "${bitcoind_user}:${bitcoind_group}" "${bitcoind_data_dir}"
if [ ! -f "${bitcoind_config_file}" ]
then
echo "Missing configuration file: ${bitcoind_config_file}"
exit 1
fi
if [ ! -x "${command}" ]
then
echo "Missing executable: ${command}"
exit 1
fi
return 0
}
bitcoind_cleanup()
{
rm -f "${pidfile}"
}
bitcoind_precmd()
{
bitcoind_checkconfig
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
rm -f "${pidfile}"
fi
if checkyesno bitcoindlimits_enable
then
eval $(/usr/bin/limits ${bitcoindlimits_args}) 2>/dev/null
else
return 0
fi
}
bitcoind_status()
{
local pid
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
echo "Bitcoind running, pid: ${pid}"
fi
}
bitcoind_start()
{
echo "Starting bitcoind:"
cd "${bitcoind_data_dir}" || return 1
${daemon_command} -u "${bitcoind_user}" -p "${pidfile}" -f \
${command} \
-conf="${bitcoind_config_file}" \
-datadir="${bitcoind_data_dir}"
}
bitcoind_stop()
{
echo "Stopping bitcoind:"
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
kill ${pid}
fi
}
bitcoind_wait()
{
local n=60
echo "Waiting for bitcoind shutdown:"
while :
do
printf '.'
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
printf '\n'
break
fi
sleep 1
n=$((${n} - 1))
if [ ${n} -eq 0 -a -f "${pidfile}" ]
then
printf "\nForce shutdown"
kill -9 $(cat "${pidfile}")
for n in 1 2 3
do
printf '.'
sleep 1
done
printf '\n'
break
fi
done
rm -f "${pidfile}"
echo "Shutdown complete"
}
run_rc_command "$1"

View File

@ -0,0 +1,46 @@
#!/usr/local/bin/zsh
# add rust and llvm90 to rpi pkg
# load rust cargo if installed from rustup
if [ -f "${HOME}/.cargo/env" ];then
source "${HOME}/.cargo/env"
export PATH="${HOME}/.cargo/bin:${PATH}"
fi
# detect architecture
case `uname -m` in
amd64)
TARGET=x86_64-unknown-freebsd
;;
arm64) # rpi4
TARGET=aarch64-unknown-freebsd
;;
*)
echo "Error: Unknown Architecture!"
exit 1
esac
# run electrs in a loop
until false
do
# patch electrs source if necessary
cd "${HOME}"/.cargo/registry/src/github.com-*/sysconf-0.3.*/
patch -p1 < "$HOME/sysconf.patch"
# go home
cd "${HOME}/electrs"
cargo build \
--target "${TARGET}" \
--release \
--bin electrs \
-- \
-vvvv \
--address-search \
--daemon-dir "${HOME}" \
--http-addr '[::]:3000' \
--cookie "${BITCOIN_MAINNET_RPC_USER}:${BITCOIN_MAINNET_RPC_PASS}" \
--precache-scripts "${HOME}/electrs/contrib/popular-scripts.txt"
sleep 1
done
exit 0

View File

@ -0,0 +1,58 @@
#!/usr/local/bin/zsh
# TODO: add rust and llvm90 to installer pkg list if rpi4 arch detected
# TODO: add network as argument
# TODO: get env vars from global settings file for RPC, etc.
# TODO: patch to disable compaction if settings wants that
# load rust cargo if installed from rustup
if [ -f "${HOME}/.cargo/env" ];then
source "${HOME}/.cargo/env"
export PATH="${HOME}/.cargo/bin:${PATH}"
fi
# detect architecture
case `uname -m` in
amd64)
export TARGET=x86_64-unknown-freebsd
;;
arm64)
# need to compile rustc with target set for rpi4 etc.
export TARGET=aarch64-unknown-freebsd
# NB: need to load libgcc_s.so from gcc9 instead of /lib !!
export LD_LIBRARY_PATH=/usr/local/lib/gcc9
;;
*)
echo "Error: Unknown Architecture!"
exit 1
esac
# run electrs in a loop
until false
do
# patch electrs source
# if file exists and grep contains strings, patch it
cd "${HOME}"/.cargo/registry/src/github.com-*/sysconf-0.3.*/
patch -p1 < sysconf.patch
# go home
cd "${HOME}/electrs"
cargo run \
--target "${TARGET}" \
--release \
--bin electrs \
-- \
-vvvv \
--light-mode \
--address-search \
--db-dir /electrs \
--daemon-dir "${HOME}" \
--http-addr '[::]:3000' \
--cookie "${BITCOIN_MAINNET_RPC_USER}:${BITCOIN_MAINNET_RPC_PASS}" \
--precache-scripts "${HOME}/electrs/contrib/popular-scripts.txt"
sleep 1
done
exit 0

View File

@ -1,19 +0,0 @@
#!/usr/local/bin/zsh
cd /electrs
source $HOME/.cargo/env
export PATH=$HOME/.cargo/bin:$PATH
until false
do
cargo run \
--release \
--bin electrs \
-- \
-vvvv \
--address-search \
--daemon-dir /bitcoin \
--http-addr '[::]:3000' \
--cookie 'user:pass' \
--precache-scripts /electrs/contrib/popular-scripts.txt
sleep 1
done

View File

@ -1,19 +0,0 @@
#!/usr/local/bin/zsh
cd /electrs
source $HOME/.cargo/env
export PATH=$HOME/.cargo/bin:$PATH
until false
do
cargo run \
--release \
--bin electrs \
-- \
-vv \
--network testnet \
--daemon-dir /bitcoin \
--http-addr '[::]:3002' \
--cookie 'user:pass' \
--precache-scripts /electrs/contrib/popular-scripts.txt
sleep 1
done

12
production/sysconf.patch Normal file
View File

@ -0,0 +1,12 @@
--- a/src/raw.rs 2020-10-22 05:59:43.747207000 +0000
+++ b/src/raw2.rs 2020-10-22 06:00:04.016688000 +0000
@@ -82,9 +82,6 @@
Sc2CharTerm = sc!(_SC_2_CHAR_TERM),
Sc2CVersion = 96, // TODO(joshlf): Switch to a libc constant once it's added
Sc2Upe = sc!(_SC_2_UPE),
- ScXbs5Ilp32Off32 = sc!(_SC_XBS5_ILP32_OFF32),
- ScXbs5Ilp32Offbig = sc!(_SC_XBS5_ILP32_OFFBIG),
- ScXbs5LpbigOffbig = sc!(_SC_XBS5_LPBIG_OFFBIG),
}
/// Query the system's configuration.

View File

@ -5,6 +5,7 @@ Log notice syslog
CookieAuthentication 1
CookieAuthFileGroupReadable 1
CookieAuthFile /var/db/tor/control_auth_cookie
DataDirectoryGroupReadable 1
HiddenServiceDir /var/db/tor/mempool