nis_testnet_setup.sh
#!/bin/bash
# curl -kL ${RAW_SOURCE_ADDRESS} | bash
BASE_URL=https://nem.ninja
TMP_DIR=.cache-testnet
BLOCK_SIZE=835k
VERSION=0.6.95
java -version 2>&1 | grep 1.8
[ $? -eq 1 ] && apt-get update && apt-get install openjdk-8-jre -y
[ ! -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
# download files
[ ! -e $TMP_DIR/nis-$VERSION.tgz ] \
&& curl -o $TMP_DIR/nis-$VERSION.tgz $BASE_URL/beta-testnet/nis-$VERSION.tgz
# extract files
tar zxf $TMP_DIR/nis-$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 ] \
&& jar xf $TMP_DIR/nis5_testnet-$BLOCK_SIZE.h2.db.zip && mv nis5_testnet.h2.db $HOME/nem/nis/data/
# create nis.service for systemd
cat << __EOD__ > $TMP_DIR/nis.service
[Unit]
Description = NEM Infrastructure Server
[Service]
WorkingDirectory=$HOME/package/
ExecStart=$HOME/package/nix.runNis.sh
Restart=always
Type=simple
[Install]
WantedBy=multi-user.target
__EOD__
# enable nis.service
mv $TMP_DIR/nis.service /etc/systemd/system/
systemctl enable nis
systemctl start nis
# preparing for https
add-apt-repository ppa:gslin/dehydrated
apt-get update && apt-get install stunnel4 dehydrated -y --allow-unauthenticated