2020-04-29 17:35:35 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-10-17 00:38:29 +02:00
|
|
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
|
|
|
export LC_ALL=en_US.UTF-8
|
2020-03-15 05:13:46 +01:00
|
|
|
|
|
|
|
#wrapper script for running weather on interval
|
|
|
|
|
2020-04-29 20:33:51 +02:00
|
|
|
fahrenheit=$1
|
2020-10-16 11:56:41 +02:00
|
|
|
location=$2
|
2021-12-03 18:49:34 +01:00
|
|
|
fixedlocation=$3
|
2020-04-29 20:33:51 +02:00
|
|
|
|
2020-08-03 00:38:49 +02:00
|
|
|
LOCKFILE=/tmp/.dracula-tmux-weather.lock
|
2021-06-21 04:02:57 +02:00
|
|
|
DATAFILE=/tmp/.dracula-tmux-data
|
2020-08-03 00:38:49 +02:00
|
|
|
|
|
|
|
ensure_single_process()
|
|
|
|
{
|
2021-07-06 10:22:36 +02:00
|
|
|
# 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
|
2020-08-03 00:38:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-15 05:13:46 +01:00
|
|
|
main()
|
|
|
|
{
|
2021-07-06 10:22:36 +02:00
|
|
|
ensure_single_process
|
2020-08-03 00:38:49 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2020-03-16 07:15:26 +01:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
if [ ! -f $DATAFILE ]; then
|
|
|
|
printf "Loading..." > $DATAFILE
|
|
|
|
fi
|
2020-09-13 01:04:22 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
$current_dir/weather.sh > $DATAFILE
|
2020-08-03 00:38:49 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
while tmux has-session &> /dev/null
|
|
|
|
do
|
2021-12-03 18:49:34 +01:00
|
|
|
$current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE
|
2021-07-06 10:22:36 +02:00
|
|
|
if tmux has-session &> /dev/null
|
|
|
|
then
|
|
|
|
sleep 1200
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2020-08-03 00:38:49 +02:00
|
|
|
|
2021-07-06 10:22:36 +02:00
|
|
|
rm $LOCKFILE
|
2020-03-15 05:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#run main driver function
|
|
|
|
main
|