summaryrefslogtreecommitdiff
path: root/SparkleShare/Linux/sparkleshare.in
blob: adf3a2e8a56d6885ad5c2faba4ea619f38e366bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash

if [[ $UID -eq 0 ]]; then
  echo "SparkleShare can't be run as root. Things would go utterly wrong."
  exit 1
fi

if [ "$XDG_RUNTIME_DIR" ]; then
  pidfile=${XDG_RUNTIME_DIR}/sparkleshare.pid
else
  pidfile=/tmp/sparkleshare-${USER}.pid
fi

start() {
  if [ -e "${pidfile}" ]; then
    sparklepid=`cat ${pidfile}`
    if [ -n "`ps -p ${sparklepid} | grep ${sparklepid}`" ]; then
      echo "SparkleShare is already running."
      exit 0
    else
      echo "Stale SparkleShare PID file found, starting a new instance..."
      rm -f $pidfile
    fi
  fi

  echo -n "Starting SparkleShare... "
  if [ -n "${SSH_AGENT_PID}" -o -n "${SSH_AUTH_SOCK}" ] ; then
    mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" $2 &
  else
    ssh-agent mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" $2 &
  fi
  ( umask 066; echo $! > ${pidfile} )
  echo "Done."
}

stop() {
  if [ -e "${pidfile}" ]; then
    sparklepid=`cat ${pidfile}`
    if [ -n "`ps -p ${sparklepid} | grep ${sparklepid}`" ]; then
      echo -n "Stopping SparkleShare... "
      kill ${sparklepid}
      rm -f ${pidfile}
      echo "Done."
    else
      echo "SparkleShare is not running, removing stale PID file..."
      rm -f ${pidfile}
    fi
  else
    echo "SparkleShare is not running."
  fi
}

case $1 in
  start|--start)
    start
    ;;
  stop|--stop)
    stop
    ;;
  restart|--restart)
    stop
    start
    ;;
  open|--open)
    invite=`date -u +%N`
    curl -o ~/SparkleShare/$invite.xml `echo $2 | sed s/sparkleshare:/https:/`
    ;;
  *)
    mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
    ;;
esac