#!/bin/sh -efu # # Copyright (C) 2010 Michael Shigorin # # This file 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, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # . gear-sh-functions . girar-client-sh-functions show_help() { cat < [...]] $PROG facilitates downloading an existing project repo from git.alt. Desired package name should be either specified explicitly or $PROG will assume that current working directory is inside a corresponding existing git repo (to just add remotes). Options: -N,--no-update do not try to download remote repos; -q,--quiet try to be more quiet; -v,--verbose print a message for each action; -V,--version print program version and exit; -h,--help show this text and exit. Report bugs to http://bugs.altlinux.ru/ EOF exit } print_version() { cat < Copyright (C) 2010 Michael Shigorin This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. EOF exit } init_repo() { verbose "initializing gear repo" mkdir -p "$1" cd "$1" git init } git_dir() { verbose "figuring out git directory" GIT_DIR="$(git rev-parse --git-dir)" GIT_DIR="$(readlink -ev "$GIT_DIR")" export GIT_DIR package="${GIT_DIR%.git}" package="${package%/}" printf "%s\n" "${package##*/}" } add_remote() { verbose "adding $1" git remote add "$1" "$(girar-remote-uri "$package" "$1")" } TEMP=`getopt -n $PROG -o N,q,v,V,h \ -l no-update,quiet,verbose,version,help -- "$@"` || show_usage eval set -- "$TEMP" no_update= while :; do case "$1" in -N|--no-update) no_update=1;; -q|--quiet) quiet=-q;; -v|--verbose) verbose=-v;; -V|--version) print_version;; -h|--help) show_help;; --) shift; break;; *) fatal "unrecognized option: $1";; esac shift done if [ "$#" -gt 0 ]; then package="$1"; shift [ -d "$package" ] || init_repo "$package" else package="$(git_dir)" || show_help fi if [ "$#" -gt 0 ]; then verbose "going after specified maintainers" for maintainer in "$@"; do add_remote "$maintainer" done else verbose "looking for remote repositories" run_remote_command find-package "$package" | while read path timestamp; do maintainer="${path#/people/}" add_remote "${maintainer%/packages/*}" done fi [ -n "$no_update" ] || { verbose "updating remotes" git remote update } # TODO: # - options to add only package maintainer/acl folks/N recent # - add gears remote too # - automate initial merge e.g. according to gears archive # - compare proposed remotes against `git remote show` # to either skip or force adding existing ones # - consider --max-age option to omit stale repos