Skip to content

Instantly share code, notes, and snippets.

@travishaynes
Created August 14, 2017 23:22
Show Gist options
  • Save travishaynes/a763873f9536795666c38e4405ae3750 to your computer and use it in GitHub Desktop.
Save travishaynes/a763873f9536795666c38e4405ae3750 to your computer and use it in GitHub Desktop.
A shell script to download and update Atom (atom.io) for Debian based operating systems.
#!/usr/bin/env bash
#
# Checks to see if atom.io has a newer stable release than what is currently
# installed, and updates it when necessary.
#
# Dependencies:
#
# * awk
# * curl
# * dpkg
# * sudo
# * wget
# Get the URL for downloading the latest version.
DOWNLOAD_URL=`
# Redirects to the latest stable release - fetching the document's HEAD.
curl https://atom.io/download/deb -Is | \
# Extract the URL of the location from the HTTP header.
awk 'BEGIN {FS=": "}/^Location/{print $2}'
`
# Get the version of Atom that is currently installed.
INSTALLED_VERSION=`
# Show the status of the installed version of Atom.
dpkg -s atom | \
# Find the status line that has the version number and get the version.
awk 'BEGIN {FS=": "}/^Version/{print $2}'
`
# Get the latest version of Atom.
LATEST_VERSION=`
# Pipe the download URL to awk.
echo $DOWNLOAD_URL | \
# Extract the version from the URL.
awk -F'/v' '{print $2}' | awk -F'/' '{print $1}'
`
# Check if the latest version is already installed.
if [ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]; then
echo "Latest stable release, $INSTALLED_VERSION, is already installed."
else
echo "Downloading Atom from atom.io ..."
wget https://atom.io/download/deb -O /tmp/atom.deb -q --show-progress
echo "Updating Atom from $INSTALLED_VERSION to $LATEST_VERSION"
sudo dpkg -i /tmp/atom.deb
# Delete the downloaded package from the tmp folder.
rm /tmp/atom.deb
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment