setup_testnet_nis.sh
#!/bin/bash
NIS_URL=http://localhost:7890
BASE_URL=http://www.nem.ninja
TMP_DIR=.cache-testnet
BLOCK_SIZE=835k
VERSION=0.6.86
API_CURL_OPTS='-s -H "Accept: application/json" -H "Content-Type: application/json"'
[ ! -e $TMP_DIR ] && mkdir $TMP_DIR
# NEM!
if [ -e $TMP_DIR/README.txt ]; then
cat $TMP_DIR/README.txt
else
curl -s $BASE_URL/beta-testnet/README.txt | tee $TMP_DIR/README.txt
fi
# Are you sure?
# download files
[ ! -e $TMP_DIR/nis-ncc-$VERSION.tgz ] ¥
&& curl -o $TMP_DIR/nis-ncc-$VERSION.tgz $BASE_URL/beta-testnet/nis-ncc-$VERSION.tgz
# extract files
tar zxf $TMP_DIR/nis-ncc-$VERSION.tgz
# download db
[ ! -e $TMP_DIR/nis5_testnet-$BLOCK_SIZE.h2.db.zip ] ¥
&& curl -o $TMP_DIR/nis5_testnet-$BLOCK_SIZE.h2.db.zip $BASE_URL/beta-testnet/nis5_testnet-$BLOCK_SIZE.h2.db.zip
[ ! -e $HOME/nem/nis/data ] ¥
&& mkdir -p $HOME/nem/nis/data
[ ! -e $HOME/nem/nis/data/nis5_testnet.h2.db ] ¥
&& unzip $TMP_DIR/nis5_testnet-$BLOCK_SIZE.h2.db.zip -d $HOME/nem/nis/data/
## custom harvest.sh
cat << __EOD__ > package/harvest.with_wait.sh
#!/bin/bash
if [ ¥$# -ne 1 ]; then
echo "you need to provide private key";
exit 1
fi
key=¥`echo ¥$1 | sed 's/[0-9a-fA-F]*//'¥`
if [ -n "¥$key" ];
then
echo "provided key must be in hexadecimal format"
exit 2
fi
# additional script { ----
echo -n "waiting for NIS to recieve request."
until (curl -m 1s $API_CURL_OPTS $NIS_URL/status | grep -ioE '"code":6' > /dev/null); do
echo -n "."
sleep 1s
done
# ---- }
curl $API_CURL_OPTS -d "{'value':'¥$1'}" $NIS_URL/account/unlock
__EOD__
chmod +x package/harvest.with_wait.sh
## custom nix.runNis.sh
cat << __EOD__ > package/nix.runNis.with_start_harvesting.sh
#!/bin/bash
cd nis
java -Xms512M -Xmx1G -cp ".:./*:../libs/*" org.nem.deploy.CommonStarter
cd -
# additional script { ----
./harvest.with_wait.sh 'private key' > /dev/null 2>&1 &
# ---- }
__EOD__
chmod +x package/nix.runNis.with_start_harvesting.sh
# create nis.service for systemd
cat << __EOD__ > $TMP_DIR/nis.service
[Unit]
Description = NEM Infrastructure Server
[Service]
ExecStart=$HOME/package/nix.runNis.with_start_harvesting.sh
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
__EOD__
# enable nis.service
# sudo mv $TMP_DIR/nis.service /etc/systemd/system/