#!/bin/bash -e # Copyright (c) 2012-2013 Pacman Development Team # Copyright (c) 2012-2013 Luke Shumaker # # 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 . . libremessages usage() { echo "Usage: ${0##*/} SOURCE" echo 'Downloads a source as configured in `pbs-convert.conf`.' echo echo 'Options:' echo ' -h Show this message' } main() { in_array '-h' "$@" && { usage; return 0; } [[ $# != 1 ]] && { usage; return 1; } local source=$1 local url="$(pbs-plumb-config get "source.$source.url")" local cachedir="$(pbs-plumb-config get core.cachedir)" [[ -d "${cachedir}" ]] || mkdir -p "${cachedir}" if [[ ! -d "${cachedir}/${source}.git" ]]; then cd "${cachedir}" msg "$(gettext "Cloning %s")" "${cachedir}/${source}.git" if ! git clone --mirror "$url" "$source.git"; then error "$(gettext "Failed to download source %s")" "$source" exit 1 fi else cd "${cachedir}/${source}.git" # 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")" "$source" "$url" plain "$(gettext "Aborting...")" exit 1 fi msg "$(gettext "Updating %s")" "${cachedir}/${source}.git" if ! git fetch --all -p; then error "$(gettext "Failed to update source %s")" "$source" exit 1 fi fi } main "$@"