From 3d4529335c598e79b5a483fedc4c9d5c12ef10f1 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Mon, 18 May 2015 00:02:17 +1000 Subject: libmakepkg: extract functions for source download and extraction Signed-off-by: Allan McRae --- scripts/libmakepkg/source/bzr.sh.in | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 scripts/libmakepkg/source/bzr.sh.in (limited to 'scripts/libmakepkg/source/bzr.sh.in') 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 +# +# 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 . +# + +[[ -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 +} -- cgit v1.2.3-70-g09d2