#!/bin/bash tools_dir=$(dirname "$0") # shellcheck source=/dev/null . "$tools_dir/common.sh" '' if [ "$1" = '-n' ]; then shift last=$(tail -n1 "$SHA1_FILE" | cut -f1 -d$'\t') start_from=$(awk -F '\t' '/^[^#]/ && $3 == "'"$last"'" { do getline; while (/^#/ || $2 == "branch"); print $3; exit 0; }' "$CTRL_FILE") fi if [ "$1" = '-s' ]; then shift start_from="$1" if [ -z "$start_from" ]; then printf '-s requires a start tree\n' 1>&2 exit 1 fi shift fi get_field() { awk -F '\t' '/^[^#]/ && $3 == "'"$1"'" { print $'"$2"'; }' "$CTRL_FILE" } fetch_git() { git fetch "$1" } fetch_mmotm() ( if ! cd ../mmotm; then printf 'Cannot chdir to ../mmotm\n' 1>&2 return fi if ! rsync -az --partial --exclude '.git*' \ --exclude broken-out.tar.gz --delete \ gandalf.ozlabs.org::akpm/mmotm/. .; then git reset --hard printf 'Fetcing mmotm failed\n' 1>&2 return fi git add -A . if [ "$(git status --porcelain)" ]; then git commit -m "$(head -n 1 .DATE)" fi ) trees="$*" if ! [ "$trees" ]; then trees=$(awk -F '\t' '/^[^#]/ && $2 != "branch" { print $3 }' "$CTRL_FILE") fi for name in $trees; do if [ -n "$start_from" ]; then if [ "$name" = "$start_from" ]; then start_from='' else continue fi fi type=$(get_field "$name" 2) if ! [ "$type" ]; then printf '%s: unknown tree\n' "$name" 1>&2 continue fi printf '%s: %s\n' "$name" "$type" fun="fetch_$type" tfun=$(type -t "$fun") if [ "$tfun" = 'function' ]; then "$fun" "$name" fi done exit 0