#!/bin/bash set -e verwendung() { >&2 echo 'mark-as-expendable-dir creates CACHEDIR.TAG and .rsync-filter files to hide directory from backups by "tar --exclude-caches" and "rsync -F".' >&2 echo '' >&2 echo 'Usage: mark-as-expendable-dir [OPTIONS] [DIRECTORIES]' >&2 echo ' -c,--caller=caller name of caller to put into comment of CACHEDIR.TAG' >&2 echo \ '#HELPTEXT# #' exit 1 } eval set -- "$(getopt -o c: --long caller:,help,version -n "$(basename "$0")" -- "$@" || echo verwendung)" caller="$(ps -o comm= $PPID)" while true do case "$1" in -c|--caller) shift caller="$1" ;; --help) verwendung 0 ;; --version) echo '#VERSION#' exit 0 ;; --) shift break ;; *) >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende." verwendung ;; esac shift done if [ $# -eq 0 ] then >&2 echo 'No directories given - was this intented?' verwendung fi for dir in "$@" do if [ ! -d "${dir}" ] then >&2 echo "Argument '${dir}' is not a directory." verwendung fi done for dir in "$@" do { printf 'Signature: ' printf '.IsCacheDirectory' | \ md5sum - | \ cut -d' ' -f 1 printf '# This file is a cache directory tag created by %s for %s.\n' \ "$(basename "$0")" \ "${caller}" printf '# For information about cache directory tags, see:\n' printf '# http://www.brynosaurus.com/cachedir/\n' } > "${dir}/CACHEDIR.TAG" { printf '+ .rsync-filter\n' printf -- '- *\n' } > "${dir}/.rsync-filter" touch "${dir}/.nobackup" done