#! /bin/bash
# Only 'yes' will enable the debugging to ~/.var/app/org.tabos.roger/data/lastlog
debug='no';
#debug='yes';
# @First kill old session:
pid=$(ps ax | grep -P "roger( -d)*$" | grep -v "flatpak" | cut -d ' ' -f2);
if [ -n "${pid}" ]; then
kill ${pid};
fi
if [ 'yes' = $debug ]; then
# Remove the oldest Log
if [ -f ~/.var/app/org.tabos.roger/data/lastlog.old ]; then
rm ~/.var/app/org.tabos.roger/data/lastlog.old
fi
# Move the last log to .old
if [ -f ~/.var/app/org.tabos.roger/data/lastlog ]; then
mv ~/.var/app/org.tabos.roger/data/lastlog ~/.var/app/org.tabos.roger/data/lastlog.old
fi
# Run!
flatpak run org.tabos.roger > ~/.var/app/org.tabos.roger/data/lastlog
else
# Run!
flatpak run org.tabos.roger -d > ~/.var/app/org.tabos.roger/data/lastlog
fi