Skip to content

Instantly share code, notes, and snippets.

@alexdo
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdo/4d941dca07bba97a6979 to your computer and use it in GitHub Desktop.
Save alexdo/4d941dca07bba97a6979 to your computer and use it in GitHub Desktop.
omv-hubic-wrapper
#!/bin/bash
HUBIC="/usr/bin/hubic"
USER="MY_USERNAME"
SESSION_ADDR_FILE="/home/USERNAME/.dbus-session-addr"
SESSION_PID_FILE="/home/USERNAME/.dbus-pid"
HUBIC_STATE=""
DBUS_EXISTS=0
DBUS_PID=""
DBUS_ADDR=""
current_hubic_state() {
HUBIC_STATE="$($HUBIC status | egrep -i state | awk '{print tolower($2)}')"
}
if [ -f "$SESSION_PID_FILE" ] ; then
DBUS_PID="$(cat $SESSION_PID_FILE)"
fi
if [ -f "$SESSION_ADDR_FILE" ] ; then
DBUS_ADDR="$(cat $SESSION_ADDR_FILE)"
fi
if [ -n "$DBUS_PID" ] ; then
if ps ax -u $USER | egrep "^$DBUS_PID" > /dev/null ; then
DBUS_EXISTS=1
fi
fi
if [ $DBUS_EXISTS -eq 0 ] ; then
$(dbus-daemon --session --fork --print-address > $SESSION_ADDR_FILE)
$(ps ax -u $USER | grep dbus | grep address | cut --delimiter=" " --fields=1 > $SESSION_PID_FILE)
DBUS_EXISTS=1
DBUS_PID="$(cat $SESSION_PID_FILE)"
DBUS_ADDR="$(cat $SESSION_ADDR_FILE)"
fi
export DBUS_SESSION_BUS_ADDRESS="$DBUS_ADDR"
current_hubic_state
while [[ "$HUBIC_STATE" = "notconnected" || "$HUBIC_STATE" = "connecting" ]] ; do
sleep 10
current_hubic_state
done
echo "Executing hubi $1..."
$HUBIC $1
sleep 3
echo -e "\n\n"
$HUBIC status
exit 0

Make this executable and use it like so:

./hubic-wrapper.sh status ./hubic-wrapper.sh start ./hubic-wrapper.sh pause ./hubic-wrapper.sh resume ./hubic-wrapper.sh stop

A perfect fit for OMV anacron :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment