index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | scripts/pkgdelta.sh.in | 55 |
diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index ae0bfc38..08835ac8 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -26,7 +26,7 @@ set -o errexit export TEXTDOMAIN='pacman-scripts' export TEXTDOMAINDIR='@localedir@' -myver='@PACKAGE_VERSION@' +declare -r myver='@PACKAGE_VERSION@' QUIET=0 @@ -40,6 +40,7 @@ max_delta_size=70 # ensure we have a sane umask set umask 0022 +m4_include(library/parseopts.sh) m4_include(library/output_format.sh) # print usage instructions @@ -53,8 +54,8 @@ This delta file can then be added to a database using repo-add.\n\n")" echo printf -- "$(gettext "Options:\n")" printf -- "$(gettext " -q, --quiet minimize output\n")" - printf -- "$(gettext " --min-pkg-size minimum package size before deltas are generated (bytes)\n")" - printf -- "$(gettext " --max-delta-size percent of package size above which deltas will be discarded\n")" + printf -- "$(gettext " --min-pkg-size minimum package size before deltas are generated\n")" + printf -- "$(gettext " --max-delta-size percent of new package above which the delta will be discarded\n")" } version() { @@ -65,6 +66,8 @@ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } +m4_include(library/human_to_size.sh) + isnumeric() { [[ $1 != *[!0-9]* ]] } @@ -155,44 +158,52 @@ create_xdelta() return 0 } -declare -a args +OPT_SHORT='hqV' +OPT_LONG=('help' 'quiet' 'max-delta-size:' 'min-pkg-size:' 'version') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET # parse arguments -while (( $# )); do - case "$1" in - -h|--help) usage; exit 0 ;; - -V|--version) version; exit 0 ;; - -q|--quiet) QUIET=1;; +while :; do + case $1 in + -h|--help) + usage + exit 0 ;; + -V|--version) + version + exit 0 ;; + -q|--quiet) + QUIET=1;; --min-pkg-size) - if ! isnumeric "$2"; then + if ! min_pkg_size=$(human_to_size "$2"); then echo "invalid argument '$2' for option -- '$1'" exit 1 fi - min_pkg_size=$2 - shift - ;; + shift ;; --max-delta-size) - arg=$(echo "$2" | awk '{print $1 * 100}') - if ! isnumeric "$arg" || (($arg > 200)); then + arg=$(awk -v val="$2" 'BEGIN { print val * 100 }') + if ! isnumeric "$arg" || (( arg > 200 )); then echo "invalid argument '$2' for option -- '$1'" exit 1 fi max_delta_size=$arg + shift ;; + --) shift - ;; - --) shift; args+=("$@"); break 2 ;; - -*) echo "invalid option -- '$1'"; usage; exit 1 ;; - *) args+=("$1");; + break 2 ;; esac shift done -if (( ${#args[@]} != 2 )); then +if (( $# != 2 )); then usage exit 1 fi -for i in "${args[@]}"; do +for i in "$@"; do if [[ ! -f $i ]]; then error "$(gettext "File '%s' does not exist")" "$i" exit 1 @@ -204,6 +215,6 @@ if ! type xdelta3 &>/dev/null; then exit 1 fi -create_xdelta "${args[@]}" +create_xdelta "$@" # vim: set ts=2 sw=2 noet: |