diff options
Diffstat (limited to 'scripts/libmakepkg')
52 files changed, 472 insertions, 116 deletions
diff --git a/scripts/libmakepkg/.gitignore b/scripts/libmakepkg/.gitignore index 941d39a5..ceb7bfc4 100644 --- a/scripts/libmakepkg/.gitignore +++ b/scripts/libmakepkg/.gitignore @@ -10,5 +10,8 @@ srcinfo.sh tidy.sh tidy/*.sh util.sh +util/message.sh +util/option.sh +util/parseopts.sh util/pkgbuild.sh util/source.sh diff --git a/scripts/libmakepkg/integrity.sh.in b/scripts/libmakepkg/integrity.sh.in index cb8159d3..3a77ef16 100644 --- a/scripts/libmakepkg/integrity.sh.in +++ b/scripts/libmakepkg/integrity.sh.in @@ -2,7 +2,7 @@ # # integrity.sh - functions relating to source integrity checking # -# Copyright (c) 2011-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2011-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/integrity/generate_checksum.sh.in b/scripts/libmakepkg/integrity/generate_checksum.sh.in index 7a567100..902a989e 100644 --- a/scripts/libmakepkg/integrity/generate_checksum.sh.in +++ b/scripts/libmakepkg/integrity/generate_checksum.sh.in @@ -2,7 +2,7 @@ # # generate_checksum.sh - functions for generating source checksums # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -59,8 +59,8 @@ generate_one_checksum() { if [[ $netfile != *.@(sig?(n)|asc) ]]; then local file file="$(get_filepath "$netfile")" || missing_source_file "$netfile" - sum="$(openssl dgst -${integ} "$file")" - sum=${sum##* } + sum="$("${integ}sum" "$file")" + sum=${sum%% *} else sum="SKIP" fi @@ -80,11 +80,6 @@ generate_one_checksum() { generate_checksums() { msg "$(gettext "Generating checksums for source files...")" - if ! type -p openssl >/dev/null; then - error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl" - exit 1 # $E_MISSING_PROGRAM - fi - local integlist if (( $# == 0 )); then IFS=$'\n' read -rd '' -a integlist < <(get_integlist) diff --git a/scripts/libmakepkg/integrity/generate_signature.sh.in b/scripts/libmakepkg/integrity/generate_signature.sh.in index d7f7cb14..060ae344 100644 --- a/scripts/libmakepkg/integrity/generate_signature.sh.in +++ b/scripts/libmakepkg/integrity/generate_signature.sh.in @@ -2,7 +2,7 @@ # # generate_signature.sh - functions for generating PGP signatures # -# Copyright (c) 2008-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2008-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/integrity/verify_checksum.sh.in b/scripts/libmakepkg/integrity/verify_checksum.sh.in index 44a2b2e1..1a11a082 100644 --- a/scripts/libmakepkg/integrity/verify_checksum.sh.in +++ b/scripts/libmakepkg/integrity/verify_checksum.sh.in @@ -2,7 +2,7 @@ # # verify_checksum.sh - functions for checking source checksums # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -82,8 +82,8 @@ verify_integrity_one() { return 1 fi - local realsum="$(openssl dgst -${integ} "$file")" - realsum="${realsum##* }" + local realsum="$("${integ}sum" "$file")" + realsum="${realsum%% *}" if [[ ${expectedsum,,} = "$realsum" ]]; then printf '%s\n' "$(gettext "Passed")" >&2 else diff --git a/scripts/libmakepkg/integrity/verify_signature.sh.in b/scripts/libmakepkg/integrity/verify_signature.sh.in index 6df62727..b5577523 100644 --- a/scripts/libmakepkg/integrity/verify_signature.sh.in +++ b/scripts/libmakepkg/integrity/verify_signature.sh.in @@ -2,7 +2,7 @@ # # verify_signature.sh - functions for checking PGP signatures # -# Copyright (c) 2011-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2011-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ check_pgpsigs() { msg "$(gettext "Verifying source file signatures with %s...")" "gpg" - local file ext decompress found pubkey success status fingerprint trusted + local netfile proto pubkey success status fingerprint trusted local warning=0 local errors=0 local statusfile=$(mktemp) @@ -46,44 +46,15 @@ check_pgpsigs() { get_all_sources_for_arch 'all_sources' ;; esac - for file in "${all_sources[@]}"; do - file="$(get_filename "$file")" - if [[ $file != *.@(sig?(n)|asc) ]]; then - continue - fi - - printf " %s ... " "${file%.*}" >&2 - - if ! file="$(get_filepath "$file")"; then - printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2 - errors=1 - continue - fi + for netfile in "${all_sources[@]}"; do + proto="$(get_protocol "$netfile")" - found=0 - for ext in "" gz bz2 xz lrz lzo Z; do - if sourcefile="$(get_filepath "${file%.*}${ext:+.$ext}")"; then - found=1 - break; - fi - done - if (( ! found )); then - printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2 - errors=1 - continue + if [[ $proto = git* ]]; then + verify_git_signature "$netfile" "$statusfile" || continue + else + verify_file_signature "$netfile" "$statusfile" || continue fi - case "$ext" in - gz) decompress="gzip -c -d -f" ;; - bz2) decompress="bzip2 -c -d -f" ;; - xz) decompress="xz -c -d" ;; - lrz) decompress="lrzip -q -d" ;; - lzo) decompress="lzop -c -d -q" ;; - Z) decompress="uncompress -c -f" ;; - "") decompress="cat" ;; - esac - - $decompress < "$sourcefile" | gpg --quiet --batch --status-file "$statusfile" --verify "$file" - 2> /dev/null # these variables are assigned values in parse_gpg_statusfile success=0 status= @@ -145,6 +116,85 @@ check_pgpsigs() { fi } +verify_file_signature() { + local netfile="$1" statusfile="$2" + local file ext decompress found sourcefile + + file="$(get_filename "$netfile")" + if [[ $file != *.@(sig?(n)|asc) ]]; then + return 1 + fi + + printf " %s ... " "${file%.*}" >&2 + + if ! file="$(get_filepath "$netfile")"; then + printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2 + errors=1 + return 1 + fi + + found=0 + for ext in "" gz bz2 xz lrz lzo Z; do + if sourcefile="$(get_filepath "${file%.*}${ext:+.$ext}")"; then + found=1 + break; + fi + done + if (( ! found )); then + printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2 + errors=1 + return 1 + fi + + case "$ext" in + gz) decompress="gzip -c -d -f" ;; + bz2) decompress="bzip2 -c -d -f" ;; + xz) decompress="xz -c -d" ;; + lrz) decompress="lrzip -q -d" ;; + lzo) decompress="lzop -c -d -q" ;; + Z) decompress="uncompress -c -f" ;; + "") decompress="cat" ;; + esac + + $decompress < "$sourcefile" | gpg --quiet --batch --status-file "$statusfile" --verify "$file" - 2> /dev/null +} + +verify_git_signature() { + local netfile=$1 statusfile=$2 + local dir fragment query fragtype fragval + + dir=$(get_filepath "$netfile") + fragment=$(get_uri_fragment "$netfile") + query=$(get_uri_query "$netfile") + + if [[ $query != signed ]]; then + return 1 + fi + + case ${fragment%%=*} in + tag) + fragtype=tag + fragval=${fragment##*=} + ;; + commit|branch) + fragtype=commit + fragval=${fragment##*=} + ;; + '') + fragtype=commit + fragval=HEAD + esac + + printf " %s git repo ... " "${dir##*/}" >&2 + + git -C "$dir" verify-$fragtype --raw "$fragval" > "$statusfile" 2>&1 + if ! grep -qs NEWSIG "$statusfile"; then + printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2 + errors=1 + return 1 + fi +} + parse_gpg_statusfile() { local type arg1 arg6 arg10 @@ -204,11 +254,14 @@ parse_gpg_statusfile() { } source_has_signatures() { - local file all_sources + local file all_sources proto get_all_sources_for_arch 'all_sources' for file in "${all_sources[@]}"; do - if [[ ${file%%::*} = *.@(sig?(n)|asc) ]]; then + proto="$(get_protocol "$file")" + query=$(get_uri_query "$netfile") + + if [[ ${file%%::*} = *.@(sig?(n)|asc) || ( $proto = git* && $query = signed ) ]]; then return 0 fi done diff --git a/scripts/libmakepkg/lint_package.sh.in b/scripts/libmakepkg/lint_package.sh.in index 82b8b9b8..ff0894ec 100644 --- a/scripts/libmakepkg/lint_package.sh.in +++ b/scripts/libmakepkg/lint_package.sh.in @@ -2,7 +2,7 @@ # # lint_package.sh - functions for checking for packaging errors # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -40,7 +40,9 @@ lint_package() { cd_safe "$pkgdir" msg "$(gettext "Checking for packaging issue...")" + local ret=0 for func in ${lint_package_functions[@]}; do - $func + $func || ret=1 done + return $ret } diff --git a/scripts/libmakepkg/lint_package/build_references.sh.in b/scripts/libmakepkg/lint_package/build_references.sh.in index 67c14e66..9183fce9 100644 --- a/scripts/libmakepkg/lint_package/build_references.sh.in +++ b/scripts/libmakepkg/lint_package/build_references.sh.in @@ -2,7 +2,7 @@ # # build_references.sh - Warn about files containing references to build directories # -# Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2013-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,14 +25,17 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'} source "$LIBRARY/util/message.sh" - lint_package_functions+=('warn_build_references') warn_build_references() { - if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then - warning "$(gettext "Package contains reference to %s")" "\$srcdir" - fi - if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdirbase}" ; then - warning "$(gettext "Package contains reference to %s")" "\$pkgdir" - fi + local refs + + for var in srcdir pkgdir; do + mapfile -t refs < <(find "$pkgdir" -type f -exec grep -l "${!var}" {} +) + if (( ${#refs} > 0 )); then + warning "$(gettext 'Package contains reference to %s')" "\$$var" + printf '%s\n' "${refs[@]}" >&2 + fi + done + return 0 } diff --git a/scripts/libmakepkg/lint_package/dotfiles.sh.in b/scripts/libmakepkg/lint_package/dotfiles.sh.in new file mode 100644 index 00000000..9842028c --- /dev/null +++ b/scripts/libmakepkg/lint_package/dotfiles.sh.in @@ -0,0 +1,38 @@ +#!/bin/bash +# +# dotfiles.sh - check for dotfiles in the package root +# +# Copyright (c) 2016-2017 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_LINT_PACKAGE_DOTFILES_SH" ]] && return +LIBMAKEPKG_LINT_PACKAGE_DOTFILES_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" + +lint_package_functions+=('check_dotfiles') + +check_dotfiles() { + local ret=0 + for f in "$pkgdir"/.*; do + [[ ${f##*/} == . || ${f##*/} == .. ]] && continue + error "$(gettext "Dotfile found in package root '%s'")" "$f" + ret=1 + done + return $ret +} diff --git a/scripts/libmakepkg/lint_package/file_names.sh.in b/scripts/libmakepkg/lint_package/file_names.sh.in new file mode 100644 index 00000000..0b8e7a03 --- /dev/null +++ b/scripts/libmakepkg/lint_package/file_names.sh.in @@ -0,0 +1,42 @@ +#!/bin/bash +# +# file_names.sh - check package file names +# +# Copyright (c) 2016-2017 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_LINT_PACKAGE_FILE_NAMES_SH" ]] && return +LIBMAKEPKG_LINT_PACKAGE_FILE_NAMES_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" + +lint_package_functions+=('lint_file_names') + +lint_file_names() { + local ret=0 paths + + # alpm's local database format does not support newlines in paths + mapfile -t paths < <(find "$pkgdir" -name \*$'\n'\*) + if (( ${#paths} > 0 )); then + error "$(gettext 'Package contains paths with newlines')" + printf '%s\n' "${paths[@]}" >&2 + ret=1 + fi + + return $ret +} diff --git a/scripts/libmakepkg/lint_package/missing_backup.sh.in b/scripts/libmakepkg/lint_package/missing_backup.sh.in index 727a18bf..934dd12f 100644 --- a/scripts/libmakepkg/lint_package/missing_backup.sh.in +++ b/scripts/libmakepkg/lint_package/missing_backup.sh.in @@ -2,7 +2,7 @@ # # missing_backup.sh - Warn about missing files in the backup array # -# Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2013-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,4 +35,5 @@ warn_missing_backup() { warning "$(gettext "%s entry file not in package : %s")" "backup" "$file" fi done + return 0 } diff --git a/scripts/libmakepkg/lint_pkgbuild.sh.in b/scripts/libmakepkg/lint_pkgbuild.sh.in index 25bb848f..d3a1a083 100644 --- a/scripts/libmakepkg/lint_pkgbuild.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild.sh.in @@ -2,7 +2,7 @@ # # lint_pkgbuild.sh - functions for detecting PKGBUILD errors # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in index 623dc81a..ddc2f29e 100644 --- a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in @@ -2,7 +2,7 @@ # # arch.sh - Check the 'arch' array conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/backup.sh.in b/scripts/libmakepkg/lint_pkgbuild/backup.sh.in index 99fa15fe..5b37b4e9 100644 --- a/scripts/libmakepkg/lint_pkgbuild/backup.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/backup.sh.in @@ -2,7 +2,7 @@ # # backup.sh - Check the 'backup' array conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/changelog.sh.in b/scripts/libmakepkg/lint_pkgbuild/changelog.sh.in index 039db512..264ea105 100644 --- a/scripts/libmakepkg/lint_pkgbuild/changelog.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/changelog.sh.in @@ -2,7 +2,7 @@ # # changelog.sh - Check the files in the 'changelog' array exist. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/epoch.sh.in b/scripts/libmakepkg/lint_pkgbuild/epoch.sh.in index e6daf14c..cc11d975 100644 --- a/scripts/libmakepkg/lint_pkgbuild/epoch.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/epoch.sh.in @@ -2,7 +2,7 @@ # # epoch.sh - Check the 'epoch' variable conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/install.sh.in b/scripts/libmakepkg/lint_pkgbuild/install.sh.in index ab89ebea..3e268923 100644 --- a/scripts/libmakepkg/lint_pkgbuild/install.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/install.sh.in @@ -2,7 +2,7 @@ # # install.sh - Check the files in the 'install' array exist. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/optdepends.sh.in b/scripts/libmakepkg/lint_pkgbuild/optdepends.sh.in index fe71fd77..f5fdbb90 100644 --- a/scripts/libmakepkg/lint_pkgbuild/optdepends.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/optdepends.sh.in @@ -2,7 +2,7 @@ # # optdepends.sh - Check the 'optdepends' array conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/options.sh.in b/scripts/libmakepkg/lint_pkgbuild/options.sh.in index bf1cfa52..ffcd19e3 100644 --- a/scripts/libmakepkg/lint_pkgbuild/options.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/options.sh.in @@ -2,7 +2,7 @@ # # options.sh - Check the 'options' array conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/package_function.sh.in b/scripts/libmakepkg/lint_pkgbuild/package_function.sh.in index 78c5c7cc..14398217 100644 --- a/scripts/libmakepkg/lint_pkgbuild/package_function.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/package_function.sh.in @@ -2,7 +2,7 @@ # # package_function.sh - Check that required package functions exist. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in index 035b3abb..911e1128 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkgbase.sh.in @@ -2,7 +2,7 @@ # # pkgbase.sh - Check the 'pkgbase' variable conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/pkglist.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkglist.sh.in index 50ac3c0d..8c09ad5b 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkglist.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkglist.sh.in @@ -2,7 +2,7 @@ # # pkglist.sh - Check the packages selected to build exist. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in index a0440827..b66eda68 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkgname.sh.in @@ -2,7 +2,7 @@ # # pkgname.sh - Check the 'pkgname' variable conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,6 +32,11 @@ lint_pkgbuild_functions+=('lint_pkgname') lint_pkgname() { local ret=0 i + if [[ -z ${pkgname[@]} ]]; then + error "$(gettext "%s is not allowed to be empty.")" "pkgname" + return 1 + fi + for i in "${pkgname[@]}"; do if [[ -z $i ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgrel.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkgrel.sh.in index 95cb8080..b5cdfcf1 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkgrel.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkgrel.sh.in @@ -2,7 +2,7 @@ # # pkgrel.sh - Check the 'pkgrel' variable conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in b/scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in index 09041d17..0ec6584c 100644 --- a/scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in @@ -2,7 +2,7 @@ # # pkgver.sh - Check the 'pkgver' variable conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,8 +35,8 @@ check_pkgver() { return 1 fi - if [[ $1 = *[[:space:]:-]* ]]; then - error "$(gettext "%s is not allowed to contain colons, hyphens or whitespace.")" "pkgver" + if [[ $1 = *[[:space:]/:-]* ]]; then + error "$(gettext "%s is not allowed to contain colons, forward slashes, hyphens or whitespace.")" "pkgver" return 1 fi } diff --git a/scripts/libmakepkg/lint_pkgbuild/provides.sh.in b/scripts/libmakepkg/lint_pkgbuild/provides.sh.in index 5fedd7fc..f521d0f5 100644 --- a/scripts/libmakepkg/lint_pkgbuild/provides.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/provides.sh.in @@ -2,7 +2,7 @@ # # provides.sh - Check the 'provides' array conforms to requirements. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/source.sh.in b/scripts/libmakepkg/lint_pkgbuild/source.sh.in index b6edf1ce..052b9d54 100644 --- a/scripts/libmakepkg/lint_pkgbuild/source.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/source.sh.in @@ -2,7 +2,7 @@ # # source.sh - Check the 'source' array is not sparse. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/util.sh.in b/scripts/libmakepkg/lint_pkgbuild/util.sh.in index 3c248f91..e8a35933 100644 --- a/scripts/libmakepkg/lint_pkgbuild/util.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/util.sh.in @@ -2,7 +2,7 @@ # # util.sh - utility functions for pkgbuild linting. # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in index 30c99090..1e749638 100644 --- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in @@ -2,7 +2,7 @@ # # variable.sh - Check that variables are or are not arrays as appropriate # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in index 9bed41da..234e35e4 100644 --- a/scripts/libmakepkg/source.sh.in +++ b/scripts/libmakepkg/source.sh.in @@ -2,7 +2,7 @@ # # source.sh - functions for downloading and extracting sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source/bzr.sh.in b/scripts/libmakepkg/source/bzr.sh.in index af8c3c50..97206714 100644 --- a/scripts/libmakepkg/source/bzr.sh.in +++ b/scripts/libmakepkg/source/bzr.sh.in @@ -2,7 +2,7 @@ # # bzr.sh - function for handling the download and "extraction" of Bazaar sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source/file.sh.in b/scripts/libmakepkg/source/file.sh.in index 20493a67..1d85ea9b 100644 --- a/scripts/libmakepkg/source/file.sh.in +++ b/scripts/libmakepkg/source/file.sh.in @@ -2,7 +2,7 @@ # # file.sh - function for handling the download and extraction of source files # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in index cc27663d..6d7e0a67 100644 --- a/scripts/libmakepkg/source/git.sh.in +++ b/scripts/libmakepkg/source/git.sh.in @@ -2,7 +2,7 @@ # # git.sh - function for handling the download and "extraction" of Git sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,6 +39,7 @@ download_git() { local url=$(get_url "$netfile") url=${url#git+} url=${url%%#*} + url=${url%%\?*} if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" @@ -66,14 +67,8 @@ download_git() { extract_git() { local netfile=$1 - local fragment=${netfile#*#} - if [[ $fragment = "$netfile" ]]; then - unset fragment - fi - - local repo=${netfile##*/} - repo=${repo%%#*} - repo=${repo%%.git*} + local fragment=$(get_uri_fragment "$netfile") + local repo=$(get_filename "$netfile") local dir=$(get_filepath "$netfile") [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" diff --git a/scripts/libmakepkg/source/hg.sh.in b/scripts/libmakepkg/source/hg.sh.in index 61774e81..4e6ebad9 100644 --- a/scripts/libmakepkg/source/hg.sh.in +++ b/scripts/libmakepkg/source/hg.sh.in @@ -2,7 +2,7 @@ # # hg.sh - function for handling the download and "extraction" of Mercurial sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source/local.sh.in b/scripts/libmakepkg/source/local.sh.in index 6a4b8824..8104141a 100644 --- a/scripts/libmakepkg/source/local.sh.in +++ b/scripts/libmakepkg/source/local.sh.in @@ -2,7 +2,7 @@ # # local.sh - function for handling the "download" of local sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/source/svn.sh.in b/scripts/libmakepkg/source/svn.sh.in index a78fca3d..6cb78235 100644 --- a/scripts/libmakepkg/source/svn.sh.in +++ b/scripts/libmakepkg/source/svn.sh.in @@ -2,7 +2,7 @@ # # svn.sh - function for handling the download and "extraction" of Subversion sources # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/srcinfo.sh.in b/scripts/libmakepkg/srcinfo.sh.in index 83765fa5..99f5628a 100644 --- a/scripts/libmakepkg/srcinfo.sh.in +++ b/scripts/libmakepkg/srcinfo.sh.in @@ -2,7 +2,7 @@ # # srcinfo.sh - functions for writing .SRCINFO files # -# Copyright (c) 2014-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2014-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy.sh.in b/scripts/libmakepkg/tidy.sh.in index fc14c6e2..856f2394 100644 --- a/scripts/libmakepkg/tidy.sh.in +++ b/scripts/libmakepkg/tidy.sh.in @@ -3,7 +3,7 @@ # tidy.sh - functions for modifying/removing installed files before # package creation # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/docs.sh.in b/scripts/libmakepkg/tidy/docs.sh.in index ac86573b..0919f201 100644 --- a/scripts/libmakepkg/tidy/docs.sh.in +++ b/scripts/libmakepkg/tidy/docs.sh.in @@ -2,7 +2,7 @@ # # docs.sh - Remove documentation files from the package # -# Copyright (c) 2008-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2008-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/emptydirs.sh.in b/scripts/libmakepkg/tidy/emptydirs.sh.in index 85ab39df..2b16afdf 100644 --- a/scripts/libmakepkg/tidy/emptydirs.sh.in +++ b/scripts/libmakepkg/tidy/emptydirs.sh.in @@ -2,7 +2,7 @@ # # emptydirs.sh - Remove empty directories from the package # -# Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2013-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/libtool.sh.in b/scripts/libmakepkg/tidy/libtool.sh.in index e8187c78..b844c792 100644 --- a/scripts/libmakepkg/tidy/libtool.sh.in +++ b/scripts/libmakepkg/tidy/libtool.sh.in @@ -2,7 +2,7 @@ # # libtool.sh - Remove libtool files from the package # -# Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2013-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/purge.sh.in b/scripts/libmakepkg/tidy/purge.sh.in index 501d7531..5d37ded5 100644 --- a/scripts/libmakepkg/tidy/purge.sh.in +++ b/scripts/libmakepkg/tidy/purge.sh.in @@ -2,7 +2,7 @@ # # purge.sh - Remove unwanted files from the package # -# Copyright (c) 2008-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2008-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/staticlibs.sh.in b/scripts/libmakepkg/tidy/staticlibs.sh.in index 07282a80..643932dd 100644 --- a/scripts/libmakepkg/tidy/staticlibs.sh.in +++ b/scripts/libmakepkg/tidy/staticlibs.sh.in @@ -2,7 +2,7 @@ # # staticlibs.sh - Remove static library files from the package # -# Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2013-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 1c7aacfd..76562808 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -2,7 +2,7 @@ # # strip.sh - Strip debugging symbols from binary files # -# Copyright (c) 2007-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2007-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,7 +32,12 @@ tidy_modify+=('tidy_strip') build_id() { - LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }' + LANG=C readelf -n "$1" | sed -n '/Build ID/ { s/.*: //p; q; }' +} + +source_files() { + LANG=C readelf "$1" --debug-dump | \ + awk '/DW_AT_name +:/{name=$8}/DW_AT_comp_dir +:/{print $8 "/" name}' } strip_file() { @@ -50,6 +55,18 @@ strip_file() { return fi + # copy source files to debug directory + local f t + while read -r f; do + t=${f/"$srcdir"/$dbgsrc} + mkdir -p "${t%/*}" + cp -- "$f" "$t" + done < <(source_files "$binary") + + # adjust debug symbols to point at sources + debugedit -b "${srcdir}" -d /usr/src/debug/ -i "$binary" &> /dev/null + + # copy debug symbols to debug directory mkdir -p "$dbgdir/${binary%/*}" objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" @@ -88,8 +105,10 @@ tidy_strip() { [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S" if check_option "debug" "y"; then - dbgdir="$pkgdir-@DEBUGSUFFIX@/usr/lib/debug" - mkdir -p "$dbgdir" + + dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug" + dbgsrc="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/src/debug" + mkdir -p "$dbgdir" "$dbgsrc" fi local binary strip_flags diff --git a/scripts/libmakepkg/tidy/zipman.sh.in b/scripts/libmakepkg/tidy/zipman.sh.in index 7ef4d5c3..ff82d43c 100644 --- a/scripts/libmakepkg/tidy/zipman.sh.in +++ b/scripts/libmakepkg/tidy/zipman.sh.in @@ -2,7 +2,7 @@ # # zipman.sh - Compress man and info pages # -# Copyright (c) 2011-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2011-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/util.sh.in b/scripts/libmakepkg/util.sh.in index c296d565..b7b56d34 100644 --- a/scripts/libmakepkg/util.sh.in +++ b/scripts/libmakepkg/util.sh.in @@ -2,7 +2,7 @@ # # util.sh - utility functions for makepkg # -# Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2015-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/util/message.sh b/scripts/libmakepkg/util/message.sh.in index 341ccf3f..33808de7 100644 --- a/scripts/libmakepkg/util/message.sh +++ b/scripts/libmakepkg/util/message.sh.in @@ -2,7 +2,7 @@ # # message.sh - functions for outputting messages in makepkg # -# Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2006-2017 Pacman Development Team <pacman-dev@archlinux.org> # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> # # This program is free software; you can redistribute it and/or modify diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh.in index 54ba4740..8cf0039b 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh.in @@ -2,7 +2,7 @@ # # option.sh - functions to test if build/packaging options are enabled # -# Copyright (c) 2009-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2009-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/util/parseopts.sh.in b/scripts/libmakepkg/util/parseopts.sh.in new file mode 100644 index 00000000..a7638cf1 --- /dev/null +++ b/scripts/libmakepkg/util/parseopts.sh.in @@ -0,0 +1,173 @@ +#!/bin/bash +# +# parseopts.sh - getopt_long-like parser +# +# Copyright (c) 2012-2017 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# A getopt_long-like parser which portably supports longopts and +# shortopts with some GNU extensions. It does not allow for options +# with optional arguments. For both short and long opts, options +# requiring an argument should be suffixed with a colon. After the +# first argument containing the short opts, any number of valid long +# opts may be be passed. The end of the options delimiter must then be +# added, followed by the user arguments to the calling program. +# +# Recommended Usage: +# OPT_SHORT='fb:z' +# OPT_LONG=('foo' 'bar:' 'baz') +# if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then +# exit 1 +# fi +# set -- "${OPTRET[@]}" +# Returns: +# 0: parse success +# 1: parse failure (error message supplied) +parseopts() { + local opt= optarg= i= shortopts=$1 + local -a longopts=() unused_argv=() + + shift + while [[ $1 && $1 != '--' ]]; do + longopts+=("$1") + shift + done + shift + + longoptmatch() { + local o longmatch=() + for o in "${longopts[@]}"; do + if [[ ${o%:} = "$1" ]]; then + longmatch=("$o") + break + fi + [[ ${o%:} = "$1"* ]] && longmatch+=("$o") + done + + case ${#longmatch[*]} in + 1) + # success, override with opt and return arg req (0 == none, 1 == required) + opt=${longmatch%:} + if [[ $longmatch = *: ]]; then + return 1 + else + return 0 + fi ;; + 0) + # fail, no match found + return 255 ;; + *) + # fail, ambiguous match + printf "${0##*/}: $(gettext "option '%s' is ambiguous; possibilities:")" "--$1" + printf " '%s'" "${longmatch[@]%:}" + printf '\n' + return 254 ;; + esac >&2 + } + + while (( $# )); do + case $1 in + --) # explicit end of options + shift + break + ;; + -[!-]*) # short option + for (( i = 1; i < ${#1}; i++ )); do + opt=${1:i:1} + + # option doesn't exist + if [[ $shortopts != *$opt* ]]; then + printf "${0##*/}: $(gettext "invalid option") -- '%s'\n" "$opt" >&2 + OPTRET=(--) + return 1 + fi + + OPTRET+=("-$opt") + # option requires optarg + if [[ $shortopts = *$opt:* ]]; then + # if we're not at the end of the option chunk, the rest is the optarg + if (( i < ${#1} - 1 )); then + OPTRET+=("${1:i+1}") + break + # if we're at the end, grab the the next positional, if it exists + elif (( i == ${#1} - 1 )) && [[ $2 ]]; then + OPTRET+=("$2") + shift + break + # parse failure + else + printf "${0##*/}: $(gettext "option requires an argument") -- '%s'\n" "$opt" >&2 + OPTRET=(--) + return 1 + fi + fi + done + ;; + --?*=*|--?*) # long option + IFS='=' read -r opt optarg <<< "${1#--}" + longoptmatch "$opt" + case $? in + 0) + # parse failure + if [[ $optarg ]]; then + printf "${0##*/}: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2 + OPTRET=(--) + return 1 + # --longopt + else + OPTRET+=("--$opt") + fi + ;; + 1) + # --longopt=optarg + if [[ $optarg ]]; then + OPTRET+=("--$opt" "$optarg") + # --longopt optarg + elif [[ $2 ]]; then + OPTRET+=("--$opt" "$2" ) + shift + # parse failure + else + printf "${0##*/}: $(gettext "option '%s' requires an argument")\n" "--$opt" >&2 + OPTRET=(--) + return 1 + fi + ;; + 254) + # ambiguous option -- error was reported for us by longoptmatch() + OPTRET=(--) + return 1 + ;; + 255) + # parse failure + printf "${0##*/}: $(gettext "invalid option") '--%s'\n" "$opt" >&2 + OPTRET=(--) + return 1 + ;; + esac + ;; + *) # non-option arg encountered, add it as a parameter + unused_argv+=("$1") + ;; + esac + shift + done + + # add end-of-opt terminator and any leftover positional parameters + OPTRET+=('--' "${unused_argv[@]}" "$@") + unset longoptmatch + + return 0 +} diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in b/scripts/libmakepkg/util/pkgbuild.sh.in index 7bf7c3e4..2a4bd3af 100644 --- a/scripts/libmakepkg/util/pkgbuild.sh.in +++ b/scripts/libmakepkg/util/pkgbuild.sh.in @@ -2,7 +2,7 @@ # # pkgbuild.sh - functions to extract information from PKGBUILD files # -# Copyright (c) 2009-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2009-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/libmakepkg/util/source.sh.in b/scripts/libmakepkg/util/source.sh.in index 9d4ba4a6..238d1f58 100644 --- a/scripts/libmakepkg/util/source.sh.in +++ b/scripts/libmakepkg/util/source.sh.in @@ -2,7 +2,7 @@ # # source.sh - functions to extract information from source URLs # -# Copyright (c) 2010-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2010-2017 Pacman Development Team <pacman-dev@archlinux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -65,6 +65,7 @@ get_filename() { case $proto in bzr*|git*|hg*|svn*) filename=${netfile%%#*} + filename=${filename%%\?*} filename=${filename%/} filename=${filename##*/} if [[ $proto = bzr* ]]; then @@ -111,6 +112,32 @@ get_filepath() { printf "%s\n" "$file" } +# extract the VCS revision/branch specifier from a source entry +get_uri_fragment() { + local netfile=$1 + + local fragment=${netfile#*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + fragment=${fragment%\?*} + + printf "%s\n" "$fragment" +} + +# extract the VCS "signed" status from a source entry +get_uri_query() { + local netfile=$1 + + local query=${netfile#*\?} + if [[ $query = "$netfile" ]]; then + unset query + fi + query=${query%#*} + + printf "%s\n" "$query" +} + get_downloadclient() { local proto=$1 diff --git a/scripts/libmakepkg/util/util.sh b/scripts/libmakepkg/util/util.sh.in index f9f1c200..d676249d 100644 --- a/scripts/libmakepkg/util/util.sh +++ b/scripts/libmakepkg/util/util.sh.in @@ -2,7 +2,7 @@ # # util.sh - general utility functions # -# Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (c) 2006-2017 Pacman Development Team <pacman-dev@archlinux.org> # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> # # This program is free software; you can redistribute it and/or modify |