Skip to content

Instantly share code, notes, and snippets.

@RogueScholar
Last active October 6, 2023 01:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RogueScholar/e15127b5c43ba79d75c3db399c34a523 to your computer and use it in GitHub Desktop.
Save RogueScholar/e15127b5c43ba79d75c3db399c34a523 to your computer and use it in GitHub Desktop.
POSIX script to update keybase package to latest nightly on Debian-based Linux
#!/usr/bin/env bash
# Keybase publishes a JSON file concurrent with every nightly build upload to their public download web server,
# though they're real cute in the way they parse the timestamp as a UNIX epoch...in milliseconds :-/ That means
# we need to fuss with rounding errors in Bash built-in computations on top of using jq as a parser for the raw
# file instead of what I expected to be some quick "awk-to-humantime-to-apt" pipeline-foo. Still it came out
# fairly snappy and is solid as a rock.
# Set this up as a cron job at the interval of your choosing, it won't do anything until it sees that the
# installed version reported by apt has an older timestamp than the one in the JSON file. When that happens it
# does an unattended update and as a bonus also calls HardCode-Tray (Google it, it's good) to shove another
# tray/panel icon up its Electron-based backside, since the one they include doesn't scale and looks like shit
# on KDE Plasma 5. (At least I think so...)
NIGHTLY_URL="https://prerelease.keybase.io/nightly"
NIGHTLY_EPOCH="$(curl -s -n ${NIGHTLY_URL}/update-linux-prod.json | jq '.publishedAt')"
((NIGHTLY_EPOCH += 500))
((NIGHTLY_EPOCH /= 1000))
NIGHTLY_DATE="$(date -ud @"${NIGHTLY_EPOCH}" +%Y%m%d%H%M%S)"
INSTALLED_DATE="$(sudo -u "$SUDO_USER" keybase version | grep -Po '(?<=^Client:\s{2}[\.\d]{5}-)\d{14}(?=\+[\d|a-f]+)')"
WORKING_DIR="/tmp/keybase_nightly"
NIGHTLY_DEB="${WORKING_DIR}/keybase_amd64_nightly_${NIGHTLY_DATE}.deb"
DARK_THEME="Papirus-Dark"
LIGHT_THEME="Papirus"
if [ "$NIGHTLY_DATE" -gt "$INSTALLED_DATE" ]; then
echo "Installed version: $INSTALLED_DATE Newer version found: $NIGHTLY_DATE"
logger --tag keybase-nightly --id=$PPID "Found new Keybase client nightly release; commencing download and installation process."
mkdir -p "${WORKING_DIR}" && wget -O "${NIGHTLY_DEB}" "${NIGHTLY_URL}"/keybase_amd64.deb
dpkg -i "${NIGHTLY_DEB}" || (
echo "Unable to install package, file saved to ${NIGHTLY_DEB}."
exit 1
)
if [ -d /srv/local-apt-repository ]; then
rm -f /srv/local-apt-repository/keybase_amd64_nightly*
mv -f "${NIGHTLY_DEB}" /srv/local-apt-repository && /usr/lib/local-apt-repository/rebuild
fi
rm -rf "${WORKING_DIR}" || echo "Unable to delete the working directory at ${WORKING_DIR}."
if [ -x /usr/bin/hardcode-tray ]; then
hardcode-tray -s 22 -ct RSVGConvert -dt "${DARK_THEME}" -lt "${LIGHT_THEME}" -o keybase -a
fi
# sudo -u "$SUDO_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$SUDO_USER")" \
# DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u "$SUDO_USER")/bus" \
# systemctl --user restart keybase.gui.service
logger --tag keybase-nightly --id=$PPID "Successfully installed new Keybase client nightly release."
else
echo "You already have the latest version : $INSTALLED_DATE"
logger --tag keybase-nightly --id=$PPID "Checking Keybase client nightly version...latest nightly already installed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment