extremeshok / clamav-unofficial-sigs

ClamAV Unofficial Signatures Updater maintained by eXtremeSHOK.com
https://eXtremeSHOK.com
Other
517 stars 118 forks source link

multiple command line options ignored #388

Open MASHtm opened 3 years ago

MASHtm commented 3 years ago

If multiple command line options are used only the first one gets parsed. eg. "-c configpath --force". This is caused by misplaced "break" commands

# Generic command line options
while true ; do
  case "${1}" in
    -c|--config) xshok_check_s2 "${2}"; custom_config="${2}"; shift 2; break ;;
    -F|--force) force_updates="yes"; shift 1; break ;;
    -v|--verbose) force_verbose="yes"; shift 1; break ;;
    -s|--silence) force_verbose="no"; shift 1; break ;;
    *) break ;;
  esac
done

I think it would be better to use the bash builtin getopts like

while getopts ":c:Fvs" opt; do
  case ${opt} in
.....
  esac
done
shift $((OPTIND -1))
MASHtm commented 3 years ago

Since getopts doesn't support long opts I used:

--- clamav-unofficial-sigs.sh   (revision 5032)
+++ clamav-unofficial-sigs.sh   (working copy)
@@ -1710,14 +1710,15 @@
 fi

 # Generic command line options
-while true ; do
+while :; do
   case "${1}" in
-    -c|--config) xshok_check_s2 "${2}"; custom_config="${2}"; shift 2; break ;;
-    -F|--force) force_updates="yes"; shift 1; break ;;
-    -v|--verbose) force_verbose="yes"; shift 1; break ;;
-    -s|--silence) force_verbose="no"; shift 1; break ;;
+    -c|--config) xshok_check_s2 "${2}"; custom_config="${2}"; shift ;;
+    -F|--force) force_updates="yes" ;;
+    -v|--verbose) force_verbose="yes" ;;
+    -s|--silence) force_verbose="no" ;;
     *) break ;;
   esac
+  shift
 done

 # Set the verbosity
perplexityjeff commented 3 years ago

Would this fix work on all versions that the script supports? If so then feel free to create a pull request with these changes. Even if not final this creates discussion hopefully to fix this.