#!/bin/bash # Modules . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff DIRS=( intros songs outros silences reminders ) # Other globals main() { local MY_ARGS PROGNAME SIMULATE # Defaults for options # Process options special_opts_handler() { case $1 in *) return 1 ;; esac } miniade_do_option_processing --help-handler=help_handler --special-opts-handler=special_opts_handler MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# = 2 ] || miniade_do_bad_usage SRC_DIR=$1 DST_DIR=$2 # Sanity checks and derivations miniade_get_progname PROGNAME for DIR in "${DIRS[@]}"; do [ -d "$SRC_DIR/$DIR" ] || miniade_error "$SRC_DIR/$DIR: not found (hint: is $SRC_DIR really the Akoonah data directory?)" done [ -f $DST_DIR/.akoonah ] || miniade_error "$DST_DIR: doesn't look like the Akoonah micro-SD card's mountpoint" STAGING_DIR=$(mktemp -d) miniade_get_simulate SIMULATE if $SIMULATE; then RSYNC_SIMULATE_OPT=-n else RSYNC_SIMULATE_OPT= fi # Guts miniade_info "symlinking files to staging area ..." # Note that we do the symlink farm for real, regardless of if in simulate mode or not ('cos it's just temp stuff). DIR_COUNTER=1 for DIR in "${DIRS[@]}"; do FILE_COUNTER=1 mkdir -p "$STAGING_DIR/$(printf "%02d" $DIR_COUNTER)" for SYMLINK_TGT in "$SRC_DIR"/$DIR/*; do SYMLINK="$STAGING_DIR/$(printf "%02d" $DIR_COUNTER)/$(printf "%03d" $FILE_COUNTER).mp3" ln -sr "$SYMLINK_TGT" "$SYMLINK" #miniade_evaler "touch -h --reference=\"$SYMLINK_TGT\" \"$SYMLINK\"" ((FILE_COUNTER++)) done ((DIR_COUNTER++)) done miniade_info "copying files from staging area to micro-SD card ..." rsync -rLtv $RSYNC_SIMULATE_OPT --omit-dir-times --modify-window=2 --no-perms --no-owner --no-group --delete --exclude='.akoonah' "$STAGING_DIR"/ "$DST_DIR"/ echo "Contents of this micro-SD card updated by $LOGNAME on $(date) using $PROGNAME." > $DST_DIR/.akoonah miniade_info "flushing caches ..." miniade_evaler "sync" } help_handler() { local PROGNAME miniade_get_progname PROGNAME echo "Usage: $PROGNAME [ ] " exit 0 } main "$@"