Peter Lyons

Atom Self-Update Script

August 08, 2016

My work setup requires a non-administrator account for normal login. I have sudo access set up for my normal user. For some reason, Atom's autoupdate feature can't seem to deal with this and gets stuck in a loop trying to install updates. So I just scripted it as below:

update_atom() {
  local atom="${HOME}Downloads/"
  echo -n "downloading…"
  curl --silent --fail --location '' > "${atom}"
  echo "✓"
  local version
  version=$(unzip -p "${atom}" \
    | grep -A 1 -i CFBundleVersion \
    | grep string \
    | tr -d -c 0-9.)
  echo -n "install Atom ${version}? (y/n): "
  if [[ -n "${ZSH_VERSION}" ]]; then
    read -q confirm
    read -n 1 confirm
  if [[ "${confirm}" != "y" ]]; then
    return 1
  echo -n "installing…"
  sudo rm -rf /Applications/
  sudo unzip -q -d /Applications "${atom}"
  sudo chown -R "${USER}" /Applications/
  echo -n "✓"