Last active
August 31, 2018 09:53
Star
You must be signed in to star a gist
updater for etcher.io
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 | |
# get current dir | |
prog_dir="/opt/$(ls /opt/ | grep etcher | grep -v zip)" | |
echo "DIR: $prog_dir" | |
prog_dir_version=$(echo $prog_dir | awk -F/ '{ print $3 }' | awk -F- '{ print $2 }') | |
if [ "$prog_dir_version" == "electron" ] | |
then | |
prog_dir_version=$(echo $prog_dir | awk -F/ '{ print $3 }' | awk -F- '{ print $3 }') | |
fi | |
echo "DIR Version: $prog_dir_version" | |
# get current url | |
prog_url=$(curl -s https://github.com/resin-io/etcher/releases | grep linux | grep 64 | grep zip | grep '\<a' | head -n1 | sed s/'.*href="'/'https:\/\/github.com'/ | sed s/'".*'/''/) | |
echo "URL: $prog_url" | |
prog_url_version=$(echo $prog_url | awk -F/ '{print $(NF-1)}' | sed s/'v'/''/) | |
echo "URL Version: $prog_url_version" | |
# check that a current version is found | |
if [ "$prog_dir_version" == "" ] | |
then | |
echo "New Installation! (no old version found)" | |
new_install="1" | |
fi | |
# check that a new version and url are found | |
if [ "$prog_url" == "" ] || [ "$prog_url_version" == "" ] | |
then | |
echo "couldn't find url for new version" | |
exit | |
fi | |
# check current dir version with current url version | |
if [ "$prog_dir_version" != "$prog_url_version" ] | |
then | |
if [ "$new_install" != "1" ] | |
then | |
echo "New Version Found!" | |
fi | |
cd /opt/ | |
# download | |
wget --quiet --show-progress -O etcher.zip $prog_url | |
# unpack zip | |
unzip etcher.zip | |
# remove download | |
rm etcher.zip | |
# remove old version | |
if [ "$new_install" != "1" ] | |
then | |
if [ -f ./etcher-$prog_dir_version-x86_64.AppImage ] | |
then | |
rm ./etcher-$prog_dir_version-x86_64.AppImage | |
fi | |
if [ -f ./etcher-electron-$prog_dir_version-x86_64.AppImage ] | |
then | |
rm ./etcher-electron-$prog_dir_version-x86_64.AppImage | |
fi | |
fi | |
# run etcher | |
if [ "$new_install" == "1" ] | |
then | |
./etcher-electron-$prog_url_version-x86_64.AppImage & | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment