#!/bin/bash set -e # https://github.com/cryptoadvance/specter-desktop # ~/.config/btc-rpc-explorer.env # https://github.com/janoside/btc-rpc-explorer/blob/master/.env-sample # command info if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "small config script to switch cryptoadvance specter on or off" echo "bonus.cryptoadvance-specter.sh [status|on|off]" exit 1 fi source /mnt/hdd/raspiblitz.conf # show info menu if [ "$1" = "menu" ]; then # get status echo "# collecting status info ... (please wait)" source <(sudo /home/admin/config.scripts/bonus.cryptoadvance-specter.sh status) # get network info localip=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') toraddress=$(sudo cat /mnt/hdd/tor/cryptoadvance-specter/hostname 2>/dev/null) fingerprint=$(openssl x509 -in /home/bitcoin/.specter/cert.pem -fingerprint -noout | cut -d"=" -f2) if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then # TOR /home/admin/config.scripts/blitz.lcd.sh qr "${toraddress}" whiptail --title " Cryptoadvance Specter " --msgbox "Open in your local web browser & accept self-signed cert: https://${localip}:25441 SHA1 Thumb/Fingerprint: ${fingerprint} Login with the Pin being Password B. If you have connected to a different Bitcoin RPC Endpoint, the Pin is the configured RPCPassword. Hidden Service address for TOR Browser (QR see LCD): https://${toraddress}\n " 17 74 /home/admin/config.scripts/blitz.lcd.sh hide else # IP + Domain whiptail --title " Cryptoadvance Specter " --msgbox "Open in your local web browser & accept self-signed cert: https://${localip}:25441 SHA1 Thumb/Fingerprint: ${fingerprint} Login with the Pin being Password B. If you have connected to a different Bitcoin RPC Endpoint, the Pin is the configured RPCPassword.\n Activate TOR to access the web block explorer from outside your local network. Unfortunately the camera is currently not usable via Tor, though. " 15 54 fi echo "# please wait ..." exit 0 fi # add default value to raspi config if needed if ! grep -Eq "^specter=" /mnt/hdd/raspiblitz.conf; then echo "specter=off" >> /mnt/hdd/raspiblitz.conf fi # status if [ "$1" = "status" ]; then if [ "${specter}" = "on" ]; then echo "configured=1" # check for error isDead=$(sudo systemctl status cryptoadvance-specter | grep -c 'inactive (dead)') if [ ${isDead} -eq 1 ]; then echo "error='Service Failed'" exit 1 fi else echo "configured=0" fi exit 0 fi # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "# --> INSTALL Cryptoadvance Specter ***" isInstalled=$(sudo ls /etc/systemd/system/cryptoadvance-specter.service 2>/dev/null | grep -c 'cryptoadvance-specter.service' || /bin/true) if [ ${isInstalled} -eq 0 ]; then echo "# --> Enable wallets in Bitcoin Core" /home/admin/config.scripts/network.wallet.sh on echo "# --> Installing prerequisites" sudo apt install -y libusb-1.0.0-dev libudev-dev virtualenv # activating Authentication here ... echo "# --> creating App-config" cat > /home/admin/config.json < creating a virtualenv" sudo -u bitcoin virtualenv --python=python3 /home/bitcoin/.specter/.env echo "# --> pip-installing specter" sudo -u bitcoin /home/bitcoin/.specter/.env/bin/python3 -m pip install --upgrade cryptoadvance.specter==0.5.5 # Mandatory as the camera doesn't work without https echo "# --> Creating self-signed certificate" openssl req -x509 -newkey rsa:4096 -nodes -out /tmp/cert.pem -keyout /tmp/key.pem -days 365 -subj "/C=US/ST=Nooneknows/L=Springfield/O=Dis/CN=www.fakeurl.com" sudo mv /tmp/cert.pem /home/bitcoin/.specter sudo chown -R bitcoin:bitcoin /home/bitcoin/.specter/cert.pem sudo mv /tmp/key.pem /home/bitcoin/.specter sudo chown -R bitcoin:bitcoin /home/bitcoin/.specter/key.pem # open firewall echo "# --> Updating Firewall" sudo ufw allow 25441 comment 'cryptoadvance-specter' sudo ufw --force enable echo "" echo "# --> Installing udev-rules for hardware-wallets" cat > /home/admin/20-hw1.rules < /home/admin/51-coinkite.rules < KERNEL=="hidraw*", ATTRS{idVendor}=="d13e", ATTRS{idProduct}=="cc10", GROUP="plugdev", MODE="0666" EOF cat > /home/admin/51-trezor.rules < /home/admin/51-usb-keepkey.rules < Install cryptoadvance-specter systemd service" cat > /home/admin/cryptoadvance-specter.service < OK - the cryptoadvance-specter service is now enabled and started" else echo "# --> cryptoadvance-specter already installed." fi # setting value in raspi blitz config sudo sed -i "s/^specter=.*/specter=on/g" /mnt/hdd/raspiblitz.conf # Hidden Service for SERVICE if Tor is active source /mnt/hdd/raspiblitz.conf if [ "${runBehindTor}" = "on" ]; then # make sure to keep in sync with internet.tor.sh script # port 25441 is HTTPS with self-signed cert - specte only makes sense to be served over HTTPS /home/admin/config.scripts/internet.hiddenservice.sh cryptoadvance-specter 443 25441 fi exit 0 fi # switch off if [ "$1" = "0" ] || [ "$1" = "off" ]; then # setting value in raspi blitz config sudo sed -i "s/^specter=.*/specter=off/g" /mnt/hdd/raspiblitz.conf # Hidden Service if Tor is active if [ "${runBehindTor}" = "on" ]; then /home/admin/config.scripts/internet.hiddenservice.sh off cryptoadvance-specter fi isInstalled=$(sudo ls /etc/systemd/system/cryptoadvance-specter.service 2>/dev/null | grep -c 'cryptoadvance-specter.service') if [ ${isInstalled} -eq 1 ]; then echo "# --> REMOVING Cryptoadvance Specter" sudo systemctl stop cryptoadvance-specter sudo systemctl disable cryptoadvance-specter sudo rm /etc/systemd/system/cryptoadvance-specter.service sudo -u bitcoin /home/bitcoin/.specter/.env/bin/python3 -m pip uninstall --yes cryptoadvance.specter if whiptail --defaultno --yesno "Do you want to delete all Data related to specter? This includes also Bitcoin-Core-Wallets managed by specter?" 0 0; then echo "# --> Removing wallets in core" bitcoin-cli listwallets | jq -r .[] | tail -n +2 for i in $(bitcoin-cli listwallets | jq -r .[] | tail -n +2) do name=$(echo $i | cut -d"/" -f2) bitcoin-cli unloadwallet specter/$name done sudo rm -rf /home/bitcoin/.bitcoin/specter echo "# --> Removing /home/bitcoin/.specter" sudo rm -rf /home/bitcoin/.specter fi echo "# --> OK Cryptoadvance Specter removed." else echo "# --> Cryptoadvance Specter is not installed." fi exit 0 fi echo "error='unknown parameter'" exit 1