/SparkleShare/sparkleshare.in

http://github.com/hbons/SparkleShare · Autoconf · 77 lines · 69 code · 7 blank · 1 comment · 7 complexity · c2f5d200865617c0753ee1b013bbc2bb MD5 · raw file

  1. #!/bin/bash
  2. if [[ $UID -eq 0 ]]; then
  3. echo "Cannot run as root. Things would go utterly wrong."
  4. exit 1
  5. fi
  6. if [ "$XDG_RUNTIME_DIR" ]; then
  7. pidfile=${XDG_RUNTIME_DIR}/sparkleshare.pid
  8. else
  9. pidfile=/tmp/sparkleshare-${USER}.pid
  10. fi
  11. start() {
  12. if [ -e "${pidfile}" ]; then
  13. sparklepid=`cat ${pidfile}`
  14. if [ -n "`ps -p ${sparklepid} | grep ${sparklepid}`" ]; then
  15. echo "SparkleShare is already running."
  16. exit 0
  17. else
  18. echo "SparkleShare stale pid file found, starting a new instance."
  19. rm -f $pidfile
  20. fi
  21. fi
  22. echo -n "Starting SparkleShare... "
  23. if [ -n "${SSH_AGENT_PID}" -o -n "${SSH_AUTH_SOCK}" ] ; then
  24. mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" $2 &
  25. else
  26. ssh-agent mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" $2 &
  27. fi
  28. ( umask 066; echo $! > ${pidfile} )
  29. echo "Done."
  30. }
  31. stop() {
  32. if [ -e "${pidfile}" ]; then
  33. sparklepid=`cat ${pidfile}`
  34. if [ -n "`ps -p ${sparklepid} | grep ${sparklepid}`" ]; then
  35. echo -n "Stopping SparkleShare... "
  36. kill ${sparklepid}
  37. rm -f ${pidfile}
  38. echo "Done."
  39. else
  40. echo "SparkleShare is not running, removing stale pid file."
  41. rm -f ${pidfile}
  42. fi
  43. else
  44. echo "SparkleShare is not running."
  45. fi
  46. }
  47. case $1 in
  48. start|--start)
  49. start
  50. ;;
  51. stop|--stop)
  52. stop
  53. ;;
  54. restart|--restart)
  55. stop
  56. start
  57. ;;
  58. help|--help|-h)
  59. mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
  60. ;;
  61. -d|--disable-gui)
  62. mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --disable-gui
  63. ;;
  64. -v|--version)
  65. mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --version
  66. ;;
  67. *)
  68. echo "Usage: sparkleshare {start|stop|restart|help}"
  69. ;;
  70. esac