[pacman-dev] [PATCH v2 4/4] Moved makepkg download functions into libmakepkg

ashley at awhetter.co.uk ashley at awhetter.co.uk
Thu Sep 5 18:13:21 EDT 2013


From: Ashley Whetter <ashley at awhetter.co.uk>

Signed-off-by: Ashley Whetter <ashley at awhetter.co.uk>
---
 scripts/.gitignore                        |   8 +
 scripts/Makefile.am                       |  26 ++-
 scripts/libmakepkg/download.sh.in         |  30 ++++
 scripts/libmakepkg/download/bzr.sh.in     |  77 +++++++++
 scripts/libmakepkg/download/file.sh.in    |  89 ++++++++++
 scripts/libmakepkg/download/git.sh.in     |  65 ++++++++
 scripts/libmakepkg/download/hg.sh.in      |  59 +++++++
 scripts/libmakepkg/download/local.sh.in   |  44 +++++
 scripts/libmakepkg/download/sources.sh.in |  71 ++++++++
 scripts/libmakepkg/download/svn.sh.in     |  67 ++++++++
 scripts/makepkg.sh.in                     | 261 ------------------------------
 11 files changed, 535 insertions(+), 262 deletions(-)
 create mode 100644 scripts/libmakepkg/download.sh.in
 create mode 100644 scripts/libmakepkg/download/bzr.sh.in
 create mode 100644 scripts/libmakepkg/download/file.sh.in
 create mode 100644 scripts/libmakepkg/download/git.sh.in
 create mode 100644 scripts/libmakepkg/download/hg.sh.in
 create mode 100644 scripts/libmakepkg/download/local.sh.in
 create mode 100644 scripts/libmakepkg/download/sources.sh.in
 create mode 100644 scripts/libmakepkg/download/svn.sh.in

diff --git a/scripts/.gitignore b/scripts/.gitignore
index c8ccc07..e7ffc4c 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -9,6 +9,14 @@ repo-add
 repo-elephant
 repo-remove
 
+libmakepkg/download.sh
+libmakepkg/download/bzr.sh
+libmakepkg/download/file.sh
+libmakepkg/download/git.sh
+libmakepkg/download/hg.sh
+libmakepkg/download/local.sh
+libmakepkg/download/sources.sh
+libmakepkg/download/svn.sh
 libmakepkg/messages.sh
 libmakepkg/pkgbuild.sh
 libmakepkg/pkgbuild/get_downloadclient.sh
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 9d81878..35420a2 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -49,6 +49,14 @@ LIBMAKEPKG = \
 	util/in_array.sh
 
 LIBMAKEPKG_INC = \
+	download.sh \
+	download/bzr.sh \
+	download/file.sh \
+	download/git.sh \
+	download/hg.sh \
+	download/local.sh \
+	download/sources.sh \
+	download/svn.sh \
 	messages.sh \
 	pkgbuild.sh \
 	pkgbuild/get_downloadclient.sh \
@@ -110,6 +118,14 @@ $(addprefix libmakepkg/,$(LIBMAKEPKG_INC)): Makefile
 	@$(BASH_SHELL) -O extglob -n $@
 
 libmakepkg: \
+	$(srcdir)/libmakepkg/download.sh \
+	$(srcdir)/libmakepkg/download/bzr.sh \
+	$(srcdir)/libmakepkg/download/file.sh \
+	$(srcdir)/libmakepkg/download/git.sh \
+	$(srcdir)/libmakepkg/download/hg.sh \
+	$(srcdir)/libmakepkg/download/local.sh \
+	$(srcdir)/libmakepkg/download/sources.sh \
+	$(srcdir)/libmakepkg/download/svn.sh \
 	$(srcdir)/libmakepkg/messages.sh \
 	$(srcdir)/libmakepkg/messages/error.sh \
 	$(srcdir)/libmakepkg/messages/msg.sh \
@@ -176,6 +192,14 @@ makepkg-wrapper: \
 	$(srcdir)/makepkg-wrapper.sh.in \
 	$(srcdir)/makepkg.sh.in \
 	$(srcdir)/library/parseopts.sh \
+	$(srcdir)/libmakepkg/download.sh \
+	$(srcdir)/libmakepkg/download/bzr.sh \
+	$(srcdir)/libmakepkg/download/file.sh \
+	$(srcdir)/libmakepkg/download/git.sh \
+	$(srcdir)/libmakepkg/download/hg.sh \
+	$(srcdir)/libmakepkg/download/local.sh \
+	$(srcdir)/libmakepkg/download/sources.sh \
+	$(srcdir)/libmakepkg/download/svn.sh \
 	$(srcdir)/libmakepkg/messages.sh \
 	$(srcdir)/libmakepkg/messages/error.sh \
 	$(srcdir)/libmakepkg/messages/msg.sh \
@@ -208,7 +232,7 @@ install-data-hook:
 	cd $(DESTDIR)$(bindir) && \
 		$(RM) makepkg makepkg-wrapper
 	$(INSTALL) .lib/makepkg $(DESTDIR)$(bindir)/makepkg
