dirs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. #
  3. # dirs: some dirs needed by all library status scripts
  4. #
  5. # Copyright (C) 2011-2014 Dustin Kirkland
  6. #
  7. # Authors: Dustin Kirkland <kirkland@byobu.org>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, version 3 of the License.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. PKG="byobu"
  21. # Some users build and install byobu themselves, rather than from a distro
  22. [ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
  23. [ -n "$BYOBU_PREFIX" ] || BYOBU_PREFIX="/usr"
  24. # Create and export the user configuration directory
  25. if [ -d "$BYOBU_CONFIG_DIR" ]; then
  26. export BYOBU_CONFIG_DIR="$BYOBU_CONFIG_DIR"
  27. elif [ -d "$XDG_CONFIG_HOME" ]; then
  28. # Use XDG, as some users insist on such nonsense :-)
  29. export BYOBU_CONFIG_DIR="$XDG_CONFIG_HOME/$PKG"
  30. elif [ -d "$HOME/.config/$PKG" ]; then
  31. # Use XDG config directory, if it exists
  32. export BYOBU_CONFIG_DIR="$HOME/.config/$PKG"
  33. elif [ -d "$HOME/.local/share/$PKG" ]; then
  34. # Use XDG local directory, if it exists
  35. export BYOBU_CONFIG_DIR="$HOME/.local/share/$PKG"
  36. else
  37. # And to default to good old classic config dir location!
  38. export BYOBU_CONFIG_DIR="$HOME/.$PKG"
  39. fi
  40. [ -d "$BYOBU_CONFIG_DIR" ] || mkdir -p "$BYOBU_CONFIG_DIR/bin"
  41. # Grab the global, then local socket directory
  42. [ -r "/etc/$PKG/socketdir" ] && . "/etc/$PKG/socketdir"
  43. [ -r "$BYOBU_CONFIG_DIR/socketdir" ] && . "$BYOBU_CONFIG_DIR/socketdir"
  44. # Create and export the runtime cache directory
  45. if [ -w /dev/shm ]; then
  46. # Use shm for performance, if possible
  47. for i in /dev/shm/$PKG-$USER-*; do
  48. if [ -d "$i" ] && [ -O "$i" ]; then
  49. export BYOBU_RUN_DIR="$i"
  50. break
  51. fi
  52. done
  53. # Still empty, make a new one
  54. if [ ! -d "$BYOBU_RUN_DIR" ] || [ ! -O "$BYOBU_RUN_DIR" ]; then
  55. export BYOBU_RUN_DIR=$(mktemp -d /dev/shm/$PKG-$USER-XXXXXXXX)
  56. fi
  57. fi
  58. if [ ! -d "$BYOBU_RUN_DIR" ] || [ ! -O "$BYOBU_RUN_DIR" ] || [ ! -w "$BYOBU_RUN_DIR" ]; then
  59. # For distros that don't have a /dev/shm, use local disk
  60. if [ -d "$XDG_CACHE_HOME" ]; then
  61. # Use XDG, as some users insist on such nonsense :-)
  62. export BYOBU_RUN_DIR="$XDG_CACHE_HOME/$PKG"
  63. else
  64. # But if not, we'll use a cache directory
  65. export BYOBU_RUN_DIR="$HOME/.cache/$PKG"
  66. fi
  67. fi