[pacman-dev] [PATCH v2 3/4] Moved dependencies of download functions into a library

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


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

Moved functions out in preparation for splitting out download functions.
scripts/libmakepkg/*.sh files only import the files from their relevant
directory.
All libmakepkg files have an inclusion guard.
Also added libmakepkg targets to Makefile.am.

Signed-off-by: Ashley Whetter <ashley at awhetter.co.uk>
---
 scripts/.gitignore                                 |   8 +
 scripts/Makefile.am                                |  73 ++++++++-
 scripts/libmakepkg/messages.sh.in                  |  30 ++++
 scripts/libmakepkg/messages/error.sh               |  32 ++++
 scripts/libmakepkg/messages/msg.sh                 |  35 ++++
 scripts/libmakepkg/messages/msg2.sh                |  33 ++++
 scripts/libmakepkg/messages/plain.sh               |  35 ++++
 scripts/libmakepkg/messages/warning.sh             |  35 ++++
 scripts/libmakepkg/pkgbuild.sh.in                  |  30 ++++
 .../libmakepkg/pkgbuild/get_downloadclient.sh.in   |  60 +++++++
 scripts/libmakepkg/pkgbuild/get_filename.sh.in     |  60 +++++++
 scripts/libmakepkg/pkgbuild/get_filepath.sh.in     |  62 +++++++
 scripts/libmakepkg/pkgbuild/get_protocol.sh        |  38 +++++
 scripts/libmakepkg/pkgbuild/get_url.sh             |  30 ++++
 scripts/libmakepkg/util.sh.in                      |  30 ++++
 scripts/libmakepkg/util/cd_safe.sh.in              |  36 +++++
 scripts/libmakepkg/util/dir_is_empty.sh            |  32 ++++
 scripts/libmakepkg/util/in_array.sh                |  38 +++++
 scripts/makepkg.sh.in                              | 180 +--------------------
 19 files changed, 700 insertions(+), 177 deletions(-)
 create mode 100644 scripts/libmakepkg/messages.sh.in
 create mode 100644 scripts/libmakepkg/messages/error.sh
 create mode 100644 scripts/libmakepkg/messages/msg.sh
 create mode 100644 scripts/libmakepkg/messages/msg2.sh
 create mode 100644 scripts/libmakepkg/messages/plain.sh
 create mode 100644 scripts/libmakepkg/messages/warning.sh
 create mode 100644 scripts/libmakepkg/pkgbuild.sh.in
 create mode 100644 scripts/libmakepkg/pkgbuild/get_downloadclient.sh.in
 create mode 100644 scripts/libmakepkg/pkgbuild/get_filename.sh.in
 create mode 100644 scripts/libmakepkg/pkgbuild/get_filepath.sh.in
 create mode 100644 scripts/libmakepkg/pkgbuild/get_protocol.sh
 create mode 100644 scripts/libmakepkg/pkgbuild/get_url.sh
 create mode 100644 scripts/libmakepkg/util.sh.in
 create mode 100644 scripts/libmakepkg/util/cd_safe.sh.in
 create mode 100644 scripts/libmakepkg/util/dir_is_empty.sh
 create mode 100644 scripts/libmakepkg/util/in_array.sh

diff --git a/scripts/.gitignore b/scripts/.gitignore
index 8dac503..c8ccc07 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -8,3 +8,11 @@ pkgdelta
 repo-add
 repo-elephant
 repo-remove
+
+libmakepkg/messages.sh
+libmakepkg/pkgbuild.sh
+libmakepkg/pkgbuild/get_downloadclient.sh
+libmakepkg/pkgbuild/get_filename.sh
+libmakepkg/pkgbuild/get_filepath.sh
+libmakepkg/util.sh
+libmakepkg/util/cd_safe.sh
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 8130704..9d81878 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -36,13 +36,34 @@ LIBRARY = \
 	library/size_to_human.sh \
 	library/term_colors.sh
 
+LIBMAKEPKG = \
+	$(LIBMAKEPKG_INC) \
+	messages/error.sh \
+	messages/msg.sh \
+	messages/msg2.sh \
+	messages/plain.sh \
+	messages/warning.sh \
+	pkgbuild/get_protocol.sh \
+	pkgbuild/get_url.sh \
+	util/dir_is_empty.sh \
+	util/in_array.sh
+
+LIBMAKEPKG_INC = \
+	messages.sh \
+	pkgbuild.sh \
+	pkgbuild/get_downloadclient.sh \
+	pkgbuild/get_filename.sh \
+	pkgbuild/get_filepath.sh \
+	util.sh \
+	util/cd_safe.sh
+
 # Files that should be removed, but which Automake does not know.
 MOSTLYCLEANFILES = $(bin_SCRIPTS)
 
 libmakepkgdir = $(libdir)/makepkg
 
 clean-local:
-	$(AM_V_at)$(RM) -r .lib
+	$(AM_V_at)$(RM) -r .lib $(addprefix libmakepkg/,$(LIBMAKEPKG_INC))
 
 if USE_GIT_VERSION
 GIT_VERSION := $(shell sh -c 'git describe --abbrev=4 --dirty | sed s/^v//')
@@ -83,7 +104,31 @@ $(OURSCRIPTS): Makefile
 	$(AM_V_at)chmod +x,a-w $@
 	@$(BASH_SHELL) -O extglob -n $@
 
+$(addprefix libmakepkg/,$(LIBMAKEPKG_INC)): Makefile
+	$(AM_V_at)$(RM) $@
+	$(AM_V_GEN)test -f $(srcdir)/$@.in && m4 -P -I $(srcdir) $(srcdir)/$@.in | $(edit) >$@
+	@$(BASH_SHELL) -O extglob -n $@
+
+libmakepkg: \
+	$(srcdir)/libmakepkg/messages.sh \
+	$(srcdir)/libmakepkg/messages/error.sh \
+	$(srcdir)/libmakepkg/messages/msg.sh \
+	$(srcdir)/libmakepkg/messages/msg2.sh \
+	$(srcdir)/libmakepkg/messages/plain.sh \
+	$(srcdir)/libmakepkg/messages/warning.sh \
+	$(srcdir)/libmakepkg/pkgbuild.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_downloadclient.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_filename.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_filepath.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_protocol.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_url.sh \
+	$(srcdir)/libmakepkg/util.sh \
+	$(srcdir)/libmakepkg/util/cd_safe.sh \
+	$(srcdir)/libmakepkg/util/dir_is_empty.sh \
+	$(srcdir)/libmakepkg/util/in_array.sh
+
 makepkg: \
+	libmakepkg \
 	$(srcdir)/makepkg.sh.in \
 	$(srcdir)/makepkg-wrapper.sh.in \
 	$(srcdir)/library/parseopts.sh
@@ -131,7 +176,24 @@ makepkg-wrapper: \
 	$(srcdir)/makepkg-wrapper.sh.in \
 	$(srcdir)/makepkg.sh.in \
 	$(srcdir)/library/parseopts.sh \
-	| makepkg
+	$(srcdir)/libmakepkg/messages.sh \
+	$(srcdir)/libmakepkg/messages/error.sh \
+	$(srcdir)/libmakepkg/messages/msg.sh \
+	$(srcdir)/libmakepkg/messages/msg2.sh \
+	$(srcdir)/libmakepkg/messages/plain.sh \
+	$(srcdir)/libmakepkg/messages/warning.sh \
+	$(srcdir)/libmakepkg/pkgbuild.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_downloadclient.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_filename.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_filepath.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_protocol.sh \
+	$(srcdir)/libmakepkg/pkgbuild/get_url.sh \
+	$(srcdir)/libmakepkg/util.sh \
+	$(srcdir)/libmakepkg/util/cd_safe.sh \
+	$(srcdir)/libmakepkg/util/dir_is_empty.sh \
+	$(srcdir)/libmakepkg/util/in_array.sh \
+	| libmakepkg \
+	makepkg
 	$(AM_V_at)$(MKDIR_P) .lib
 	$(AM_V_at)mv -f makepkg .lib
 	$(AM_V_at)$(RM) $@
@@ -146,6 +208,10 @@ 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}
+	for lib in $(LIBMAKEPKG); do \
+		$(INSTALL) libmakepkg/$$lib $(DESTDIR)$(libmakepkgdir)/$$lib; \
+	done
 	cd $(DESTDIR)$(bindir) && \
 		$(RM) repo-elephant && \
 		( $(LN_S) repo-add repo-elephant || \
@@ -160,5 +226,8 @@ install-data-hook:
 uninstall-hook:
 	cd $(DESTDIR)$(bindir) && \
 		$(RM) repo-remove repo-elephant
+	for lib in $(LIBMAKEPKG); do \
+		$(RM) -r $(DESTDIR)$(libmakepkgdir)/$$lib; \
+	done
 
 # vim:set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages.sh.in b/scripts/libmakepkg/messages.sh.in
new file mode 100644
index 0000000..b87219b
--- /dev/null
+++ b/scripts/libmakepkg/messages.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#   messages.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_MESSAGES_SH" ] && return
+LIBMAKEPKG_MESSAGES_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+for lib in "$LIBRARY"/messages/*.sh; do
+	source "$lib"
+done
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages/error.sh b/scripts/libmakepkg/messages/error.sh
new file mode 100644
index 0000000..6908700
--- /dev/null
+++ b/scripts/libmakepkg/messages/error.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+#   error.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+#   Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+#   Copyright (c) 2005 by Aurelien Foret <orelien at chez.com>
+#   Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+#   Copyright (c) 2005 by Christian Hamar <krics at linuxforum.hu>
+#   Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+#   Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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/>.
+#
+
+error() {
+	local mesg=$1; shift
+	printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages/msg.sh b/scripts/libmakepkg/messages/msg.sh
new file mode 100644
index 0000000..a2b1489
--- /dev/null
+++ b/scripts/libmakepkg/messages/msg.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+#   msg.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+#   Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+#   Copyright (c) 2005 by Aurelien Foret <orelien at chez.com>
+#   Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+#   Copyright (c) 2005 by Christian Hamar <krics at linuxforum.hu>
+#   Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+#   Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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_MESSAGES_MSG_SH" ] && return
+LIBMAKEPKG_MESSAGES_MSG_SH=1
+
+msg() {
+	local mesg=$1; shift
+	printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages/msg2.sh b/scripts/libmakepkg/messages/msg2.sh
new file mode 100644
index 0000000..c798d1c
--- /dev/null
+++ b/scripts/libmakepkg/messages/msg2.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+#   msg2.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+#   Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+#   Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+#   Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+#   Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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_MESSAGES_MSG2_SH" ] && return
+LIBMAKEPKG_MESSAGES_MSG2_SH=1
+
+msg2() {
+	local mesg=$1; shift
+	printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages/plain.sh b/scripts/libmakepkg/messages/plain.sh
new file mode 100644
index 0000000..762beb3
--- /dev/null
+++ b/scripts/libmakepkg/messages/plain.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+#   plain.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+#   Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+#   Copyright (c) 2005 by Aurelien Foret <orelien at chez.com>
+#   Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+#   Copyright (c) 2005 by Christian Hamar <krics at linuxforum.hu>
+#   Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+#   Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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_MESSAGES_PLAIN_SH" ] && return
+LIBMAKEPKG_MESSAGES_PLAIN_SH=1
+
+plain() {
+	local mesg=$1; shift
+	printf "${BOLD}    ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/messages/warning.sh b/scripts/libmakepkg/messages/warning.sh
new file mode 100644
index 0000000..2ea86bd
--- /dev/null
+++ b/scripts/libmakepkg/messages/warning.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+#   warning.sh
+#
+#   Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+#   Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+#   Copyright (c) 2005 by Aurelien Foret <orelien at chez.com>
+#   Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+#   Copyright (c) 2005 by Christian Hamar <krics at linuxforum.hu>
+#   Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+#   Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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_MESSAGES_WARNING_SH" ] && return
+LIBMAKEPKG_MESSAGES_WARNING_SH=1
+
+warning() {
+	local mesg=$1; shift
+	printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild.sh.in b/scripts/libmakepkg/pkgbuild.sh.in
new file mode 100644
index 0000000..7986eec
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#   pkgbuild.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_PKGBUILD_SH" ] && return
+LIBMAKEPKG_PKGBUILD_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+for lib in "$LIBRARY"/pkgbuild/*.sh; do
+    source "$lib"
+done
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild/get_downloadclient.sh.in b/scripts/libmakepkg/pkgbuild/get_downloadclient.sh.in
new file mode 100644
index 0000000..50d1ce2
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild/get_downloadclient.sh.in
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+#   get_downloadclient.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_PKGBUILD_GET_DOWNLOADCLIENT_SH" ] && return
+LIBMAKEPKG_PKGBUILD_GET_DOWNLOADCLIENT_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+
+get_downloadclient() {
+	local proto=$1
+
+	# loop through DOWNLOAD_AGENTS variable looking for protocol
+	local i
+	for i in "${DLAGENTS[@]}"; do
+		local handler="${i%%::*}"
+		if [[ $proto = "$handler" ]]; then
+			local agent="${i##*::}"
+			break
+		fi
+	done
+
+	# if we didn't find an agent, return an error
+	if [[ -z $agent ]]; then
+		error "$(gettext "Unknown download protocol: %s")" "$proto"
+		plain "$(gettext "Aborting...")"
+		exit 1 # $E_CONFIG_ERROR
+	fi
+
+	# ensure specified program is installed
+	local program="${agent%% *}"
+	if [[ ! -x $program ]]; then
+		local baseprog="${program##*/}"
+		error "$(gettext "The download program %s is not installed.")" "$baseprog"
+		plain "$(gettext "Aborting...")"
+		exit 1 # $E_MISSING_PROGRAM
+	fi
+
+	printf "%s\n" "$agent"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild/get_filename.sh.in b/scripts/libmakepkg/pkgbuild/get_filename.sh.in
new file mode 100644
index 0000000..3028f1b
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild/get_filename.sh.in
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+#   get_filename.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_PKGBUILD_GET_FILENAME_SH" ] && return
+LIBMAKEPKG_PKGBUILD_GET_FILENAME_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/pkgbuild/get_protocol.sh"
+
+# extract the filename from a source entry
+get_filename() {
+	local netfile=$1
+
+	# if a filename is specified, use it
+	if [[ $netfile = *::* ]]; then
+		printf "%s\n" ${netfile%%::*}
+		return
+	fi
+
+	local proto=$(get_protocol "$netfile")
+
+	case $proto in
+		bzr*|git*|hg*|svn*)
+			filename=${netfile%%#*}
+			filename=${filename%/}
+			filename=${filename##*/}
+			if [[ $proto = bzr* ]]; then
+				filename=${filename#*lp:}
+			fi
+			if [[ $proto = git* ]]; then
+				filename=${filename%%.git*}
+			fi
+			;;
+		*)
+			# if it is just an URL, we only keep the last component
+			filename="${netfile##*/}"
+			;;
+	esac
+	printf "%s\n" "${filename}"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild/get_filepath.sh.in b/scripts/libmakepkg/pkgbuild/get_filepath.sh.in
new file mode 100644
index 0000000..860fbef
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild/get_filepath.sh.in
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+#   get_filepath.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_PKGBUILD_GET_FILEPATH_SH" ] && return
+LIBMAKEPKG_PKGBUILD_GET_FILEPATH_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/pkgbuild/get_filename.sh"
+source "$LIBRARY/pkgbuild/get_protocol.sh"
+
+# a source entry can have two forms :
+# 1) "filename::http://path/to/file"
+# 2) "http://path/to/file"
+
+# Return the absolute filename of a source entry
+get_filepath() {
+	local file="$(get_filename "$1")"
+	local proto="$(get_protocol "$1")"
+
+	case $proto in
+		bzr*|git*|hg*|svn*)
+			if [[ -d "$startdir/$file" ]]; then
+				file="$startdir/$file"
+			elif [[ -d "$SRCDEST/$file" ]]; then
+				file="$SRCDEST/$file"
+			else
+				return 1
+			fi
+			;;
+		*)
+			if [[ -f "$startdir/$file" ]]; then
+				file="$startdir/$file"
+			elif [[ -f "$SRCDEST/$file" ]]; then
+				file="$SRCDEST/$file"
+			else
+				return 1
+			fi
+			;;
+	esac
+
+	printf "%s\n" "$file"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild/get_protocol.sh b/scripts/libmakepkg/pkgbuild/get_protocol.sh
new file mode 100644
index 0000000..d0a217b
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild/get_protocol.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+#   get_protocol.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_PKGBUILD_GET_PROTOCOL_SH" ] && return
+LIBMAKEPKG_PKGBUILD_GET_PROTOCOL_SH=1
+
+# extract the protocol from a source entry - return "local" for local sources
+get_protocol() {
+	if [[ $1 = *://* ]]; then
+		# strip leading filename
+		local proto="${1##*::}"
+		printf "%s\n" "${proto%%://*}"
+	elif [[ $1 = *lp:* ]]; then
+		local proto="${1##*::}"
+		printf "%s\n" "${proto%%lp:*}"
+	else
+		printf "%s\n" local
+	fi
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/pkgbuild/get_url.sh b/scripts/libmakepkg/pkgbuild/get_url.sh
new file mode 100644
index 0000000..f25698c
--- /dev/null
+++ b/scripts/libmakepkg/pkgbuild/get_url.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#   get_url.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_PKGBUILD_GET_URL_SH" ] && return
+_LIBMAKEPKG_PKGBUILD_GET_URL_SH=1
+
+# extract the URL from a source entry
+get_url() {
+	# strip an eventual filename
+	printf "%s\n" "${1#*::}"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util.sh.in b/scripts/libmakepkg/util.sh.in
new file mode 100644
index 0000000..470e8f5
--- /dev/null
+++ b/scripts/libmakepkg/util.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#   util.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_UTIL_SH" ] && return
+LIBMAKEPKG_UTIL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+for lib in "$LIBRARY"/util/*.sh; do
+	source "$lib"
+done
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/cd_safe.sh.in b/scripts/libmakepkg/util/cd_safe.sh.in
new file mode 100644
index 0000000..5319d51
--- /dev/null
+++ b/scripts/libmakepkg/util/cd_safe.sh.in
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+#	  cd_safe.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_UTIL_CD_SAFE_SH" ] && return
+LIBMAKEPKG_UTIL_CD_SAFE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/messages.sh"
+
+cd_safe() {
+	if ! cd "$1"; then
+		error "$(gettext "Failed to change to directory %s")" "$1"
+		plain "$(gettext "Aborting...")"
+		exit 1
+	fi
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/dir_is_empty.sh b/scripts/libmakepkg/util/dir_is_empty.sh
new file mode 100644
index 0000000..1fb6ca8
--- /dev/null
+++ b/scripts/libmakepkg/util/dir_is_empty.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+#   dir_is_empty.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_UTIL_DIR_IS_EMPTY_SH" ] && return
+LIBMAKEPKG_UTIL_DIR_IS_EMPTY_SH=1
+
+dir_is_empty() {
+	(
+		shopt -s dotglob nullglob
+		files=("$1"/*)
+		(( ${#files} == 0 ))
+	)
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/in_array.sh b/scripts/libmakepkg/util/in_array.sh
new file mode 100644
index 0000000..81b43ac
--- /dev/null
+++ b/scripts/libmakepkg/util/in_array.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+#   in_array.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_UTIL_IN_ARRAY_SH" ] && return
+LIBMAKEPKG_UTIL_IN_ARRAY_SH=1
+
+##
+#  usage : in_array( $needle, $haystack )
+# return : 0 - found
+#          1 - not found
+##
+in_array() {
+	local needle=$1; shift
+	local item
+	for item in "$@"; do
+		[[ $item = "$needle" ]] && return 0 # Found
+	done
+	return 1 # Not Found
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index d122537..bce5c8d 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -97,33 +97,12 @@ PACMAN_OPTS=
 
 shopt -s extglob
 
-### SUBROUTINES ###
-
-plain() {
-	local mesg=$1; shift
-	printf "${BOLD}    ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg() {
-	local mesg=$1; shift
-	printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg2() {
-	local mesg=$1; shift
-	printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-warning() {
-	local mesg=$1; shift
-	printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-error() {
-	local mesg=$1; shift
-	printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
+# Import libmakepkg
+for lib in "$LIBRARY"/*.sh; do
+	source "$lib"
+done
 
+### SUBROUTINES ###
 
 ##
 # Special exit call for traps, Don't print any error messages when inside,
@@ -198,124 +177,6 @@ enter_fakeroot() {
 	fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
 }
 
-
-# a source entry can have two forms :
-# 1) "filename::http://path/to/file"
-# 2) "http://path/to/file"
-
-# Return the absolute filename of a source entry
-get_filepath() {
-	local file="$(get_filename "$1")"
-	local proto="$(get_protocol "$1")"
-
-	case $proto in
-		bzr*|git*|hg*|svn*)
-			if [[ -d "$startdir/$file" ]]; then
-				file="$startdir/$file"
-			elif [[ -d "$SRCDEST/$file" ]]; then
-				file="$SRCDEST/$file"
-			else
-				return 1
-			fi
-			;;
-		*)
-			if [[ -f "$startdir/$file" ]]; then
-				file="$startdir/$file"
-			elif [[ -f "$SRCDEST/$file" ]]; then
-				file="$SRCDEST/$file"
-			else
-				return 1
-			fi
-			;;
-	esac
-
-	printf "%s\n" "$file"
-}
-
-# extract the filename from a source entry
-get_filename() {
-	local netfile=$1
-
-	# if a filename is specified, use it
-	if [[ $netfile = *::* ]]; then
-		printf "%s\n" ${netfile%%::*}
-		return
-	fi
-
-	local proto=$(get_protocol "$netfile")
-
-	case $proto in
-		bzr*|git*|hg*|svn*)
-			filename=${netfile%%#*}
-			filename=${filename%/}
-			filename=${filename##*/}
-			if [[ $proto = bzr* ]]; then
-				filename=${filename#*lp:}
-			fi
-			if [[ $proto = git* ]]; then
-				filename=${filename%%.git*}
-			fi
-			;;
-		*)
-			# if it is just an URL, we only keep the last component
-			filename="${netfile##*/}"
-			;;
-	esac
-	printf "%s\n" "${filename}"
-}
-
-# extract the URL from a source entry
-get_url() {
-	# strip an eventual filename
-	printf "%s\n" "${1#*::}"
-}
-
-# extract the protocol from a source entry - return "local" for local sources
-get_protocol() {
-	if [[ $1 = *://* ]]; then
-		# strip leading filename
-		local proto="${1##*::}"
-		printf "%s\n" "${proto%%://*}"
-	elif [[ $1 = *lp:* ]]; then
-		local proto="${1##*::}"
-		printf "%s\n" "${proto%%lp:*}"
-	else
-		printf "%s\n" local
-	fi
-}
-
-get_downloadclient() {
-	local proto=$1
-
-	# loop through DOWNLOAD_AGENTS variable looking for protocol
-	local i
-	for i in "${DLAGENTS[@]}"; do
-		local handler="${i%%::*}"
-		if [[ $proto = "$handler" ]]; then
-			local agent="${i##*::}"
-			break
-		fi
-	done
-
-	# if we didn't find an agent, return an error
-	if [[ -z $agent ]]; then
-		error "$(gettext "Unknown download protocol: %s")" "$proto"
-		plain "$(gettext "Aborting...")"
-		exit 1 # $E_CONFIG_ERROR
-	fi
-
-	# ensure specified program is installed
-	local program="${agent%% *}"
-	if [[ ! -x $program ]]; then
-		local baseprog="${program##*/}"
-		error "$(gettext "The download program %s is not installed.")" "$baseprog"
-		plain "$(gettext "Aborting...")"
-		exit 1 # $E_MISSING_PROGRAM
-	fi
-
-	printf "%s\n" "$agent"
-}
-
 download_local() {
 	local netfile=$1
 	local filepath=$(get_filepath "$netfile")
@@ -966,21 +827,6 @@ in_opt_array() {
 	return 127
 }
 
-
-##
-#  usage : in_array( $needle, $haystack )
-# return : 0 - found
-#          1 - not found
-##
-in_array() {
-	local needle=$1; shift
-	local item
-	for item in "$@"; do
-		[[ $item = "$needle" ]] && return 0 # Found
-	done
-	return 1 # Not Found
-}
-
 source_has_signatures() {
 	local file
 	for file in "${source[@]}"; do
@@ -1386,14 +1232,6 @@ error_function() {
 	exit 2 # $E_BUILD_FAILED
 }
 
-cd_safe() {
-	if ! cd "$1"; then
-		error "$(gettext "Failed to change to directory %s")" "$1"
-		plain "$(gettext "Aborting...")"
-		exit 1
-	fi
-}
-
 source_safe() {
 	shopt -u extglob
 	if ! source "$@"; then
@@ -2481,14 +2319,6 @@ canonicalize_path() {
 	fi
 }
 
-dir_is_empty() {
-	(
-		shopt -s dotglob nullglob
-		files=("$1"/*)
-		(( ${#files} == 0 ))
-	)
-}
-
 m4_include(library/parseopts.sh)
 
 usage() {
-- 
1.8.4



More information about the pacman-dev mailing list