diff --git a/data/config b/data/config index bac6f13..1f3cee9 100644 --- a/data/config +++ b/data/config @@ -54,8 +54,9 @@ AudioScrollSpeed: 5 # Command that is run to check if there are out-of-date packages. # The script should return *ONLY* a number. If it doesn't output a number, updates are no longer checked. -# Default value is applicable for Arch Linux. (See src/Config.h for explanation on the default command) -CheckPackagesCommand: pac="$(checkupdates)"; if [ $? -eq 127 ] ; then exit 127; fi; echo -n "$pac" | wc -l +# Default value is applicable for Arch Linux. (See data/update.sh for a human-readable version) +CheckPackagesCommand: p="$(checkupdates)"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo "0" && exit 0; fi; echo "$p" | wc -l + # How often to check for updates. In seconds CheckUpdateInterval: 300 diff --git a/data/update.sh b/data/update.sh new file mode 100755 index 0000000..29fa158 --- /dev/null +++ b/data/update.sh @@ -0,0 +1,23 @@ +#/bin/sh + +# This script is not used by default. It is a human-readable version of the default Arch-applicable +# package command with explanations + +updates="$(checkupdates)"; +exitCode=$?; + +if [ $exitCode -eq 127 ] ; then + # checkupdates wasn't found. + # Forward the error to gBar, so gBar can shut down the widget + # This is done, so we don't bother non-Arch systems with update checking + exit 127; +fi + +if [ $exitCode -eq 2 ] ; then + # Zero packages out-of-date. We need to handle this case, since 'echo "$updates" | wc -l' would return 1 + echo "0" && exit 0 +fi + +# We need the extra newline (-n option omitted), since 'echo -n $"updates" | wc -l' is off by one, +# since 'echo -n $"updates"' has a \0 at the end +echo "$updates" | wc -l diff --git a/src/Config.h b/src/Config.h index 0c268a8..9cda230 100644 --- a/src/Config.h +++ b/src/Config.h @@ -17,9 +17,8 @@ public: std::string defaultWorkspaceSymbol = ""; // Script that returns how many packages are out-of-date. The script should only print a number! - // The default script runs checkupdates, and forcefully exits when checkupdates is not found, so gBar can disable the package widget. - // "checkupdates | wc -l" would always return 0 on stdout, which gBar accepts - std::string checkPackagesCommand = "pac=\"$(checkupdates)\"; if [ $? -eq 127 ] ; then exit 127; fi; echo -n \"$pac\" | wc -l"; + // See data/update.sh for a human-readable version + std::string checkPackagesCommand = "p=\"$(checkupdates)\"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo \"0\" && exit 0; fi; echo \"$p\" | wc -l"; bool centerTime = true; bool audioRevealer = false; diff --git a/src/System.cpp b/src/System.cpp index bc26059..9de9ebe 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -563,10 +563,10 @@ namespace System ASSERT(feof(pipe), "GetOutdatedPackages: Cannot read to eof!"); int exitCode = pclose(pipe) / 256; - if (exitCode == 127) + if (exitCode != 0) { configMutex.lock(); - // Invalid script + // Invalid script/error LOG("GetOutdatedPackages: Invalid command. Disabling package widget!"); RuntimeConfig::Get().hasPackagesScript = false; configMutex.unlock();