From: Ashley Whetter <[email protected]>

Signed-off-by: Ashley Whetter <[email protected]>
---
 scripts/.gitignore                   |   1 +
 scripts/Makefile.am                  |   4 +
 scripts/libmakepkg/extractions.sh.in | 293 +++++++++++++++++++++++++++++++++++
 scripts/libmakepkg/utils.sh.in       | 267 -------------------------------
 scripts/makepkg.sh.in                |   1 +
 5 files changed, 299 insertions(+), 267 deletions(-)
 create mode 100644 scripts/libmakepkg/extractions.sh.in

diff --git a/scripts/.gitignore b/scripts/.gitignore
index b15c7ac..d7c461e 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -9,4 +9,5 @@ repo-add
 repo-elephant
 repo-remove
 libmakepkg/downloads.sh
+libmakepkg/extractions.sh
 libmakepkg/utils.sh
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 979de54..5278580 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -38,6 +38,7 @@ LIBRARY = \
 
 LIBMAKEPKG = \
        libmakepkg/downloads.sh \
+       libmakepkg/extractions.sh \
        libmakepkg/utils.sh
 
 # Files that should be removed, but which Automake does not know.
@@ -94,6 +95,7 @@ $(LIBMAKEPKG): Makefile
 
 libmakepkg: \
        $(srcdir)/libmakepkg/downloads.sh \
+       $(srcdir)/libmakepkg/extractions.sh \
        $(srcdir)/libmakepkg/utils.sh \
        $(srcdir)/library/parseopts.sh
 
@@ -145,6 +147,7 @@ makepkg-wrapper: \
        $(srcdir)/makepkg-wrapper.sh.in \
        $(srcdir)/makepkg.sh.in \
        $(srcdir)/libmakepkg/downloads.sh \
+       $(srcdir)/libmakepkg/extractions.sh \
        $(srcdir)/libmakepkg/utils.sh \
        $(srcdir)/library/parseopts.sh \
        | makepkg
@@ -164,6 +167,7 @@ install-data-hook:
        $(INSTALL) .lib/makepkg $(DESTDIR)$(bindir)/makepkg
        $(AM_V_at)$(MKDIR_P) $(DESTDIR)$(libmakepkgdir)
        $(INSTALL) libmakepkg/downloads.sh 
$(DESTDIR)$(libmakepkgdir)/downloads.sh
+       $(INSTALL) libmakepkg/extractions.sh 
$(DESTDIR)$(libmakepkgdir)/extractions.sh
        $(INSTALL) libmakepkg/utils.sh $(DESTDIR)$(libmakepkgdir)/utils.sh
        cd $(DESTDIR)$(bindir) && \
                $(RM) repo-elephant && \
