#!/bin/bash # Get the time from gpspipe, and if present, set the time. # DEBUG=1 to set debug NAME=gpsd_ubx_settime shopt -s expand_aliases alias LG="logger -t $NAME" function kill_it { cmd=$1 pid=$2 sig=$3 ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}" kill -SIG${sig} ${pid} result=$? ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result" } trap "stty echo icanon" exit OIFS=$IFS IFS=$'\n' if ! /usr/sbin/gpsd_fixed 18 )) ; then LG -p user.warn "Updating time to time, ${ISO8601}." [[ $ISO8601 =~ ([^-]*)-([^-]*)-([^T]*)T([^:]*):([^:]*):([^\.]*)\. ]] Y=${BASH_REMATCH[1]} M=${BASH_REMATCH[2]} D=${BASH_REMATCH[3]} h=${BASH_REMATCH[4]} m=${BASH_REMATCH[5]} s=${BASH_REMATCH[6]} fi if ((${#Y} == 4 )) && ((${#M} > 0)) && ((${#D} > 0)) && ((${#h} > 0)) && ((${#m} > 0)) && ((${#s} > 0)) ; then if [[ $(readlink -f /bin/date) =~ busybox ]] ; then date -u "${Y}.${M}.${D}-${h}:${m}:${s}" >/dev/null else date -u "${M}${D}${h}${m}${Y}.${s}" >/dev/null fi else LG -p user.err "gpspipe output is bad or missing" exit 1 fi exit 0