run-as-spot 908 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # generic wrapper to run as spot (when currently running as root)
  3. # (C) James Budiono 2012
  4. # License: GPL version 3 or later
  5. #130604 BK: slight mods. see also /usr/sbin/setup-spot (support/setup-spot in woof).
  6. [ ! $1 ] && exit
  7. CWD=$(pwd)
  8. APP="$1"; shift
  9. ARGS=""
  10. [ $1 ] && while [ "$1" ]; do ARGS="$ARGS \"$1\""; shift; done
  11. if [ $(id -u) -eq 0 ]; then
  12. [ $XAUTHORITY ] && cp $XAUTHORITY /root/spot/.Xauthority 2>/dev/null
  13. touch /root/spot/.Xauthority
  14. #following line is mostly there to catch any root:root files that may have got copied in...
  15. chown -R spot:spot /root/spot &
  16. export XAUTHORITY=/root/spot/.Xauthority
  17. export XDG_CONFIG_HOME=/root/spot/.config
  18. export XDG_CACHE_HOME=/root/spot/.cache
  19. export XDG_DATA_HOME=/root/spot/.local/share
  20. #exec su spot -s /bin/sh -c "cd \"$CWD\"; \"$APP\" $ARGS"
  21. exec su spot -s /bin/sh -c "\"$APP\" $ARGS"
  22. else #precaution
  23. exec "$APP" "$ARGS"
  24. fi