Created
November 20, 2015 22:37
-
-
Save Cxarli/77faa0781ff0cbd7ed86 to your computer and use it in GitHub Desktop.
An updater for Atom.
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 | |
latest=`curl -i "https://github.com/atom/atom/releases/latest" 2>/dev/null | grep "Location: " | cut -d' ' -f2 ` | |
downloadurl=`echo -n "$latest" | sed 's/tag/download/g' | sed 's/$/\/atom-amd64.deb/g' | tr -d '\r'` | |
version=`echo "$latest" | grep -Eo "v([0-9]+\.){1,}([0-9]+)"` | |
# Check if file exists | |
if [ -e .atom-version ]; then | |
curver=`cat .atom-version` | |
else | |
curver="unknown" | |
fi | |
echo "Latest version is $version." | |
echo "Current version is $curver." | |
echo | |
if [ "$curver" = "$version" ]; then | |
# Same version as downloaded version | |
echo "You're already using the latest version!" | |
else | |
# Download new version | |
if [ -e "atom-amd64-$version.deb" ]; then | |
echo "Latest version already downloaded." | |
else | |
echo "Downloading new version..." | |
wget -O "atom-amd64-$version.deb" "$downloadurl" | |
fi | |
echo | |
# Install | |
echo "Installing new version..." | |
dpkg -i "atom-amd64-$version.deb" | |
exitcode=$? | |
echo | |
if [ $exitcode -ne 0 ]; then | |
# Failed to Install | |
echo "Failed to install atom. Are you running with sudo?" | |
else | |
# Update version file | |
echo "Succesfully installed latest version!" | |
echo "$version" > .atom-version | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment