#!/bin/bash
echo "Regenerating SSH keys..."
rm /etc/ssh/ssh_host_*
/usr/sbin/dpkg-reconfigure openssh-server

echo "Creating CJDNS key..."
keystr=$(/opt/cjdns/makekeys | head -1)
keyarr=($keystr)
prikey=${keyarr[0]}
pubkey=${keyarr[2]}
ipv6=${keyarr[1]}
pass=$(/opt/cjdns/mkpasswd)
sed -i -E "s/\"privateKey\":\s+\"(.*)\"/\"privateKey\": \"$prikey\"/" /etc/cjdroute.conf
sed -i -E "0,/\"publicKey\":\s+\"(.*)\"/s/\"publicKey\":\s+\"(.*)\"/\"publicKey\": \"$pubkey\"/" /etc/cjdroute.conf
sed -i -E "0,/\"ipv6\":\s+\"(.*)\"/s/\"ipv6\":\s+\"(.*)\"/\"ipv6\": \"$ipv6\"/" /etc/cjdroute.conf
sed -i -E "s/\{\"password\": \"(.*)\", \"user\": \"default-login\"\}/\{\"password\": \"$pass\", \"user\": \"default-login\"\}/" /etc/cjdroute.conf
