summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-05-17 16:02:17 +0200
committerAllan McRae <allan@archlinux.org>2015-05-19 15:43:00 +0200
commit3d4529335c598e79b5a483fedc4c9d5c12ef10f1 (patch)
treef965489bcea98a5461f064584fffb16d559e7e84 /scripts
parent1a17249159d2425dfd5103b8699673f72394a385 (diff)
downloadpacman-3d4529335c598e79b5a483fedc4c9d5c12ef10f1.tar.gz
pacman-3d4529335c598e79b5a483fedc4c9d5c12ef10f1.tar.xz
libmakepkg: extract functions for source download and extraction
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am8
-rw-r--r--scripts/libmakepkg/.gitignore2
-rw-r--r--scripts/libmakepkg/source.sh.in113
-rw-r--r--scripts/libmakepkg/source/bzr.sh.in106
-rw-r--r--scripts/libmakepkg/source/file.sh.in147
-rw-r--r--scripts/libmakepkg/source/git.sh.in127
-rw-r--r--scripts/libmakepkg/source/hg.sh.in104
-rw-r--r--scripts/libmakepkg/source/local.sh.in42
-rw-r--r--scripts/libmakepkg/source/svn.sh.in93
-rw-r--r--scripts/makepkg.sh.in524
-rw-r--r--scripts/po/POTFILES.in7
11 files changed, 749 insertions, 524 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 5cced98f..907dc4fa 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -43,6 +43,7 @@ libmakepkgdir = $(datarootdir)/makepkg
LIBMAKEPKGDIRS = \
lint_package \
lint_pkgbuild \
+ source \
tidy \
util
@@ -73,6 +74,13 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_pkgbuild/provides.sh \
libmakepkg/lint_pkgbuild/source.sh \
libmakepkg/lint_pkgbuild/util.sh \
+ libmakepkg/source.sh \
+ libmakepkg/source/bzr.sh \
+ libmakepkg/source/file.sh \
+ libmakepkg/source/git.sh \
+ libmakepkg/source/hg.sh \
+ libmakepkg/source/local.sh \
+ libmakepkg/source/svn.sh \
libmakepkg/tidy.sh \
libmakepkg/tidy/docs.sh \
libmakepkg/tidy/emptydirs.sh \
diff --git a/scripts/libmakepkg/.gitignore b/scripts/libmakepkg/.gitignore
index 18442a8d..1b1f186f 100644
--- a/scripts/libmakepkg/.gitignore
+++ b/scripts/libmakepkg/.gitignore
@@ -2,6 +2,8 @@ lint_package.sh
lint_package/*.sh
lint_pkgbuild.sh
lint_pkgbuild/*.sh
+source.sh
+source/*.sh
tidy.sh
tidy/*.sh
/util.sh
diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in
new file mode 100644
index 00000000..93a69b4b
--- /dev/null
+++ b/scripts/libmakepkg/source.sh.in
@@ -0,0 +1,113 @@
+#!/bin/bash
+#
+# source.sh - functions for downloading and extracting sources
+#
+# Copyright (c) 2015 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_SOURCE_SH" ]] && return
+LIBMAKEPKG_SOURCE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/source.sh"
+
+
+for lib in "$LIBRARY/source/"*.sh; do
+ source "$lib"
+done
+
+
+download_sources() {
+ local netfile all_sources
+ local get_source_fn=get_all_sources_for_arch get_vcs=1
+
+ msg "$(gettext "Retrieving sources...")"
+
+ while true; do
+ case $1 in
+ allarch)
+ get_source_fn=get_all_sources
+ ;;
+ novcs)
+ get_vcs=0
+ ;;
+ *)
+ break 2
+ ;;
+ esac
+ shift
+ done
+
+ "$get_source_fn" 'all_sources'
+ for netfile in "${all_sources[@]}"; do
+ pushd "$SRCDEST" &>/dev/null
+
+ local proto=$(get_protocol "$netfile")
+ case "$proto" in
+ local)
+ download_local "$netfile"
+ ;;
+ bzr*)
+ (( get_vcs )) && download_bzr "$netfile"
+ ;;
+ git*)
+ (( get_vcs )) && download_git "$netfile"
+ ;;
+ hg*)
+ (( get_vcs )) && download_hg "$netfile"
+ ;;
+ svn*)
+ (( get_vcs )) && download_svn "$netfile"
+ ;;
+ *)
+ download_file "$netfile"
+ ;;
+ esac
+
+ popd &>/dev/null
+ done
+}
+
+extract_sources() {
+ msg "$(gettext "Extracting sources...")"
+ local netfile all_sources
+
+ get_all_sources_for_arch 'all_sources'
+ for netfile in "${all_sources[@]}"; do
+ local file=$(get_filename "$netfile")
+ 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
+}
diff --git a/scripts/libmakepkg/source/bzr.sh.in b/scripts/libmakepkg/source/bzr.sh.in
new file mode 100644
index 00000000..e8da28be
--- /dev/null
+++ b/scripts/libmakepkg/source/bzr.sh.in
@@ -0,0 +1,106 @@
+#!/bin/bash
+#
+# bzr.sh - function for handling the download and "extraction" of Bazaar sources
+#
+# Copyright (c) 2015 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_SOURCE_BZR_SH" ]] && return
+LIBMAKEPKG_SOURCE_BZR_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_bzr() {
+ local netfile=$1
+
+ local url=$(get_url "$netfile")
+ if [[ $url != bzr+ssh* ]]; then
+ url=${url#bzr+}
+ fi
+ url=${url%%#*}
+
+ local repo=$(get_filename "$netfile")
+ local displaylocation="$url"
+
+ local dir=$(get_filepath "$netfile")
+ [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+ if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+ msg2 "$(gettext "Branching %s ...")" "${displaylocation}"
+ if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then
+ error "$(gettext "Failure while branching %s")" "${displaylocation}"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif (( ! HOLDVER )); then
+ msg2 "$(gettext "Pulling %s ...")" "${displaylocation}"
+ cd_safe "$dir"
+ if ! bzr pull "$url"; then
+ # only warn on failure to allow offline builds
+ warning "$(gettext "Failure while pulling %s")" "${displaylocation}"
+ fi
+ fi
+}
+
+extract_bzr() {
+ local netfile=$1
+
+ local repo=$(get_filename "$netfile")
+ local fragment=${netfile#*#}
+ if [[ $fragment = "$netfile" ]]; then
+ unset fragment
+ fi
+
+ rev="last:1"
+ if [[ -n $fragment ]]; then
+ case ${fragment%%=*} in
+ revision)
+ rev="${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
+
+ if [[ -d "${dir##*/}" ]]; then
+ cd_safe "${dir##*/}"
+ if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then
+ error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif ! bzr checkout "$dir" -r "$rev"; then
+ error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+
+ popd &>/dev/null
+}
diff --git a/scripts/libmakepkg/source/file.sh.in b/scripts/libmakepkg/source/file.sh.in
new file mode 100644
index 00000000..03dabe63
--- /dev/null
+++ b/scripts/libmakepkg/source/file.sh.in
@@ -0,0 +1,147 @@
+#!/bin/bash
+#
+# file.sh - function for handling the download and extraction of source files
+#
+# Copyright (c) 2015 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_SOURCE_FILE_SH" ]] && return
+LIBMAKEPKG_SOURCE_FILE_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_file() {
+ local netfile=$1
+
+ local filepath=$(get_filepath "$netfile")
+ if [[ -n "$filepath" ]]; then
+ msg2 "$(gettext "Found %s")" "${filepath##*/}"
+ return
+ fi
+
+ local proto=$(get_protocol "$netfile")
+
+ # find the client we should use for this URL
+ local -a cmdline
+ IFS=' ' read -a cmdline < <(get_downloadclient "$proto")
+ (( ${#cmdline[@]} )) || exit
+
+ local filename=$(get_filename "$netfile")
+ local url=$(get_url "$netfile")
+
+ if [[ $proto = "scp" ]]; then
+ # scp downloads should not pass the protocol in the url
+ url="${url##*://}"
+ fi
+
+ msg2 "$(gettext "Downloading %s...")" "$filename"
+
+ # temporary download file, default to last component of the URL
+ local dlfile="${url##*/}"
+
+ # replace %o by the temporary dlfile if it exists
+ if [[ ${cmdline[*]} = *%o* ]]; then
+ dlfile=$filename.part
+ cmdline=("${cmdline[@]//%o/$dlfile}")
+ fi
+ # add the URL, either in place of %u or at the end
+ if [[ ${cmdline[*]} = *%u* ]]; then
+ cmdline=("${cmdline[@]//%u/$url}")
+ else
+ cmdline+=("$url")
+ fi
+
+ if ! command -- "${cmdline[@]}" >&2; then
+ [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
+ error "$(gettext "Failure while downloading %s")" "$filename"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+
+ # rename the temporary download file to the final destination
+ if [[ $dlfile != "$filename" ]]; then
+ mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename"
+ fi
+}
+
+extract_file() {
+ local file=$1
+
+ local filepath=$(get_filepath "$file")
+ rm -f "$srcdir/${file}"
+ ln -s "$filepath" "$srcdir/"
+
+ if in_array "$file" "${noextract[@]}"; then
+ # skip source files in the noextract=() array
+ # these are marked explicitly to NOT be extracted
+ return 0
+ fi
+
+ # 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" ;;
+ *) return;;
+ esac ;;
+ *application/x-bzip*)
+ case "$ext" in
+ bz2|bz) cmd="bzip2" ;;
+ *) return;;
+ esac ;;
+ *application/x-xz*)
+ case "$ext" in
+ xz) cmd="xz" ;;
+ *) return;;
+ esac ;;
+ *)
+ # See if bsdtar can recognize the file
+ if bsdtar -tf "$file" -q '*' &>/dev/null; then
+ cmd="bsdtar"
+ else
+ return 0
+ 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
+}
diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in
new file mode 100644
index 00000000..4d2f2d7c
--- /dev/null
+++ b/scripts/libmakepkg/source/git.sh.in
@@ -0,0 +1,127 @@
+#!/bin/bash
+#
+# git.sh - function for handling the download and "extraction" of Git sources
+#
+# Copyright (c) 2015 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_SOURCE_GIT_SH" ]] && return
+LIBMAKEPKG_SOURCE_GIT_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_git() {
+ local netfile=$1
+
+ local dir=$(get_filepath "$netfile")
+ [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+ local repo=$(get_filename "$netfile")
+
+ local url=$(get_url "$netfile")
+ url=${url#git+}
+ url=${url%%#*}
+
+ if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+ msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
+ if ! git clone --mirror "$url" "$dir"; then
+ error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif (( ! HOLDVER )); then
+ cd_safe "$dir"
+ # Make sure we are fetching the right repo
+ if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
+ error "$(gettext "%s is not a clone of %s")" "$dir" "$url"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
+ if ! git fetch --all -p; then
+ # only warn on failure to allow offline builds
+ warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
+ fi
+ fi
+}
+
+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
+
+ local updating=0
+ if [[ -d "${dir##*/}" ]]; then
+ updating=1
+ cd_safe "${dir##*/}"
+ if ! git fetch; then
+ error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "git"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ cd_safe "$srcdir"
+ elif ! git clone "$dir" "${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=origin/HEAD
+ 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 [[ $ref != "origin/HEAD" ]] || (( updating )) ; then
+ if ! git checkout --force --no-track -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
+}
diff --git a/scripts/libmakepkg/source/hg.sh.in b/scripts/libmakepkg/source/hg.sh.in
new file mode 100644
index 00000000..6b21dad2
--- /dev/null
+++ b/scripts/libmakepkg/source/hg.sh.in
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# hg.sh - function for handling the download and "extraction" of Mercurial sources
+#
+# Copyright (c) 2015 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_SOURCE_HG_SH" ]] && return
+LIBMAKEPKG_SOURCE_HG_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_hg() {
+ local netfile=$1
+
+ local dir=$(get_filepath "$netfile")
+ [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+ local repo=$(get_filename "$netfile")
+
+ local url=$(get_url "$netfile")
+ url=${url#hg+}
+ url=${url%%#*}
+
+ if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+ msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg"
+ if ! hg clone -U "$url" "$dir"; then
+ error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif (( ! HOLDVER )); then
+ msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg"
+ cd_safe "$dir"
+ if ! hg pull; then
+ # only warn on failure to allow offline builds
+ warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg"
+ fi
+ fi
+}
+
+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
+
+ local ref=tip
+ if [[ -n $fragment ]]; then
+ case ${fragment%%=*} in
+ branch|revision|tag)
+ ref="${fragment##*=}"
+ ;;
+ *)
+ error "$(gettext "Unrecognized reference: %s")" "${fragment}"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ esac
+ fi
+
+ if [[ -d "${dir##*/}" ]]; then
+ cd_safe "${dir##*/}"
+ if ! (hg pull && hg update -C -r "$ref"); then
+ error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif ! hg clone -u "$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
+}
diff --git a/scripts/libmakepkg/source/local.sh.in b/scripts/libmakepkg/source/local.sh.in
new file mode 100644
index 00000000..bf659936
--- /dev/null
+++ b/scripts/libmakepkg/source/local.sh.in
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# local.sh - function for handling the "download" of local sources
+#
+# Copyright (c) 2015 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_SOURCE_LOCAL_SH" ]] && return
+LIBMAKEPKG_SOURCE_LOCAL_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_local() {
+ local netfile=$1
+ local filepath=$(get_filepath "$netfile")
+
+ if [[ -n "$filepath" ]]; then
+ msg2 "$(gettext "Found %s")" "${filepath##*/}"
+ else
+ local filename=$(get_filename "$netfile")
+ error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename"
+ exit 1 # $E_MISSING_FILE
+ fi
+}
diff --git a/scripts/libmakepkg/source/svn.sh.in b/scripts/libmakepkg/source/svn.sh.in
new file mode 100644
index 00000000..d706cac5
--- /dev/null
+++ b/scripts/libmakepkg/source/svn.sh.in
@@ -0,0 +1,93 @@
+#!/bin/bash
+#
+# svn.sh - function for handling the download and "extraction" of Subversion sources
+#
+# Copyright (c) 2015 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_SOURCE_SVN_SH" ]] && return
+LIBMAKEPKG_SOURCE_SVN_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_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=$(get_filename "$netfile")
+
+ local url=$(get_url "$netfile")
+ if [[ $url != svn+ssh* ]]; then
+ url=${url#svn+}
+ fi
+ url=${url%%#*}
+
+ local ref=HEAD
+ if [[ -n $fragment ]]; then
+ case ${fragment%%=*} in
+ revision)
+ ref="${fragment##*=}"
+ ;;
+ *)
+ error "$(gettext "Unrecognized reference: %s")" "${fragment}"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ esac
+ fi
+
+ if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+ msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
+ mkdir -p "$dir/.makepkg"
+ if ! svn checkout -r ${ref} --config-dir "$dir/.makepkg" "$url" "$dir"; then
+ error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif (( ! HOLDVER )); then
+ msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn"
+ cd_safe "$dir"
+ if ! svn update -r ${ref}; then
+ # only warn on failure to allow offline builds
+ warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn"
+ fi
+ fi
+}
+
+extract_svn() {
+ local netfile=$1
+
+ 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"
+
+ cp -au "$dir" "$srcdir"
+}
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 140bb1a2..c74e84a8 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -175,502 +175,6 @@ enter_fakeroot() {
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
}
-download_local() {
- local netfile=$1
- local filepath=$(get_filepath "$netfile")
-
- if [[ -n "$filepath" ]]; then
- msg2 "$(gettext "Found %s")" "${filepath##*/}"
- else
- local filename=$(get_filename "$netfile")
- error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename"
- exit 1 # $E_MISSING_FILE
- fi
-}
-
-download_file() {
- local netfile=$1
-
- local filepath=$(get_filepath "$netfile")
- if [[ -n "$filepath" ]]; then
- msg2 "$(gettext "Found %s")" "${filepath##*/}"
- return
- fi
-
- local proto=$(get_protocol "$netfile")
-
- # find the client we should use for this URL
- local -a cmdline
- IFS=' ' read -a cmdline < <(get_downloadclient "$proto")
- (( ${#cmdline[@]} )) || exit
-
- local filename=$(get_filename "$netfile")
- local url=$(get_url "$netfile")
-
- if [[ $proto = "scp" ]]; then
- # scp downloads should not pass the protocol in the url
- url="${url##*://}"
- fi
-
- msg2 "$(gettext "Downloading %s...")" "$filename"
-
- # temporary download file, default to last component of the URL
- local dlfile="${url##*/}"
-
- # replace %o by the temporary dlfile if it exists
- if [[ ${cmdline[*]} = *%o* ]]; then
- dlfile=$filename.part
- cmdline=("${cmdline[@]//%o/$dlfile}")
- fi
- # add the URL, either in place of %u or at the end
- if [[ ${cmdline[*]} = *%u* ]]; then
- cmdline=("${cmdline[@]//%u/$url}")
- else
- cmdline+=("$url")
- fi
-
- if ! command -- "${cmdline[@]}" >&2; then
- [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
- error "$(gettext "Failure while downloading %s")" "$filename"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
-
- # rename the temporary download file to the final destination
- if [[ $dlfile != "$filename" ]]; then
- mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename"
- fi
-}
-
-extract_file() {
- local file=$1
-
- local filepath=$(get_filepath "$file")
- rm -f "$srcdir/${file}"
- ln -s "$filepath" "$srcdir/"
-
- if in_array "$file" "${noextract[@]}"; then
- # skip source files in the noextract=() array
- # these are marked explicitly to NOT be extracted
- return 0
- fi
-
- # 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" ;;
- *) return;;
- esac ;;
- *application/x-bzip*)
- case "$ext" in
- bz2|bz) cmd="bzip2" ;;
- *) return;;
- esac ;;
- *application/x-xz*)
- case "$ext" in
- xz) cmd="xz" ;;
- *) return;;
- esac ;;
- *)
- # See if bsdtar can recognize the file
- if bsdtar -tf "$file" -q '*' &>/dev/null; then
- cmd="bsdtar"
- else
- return 0
- 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
-}
-
-download_bzr() {
- local netfile=$1
-
- local url=$(get_url "$netfile")
- if [[ $url != bzr+ssh* ]]; then
- url=${url#bzr+}
- fi
- url=${url%%#*}
-
- local repo=$(get_filename "$netfile")
- local displaylocation="$url"
-
- local dir=$(get_filepath "$netfile")
- [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
- if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
- msg2 "$(gettext "Branching %s ...")" "${displaylocation}"
- if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then
- error "$(gettext "Failure while branching %s")" "${displaylocation}"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif (( ! HOLDVER )); then
- msg2 "$(gettext "Pulling %s ...")" "${displaylocation}"
- cd_safe "$dir"
- if ! bzr pull "$url"; then
- # only warn on failure to allow offline builds
- warning "$(gettext "Failure while pulling %s")" "${displaylocation}"
- fi
- fi
-}
-
-extract_bzr() {
- local netfile=$1
-
- local repo=$(get_filename "$netfile")
- local fragment=${netfile#*#}
- if [[ $fragment = "$netfile" ]]; then
- unset fragment
- fi
-
- rev="last:1"
- if [[ -n $fragment ]]; then
- case ${fragment%%=*} in
- revision)
- rev="${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
-
- if [[ -d "${dir##*/}" ]]; then
- cd_safe "${dir##*/}"
- if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then
- error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif ! bzr checkout "$dir" -r "$rev"; then
- error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
-
- popd &>/dev/null
-}
-
-download_git() {
- local netfile=$1
-
- local dir=$(get_filepath "$netfile")
- [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
- local repo=$(get_filename "$netfile")
-
- local url=$(get_url "$netfile")
- url=${url#git+}
- url=${url%%#*}
-
- if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
- msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
- if ! git clone --mirror "$url" "$dir"; then
- error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif (( ! HOLDVER )); then
- cd_safe "$dir"
- # Make sure we are fetching the right repo
- if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
- error "$(gettext "%s is not a clone of %s")" "$dir" "$url"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
- if ! git fetch --all -p; then
- # only warn on failure to allow offline builds
- warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
- fi
- fi
-}
-
-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
-
- local updating=0
- if [[ -d "${dir##*/}" ]]; then
- updating=1
- cd_safe "${dir##*/}"
- if ! git fetch; then
- error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "git"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- cd_safe "$srcdir"
- elif ! git clone "$dir" "${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=origin/HEAD
- 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 [[ $ref != "origin/HEAD" ]] || (( updating )) ; then
- if ! git checkout --force --no-track -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
-}
-
-download_hg() {
- local netfile=$1
-
- local dir=$(get_filepath "$netfile")
- [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
-
- local repo=$(get_filename "$netfile")
-
- local url=$(get_url "$netfile")
- url=${url#hg+}
- url=${url%%#*}
-
- if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
- msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg"
- if ! hg clone -U "$url" "$dir"; then
- error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif (( ! HOLDVER )); then
- msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg"
- cd_safe "$dir"
- if ! hg pull; then
- # only warn on failure to allow offline builds
- warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg"
- fi
- fi
-}
-
-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
-
- local ref=tip
- if [[ -n $fragment ]]; then
- case ${fragment%%=*} in
- branch|revision|tag)
- ref="${fragment##*=}"
- ;;
- *)
- error "$(gettext "Unrecognized reference: %s")" "${fragment}"
- plain "$(gettext "Aborting...")"
- exit 1
- esac
- fi
-
- if [[ -d "${dir##*/}" ]]; then
- cd_safe "${dir##*/}"
- if ! (hg pull && hg update -C -r "$ref"); then
- error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif ! hg clone -u "$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
-}
-
-download_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=$(get_filename "$netfile")
-
- local url=$(get_url "$netfile")
- if [[ $url != svn+ssh* ]]; then
- url=${url#svn+}
- fi
- url=${url%%#*}
-
- local ref=HEAD
- if [[ -n $fragment ]]; then
- case ${fragment%%=*} in
- revision)
- ref="${fragment##*=}"
- ;;
- *)
- error "$(gettext "Unrecognized reference: %s")" "${fragment}"
- plain "$(gettext "Aborting...")"
- exit 1
- esac
- fi
-
- if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
- msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
- mkdir -p "$dir/.makepkg"
- if ! svn checkout -r ${ref} --config-dir "$dir/.makepkg" "$url" "$dir"; then
- error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- elif (( ! HOLDVER )); then
- msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn"
- cd_safe "$dir"
- if ! svn update -r ${ref}; then
- # only warn on failure to allow offline builds
- warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn"
- fi
- fi
-}
-
-extract_svn() {
- local netfile=$1
-
- 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"
-
- cp -au "$dir" "$srcdir"
-}
-
-download_sources() {
- local netfile all_sources
- local get_source_fn=get_all_sources_for_arch get_vcs=1
-
- msg "$(gettext "Retrieving sources...")"
-
- while true; do
- case $1 in
- allarch)
- get_source_fn=get_all_sources
- ;;
- novcs)
- get_vcs=0
- ;;
- *)
- break 2
- ;;
- esac
- shift
- done
-
- "$get_source_fn" 'all_sources'
- for netfile in "${all_sources[@]}"; do
- pushd "$SRCDEST" &>/dev/null
-
- local proto=$(get_protocol "$netfile")
- case "$proto" in
- local)
- download_local "$netfile"
- ;;
- bzr*)
- (( get_vcs )) && download_bzr "$netfile"
- ;;
- git*)
- (( get_vcs )) && download_git "$netfile"
- ;;
- hg*)
- (( get_vcs )) && download_hg "$netfile"
- ;;
- svn*)
- (( get_vcs )) && download_svn "$netfile"
- ;;
- *)
- download_file "$netfile"
- ;;
- esac
-
- popd &>/dev/null
- done
-}
-
# 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() {
@@ -1226,34 +730,6 @@ check_source_integrity() {
fi
}
-extract_sources() {
- msg "$(gettext "Extracting sources...")"
- local netfile all_sources
-
- get_all_sources_for_arch 'all_sources'
- for netfile in "${all_sources[@]}"; do
- local file=$(get_filename "$netfile")
- 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
-}
-
error_function() {
if [[ -p $logpipe ]]; then
rm "$logpipe"
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index 30bc3f48..00cb1b8d 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -28,6 +28,13 @@ scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in
scripts/libmakepkg/lint_pkgbuild/provides.sh.in
scripts/libmakepkg/lint_pkgbuild/source.sh.in
scripts/libmakepkg/lint_pkgbuild/util.sh.in
+scripts/libmakepkg/source.sh.in
+scripts/libmakepkg/source/bzr.sh.in
+scripts/libmakepkg/source/file.sh.in
+scripts/libmakepkg/source/git.sh.in
+scripts/libmakepkg/source/hg.sh.in
+scripts/libmakepkg/source/local.sh.in
+scripts/libmakepkg/source/svn.sh.in
scripts/libmakepkg/tidy.sh.in
scripts/libmakepkg/tidy/docs.sh.in
scripts/libmakepkg/tidy/emptydirs.sh.in