#!/bin/bash PROGNAME=${0##*/} # $HeadURL$ $LastChangedRevision$ # Configurable stuff VIDEO_VIEW_CMD=mpv IMAGE_VIEW_CMD=mpv PERIOD=10 # Other globals HAVE_WARNED_THAT_MIRRORING_OVER_HTTP_IS_UNRELIABLE_FLAG=false # Includes . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } main() { local MY_ARGS local PORT RELEASE PORTS RELEASES SRC DST SRC2 DST2 LAYOUT SIMULATE_FLAG MIRROR_CMD CUTDIRS_COUNT # Defaults for options # Process options special_opts_handler() { case $1 in --fs) FS_FRACTION=1 ;; --ports=*) PORTS=${1#*=} ;; --releases=*) RELEASES=${1#*=} ;; --layout=*) LAYOUT=${1#*=} ;; *) return 1 ;; esac shift } miniade_process_options --help-handler=help --special-opts-handler=special_opts_handler MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# = 2 ] || miniade_bad_usage SRC=$1 DST=$2 miniade_debug 10 "main: SRC=$SRC, DST=$DST, PORTS=$PORTS, RELEASES=$RELEASES, LAYOUT=$LAYOUT" # Sanity checks and derivations for VAR in PORTS RELEASES LAYOUT; do eval "[ \"X\$$VAR\" != X ] || miniade_bad_usage" done case $SRC in rsync://*) : ;; http://*) : ;; file:///*) : ;; # deliberate third slash *) miniade_error "$SRC2: protocol not recognised" ;; esac SRC=${SRC%/} DST=${DST%/} LAYOUT=${LAYOUT%/} LAYOUT=${LAYOUT#/} # Guts for RELEASE in ${RELEASES//,/ }; do for PORT in ${PORTS//,/ }; do miniade_info "mirroring release $RELEASE port $PORT ..." SRC2=$SRC/$LAYOUT SRC2=${SRC2///$RELEASE} SRC2=${SRC2///$PORT} DST2=$DST/$LAYOUT DST2=${DST2///$RELEASE} DST2=${DST2///$PORT} # If the layout is '.' then we have a trailing '/.' which will confuse the # cut-dir counter. SRC2=${SRC2%/.} DST2=${DST2%/.} case $SRC in rsync://*) rpmmirror_rsync $SRC2 $DST2 ;; file:///*) rpmmirror_file $SRC2 $DST2 ;; http://*) rpmmirror_http $SRC2 $DST2 ;; esac done done } rpmmirror_rsync() { local SRC DST SRC=$1 DST=$2 miniade_evaler "mkdir -p $DST" miniade_evaler "rsync --no-motd -a --delete --delete-excluded --exclude=\"*src.rpm\" --exclude=/debug/ $SRC/ $DST/" } rpmmirror_file() { local SRC DST SRC=$1 DST=$2 miniade_evaler "mkdir -p $DST" miniade_evaler "rsync -a --delete --delete-excluded --exclude=\"*src.rpm\" --exclude=/debug/ ${SRC#file://}/ $DST/" } rpmmirror_http() { local SRC DST SRC=$1 DST=$2 if ! $HAVE_WARNED_THAT_MIRRORING_OVER_HTTP_IS_UNRELIABLE_FLAG; then miniade_warning "mirroring over http:// is unreliable (can you switch to rsync:// instead?)" sleep 5 HAVE_WARNED_THAT_MIRRORING_OVER_HTTP_IS_UNRELIABLE_FLAG=true fi # cut all dirs off source (3 comes from // and newline). CUTDIRS_COUNT=$(($(echo $SRC | sed 's/[^/]//g' | wc -c) - 3)) miniade_evaler "mkdir -p $DST" miniade_evaler "cd $DST" miniade_evaler "wget -m -nH --reject \"index.html*\" --cut-dirs=$CUTDIRS_COUNT --reject=src.rpm -np --exclude-directories=/${SRC#http://*/}/debug/ --quiet $SRC/" } help() { local PROGNAME miniade_get_progname PROGNAME echo "Usage: $PROGNAME [ ] " echo echo "Obligatory options: --ports=[,...] which ports" echo " --releases=[,...] which releases" echo " --layout= intra-repo layout" echo echo "Notes: may include '' and ''" echo " is an rsync-able URL for the upstream repository" echo " is a directory into which the mirror will be made" echo exit 0 } version() { local PROGNAME miniade_get_progname PROGNAME echo "$PROGNAME version 0" exit 0 } paths() { exit 0 } main "$@"