From 8a92d7eabc1dfa1864a2dcf5124965f728802202 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 3 Aug 2021 00:05:26 +0300 Subject: [PATCH] Keybase management script. I don't like Keybase. I don't like installing Debian packages without a repository, I don't like the Cron jobs it adds, I don't like the fuse mount, I don't like the processes that keep running when the I close the application. All of this just for a mediocre password manager. But this is not the first time I had to work with it so being as stubborn as I am I went a different route. The workbench image has just the CLI and fuse driver. This script start the daemon (why the hell does a password manager needs to have a daemon running?) and mounts the Keybase filesystem, stops and unmounts and copies the files locally and creates some links so that scripts that have hard-coded paths would work. This may be going way too deep in to the unsupported setup route. At least if this doesn't work I'll have someone to blame. --- Documents/bin/kb | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 Documents/bin/kb diff --git a/Documents/bin/kb b/Documents/bin/kb new file mode 100755 index 0000000..e6f0b8d --- /dev/null +++ b/Documents/bin/kb @@ -0,0 +1,84 @@ +#!/bin/sh +set -eu + +CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/keybase" +RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user$(id -u)}/keybase" + +if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" ] +then + # shellcheck disable=SC1091 + . "${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs" +else + XDG_DOCUMENTS_DIR="$HOME/Documents" +fi +DOCUMENTS_DIR="$XDG_DOCUMENTS_DIR/Smile/keybase" + +start () { + mkdir -p "$CACHE_DIR" + mkdir -p "$RUNTIME_DIR" + + if [ "$(ss -Hpx src /run/user/1000/keybase/keybased.sock)" = '' ] + then + keybase --log-file "$CACHE_DIR/keybase.service.log" \ + service \ + --chdir "$RUNTIME_DIR" & + fi + + if ! mountpoint --quiet "$RUNTIME_DIR/kbfs" + then + KEYBASE_RUN_MODE=prod kbfsfuse \ + -log-file "$CACHE_DIR/keybase.kbfs.log" \ + -runtime-dir "$RUNTIME_DIR" & + fi +} + +stop () { + if mountpoint --quiet "$RUNTIME_DIR/kbfs" + then + fusermount -uz "$RUNTIME_DIR/kbfs" + fi + + if [ -f "$RUNTIME_DIR/keybased.pid" ] + then + kill "$(cat "$RUNTIME_DIR/keybased.pid")" + else + pkill keybase || true + fi + + pkill kbfsfuse || true +} + +sync () { + if ! mountpoint --quiet "$RUNTIME_DIR/kbfs" + then + start + fi + mkdir -p "$DOCUMENTS_DIR" + cp -rf "$RUNTIME_DIR/kbfs/"* "$DOCUMENTS_DIR/" + if [ ! -w "/Volumes" ] + then + echo "Skiped creating links in /Volumes/Keybase, directory not writeable." >&2 + else + ln -sf "$DOCUMENTS_DIR" /Volumes/Keybase + fi + if [ ! -w "/keybase" ] + then + echo "Skiped creating links in /keybase, directory not writeable." >&2 + else + find /home/nimrod/Documents/Smile/keybase/ -maxdepth 1 -mindepth 1 -exec ln -sf --target /keybase/ '{}' \; + fi +} + +usage () { + echo "usage: $0 start|stop|sync" >&2 + exit 1 +} + +command="${1:-}" + +case "$command" in + start) shift; start "$@";; + stop) shift; stop "$@";; + sync) shift; sync "$@";; + *) usage;; +esac -- GitLab