-	$(AM_V_at)$(MKDIR_P) $(DESTDIR)$(libmakepkgdir)/{messages,pkgbuild,util}
+	$(AM_V_at)$(MKDIR_P) $(DESTDIR)$(libmakepkgdir)/{download,messages,pkgbuild,util}
 	for lib in $(LIBMAKEPKG); do \
 		$(INSTALL) libmakepkg/$$lib $(DESTDIR)$(libmakepkgdir)/$$lib; \
 	done
diff --git a/scripts/libmakepkg/download.sh.in b/scripts/libmakepkg/download.sh.in
new file mode 100644
index 0000000..fb8ec7e
--- /dev/null
+++ b/scripts/libmakepkg/download.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#   download.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+for lib in "$LIBRARY"/download/*.sh; do
+	source "$lib"
+done
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/bzr.sh.in b/scripts/libmakepkg/download/bzr.sh.in
new file mode 100644
index 0000000..e980403
--- /dev/null
+++ b/scripts/libmakepkg/download/bzr.sh.in
@@ -0,0 +1,77 @@
+#!/bin/bash
+#
+#   bzr.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_BZR_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_BZR_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+source "$LIBRARY/util.sh"
+
+download_bzr() {
+	local netfile=$1
+
+	local url=$(get_url "$netfile")
+	url=${url##*bzr+}
+	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
+		# Make sure we are fetching the right repo
+		local distant_url="$(bzr info $url 2> /dev/null | sed -n '/branch root/{s/  branch root: //p;q;}')"
+		local local_url="$(bzr config parent_location -d $dir)"
+		if [[ -n $distant_url ]]; then
+			if [[ $distant_url != "$local_url" ]]; then
+				error "$(gettext "%s is not a branch of %s")" "$dir" "$url"
+				plain "$(gettext "Aborting...")"
+				exit 1
+			fi
+		else
+			if [[ $url != "$local_url" ]] ; then
+				error "$(gettext "%s is not a branch of %s")" "$dir" "$url"
+				error "$(gettext "The local URL is %s")" "$local_url"
+				plain "$(gettext "Aborting...")"
+				exit 1
+			fi
+		fi
+		msg2 "$(gettext "Pulling %s ...")" "${displaylocation}"
+		cd_safe "$dir"
+		if ! bzr pull "$url" --overwrite; then
+			# only warn on failure to allow offline builds
+			warning "$(gettext "Failure while pulling %s")" "${displaylocation}"
+		fi
+	fi
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/file.sh.in b/scripts/libmakepkg/download/file.sh.in
new file mode 100644
index 0000000..7831875
--- /dev/null
+++ b/scripts/libmakepkg/download/file.sh.in
@@ -0,0 +1,89 @@
+#!/bin/bash
+#
+#   file.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_FILE_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_FILE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+
+download_file() {
+	local netfile=$1
+
+	local filepath=$(get_filepath "$netfile")
+	if [[ -n "$filepath" ]]; then
+		msg2 "$(gettext "Found %s")" "${filepath##*/}"
+		rm -f "$srcdir/${filepath##*/}"
+		ln -s "$filepath" "$srcdir/"
+		return
+	fi
+
+	local proto=$(get_protocol "$netfile")
+
+	# find the client we should use for this URL
+	local dlcmd
+	dlcmd=$(get_downloadclient "$proto") || 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 [[ $dlcmd = *%o* ]]; then
+		dlcmd=${dlcmd//\%o/\"$filename.part\"}
+		dlfile="$filename.part"
+	fi
+	# add the URL, either in place of %u or at the end
+	if [[ $dlcmd = *%u* ]]; then
+		dlcmd=${dlcmd//\%u/\"$url\"}
+	else
+		dlcmd="$dlcmd \"$url\""
+	fi
+
+	local ret=0
+	eval "$dlcmd || ret=\$?"
+	if (( ret )); 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
+
+	rm -f "$srcdir/$filename"
+	ln -s "$SRCDEST/$filename" "$srcdir/"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/git.sh.in b/scripts/libmakepkg/download/git.sh.in
new file mode 100644
index 0000000..653d3a1
--- /dev/null
+++ b/scripts/libmakepkg/download/git.sh.in
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+#   git.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_GIT_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_GIT_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+source "$LIBRARY/util.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
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/hg.sh.in b/scripts/libmakepkg/download/hg.sh.in
new file mode 100644
index 0000000..5494775
--- /dev/null
+++ b/scripts/libmakepkg/download/hg.sh.in
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+#   hg.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_HG_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_HG_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+source "$LIBRARY/util.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
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/local.sh.in b/scripts/libmakepkg/download/local.sh.in
new file mode 100644
index 0000000..a9c4ac9
--- /dev/null
+++ b/scripts/libmakepkg/download/local.sh.in
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+#   local.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_LOCAL_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_LOCAL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+
+download_local() {
+	local netfile=$1
+	local filepath=$(get_filepath "$netfile")
+
+	if [[ -n "$filepath" ]]; then
+		msg2 "$(gettext "Found %s")" "${filepath##*/}"
+		rm -f "$srcdir/${filepath##*/}"
+		ln -s "$filepath" "$srcdir/"
+	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
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/sources.sh.in b/scripts/libmakepkg/download/sources.sh.in
new file mode 100644
index 0000000..d118cc5
--- /dev/null
+++ b/scripts/libmakepkg/download/sources.sh.in
@@ -0,0 +1,71 @@
+#!/bin/bash
+#
+#   sources.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_SOURCES_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_SOURCES_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/download/bzr.sh"
+source "$LIBRARY/download/file.sh"
+source "$LIBRARY/download/git.sh"
+source "$LIBRARY/download/hg.sh"
+source "$LIBRARY/download/local.sh"
+source "$LIBRARY/download/svn.sh"
+
+download_sources() {
+	msg "$(gettext "Retrieving sources...")"
+
+	local GET_VCS=1
+	if [[ $1 == "fast" ]]; then
+		GET_VCS=0
+	fi
+
+	local netfile
+	for netfile in "${source[@]}"; 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
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/download/svn.sh.in b/scripts/libmakepkg/download/svn.sh.in
new file mode 100644
index 0000000..51e264e
--- /dev/null
+++ b/scripts/libmakepkg/download/svn.sh.in
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+#   svn.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_DOWNLOAD_SVN_SH" ] && return
+LIBMAKEPKG_DOWNLOAD_SVN_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+source "$LIBRARY/pkgbuild.sh"
+source "$LIBRARY/util.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%%#*}
+
+	if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+		msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
+		mkdir -p "$dir/.makepkg"
+		if ! svn checkout --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; then
+			# only warn on failure to allow offline builds
+			warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn"
+		fi
+	fi
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index bce5c8d..b5ec21f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -177,81 +177,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##*/}"
-		rm -f "$srcdir/${filepath##*/}"
-		ln -s "$filepath" "$srcdir/"
-	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##*/}"
-		rm -f "$srcdir/${filepath##*/}"
-		ln -s "$filepath" "$srcdir/"
-		return
-	fi
-
-	local proto=$(get_protocol "$netfile")
-
-	# find the client we should use for this URL
-	local dlcmd
-	dlcmd=$(get_downloadclient "$proto") || 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 [[ $dlcmd = *%o* ]]; then
-		dlcmd=${dlcmd//\%o/\"$filename.part\"}
-		dlfile="$filename.part"
-	fi
-	# add the URL, either in place of %u or at the end
-	if [[ $dlcmd = *%u* ]]; then
-		dlcmd=${dlcmd//\%u/\"$url\"}
-	else
-		dlcmd="$dlcmd \"$url\""
-	fi
-
-	local ret=0
-	eval "$dlcmd || ret=\$?"
-	if (( ret )); 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
-
-	rm -f "$srcdir/$filename"
-	ln -s "$SRCDEST/$filename" "$srcdir/"
-}
-
 extract_file() {
 	local file=$1
 	# do not rely on extension for file type
@@ -305,53 +230,6 @@ extract_file() {
 	fi
 }
 
-download_bzr() {
-	local netfile=$1
-
-	local url=$(get_url "$netfile")
-	url=${url##*bzr+}
-	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
-		# Make sure we are fetching the right repo
-		local distant_url="$(bzr info $url 2> /dev/null | sed -n '/branch root/{s/  branch root: //p;q;}')"
-		local local_url="$(bzr config parent_location -d $dir)"
-		if [[ -n $distant_url ]]; then
-			if [[ $distant_url != "$local_url" ]]; then
-				error "$(gettext "%s is not a branch of %s")" "$dir" "$url"
-				plain "$(gettext "Aborting...")"
-				exit 1
-			fi
-		else
-			if [[ $url != "$local_url" ]] ; then
-				error "$(gettext "%s is not a branch of %s")" "$dir" "$url"
-				error "$(gettext "The local URL is %s")" "$local_url"
-				plain "$(gettext "Aborting...")"
-				exit 1
-			fi
-		fi
-		msg2 "$(gettext "Pulling %s ...")" "${displaylocation}"
-		cd_safe "$dir"
-		if ! bzr pull "$url" --overwrite; then
-			# only warn on failure to allow offline builds
-			warning "$(gettext "Failure while pulling %s")" "${displaylocation}"
-		fi
-	fi
-}
-
 extract_bzr() {
 	local netfile=$1
 
@@ -391,41 +269,6 @@ extract_bzr() {
 	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
 
@@ -480,35 +323,6 @@ extract_git() {
 	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
 
@@ -549,43 +363,6 @@ extract_hg() {
 	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%%#*}
-
-	if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
-		msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn"
-		mkdir -p "$dir/.makepkg"
-		if ! svn checkout --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; 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
 
@@ -630,44 +407,6 @@ extract_svn() {
 	popd &>/dev/null
 }
 
-download_sources() {
-	msg "$(gettext "Retrieving sources...")"
-
-	local GET_VCS=1
-	if [[ $1 == "fast" ]]; then
-		GET_VCS=0
-	fi
-
-	local netfile
-	for netfile in "${source[@]}"; 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() {
-- 
1.8.4



More information about the pacman-dev mailing list