diff --git a/scripts/sleep_weather.sh b/scripts/sleep_weather.sh new file mode 100755 index 0000000..e8f8d25 --- /dev/null +++ b/scripts/sleep_weather.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# setting the locale, some users have issues with different locales, this forces the correct one +export LC_ALL=en_US.UTF-8 + +#wrapper script for running weather on interval + +fahrenheit=$1 +location=$2 +fixedlocation=$3 + +LOCKFILE=/tmp/.tmux2k-tmux-weather.lock +DATAFILE=/tmp/.tmux2k-tmux-data + +ensure_single_process() +{ + # check for another running instance of this script and terminate it if found + [ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)" + echo $$ > $LOCKFILE +} + +main() +{ + ensure_single_process + + current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + + if [ ! -f $DATAFILE ]; then + printf "Loading..." > $DATAFILE + fi + + $current_dir/weather.sh > $DATAFILE + + while tmux has-session &> /dev/null + do + $current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE + if tmux has-session &> /dev/null + then + sleep 1200 + else + break + fi + done + + rm $LOCKFILE +} + +#run main driver function +main