diff --git a/scripts/libmakepkg/extractions.sh.in 
b/scripts/libmakepkg/extractions.sh.in
new file mode 100644
index 0000000..0ea7331
--- /dev/null
+++ b/scripts/libmakepkg/extractions.sh.in
@@ -0,0 +1,293 @@
+#
+#   extractions.sh
+#
+#   Copyright (c) 2013 Pacman Development Team <[email protected]>
+#
+#   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_EXTRACTIONS_SH" ] && return || LIBMAKEPKG_EXTRACTIONS_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source $LIBRARY/utils.sh
+
+extract_file() {
+       local file=$1
+       # do not rely on extension for file type
+       local file_type=$(file -bizL "$file")
+       local ext=${file##*.}
+       local cmd=''
+       case "$file_type" in
+               
*application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
+                       cmd="bsdtar" ;;
+               *application/x-gzip*)
+                       case "$ext" in
+                               gz|z|Z) cmd="gzip" ;;
+                               *) continue;;
+                       esac ;;
+               *application/x-bzip*)
+                       case "$ext" in
+                               bz2|bz) cmd="bzip2" ;;
+                               *) continue;;
+                       esac ;;
+               *application/x-xz*)
+                       case "$ext" in
+                               xz) cmd="xz" ;;
+                               *) continue;;
+                       esac ;;
+               *)
+                       # See if bsdtar can recognize the file
+                       if bsdtar -tf "$file" -q '*' &>/dev/null; then
+                               cmd="bsdtar"
+                       else
+                               continue
+                       fi ;;
+       esac
+
+       local ret=0
+       msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
+       if [[ $cmd = "bsdtar" ]]; then
+               $cmd -xf "$file" || ret=$?
+       else
+               rm -f -- "${file%.*}"
+               $cmd -dcf "$file" > "${file%.*}" || ret=$?
+       fi
+       if (( ret )); then
+               error "$(gettext "Failed to extract %s")" "$file"
+               plain "$(gettext "Aborting...")"
+               exit 1
+       fi
+
+       if (( EUID == 0 )); then
+               # change perms of all source files to root user & root group
+               chown -R 0:0 "$srcdir"
+       fi
+}
+
+extract_bzr() {
+       local netfile=$1
+
+       local repo=$(get_filename "$netfile")
+       local fragment=${netfile#*#}
+       if [[ $fragment = "$netfile" ]]; then
+               unset fragment
+       fi
+
+       if [[ -n $fragment ]]; then
+               case ${fragment%%=*} in
+                       revision)
+                               revision=("-r" "${fragment#*=}")
+                               displaylocation="$url -r ${fragment#*=}"
+                               ;;
+                       *)
+                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
+                               plain "$(gettext "Aborting...")"
+                               exit 1
+               esac
+       fi
+
+       local dir=$(get_filepath "$netfile")
+       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"bzr"
+       pushd "$srcdir" &>/dev/null
+       rm -rf "${dir##*/}"
+
+       if ! { bzr checkout "$dir" "${revision[@]}" --lightweight &&
+               ( cd "$repo" && bzr pull "$dir" -q --overwrite "${revision[@]}" 
); }; then
+               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "bzr"
+               plain "$(gettext "Aborting...")"
+               exit 1
+       fi
+
+       popd &>/dev/null
+}
+
+extract_git() {
+       local netfile=$1
+
+       local fragment=${netfile#*#}
+       if [[ $fragment = "$netfile" ]]; then
+               unset fragment
+       fi
+
+       local repo=${netfile##*/}
+       repo=${repo%%#*}
+       repo=${repo%%.git*}
+
+       local dir=$(get_filepath "$netfile")
+       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"git"
+       pushd "$srcdir" &>/dev/null
+       rm -rf "${dir##*/}"
+
+       if ! git clone "$dir"; then
+               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "git"
+               plain "$(gettext "Aborting...")"
+               exit 1
+       fi
+
+       cd_safe "${dir##*/}"
+
+       local ref
+       if [[ -n $fragment ]]; then
+               case ${fragment%%=*} in
+                       commit|tag)
+                               ref=${fragment##*=}
+                               ;;
+                       branch)
+                               ref=origin/${fragment##*=}
+                               ;;
+                       *)
+                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
+                               plain "$(gettext "Aborting...")"
+                               exit 1
+               esac
+       fi
+
+       if [[ -n $ref ]]; then
+               if ! git checkout -b makepkg $ref; then
+                       error "$(gettext "Failure while creating working copy 
of %s %s repo")" "${repo}" "git"
+                       plain "$(gettext "Aborting...")"
+                       exit 1
+               fi
+       fi
+
+       popd &>/dev/null
+}
+
+extract_hg() {
+       local netfile=$1
+
+       local fragment=${netfile#*#}
+       if [[ $fragment = "$netfile" ]]; then
+               unset fragment
+       fi
+
+       local dir=$(get_filepath "$netfile")
+       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+       local repo=${netfile##*/}
+       repo=${repo%%#*}
+
+       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"hg"
+       pushd "$srcdir" &>/dev/null
+       rm -rf "${dir##*/}"
+
+       local ref
+       if [[ -n $fragment ]]; then
+               case ${fragment%%=*} in
+                       branch|revision|tag)
+                               ref=('-u' "${fragment##*=}")
+                               ;;
+                       *)
+                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
+                               plain "$(gettext "Aborting...")"
+                               exit 1
+               esac
+       fi
+
+       if ! hg clone "${ref[@]}" "$dir" "${dir##*/}"; then
+               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "hg"
+               plain "$(gettext "Aborting...")"
+               exit 1
+       fi
+
+       popd &>/dev/null
+}
+
+extract_svn() {
+       local netfile=$1
+
+       local fragment=${netfile#*#}
+       if [[ $fragment = "$netfile" ]]; then
+               unset fragment
+       fi
+
+       local dir=$(get_filepath "$netfile")
+       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+       local repo=${netfile##*/}
+       repo=${repo%%#*}
+
+       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"svn"
+       pushd "$srcdir" &>/dev/null
+       rm -rf "${dir##*/}"
+
+       local ref
+       if [[ -n $fragment ]]; then
+               case ${fragment%%=*} in
+                       revision)
+                               ref="${fragment##*=}"
+                               ;;
+                       *)
+                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
+                               plain "$(gettext "Aborting...")"
+                               exit 1
+               esac
+       fi
+
+       cp -a "$dir" .
+
+       if [[ -n ${ref} ]]; then
+               cd_safe "$(get_filename "$netfile")"
+               if ! svn update -r ${ref}; then
+                       error "$(gettext "Failure while creating working copy 
of %s %s repo")" "${repo}" "svn"
+                       plain "$(gettext "Aborting...")"
+               fi
+       fi
+
+       popd &>/dev/null
+}
+
+extract_sources() {
+       msg "$(gettext "Extracting sources...")"
+       local netfile
+       for netfile in "${source[@]}"; do
+               local file=$(get_filename "$netfile")
+               if in_array "$file" "${noextract[@]}"; then
+                       #skip source files in the noextract=() array
+                       #  these are marked explicitly to NOT be extracted
+                       continue
+               fi
+               local proto=$(get_protocol "$netfile")
+               case "$proto" in
+                       bzr*)
+                               extract_bzr "$netfile"
+                               ;;
+                       git*)
+                               extract_git "$netfile"
+                               ;;
+                       hg*)
+                               extract_hg "$netfile"
+                               ;;
+                       svn*)
+                               extract_svn "$netfile"
+                               ;;
+                       *)
+                               extract_file "$file"
+                               ;;
+               esac
+       done
+
+       if (( PKGVERFUNC )); then
+               update_pkgver
+               check_pkgver || exit 1
+               check_build_status
+       fi
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/utils.sh.in b/scripts/libmakepkg/utils.sh.in
index 4eba0e6..39aa7d9 100644
--- a/scripts/libmakepkg/utils.sh.in
+++ b/scripts/libmakepkg/utils.sh.in
@@ -236,236 +236,6 @@ get_downloadclient() {
        printf "%s\n" "$agent"
 }
 
