-
-
Save b-/7cc1e24f35ec2485d1137f6d358cc7a1 to your computer and use it in GitHub Desktop.
POSIX script to update keybase package to latest nightly on Distrobox
This file contains hidden or 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
#!/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="$( keybase version | grep -Po '(?<=^Client:\s{2}[\.\d]{5}-)\d{14}(?=\+[\d|a-f]+)')" | |
[ -z "$INSTALLED_DATE" ] && INSTALLED_DATE=0 # If the previous command fails, assume we need to update. | |
WORKING_DIR="$(mktemp -d)" | |
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 | |
sudo apt-get update && sudo apt-get install -y "${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 | |
mkdir -p ~/.local/share/applications | |
mkdir -p ~/.local/bin | |
> ~/.local/share/applications/keybase-keybase.desktop << EOF | |
[Desktop Entry] | |
Name = Keybase | |
Exec = /usr/bin/distrobox-enter -n keybase -- run_keybase %u | |
Icon = keybase | |
Terminal = false | |
Type = Application | |
Categories = Network; | |
StartupNotify = false | |
MimeType = x-scheme-handler/web+stellar;x-scheme-handler/keybase;application/x-saltpack; | |
EOF | |
> ~/.local/bin/keybase << EOF | |
#!/bin/sh | |
exec /usr/bin/distrobox-enter -n keybase -- "$0" | |
EOF | |
> ~/.local/bin/run_keybase << EOF | |
#!/bin/sh | |
exec /usr/bin/distrobox-enter -n keybase -- "$0" | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment