#!/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 ( echo -n 'Signature: ' echo -n '.IsCacheDirectory' | \ md5sum - | \ cut -d ' ' -f 1 echo '# This file is a cache directory tag created by '"$(basename "$0")"' for '"${caller}"'.' echo '# For information about cache directory tags, see:' echo '# http://www.brynosaurus.com/cachedir/' ) > "${dir}/CACHEDIR.TAG" ( echo '+ .rsync-filter' echo '- *' ) > "${dir}/.rsync-filter" touch "${dir}/.nobackup" done