Skip to content

Instantly share code, notes, and snippets.

@psidhu
Created July 16, 2018 15:51
Show Gist options
  • Save psidhu/a65ab9632bd6c6d400ea3fe25e959fa0 to your computer and use it in GitHub Desktop.
Save psidhu/a65ab9632bd6c6d400ea3fe25e959fa0 to your computer and use it in GitHub Desktop.
keybase-suspend
#!/bin/bash
# author: Pushpal Sidhu <psidhu.devel@gmail.com>
# date: 20180620
#
# Place this into the file "/lib/systemd/system-sleep/keybase-suspend"
# and mark it executable.
# Copied out of /usr/bin/run_keybase on 20180620. It'd be nice if they
# allowed run_keybase to be sourced then call the kill_all() function
# by itself. Or better, place helper scripts elsewhere and be able to
# source those.
kill_all_keybase() {
if killall Keybase &> /dev/null ; then
echo Shutting down Keybase GUI...
fi
# In case the package upgrade wasn't able to unmount and remove /keybase
if fusermount -uz /keybase &> /dev/null ; then
# Remove any existing legacy mount. This should never happen
# because it should have already been done by post_install.sh.
# Just in case, let the user know how to fix it.
echo Unmounting /keybase. Run `sudo rmdir /keybase; sudo ln -s /opt/keybase/mount-readme /keybase; sudo chown root:root /keybase` and then run this command again.
exit -1
fi
if fusermount -uz $mountdir &> /dev/null ; then
echo Unmounting $mountdir...
fi
if killall kbfsfuse &> /dev/null ; then
echo Shutting down kbfsfuse...
fi
if killall keybase &> /dev/null ; then
echo Shutting down keybase service...
fi
# There is a race condition where if we try to start the keybase service before
# the previous process has died, we might fail to lock the pid file and error
# out. Avoid this by waiting for the lock file to be free, on systems with flock
# installed.
lockfile="$runtime_dir/keybased.pid"
if which flock &> /dev/null && [ -e "$lockfile" ] ; then
flock "$lockfile" true
fi
}
if [ "${2}" = "suspend" ]; then
# make sure we even have keybase installed
if [ ! "$(command -v run_keybase)" ]; then
exit 0
fi
case "${1}" in
# Kill keybase
pre)
kill_all_keybase &>/dev/null
;;
# Start keybase
post)
su -c "nohup /usr/bin/run_keybase &" ${TODO_CHANGE_THIS_VAR_TO_YOUR_ACTUAL_USER_NAME_MANUALLY}
;;
esac
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment