PageRenderTime 34ms CodeModel.GetById 21ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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