initial checkin; mostly complete
[distorted-backup] / snap.trivial
CommitLineData
99248ed2
MW
1#! /bin/sh
2###
3### Make fake snapshots by doing nothing at all
4###
5### (c) 2011 Mark Wooding
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This program is free software; you can redistribute it and/or modify
11### it under the terms of the GNU General Public License as published by
12### the Free Software Foundation; either version 2 of the License, or
13### (at your option) any later version.
14###
15### This program is distributed in the hope that it will be useful,
16### but WITHOUT ANY WARRANTY; without even the implied warranty of
17### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18### GNU General Public License for more details.
19###
20### You should have received a copy of the GNU General Public License
21### along with this program; if not, write to the Free Software Foundation,
22### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24set -e
25quis=${0##*/}
26
27###--------------------------------------------------------------------------
28### Parse the command line.
29
30## Provide help or version information.
31usage="usage: $quis DEVICE [KEY=VALUE ...]"
32version="$quis, version 1.0.0"
33case "$#,$1" in
34 0,*) echo >&2 "$usage"; exit 1 ;;
35 *,-v | *,--version) echo "$version"; exit ;;
36 *,-h | *,--help)
37 cat <<EOF
38$version
39$usage
40
41Option keys:
42 op=OPERATION \`snap' to create snapshot, or \`unsnap' to remove.
43 tag=TAG Disambiguation tag to store in filesystem.
44EOF
45 exit
46 ;;
47esac
48
49## Scan the option keys.
50dev=$1; shift
51Oop=snap Otag=snap
52win=t
53for i in "$@"; do
54 case "$i" in
55 ?*=*) ;;
56 *) echo >&2 "$quis: malformed option \`$i'"; exit 1 ;;
57 esac
58 k=${i%%=*} v=${i#*=}
59 case "$k" in *.trivial) k=${k%.trivial} ;; ?*.?*) continue ;; esac
60 case "$k" in
61 op | tag) eval "O$k=\$v" ;;
62 *) echo >&2 "$quis: unknown option \`$k'"; win=nil ;;
63 esac
64done
65case $win in nil) exit 1 ;; esac
66
67###--------------------------------------------------------------------------
68### Take or remove the snapshot.
69
70case "$Oop" in
71 snap)
72 echo "$dev"
73 ;;
74 unsnap)
75 ;;
76 *)
77 echo >&2 "$quis: unknown operation \`$Oop'"
78 exit 1
79 ;;
80esac
81
82###----- That's all, folks --------------------------------------------------