]> rtime.felk.cvut.cz Git - sojka/duhome.git/commitdiff
First version that somehow works
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 5 Feb 2013 17:02:06 +0000 (18:02 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 5 Feb 2013 17:02:06 +0000 (18:02 +0100)
duhome [new file with mode: 0755]

diff --git a/duhome b/duhome
new file mode 100755 (executable)
index 0000000..01310eb
--- /dev/null
+++ b/duhome
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+set -e
+
+DATA=/var/lib/duhome
+
+case "$1" in
+    init)
+       mkdir -p $DATA
+       cd $DATA
+       git init
+       ;;
+    save)
+       cd $DATA
+       for i in /home/*; do
+           du -shx $i | cut -f1 > ${i#/home/};
+           git add ${i#/home/}
+       done
+       ;;
+    commit)
+       cd $DATA
+       shift
+       GIT_AUTHOR_NAME="$0" GIT_AUTHOR_EMAIL="$USER@$(hostname -f)" \
+           git commit -m 'Automatic commit' "$@"
+       ;;
+    status)
+       cd $DATA
+       grep . *|sort -h -k2 -t:
+       ;;
+    log)
+       cd $DATA
+       dir=$2
+       if ! [ "$dir" ]; then echo "Missing directory name" >&2; exit 1; fi
+       if ! [ -f "$dir" ]; then echo "No information about $dir in $DATA" >&2; exit 1; fi
+       git log --format='%H %ci' -- $dir | while read commit date; do
+           echo $date $(git show $commit:$dir)
+       done
+       ;;
+    help|"")
+       cat <<EOF
+Usage: $0 <command> [ <options> ]
+
+Commands:
+- init
+- save
+- commit [ <git commit arguments> ]
+- status
+- log <directory>
+EOF
+       ;;
+esac