#!/bin/bash ARCH_GIT_REPOS=(packages community) OPT_ARCH=$(uname -m) OPT_FORCE=0 : ${ASPROOT:=$HOME/asp} m4_include(remote.inc.sh) m4_include(package.inc.sh) log_meta() { printf "$1 $2\n" "${@:3}" } log_error() { log_meta 'error:' "$@" >&2 } log_fatal() { log_error "$@" exit 1 } log_warning() { log_meta 'warning:' "$@" >&2 } log_info() { log_meta '==>' "$@" } map() { local map_r=0 for _ in "${@:2}"; do "$1" "$_" || (( $# > 255 ? map_r=1 : ++r )) done return $map_r } usage() { cat</dev/null } initialize() { local remote if [[ -s config && $(git config core.bare) = 'true' ]]; then migrate_bare_repo fi [[ -f .asp ]] && return 0 git init || return 1 for remote in "${ARCH_GIT_REPOS[@]}"; do rm -rf "$remote" git remote add "$remote" git://projects.archlinux.org/svntogit/"$remote".git done touch .asp } dump_packages() { local remote refspecs dumpfn case $1 in all) dumpfn=remote_get_all_refs ;; local) dumpfn=remote_get_tracked_refs ;; esac for remote in "${ARCH_GIT_REPOS[@]}"; do "$dumpfn" "$remote" refspecs if [[ $refspecs ]]; then printf '%s\n' "${refspecs[@]/#packages/"$remote"}" fi done } list_local() { dump_packages 'local' } list_all() { dump_packages 'all' } shortlog() { package_log "$@" "$FUNCNAME" } log() { package_log "$@" "$FUNCNAME" } difflog() { package_log "$@" "$FUNCNAME" } gc() { git prune git gc } untrack() { local pkgname=$1 remote package_init -n "$pkgname" remote || return 1 remote_untrack "$remote" "$pkgname" } disk_usage() { local usage read usage _ < <(du -sh "$ASPROOT") log_info 'Using %s on disk.' "$usage" } umask 0022 startdir=$PWD cd "$ASPROOT" || log_fatal "ASPROOT ($ASPROOT) does not exist!" initialize while getopts ':a:fhV' flag; do case $flag in a) OPT_ARCH=$OPTARG ;; f) OPT_FORCE=1 ;; h) usage exit 0 ;; V) version exit 0 ;; \?) log_fatal "invalid option -- '%s'" "$OPTARG" ;; :) log_fatal "option '-%s' requires an argument" "$OPTARG" ;; esac done shift $(( OPTIND - 1 )) action=$1 shift case $action in update) if (( $# == 0 )); then update else update_packages "$@" fi ;; list-repos) map package_get_repos "$@" ;; list-arches) map package_get_arches "$@" ;; list-all) list_all ;; list-local) list_local ;; export) map package_export "$@" ;; shortlog) shortlog "$1" ;; log) log "$1" ;; difflog) difflog "$1" ;; disk-usage) disk_usage ;; gc) gc ;; untrack) map untrack "$@" ;; help) usage exit 0 ;; checkout) map package_checkout "$@" ;; '') log_fatal 'no action specified (use -h for help)' ;; *) log_fatal 'unknown action: %s' "$action" ;; esac