-extract_file() {
-       local file=$1
-       # do not rely on extension for file type
-       local file_type=$(file -bizL "$file")
-       local ext=${file##*.}
-       local cmd=''
-       case "$file_type" in
-               
*application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
-                       cmd="bsdtar" ;;
-               *application/x-gzip*)
-                       case "$ext" in
-                               gz|z|Z) cmd="gzip" ;;
-                               *) continue;;
-                       esac ;;
-               *application/x-bzip*)
-                       case "$ext" in
-                               bz2|bz) cmd="bzip2" ;;
-                               *) continue;;
-                       esac ;;
-               *application/x-xz*)
-                       case "$ext" in
-                               xz) cmd="xz" ;;
-                               *) continue;;
-                       esac ;;
-               *)
-                       # See if bsdtar can recognize the file
-                       if bsdtar -tf "$file" -q '*' &>/dev/null; then
-                               cmd="bsdtar"
-                       else
-                               continue
-                       fi ;;
-       esac
-
-       local ret=0
-       msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
-       if [[ $cmd = "bsdtar" ]]; then
-               $cmd -xf "$file" || ret=$?
-       else
-               rm -f -- "${file%.*}"
-               $cmd -dcf "$file" > "${file%.*}" || ret=$?
-       fi
-       if (( ret )); then
-               error "$(gettext "Failed to extract %s")" "$file"
-               plain "$(gettext "Aborting...")"
-               exit 1
-       fi
-
-       if (( EUID == 0 )); then
-               # change perms of all source files to root user & root group
-               chown -R 0:0 "$srcdir"
-       fi
-}
-
-extract_bzr() {
-       local netfile=$1
-
-       local repo=$(get_filename "$netfile")
-       local fragment=${netfile#*#}
-       if [[ $fragment = "$netfile" ]]; then
-               unset fragment
-       fi
-
-       if [[ -n $fragment ]]; then
-               case ${fragment%%=*} in
-                       revision)
-                               revision=("-r" "${fragment#*=}")
-                               displaylocation="$url -r ${fragment#*=}"
-                               ;;
-                       *)
-                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
-                               plain "$(gettext "Aborting...")"
-                               exit 1
-               esac
-       fi
-
-       local dir=$(get_filepath "$netfile")
-       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
-       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"bzr"
-       pushd "$srcdir" &>/dev/null
-       rm -rf "${dir##*/}"
-
-       if ! { bzr checkout "$dir" "${revision[@]}" --lightweight &&
-               ( cd "$repo" && bzr pull "$dir" -q --overwrite "${revision[@]}" 
); }; then
-               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "bzr"
-               plain "$(gettext "Aborting...")"
-               exit 1
-       fi
-
-       popd &>/dev/null
-}
-
-extract_git() {
-       local netfile=$1
-
-       local fragment=${netfile#*#}
-       if [[ $fragment = "$netfile" ]]; then
-               unset fragment
-       fi
-
-       local repo=${netfile##*/}
-       repo=${repo%%#*}
-       repo=${repo%%.git*}
-
-       local dir=$(get_filepath "$netfile")
-       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
-       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"git"
-       pushd "$srcdir" &>/dev/null
-       rm -rf "${dir##*/}"
-
-       if ! git clone "$dir"; then
-               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "git"
-               plain "$(gettext "Aborting...")"
-               exit 1
-       fi
-
-       cd_safe "${dir##*/}"
-
-       local ref
-       if [[ -n $fragment ]]; then
-               case ${fragment%%=*} in
-                       commit|tag)
-                               ref=${fragment##*=}
-                               ;;
-                       branch)
-                               ref=origin/${fragment##*=}
-                               ;;
-                       *)
-                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
-                               plain "$(gettext "Aborting...")"
-                               exit 1
-               esac
-       fi
-
-       if [[ -n $ref ]]; then
-               if ! git checkout -b makepkg $ref; then
-                       error "$(gettext "Failure while creating working copy 
of %s %s repo")" "${repo}" "git"
-                       plain "$(gettext "Aborting...")"
-                       exit 1
-               fi
-       fi
-
-       popd &>/dev/null
-}
-
-extract_hg() {
-       local netfile=$1
-
-       local fragment=${netfile#*#}
-       if [[ $fragment = "$netfile" ]]; then
-               unset fragment
-       fi
-
-       local dir=$(get_filepath "$netfile")
-       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
-       local repo=${netfile##*/}
-       repo=${repo%%#*}
-
-       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"hg"
-       pushd "$srcdir" &>/dev/null
-       rm -rf "${dir##*/}"
-
-       local ref
-       if [[ -n $fragment ]]; then
-               case ${fragment%%=*} in
-                       branch|revision|tag)
-                               ref=('-u' "${fragment##*=}")
-                               ;;
-                       *)
-                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
-                               plain "$(gettext "Aborting...")"
-                               exit 1
-               esac
-       fi
-
-       if ! hg clone "${ref[@]}" "$dir" "${dir##*/}"; then
-               error "$(gettext "Failure while creating working copy of %s %s 
repo")" "${repo}" "hg"
-               plain "$(gettext "Aborting...")"
-               exit 1
-       fi
-
-       popd &>/dev/null
-}
-
-extract_svn() {
-       local netfile=$1
-
-       local fragment=${netfile#*#}
-       if [[ $fragment = "$netfile" ]]; then
-               unset fragment
-       fi
-
-       local dir=$(get_filepath "$netfile")
-       [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
-       local repo=${netfile##*/}
-       repo=${repo%%#*}
-
-       msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" 
"svn"
-       pushd "$srcdir" &>/dev/null
-       rm -rf "${dir##*/}"
-
-       local ref
-       if [[ -n $fragment ]]; then
-               case ${fragment%%=*} in
-                       revision)
-                               ref="${fragment##*=}"
-                               ;;
-                       *)
-                               error "$(gettext "Unrecognized reference: %s")" 
"${fragment}"
-                               plain "$(gettext "Aborting...")"
-                               exit 1
-               esac
-       fi
-
-       cp -a "$dir" .
-
-       if [[ -n ${ref} ]]; then
-               cd_safe "$(get_filename "$netfile")"
-               if ! svn update -r ${ref}; then
-                       error "$(gettext "Failure while creating working copy 
of %s %s repo")" "${repo}" "svn"
-                       plain "$(gettext "Aborting...")"
-               fi
-       fi
-
-       popd &>/dev/null
-}
-
 # Automatically update pkgver variable if a pkgver() function is provided
 # Re-sources the PKGBUILD afterwards to allow for other variables that use 
$pkgver
 update_pkgver() {
@@ -997,43 +767,6 @@ check_source_integrity() {
        fi
 }
 
-extract_sources() {
-       msg "$(gettext "Extracting sources...")"
-       local netfile
-       for netfile in "${source[@]}"; do
-               local file=$(get_filename "$netfile")
-               if in_array "$file" "${noextract[@]}"; then
-                       #skip source files in the noextract=() array
-                       #  these are marked explicitly to NOT be extracted
-                       continue
-               fi
-               local proto=$(get_protocol "$netfile")
-               case "$proto" in
-                       bzr*)
-                               extract_bzr "$netfile"
-                               ;;
-                       git*)
-                               extract_git "$netfile"
-                               ;;
-                       hg*)
-                               extract_hg "$netfile"
-                               ;;
-                       svn*)
-                               extract_svn "$netfile"
-                               ;;
-                       *)
-                               extract_file "$file"
-                               ;;
-               esac
-       done
-
-       if (( PKGVERFUNC )); then
-               update_pkgver
-               check_pkgver || exit 1
-               check_build_status
-       fi
-}
-
 error_function() {
        if [[ -p $logpipe ]]; then
                rm "$logpipe"
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 0c22774..eab755b 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -96,6 +96,7 @@ PACMAN_OPTS=
 shopt -s extglob
 
 source $LIBRARY/downloads.sh
+source $LIBRARY/extractions.sh
 source $LIBRARY/utils.sh
 
 # PROGRAM START
-- 
1.8.4


Reply via email to