Skip to content

Instantly share code, notes, and snippets.

@rmeleromira
Created April 25, 2018 20:27
Show Gist options
  • Save rmeleromira/90826e63d1611fea787d08f69a3e327d to your computer and use it in GitHub Desktop.
Save rmeleromira/90826e63d1611fea787d08f69a3e327d to your computer and use it in GitHub Desktop.
root@cryptomn:~# cat clone2.sh
#!/bin/bash
set -x
template=$1
new=$2
fqdn=$3
stake=$4
newip=$5
echo "copying container $template to $new"
lxc-copy -n $1 -N $2
echo "populating fqdn $fqdn"
echo -n $fqdn > /var/lib/lxc/$new/rootfs/home/zend/secnodetracker/config/fqdn
echo "removing nodeid"
rm /var/lib/lxc/$new/rootfs/home/zend/secnodetracker/config/nodeid
echo "removing wallet"
rm /var/lib/lxc/$new/rootfs/home/zend/.zen/wallet.dat
echo "populating stake address $stake"
echo $stake > /var/lib/lxc/$new/rootfs/home/zend/secnodetracker/config/stakeaddr
echo "setting $newip ipv6 address"
echo "templating interfaces file"
cat <<EOF > /var/lib/lxc/$new/rootfs/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
iface eth0 inet6 static
address $newip
netmask 112
gateway xxxx:xxxx:xxxx:xxxx:c:c:c:1
EOF
echo "templating zen.conf"
cat <<EOF > /var/lib/lxc/$new/rootfs/home/zend/.zen/zen.conf
rpcuser=secureuser
rpcpassword=securepassword
rpcport=18231
rpcallowip=127.0.0.1
bind=[$newip]:9033
server=1
daemon=1
listen=1
txindex=1
logtimestamps=1
### testnet config
#testnet=1
tlskeypath=/home/zend/.acme.sh/$fqdn/$fqdn.key
tlscertpath=/home/zend/.acme.sh/$fqdn/$fqdn.cer
EOF
echo "turning on autostart"
sed -i "s/lxc.start.auto = 0/lxc.start.auto = 1/" /var/lib/lxc/$new/config
echo "starting node $new"
lxc-start --name $new
echo "stopping zend and tracker"
lxc-attach --name $new -- sudo systemctl stop secnodetracker
lxc-attach --name $new -- sudo systemctl stop zend
sleep 5
echo "getting ssl certificate"
lxc-attach --name $new -- su zend -c "sudo ~/.acme.sh/acme.sh --issue --standalone -d $fqdn --listen-v6"
echo "start and wait for zend"
lxc-attach --name $new -- sudo systemctl restart zend
while true
do
lxc-attach --name $new -- zen-cli getinfo | grep blocks && break
sleep 3
done
echo "generate t and z address"
lxc-attach --name $new -- zen-cli z_getnewaddress
echo "start tracker"
lxc-attach --name $new -- sudo systemctl restart secnodetracker
#./clone.sh name_of_container_to_copy new_container_name your.fqdn.com znstakeaddress xxxx:xxxx:xxxx:xxxx:c:c:c:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment