diff options
Diffstat (limited to 'recipes-core/annex-client/annex-client/push_api_mdm_connected')
-rwxr-xr-x | recipes-core/annex-client/annex-client/push_api_mdm_connected | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/recipes-core/annex-client/annex-client/push_api_mdm_connected b/recipes-core/annex-client/annex-client/push_api_mdm_connected new file mode 100755 index 0000000..ec8a23d --- /dev/null +++ b/recipes-core/annex-client/annex-client/push_api_mdm_connected @@ -0,0 +1,59 @@ +#!/bin/bash +# This script pushes the current time to the API's remote management +# to track last connected time + +STATUS_FILE="/var/config/devicehq/status.json" +DHQ_DIR="/var/config/devicehq" + +LAST_CONNECTED=$(date +%m/%d/%Y/%H:%M:%S) +INTERVAL="" + +# Reset in case getopts has been used previously in the shell. +OPTIND=1 + +function show_help() { + echo "Usage: $0 -t <TIME OF CONNECTION> -i <INTERVAL SECONDS>" +} + +while getopts "h?t:i:" opt; do + case "$opt" in + h|\?) + show_help + exit 0 + ;; + t) LAST_CONNECTED=$OPTARG + ;; + i) INTERVAL=$OPTARG + ;; + esac +done + +shift $((OPTIND-1)) +[ "$1" = "--" ] && shift + +if [ ! -f $STATUS_FILE ]; then + mkdir -p $DHQ_DIR + echo "{ + \"status\": \"unknown\", + \"lastConnected\": \"unknown\", + \"intervalSeconds\": \"10\" +}" > $STATUS_FILE +fi + + +sed -i "s~\"lastConnected\"\s*:\s*\".*\"~\"lastConnected\": \"$LAST_CONNECTED\"~" $STATUS_FILE + +if [ $? != 0 ]; then + logger -t push_api_mdm_connected "Failed to save lastConnected [$LAST_CONNECTED] to $STATUS_FILE" +fi + + +if [ "$INTERVAL" != "" ]; then + sed -i "s/\"intervalSeconds\"\s*:\s*\".*\"/\"intervalSeconds\": \"$INTERVAL\"/" $STATUS_FILE + + if [ $? != 0 ]; then + logger -t push_api_mdm_connected "Failed to save intervalSeconds [$INTERVAL] to $STATUS_FILE" + fi +fi + + |