From a22bfe1ab5109a0201e050b1cd40b612734ecb3e Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Wed, 17 Apr 2019 07:06:13 +0000 Subject: [PATCH] Author: Jeremy Huntwork Date: Tue Apr 16 13:31:09 2019 -0700 Improve testing of configuration file timestamp * Provide a default value for each so that the comparisons of the time of each file doesn't fail. * Two commands in the Makefile could acceptably fail, but would produce some ugly warnings. Signed-off-by: Pierre Labastie --- Makefile | 4 ++-- jhalfs | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index cb664a3..a928dc7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CONFIG = menu all: menuconfig # @clear - @`grep RUN_ME configuration | sed -e 's@RUN_ME=\"@@' -e 's@\"@@' ` + @$$(grep RUN_ME configuration 2>/dev/null | sed -e 's@RUN_ME=\"@@' -e 's@\"@@') $(CONFIG)/conf: $(MAKE) -C $(CONFIG) conf @@ -20,7 +20,7 @@ $(CONFIG)/mconf: $(MAKE) -C $(CONFIG) ncurses conf mconf menuconfig: $(CONFIG)/mconf - -@cp -a configuration configuration.old + @cp -a configuration configuration.old 2>/dev/null || true @$(CONFIG)/mconf $(CONFIG_CONFIG_IN) config: $(CONFIG)/conf diff --git a/jhalfs b/jhalfs index 835a055..c8e902c 100755 --- a/jhalfs +++ b/jhalfs @@ -124,15 +124,14 @@ esac # If the user has not saved his configuration file, let's ask # if he or she really wants to run this stuff -time_old=$(stat -c '%Y' configuration.old 2>/dev/null) -time_current=$(stat -c '%Y' configuration 2>/dev/null) -if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] - then echo -n "Do you want to run jhalfs? yes/no (yes): " +time_current=$(stat -c '%Y' configuration 2>/dev/null || date +%s) +time_old=$(stat -c '%Y' configuration.old 2>/dev/null || printf '%s' "$time_current") +if [ "$(printf '%d' "$time_old")" -ge "$(printf '%d' "$time_current")" ] ; then + printf 'Do you want to run jhalfs? yes/no (yes): ' read -r ANSWER - if [ "x${ANSWER:0:1}" = "xn" ] || [ "x${ANSWER:0:1}" = "xN" ] ; then - echo "${nl_}Exiting gracefully.${nl_}" - exit - fi + case ${ANSWER:0:1} in + n|N) printf "\nExiting gracefully.\n"; exit ;; + esac fi # Change this to 0 to suppress almost all messages