Last active
September 8, 2018 09:18
-
-
Save hebasto/58ef15e2fb68fe16cbd9bd706b283cfe to your computer and use it in GitHub Desktop.
Convenient script to run Electrum on Tails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
#set -o xtrace | |
# | |
# start_electrum.sh | |
# | |
# This script launches Electrum Bitcoin Wallet on Tails OS. | |
# Ledger Nano S hardware wallet is supported. | |
# | |
# Tails 3.9 (2018-09-04), https://tails.boum.org | |
# Electrum 3.2.3 (2018-09-03), https://electrum.org | |
# Ledger Nano S Firmware 1.4.2 (2018-04-17), https://www.ledger.fr, https://www.ledger.com, https://www.ledgerwallet.com | |
# | |
# IMPORTANT NOTES about files location: | |
# 1) both files Electrum-x.y.z.tar.gz and Electrum-x.y.z.tar.gz.asc are downloaded | |
# to the ELECTRUM_DOWNLOAD_PATH='/home/amnesia/Persistent/Tor Browser/' folder; | |
# 2) add_udev_rules.sh file is dowloaded to the '/home/amnesia/Persistent/' folder, | |
# see: https://support.ledgerwallet.com/hc/en-us/articles/115005165269-Fix-connection-issues | |
### Ledger Nano S constants ### | |
# Only Ledger Nano S is supported. | |
readonly LNS_VENDORID_PRODUCTID='2c97:0001' | |
# https://support.ledgerwallet.com/hc/en-us/articles/115005165269-Fix-connection-issues | |
# https://github.com/LedgerHQ/udev-rules/blob/master/add_udev_rules.sh | |
readonly LNS_UDEV_RULES_FILE='/etc/udev/rules.d/20-hw1.rules' | |
readonly LNS_ADD_UDEV_RULES_SCRIPT='/home/amnesia/Persistent/add_udev_rules.sh' | |
### Electrum Bitcoin Wallet constants ### | |
readonly ELECTRUM_DOWNLOAD_PATH='/home/amnesia/Persistent/Tor Browser/' | |
readonly ELECTRUM_LOGFILE='/home/amnesia/Persistent/electrum.log' | |
# Electrum uses wallet files version 17 since release 3.2.0 (2018-06-30). | |
readonly ELECTRUM_DEFAULT_WALLET='/home/amnesia/.electrum/wallets/empty_wallet_version_17' | |
# Detect Ledger Nano S. | |
if [[ -z "$(lsusb -d "${LNS_VENDORID_PRODUCTID}")" ]]; then | |
echo 'Ledger Nano S has NOT been detected.' | |
echo 'If one is connected unlock it. Then run this script again.' | |
echo | |
echo 'Do you wish to:' | |
option_continue='continue without a hardware wallet?' | |
option_stop='stop and exit?' | |
PS3='Enter your choice (1 or 2) and press [ENTER]: ' | |
select option in "${option_continue}" "${option_stop}"; do | |
case "${option}" in | |
"${option_continue}") echo; break ;; | |
"${option_stop}") exit 0 ;; | |
esac | |
done | |
else | |
echo 'Ledger Nano S has been connected and unlocked.' | |
if [[ -f "${LNS_UDEV_RULES_FILE}" ]]; then | |
echo 'The udev rule for Ledger Nano S has been added already.' | |
else | |
echo 'The udev rule for Ledger Nano S will be added now.' | |
sudo "${LNS_ADD_UDEV_RULES_SCRIPT}" | |
fi | |
fi | |
# Check available Electrum versions. | |
installed_electrum_version="$(electrum version)" | |
echo "Installed: Electrum-"${installed_electrum_version}"" | |
archive="$(ls "${ELECTRUM_DOWNLOAD_PATH}"Electrum-*.tar.gz | tail -1)" | |
downloaded_electrum_name="$(basename "${archive}" .tar.gz)" | |
echo "Downloaded: "${downloaded_electrum_name}"" | |
# Untar downloaded Electrum archive. | |
if ! [[ -d ~/"${downloaded_electrum_name}" ]]; then | |
echo "Sources: "${archive}"" | |
n_files="$(tar xvf "${archive}" -C ~ | wc --lines)" | |
echo "Untared "${n_files}" files." | |
fi | |
cd ~/"${downloaded_electrum_name}" | |
# Run Electrum. | |
echo | |
echo 'Do you wish to:' | |
option_close="run "${downloaded_electrum_name}" and close Terminal?" | |
option_keep_open="run "${downloaded_electrum_name}" in Terminal?" | |
PS3='Enter your choice (1 or 2) and press [ENTER]: ' | |
select option in "${option_close}" "${option_keep_open}"; do | |
case "${option}" in | |
"${option_close}") | |
date > "${ELECTRUM_LOGFILE}" | |
nohup python3 run_electrum -v --wallet "${ELECTRUM_DEFAULT_WALLET}" >> "${ELECTRUM_LOGFILE}" & | |
sleep 5 | |
/bin/kill -KILL "${PPID}" | |
# Exit is here. | |
;; | |
"${option_keep_open}") | |
echo | |
echo 'run_electrum -v ...' | |
python3 run_electrum -v --wallet "${ELECTRUM_DEFAULT_WALLET}" | |
break | |
;; | |
esac | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment