Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check and download (update) last electrum version, backup wallet. Linux Only
#!/bin/bash
# Exit if any errors
set -e
# Working directory
cd "$HOME"
# Check curl command
if ! [ -x "$(command -v curl)" ]; then
echo "could not find curl"
exit 1
fi
# Check last source version from github
echo "Fetch last version from github ..."
lastversion=$(curl -s https://raw.githubusercontent.com/spesmilo/electrum/master/lib/version.py | head -1 | awk {'print substr($3, 2, length($3)-2)'})
lastversion_source="https://download.electrum.org/$lastversion/Electrum-$lastversion.tar.gz"
# Check if installed version the same as fetched
if [ -x "$(command -v electrum)" ]; then
installed_version=$(echo $($(which electrum) version))
if [ "$installed_version" == "$lastversion" ]; then
echo -e "Installed version $installed_version equal last version $lastversion \n"
exit 1
fi
fi
if curl --output /dev/null --silent --head --fail "$lastversion_source"; then
echo "There is $lastversion version"
echo "Download electrum $lastversion wallet source ..."
else
echo "Could not find version: $lastversion on the https://download.electrum.org/"
exit 1
fi
# Download last version
echo -n "Install download electrum $lastversion (y/n)?"
read download_electrum
if echo "$download_electrum" | grep -iq "^y" ;then
dest="$HOME/electrum_$lastversion_$(date '+%Y-%m-%d_%H:%M:%S')"
mkdir -p $dest
curl -s $lastversion_source | tar xz --directory $dest
echo -n "Backup current wallet (y/n)?"
read backup_electrum
if echo "$backup_electrum" | grep -iq "^y" ;then
echo "Backup old electrum version ..."
cp -R "$HOME/.electrum" "$HOME/electrum_wallet_backup"
mv electrum_wallet_backup "$dest"
rm -rf "$HOME/electrum_wallet_backup"
echo "Electrum wallet has been backuped to the '$dest'"
fi
echo "The new version '$lastversion' downloaded to the folder '$dest'"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.