Skip to content
Back to search

keybase-client-skills

SkillWorks with Claude CodeGitHub

Development skills for the Keybase client repo

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026. Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/keybase/client with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/keybase/client'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/keybase--client/badge.svg)](/listings/keybase--client)

HTML

<a href="/listings/keybase--client"><img src="/api/listings/keybase--client/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/plugin.json · Manifest · 4 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "keybase-client-skills",
  3. "description": "Development skills for the Keybase client repo"
  4. }
README.md · README · 88 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ## Keybase
  2. Hi, and welcome to the Keybase client repo. All our client apps (macOS,
  3. Windows, Linux, iOS, and Android) are being actively developed in this
  4. repository. Please, dig around.
  5. ### Warnings
  6. We'd love you to read our source code.
  7. But - some of the things in this repo are explorations, and the app you build
  8. from source just _might not do what it says it's doing_. So, if you just want
  9. to install Keybase on your computer, you should **[monitor our releases](https://keybase.io/download)** for macOS, Linux, or Windows.
  10. If you're interested in our Docker image releases, please check out **[the Docker README](packaging/linux/docker/README.md)**.
  11. ![Sharing](https://keybase.io/images/github/repo_share.png?)
  12. ### Code Layout
  13. - **go**: Core crypto libraries; the Keybase service; the command line client. [Learn More](go/README.md)
  14. - **shared/{android,ios}**: Android and iOS apps developed with [React Native](https://facebook.github.io/react-native/).
  15. - **shared/desktop**: Desktop application for macOS, Linux, and Windows, made with the [Electron](https://github.com/atom/electron) framework, sharing React code with react-native.
  16. - **packaging**: Scripts for releasing packages across the various platforms.
  17. - **protocol**: Defines the protocol for communication for clients to the Keybase services. Uses [Avro](http://avro.apache.org/docs/1.7.7/). [Learn More](protocol/README.md)
  18. - **media**: Icons, graphics, media for Keybase apps.
  19. - **osx**: The macOS Keybase.app, development parallel to an Electron-based application above. [Learn More](osx/README.md)
  20. ### Problems?
  21. Report any issues with client software on this GitHub
  22. [issue tracker](https://github.com/keybase/client/issues).
  23. Internally, we track our progress using Jira, but all PRs come through GitHub
  24. for your review!
  25. If you're having problems with the command line `keybase` client, take a
  26. look at [the troubleshooting doc](go/doc/troubleshooting.md).
  27. If you're having problems with our Website, try the
  28. [keybase-issues](https://github.com/keybase/keybase-issues) issue tracker.
  29. We check and update both frequently.
  30. ### License
  31. Most code is released under the New BSD (3 Clause) License. If subdirectories
  32. include a different license, that license applies instead.
  33. ### Development Guidelines
  34. We check all git commits with pre-commit hooks generated via
  35. [pre-commit.com](http://pre-commit.com) pre-commit hooks.
  36. To enable use of these pre-commit hooks:
  37. - [Install](http://pre-commit.com/#install) the `pre-commit` utility. For some common cases:
  38. - `pip install pre-commit`
  39. - `brew install pre-commit`
  40. - Remove any existing pre-commit hooks via `rm .git/hooks/pre-commit`
  41. - Configure via `pre-commit install`
  42. Then proceed as normal.
  43. #### External Contributors
  44. If you forked this repository on GitHub and made a PR, then it'll show up as
  45. having failed Jenkins CI. We do not build external PRs because it's a security
  46. risk to do so without a review first. If your PR is successfully reviewed by a
  47. member of the Keybase team, then we will merge your commits to a branch on our
  48. primary fork and build from there.
  49. ### Cryptography Notice
  50. This distribution includes cryptographic software. The country in which you
  51. currently reside may have restrictions on the import, possession, use, and/or
  52. re-export to another country, of encryption software. BEFORE using any
  53. encryption software, please check your country's laws, regulations and policies
  54. concerning the import, possession, or use, and re-export of encryption
  55. software, to see if this is permitted. See http://www.wassenaar.org/ for more
  56. information.
  57. The U.S. Government Department of Commerce, Bureau of Industry and Security
  58. (BIS), has classified this software as Export Commodity Control Number (ECCN)
  59. 5D002.C.1, which includes information security software using or performing
  60. cryptographic functions with asymmetric algorithms. The form and manner of this
  61. distribution makes it eligible for export under the License Exception ENC
  62. Technology Software Unrestricted (TSU) exception (see the BIS Export
  63. Administration Regulations, Section 740.13) for both object code and source
  64. code.
osx/Fuse/install.sh · Bundled script · 25 lines · 1 finding marked
  1. #!/usr/bin/env bash
  2. set -e -u -o pipefail # Fail on error
  3. dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
  4. cd "$dir"
  5. bundle=${BUNDLE:-"kbfuse.bundle"}
  6. dest="/Library/Filesystems/kbfuse.fs"
  7. echo "Using bundle: $bundle"
  8. # Uninstall if present. This will fail if there are current kbfuse mounts.
  9. if [ -d "$dest" ]; then
  10. echo "Uninstalling $dest..."
  11. "$dir/uninstall.sh"
  12. fi
  13. echo "Installing $dest..."
  14. sudo /bin/cp -RfX "$bundle" "$dest"
  15. sudo chmod +s "/Library/Filesystems/kbfuse.fs/Contents/Resources/load_kbfuse"
    • Warning: Sets the setuid bit, so the program runs with its owner's rights
    • Line 21 on GitHub
  16. echo "Loading kext..."
  17. /Library/Filesystems/kbfuse.fs/Contents/Resources/load_kbfuse
  18. kextstat | grep kbfuse
packaging/linux/build_binaries.sh · Bundled script · 196 lines · 1 finding marked
  1. #! /usr/bin/env bash
  2. set -euox pipefail
  3. # check host arch
  4. is_arm64_host() {
  5. [[ $(uname -m) == "arm64" ]] || [[ $(uname -m) == "aarch64" ]]
  6. }
  7. here="$(dirname "${BASH_SOURCE[0]}")"
  8. this_repo="$(git -C "$here" rev-parse --show-toplevel ||
  9. echo -n "$GOPATH/src/github.com/keybase/client")"
  10. client_dir="$here/../../go"
  11. mode="$("$here/../build_mode.sh" "$@")"
  12. binary_name="$("$here/../binary_name.sh" "$@")"
  13. # Take the second argument as the build root, or a tmp dir if there is no
  14. # second argument. Absolutify the build root, because we cd around in this
  15. # script, and also because GOPATH is not allowed to be relative.
  16. build_root="${2:-/tmp/keybase_build_$(date +%Y_%m_%d_%H%M%S)}"
  17. mkdir -p "$build_root"
  18. build_root="$(realpath "$build_root")"
  19. # Record the version now, and write it to the build root. Because it uses a
  20. # timestamp in prerelease mode, it's important that other scripts use this file
  21. # instead of recomputing the version themselves.
  22. version="$("$here/../version.sh" "$@")"
  23. echo -n "$version" >"$build_root/VERSION"
  24. echo -n "$mode" >"$build_root/MODE"
  25. echo "Building version $version $mode in $build_root"
  26. # Determine the Go tags.
  27. go_tags=""
  28. if [ "$mode" = "production" ]; then
  29. go_tags="production"
  30. elif [ "$mode" = "prerelease" ]; then
  31. go_tags="production prerelease"
  32. elif [ "$mode" = "staging" ]; then
  33. go_tags="staging"
  34. fi
  35. echo "-tags '$go_tags'"
  36. # Determine the LD flags.
  37. buildmode="pie"
  38. ldflags_client=""
  39. ldflags_kbfs=""
  40. strip_flag=" -s -w "
  41. if [ "$mode" != "production" ]; then
  42. # The non-production build number is everything in the version after the hyphen.
  43. build_number="$(echo -n "$version" | sed 's/.*-//')"
  44. ldflags_client="$strip_flag -X github.com/keybase/client/go/libkb.PrereleaseBuild=$build_number"
  45. ldflags_kbfs="$strip_flag -X github.com/keybase/client/go/kbfs/libkbfs.PrereleaseBuild=$build_number"
  46. fi
  47. echo "-ldflags_client '$ldflags_client'"
  48. echo "-ldflags_kbfs '$ldflags_kbfs'"
  49. should_build_kbfs() {
  50. [ "$mode" != "production" ] && [[ ! -v KEYBASE_NO_KBFS ]]
  51. }
  52. should_build_electron() {
  53. [ "$mode" != "production" ] && [[ ! -v KEYBASE_NO_GUI ]]
  54. }
  55. # Install the electron dependencies.
  56. if should_build_electron; then
  57. echo "Installing Node modules for Electron"
  58. # Can't seem to get the right packages installed under NODE_ENV=production.
  59. export NODE_ENV=development
  60. export KEYBASE_SKIP_DEV_TOOLS=1
  61. (cd "$this_repo/shared" && yarn modules)
  62. unset KEYBASE_SKIP_DEV_TOOLS
  63. export NODE_ENV=production
  64. fi
  65. build_one_architecture() {
  66. layout_dir="$build_root/binaries/$debian_arch"
  67. mkdir -p "$layout_dir/usr/bin"
  68. # Assemble a custom GOPATH. Symlinks work for us here, because both the
  69. # client repo and the kbfs repo are fully vendored.
  70. export GOPATH="$build_root/gopaths/$debian_arch"
  71. mkdir -p "$GOPATH/src/github.com/keybase"
  72. ln -snf "$this_repo" "$GOPATH/src/github.com/keybase/client"
  73. # Build the client binary. Note that `go build` reads $GOARCH.
  74. echo "Building client for $GOARCH..."
  75. (cd "$client_dir" && go build -tags "$go_tags" -ldflags "$ldflags_client" -buildmode="$buildmode" -o \
  76. "$layout_dir/usr/bin/$binary_name" github.com/keybase/client/go/keybase)
  77. # Short-circuit if we're not building electron.
  78. if ! should_build_kbfs; then
  79. echo "SKIPPING kbfs and electron."
  80. return
  81. fi
  82. cp "$here/run_keybase" "$layout_dir/usr/bin/"
  83. # In include-KBFS mode, create the /opt/keybase dir, and include post_install.sh.
  84. mkdir -p "$layout_dir/opt/keybase"
  85. cp "$here/post_install.sh" "$layout_dir/opt/keybase/"
  86. cp "$here/crypto_squirrel.txt" "$layout_dir/opt/keybase/"
  87. # Build the kbfsfuse binary. Currently, this always builds from master.
  88. echo "Building kbfs for $GOARCH..."
  89. (cd "$client_dir" && go build -tags "$go_tags" -ldflags "$ldflags_kbfs" -buildmode="$buildmode" -o \
  90. "$layout_dir/usr/bin/kbfsfuse" github.com/keybase/client/go/kbfs/kbfsfuse)
  91. # Build the git-remote-keybase binary, also from the kbfs repo.
  92. echo "Building git-remote-keybase for $GOARCH..."
  93. (cd "$client_dir" && go build -tags "$go_tags" -ldflags "$ldflags_kbfs" -buildmode="$buildmode" -o \
  94. "$layout_dir/usr/bin/git-remote-keybase" github.com/keybase/client/go/kbfs/kbfsgit/git-remote-keybase)
  95. # Short-circuit if we're doing a Docker multi-stage build
  96. if ! should_build_electron; then
  97. echo "SKIPPING electron."
  98. return
  99. fi
  100. # Build the root redirector binary.
  101. echo "Building keybase-redirector for $GOARCH..."
  102. (cd "$client_dir" && CGO_ENABLED=1 go build -tags "$go_tags" -ldflags "$ldflags_client" -buildmode="$buildmode" -o \
  103. "$layout_dir/usr/bin/keybase-redirector" github.com/keybase/client/go/kbfs/redirector)
  104. # Build Electron.
  105. echo "Building Electron client for $electron_arch..."
  106. (
  107. cd "$this_repo/shared"
  108. yarn run desktop:package -- --platform=linux --arch="$electron_arch" --appVersion="$version" --network-concurrency=8
  109. rsync -a "desktop/release/linux-${electron_arch}/Keybase-linux-${electron_arch}/" \
  110. "$layout_dir/opt/keybase"
  111. chmod 755 "$layout_dir/opt/keybase"
  112. chmod 4755 "$layout_dir/opt/keybase/chrome-sandbox"
  113. )
  114. # Copy in the icon images and .saltpack file images.
  115. for size in 16 32 128 256 512; do
  116. icon_dest="$layout_dir/usr/share/icons/hicolor/${size}x${size}/apps"
  117. saltpack_dest="$layout_dir/usr/share/icons/hicolor/${size}x${size}/mimetypes"
  118. mkdir -p "$icon_dest"
  119. cp "$this_repo/media/icons/Keybase.iconset/icon_${size}x${size}.png" "$icon_dest/keybase.png"
  120. mkdir -p "$saltpack_dest"
  121. cp "$this_repo/media/icons/Saltpack.iconset/icon_${size}x${size}.png" "$saltpack_dest/application-x-saltpack.png"
  122. done
  123. # Copy in the desktop entry. Note that this is different from the autostart
  124. # entry, which will be created per-user the first time the service runs.
  125. apps_dir="$layout_dir/usr/share/applications"
  126. mkdir -p "$apps_dir"
  127. cp "$here/keybase.desktop" "$apps_dir"
  128. # Copy in the Saltpack file extension MIME type association.
  129. apps_dir="$layout_dir/usr/share/mime/packages"
  130. mkdir -p "$apps_dir"
  131. cp "$here/x-saltpack.xml" "$apps_dir"
  132. # Copy in the systemd unit files.
  133. units_dir="$layout_dir/usr/lib/systemd/user"
  134. mkdir -p "$units_dir"
  135. cp "$here/systemd"/* "$units_dir"
  136. # Check for whitespace in all the filenames we've copied. We don't support
  137. # whitespace in our later build scripts (for example RPM packaging), and even
  138. # if we did, it would be bad practice to use it.
  139. if (find "$layout_dir" | grep " "); then
  140. echo 'ERROR: whitespace in filenames! (shown above)'
  141. exit 1
  142. fi
  143. }
  144. if [ -n "${KEYBASE_BUILD_ARM_ONLY:-}" ]; then
  145. echo "Keybase: Building for ARM only"
  146. export GOARCH=arm64
  147. export debian_arch=arm64
  148. export electron_arch=arm64
  149. build_one_architecture
  150. echo "Keybase: Built ARM; exiting..."
  151. exit
  152. fi
  153. if [ -z "${KEYBASE_SKIP_64_BIT:-}" ]; then
  154. if is_arm64_host; then
  155. echo "Keybase: Building for x86-64 (arm64 host cross compile)"
  156. export CC=x86_64-linux-gnu-gcc
  157. export CXX=x86_64-linux-gnu-g++
  158. else
  159. echo "Keybase: Building for x86-64"
  160. fi
  161. export GOARCH=amd64
  162. export debian_arch=amd64
  163. export electron_arch=x64
  164. build_one_architecture
  165. else
  166. echo SKIPPING 64-bit build
  167. fi
packaging/linux/post_install.sh · Bundled script · 280 lines · 1 finding marked
  1. #! /usr/bin/env bash
  2. # This script handles distro-independent Linux post-install tasks. Currently
  3. # that means managing the /keybase redirector mountpoint. The deb-
  4. # and rpm-specific post-install scripts call into this after doing their
  5. # distro-specific work, which is mainly setting up package repos for updates.
  6. # The script also attempts to restart services if the mountpoint is not being used.
  7. # To disable this behavior, create /etc/keybase/config.json if it doesn't exist
  8. # and add the key value pair { "disable-autorestart": true }.
  9. set -u
  10. rootmount="/keybase"
  11. krbin="/usr/bin/keybase-redirector"
  12. BASH=$(command -v bash)
  13. redirector_enabled() {
  14. keybase --use-root-config-file config get --direct --assert-false --assert-ok-on-nil disable-root-redirector &> /dev/null
  15. }
  16. autorestart_enabled() {
  17. keybase --use-root-config-file config get --direct --assert-false --assert-ok-on-nil disable-autorestart &> /dev/null
  18. }
  19. make_mountpoint() {
  20. local_is_redirector_enabled="$1"
  21. if [ -n "$local_is_redirector_enabled" ]; then
  22. if ! mountpoint "$rootmount" &> /dev/null; then
  23. mkdir -p "$rootmount"
  24. chown root:root "$rootmount"
  25. chmod 755 "$rootmount"
  26. fi
  27. fi
  28. }
  29. systemd_exec_as() {
  30. user=$1
  31. shift
  32. # Keybase supports running with and without systemd. In order for `su`
  33. # to work with systemd commands, we need to pass in XDG_RUNTIME_DIR.
  34. # /run/user/{uid} is the default when using systemd. We can't know the
  35. # true value without installing systemd itself, which we don't want to
  36. # depend on, so we use this default. Users who want to use a custom
  37. # XDG_RUNTIME_DIR should specify it in their .profile so it is known
  38. # by su -, which doesn't load pam_systemd. Unfortunately, this also
  39. # results in an extra su invocation.
  40. user_xdg_runtime_dir=""
  41. # shellcheck disable=SC2016
  42. # Intentionally do not expand $XDG_RUNTIME_DIR; we want the user's shell to expand it
  43. if ! user_xdg_runtime_dir="$(su -s "$BASH" --login "$user" -c 'echo $XDG_RUNTIME_DIR')" || [ -z "$user_xdg_runtime_dir" ]; then
  44. user_xdg_runtime_dir="/run/user/$(id -u "$user")" || return 1
  45. fi
  46. # To support restarting without systemd, we'd also have to pass in DISPLAY,
  47. # but there's no easy way to figure that out.
  48. # With run_keybase, we pipe environment variables to the user's runtime directory,
  49. # so Keybase units will get the necessary environment from there, even though this su
  50. # shell doesn't have, e.g., DISPLAY.
  51. su --login "$user" -s "$BASH" -c "XDG_RUNTIME_DIR=$user_xdg_runtime_dir $* 2> /dev/null"
  52. }
  53. # Exits with 0 iff the given user is running the service with systemd
  54. systemd_unit_active_for() {
  55. user=$1
  56. service=$2
  57. command -v systemctl &> /dev/null && systemd_exec_as "$user" "systemctl --user -q is-active $service"
  58. }
  59. SYSTEMD_RESTARTED_REDIRECTOR=
  60. systemd_restart_if_active() {
  61. user=$1
  62. service=$2
  63. if systemd_unit_active_for "$user" "$service"; then
  64. systemd_exec_as "$user" "systemctl --user restart $service"
  65. if [ "$service" = "keybase-redirector.service" ]; then
  66. SYSTEMD_RESTARTED_REDIRECTOR=1
  67. fi
  68. fi
  69. }
  70. safe_restart_systemd_services() {
  71. if ! autorestart_enabled; then
  72. echo "Keybase autorestart disabled. Restart manually by running 'run_keybase' for each user using Keybase."
  73. return 0
  74. fi
  75. while read -r pid; do
  76. if [ -z "$pid" ]; then
  77. continue
  78. fi
  79. # Since keybase is running, we can assume run_keybase has been run before
  80. # and the mountdir is configured (so, it is not a fresh install).
  81. user="$(ps -o user= -p "$pid")"
  82. # If the process terminated since the loop started somehow, skip
  83. # restarting
  84. if [ -z "$user" ]; then
  85. continue
  86. fi
  87. restart_instructions="Restart Keybase manually by running 'run_keybase' as $user."
  88. abort_instructions="Aborting Keybase autorestart for $user. $restart_instructions"
  89. if ! systemd_unit_active_for "$user" "keybase.service"; then
  90. echo "Keybase not running via systemd for $user."
  91. echo "$restart_instructions"
  92. continue
  93. fi
  94. if systemd_unit_active_for "$user" "kbfs.service"; then
  95. if ! mount="$(systemd_exec_as "$user" "/usr/bin/keybase config get --direct --bare mountdir")" || [ -z "$mount" ]; then
  96. echo "Could not find mountdir for $user via systemd."
  97. echo "$abort_instructions"
  98. continue
  99. fi
  100. # Mount found, abort autorestart for user if currently being used.
  101. # lsof exits with zero iff there are no errors and mount is being used
  102. # Be slightly aggressive and restart if lsof did hit errors (e.g., if mount didn't exist)
  103. if lsof_output="$(systemd_exec_as "$user" "lsof $mount" 2> /dev/null)"; then
  104. programs_accessing_mount="$(echo "$lsof_output" | tail -n +2 | awk '{print $1}' | tr '\n' ', ')"
  105. echo "KBFS mount $mount for user $user currently in use by ($programs_accessing_mount)."
  106. echo "Please stop these processes before restarting manually."
  107. echo "$abort_instructions"
  108. continue
  109. fi
  110. fi
  111. echo "Autorestarting Keybase via systemd for $user."
  112. # Reload possibly-new systemd unit files first
  113. systemd_exec_as "$user" "systemctl --user daemon-reload"
  114. systemd_restart_if_active "$user" "keybase.service"
  115. systemd_restart_if_active "$user" "kbfs.service"
  116. systemd_restart_if_active "$user" "keybase.gui.service"
  117. systemd_restart_if_active "$user" "keybase-redirector.service"
  118. done <<< "$(pidof /usr/bin/keybase | tr ' ' '\n')"
  119. }
  120. is_owned_by_root() {
  121. owner_uid="$(stat --format=%u "$1" 2> /dev/null)" && [ "0" = "$owner_uid" ]
  122. }
  123. # In 4.3.0, 4.3.1, we had a bug where this post install script's usage of
  124. # Keybase commands would create .config/keybase/ with root permissions if it
  125. # didn't already exist.
  126. fix_bad_config_perms() {
  127. if userhomes=$(find /home -maxdepth 1 -mindepth 1 -type d); then
  128. while read -r userhome; do
  129. user="$(basename "$userhome")"
  130. # Don't attempt to fix for users with custom XDG_CONFIG_HOME,
  131. # hopefully they will read release notes.
  132. configdir="/home/$user/.config"
  133. keybase_configdir="$configdir/keybase"
  134. keybase_configfile="$configdir/keybase/gui_config.json"
  135. if [ -e "$keybase_configdir" ]; then
  136. if is_owned_by_root "$configdir"; then
  137. echo "Fixing bad permissions in $configdir; try 'run_keybase' after install."
  138. chown -R "$user:$user" "$configdir"
  139. elif is_owned_by_root "$keybase_configdir"; then
  140. echo "Fixing bad permissions in $keybase_configdir; try 'run_keybase' after install."
  141. chown -R "$user:$user" "$keybase_configdir"
  142. elif is_owned_by_root "$keybase_configfile"; then
  143. echo "Fixing bad permissions in $keybase_configfile; try 'run_keybase' after install."
  144. chown -R "$user:$user" "$keybase_configfile"
  145. fi
  146. fi
  147. done <<< "$userhomes"
  148. fi
  149. }
  150. fix_bad_config_perms
  151. # Associate Keybase with .saltpack files.
  152. if command -v update-mime-database &> /dev/null ; then
  153. update-mime-database /usr/share/mime
  154. fi
  155. # Update the GTK icon cache, if possible.
  156. if command -v gtk-update-icon-cache &> /dev/null ; then
  157. gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor
  158. fi
  159. is_redirector_enabled=""
  160. if redirector_enabled; then
  161. is_redirector_enabled="1"
  162. fi
  163. # Set suid on redirector before we restart it, in case package manager reverted
  164. # permissions.
  165. if [ -n "$is_redirector_enabled" ]; then
  166. chown root:root "$krbin"
  167. chmod 4755 "$krbin"
  168. else
  169. # Turn off suid if root has been turned off.
  170. chmod a-s "$krbin"
  171. fi
  172. # Restart services before restarting redirector manually
  173. # so we know if it was already restarted via systemd.
  174. safe_restart_systemd_services
  175. currlink="$(readlink "$rootmount")"
  176. if [ -n "$currlink" ] ; then
  177. # Follow the symlink one level deep if needed, to account for the
  178. # mount1 link.
  179. nextlink="$(readlink "$currlink")"
  180. if [ -n "$nextlink" ]; then
  181. currlink="$nextlink"
  182. fi
  183. # Upgrade from a rootlink-based build.
  184. if rm "$rootmount" &> /dev/null ; then
  185. echo Replacing old $rootmount symlink.
  186. fi
  187. elif [ -d "$rootmount" ] ; then
  188. # Handle upgrading from old builds that don't have the rootlink.
  189. currowner="$(stat -c %U "$rootmount")"
  190. if [ "$currowner" != "root" ]; then
  191. # Remove any existing legacy mount.
  192. echo Unmounting $rootmount...
  193. if killall kbfsfuse &> /dev/null ; then
  194. echo Shutting down kbfsfuse...
  195. fi
  196. rmdir "$rootmount"
  197. echo You must run run_keybase to restore file system access.
  198. elif [ -z "$is_redirector_enabled" ]; then
  199. if killall "$(basename "$krbin")" &> /dev/null ; then
  200. echo "Stopping existing root redirector."
  201. fi
  202. elif [ -n "$SYSTEMD_RESTARTED_REDIRECTOR" ]; then
  203. echo "Restarted existing root redirector via systemd."
  204. elif killall -USR1 "$(basename "$krbin")" &> /dev/null ; then
  205. echo "Restarting existing root redirector."
  206. # If the redirector is still owned by root, that probably
  207. # means we're sill running an old version and it needs to be
  208. # manually killed and restarted. Instead, run it as the user
  209. # currently running kbfsfuse.
  210. krName="$(basename "$krbin")"
  211. krUser="$(ps -o user= -C "$krName" 2> /dev/null | head -1)"
  212. if [ "$krUser" = "root" ]; then
  213. newUser="$(ps -o user= -C "kbfsfuse" 2> /dev/null | head -1)"
  214. killall "$krName" &> /dev/null
  215. if [ -n "$newUser" ] && [ "$newUser" != "root" ]; then
  216. # Try our best to get the user's $XDG_CACHE_HOME,
  217. # though depending on how it's set, it might not be
  218. # available to su.
  219. userCacheHome="$(su -s "$BASH" -c "echo -n \$XDG_CACHE_HOME" - "$newUser")"
  220. log="${userCacheHome:-~$newUser/.cache}/keybase/keybase.redirector.log"
  221. su -s "$BASH" -c "nohup \"$krbin\" \"$rootmount\" &>> $log &" "$newUser"
  222. echo "Root redirector now running as $newUser."
  223. else
  224. # The redirector is running as root, and either root
  225. # is running kbfsfuse, or no one is. In either case,
  226. # just make sure it restarts (since the -USR1 restart
  227. # won't work for older versions).
  228. echo "Restarting root redirector as root."
  229. killall "$krName" &> /dev/null
  230. logdir="${XDG_CACHE_HOME:-$HOME/.cache}/keybase"
  231. mkdir -p "$logdir"
  232. log="$logdir/keybase.redirector.log"
  233. nohup "$krbin" "$rootmount" &>> "$log" &
  234. fi
  235. fi
  236. t=5
  237. while ! mountpoint "$rootmount" &> /dev/null; do
  238. sleep 1
  239. t=$((t-1))
  240. if [ $t -eq 0 ]; then
  241. echo "Redirector hasn't started yet."
  242. break
  243. fi
  244. done
  245. fi
  246. fi
  247. # Make the mountpoint if it doesn't already exist by this point.
  248. make_mountpoint "$is_redirector_enabled"

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.