summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Makefile63
-rw-r--r--man.commons.in8
-rw-r--r--mark-as-expendable-dir.in75
4 files changed, 150 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..582438e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+mark-as-expendable-dir
+man.commons
+*.common
+*.1
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8924ad7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,63 @@
+#
+# mark-as-expendable-dir - create CACHEDIR.TAG and .rsync-filter files
+#
+# Copyright (c) 2017 Erich Eckner <opensource at eckner dot net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+# USA.
+#
+
+DESTDIR =
+BINDIR = /usr/bin
+MANDIR = /usr/share/man
+
+VERSION = 0.0
+
+all: man.commons mark-as-expendable-dir mark-as-expendable-dir.1
+
+%: %.in
+ sed " \
+ s/#VERSION#/$(VERSION)/; \
+ s@#BINDIR#@$(BINDIR)@; \
+ s@#ETCDIR#@$(ETCDIR)@; \
+ s@#HELPTEXT#\(\s\+\)#@ --help \1display this help and exit\n --version\1display version and exit@; \
+ " $< > $@
+ [ "$@" = "mark-as-expendable-dir" ] && chmod +x "$@" || true
+
+%.1: % man.commons
+ grep -v "^$<(" man.commons | sed '/^\[SEE ALSO]$$/{n;:a;N;/\[/b;s/\n/, /;ta;}' > "$<.common" && \
+ help2man \
+ -n 'Create CACHEDIR.TAG and .rsync-filter files' \
+ -o "$@" -N --include $<.common --no-discard-stderr "./$<"
+
+.PHONY: install dist clean
+
+install: all
+ install -D -m0755 mark-as-expendable-dir $(DESTDIR)$(BINDIR)/mark-as-expendable-dir
+ install -D -m0644 mark-as-expendable-dir.1 $(DESTDIR)$(MANDIR)/man1/mark-as-expendable-dir.1
+
+clean:
+ ls -A | \
+ grep "^\($(shell sed 's|\.|\\.|; s|\*|.*|; s|$$|\\|' .gitignore | tr '\n' '\|')\)\$$" | \
+ xargs -r rm
+
+dist: clean
+ git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true
+ ! git tag -d v$(VERSION) 2> /dev/null
+ git tag v$(VERSION)
+ git push
+ git push --tags
+
+# End of file
diff --git a/man.commons.in b/man.commons.in
new file mode 100644
index 0000000..c811002
--- /dev/null
+++ b/man.commons.in
@@ -0,0 +1,8 @@
+[FILES]
+.TP
+.B "#BINDIR#/mark-as-expendable-dir"
+program file
+[AUTHOR]
+.nf
+Erich Eckner <opensource at eckner dot net>
+.fi
diff --git a/mark-as-expendable-dir.in b/mark-as-expendable-dir.in
new file mode 100644
index 0000000..c02ae5b
--- /dev/null
+++ b/mark-as-expendable-dir.in
@@ -0,0 +1,75 @@
+#!/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"
+done