common 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. #
  3. # common: common stuff sourced by all 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. if [ -z "${BYOBU_INCLUDED_LIBS}" ]; then
  21. # Needed to set up $BYOBU_CONFIG_DIR
  22. . "${BYOBU_PREFIX}/lib/${PKG}/include/dirs"
  23. # Find command/type/which
  24. for BYOBU_TEST in "command -v" "type" "which"; do
  25. eval $BYOBU_TEST ls >/dev/null 2>&1 && break || true
  26. done
  27. # If the backend is already set (eg. running `byobu-tmux`), do nothing.
  28. if [ -z "${BYOBU_BACKEND}" ]; then
  29. [ -r "/etc/$PKG/backend" ] && . "/etc/$PKG/backend"
  30. [ -r "$BYOBU_CONFIG_DIR/backend" ] && . "$BYOBU_CONFIG_DIR/backend"
  31. # Just in case there's no config file at all
  32. if [ -z "${BYOBU_BACKEND}" ]; then
  33. # New byobu configuration, default to tmux
  34. if eval $BYOBU_TEST tmux >/dev/null; then
  35. BYOBU_BACKEND="tmux"
  36. elif eval $BYOBU_TEST screen >/dev/null; then
  37. BYOBU_BACKEND="screen"
  38. else
  39. printf "%s\n" "ERROR: $PKG won't work without tmux or screen installed" 1>&2
  40. fi
  41. fi
  42. fi
  43. # Creating backend cache
  44. [ -d "$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND" ] || mkdir -p "$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND"
  45. . "${BYOBU_PREFIX}/lib/${PKG}/include/shutil"
  46. . "${BYOBU_PREFIX}/lib/${PKG}/include/constants"
  47. get_distro || true
  48. export BYOBU_DISTRO="$_RET"
  49. BYOBU_INCLUDED_LIBS=1
  50. fi