| 1 | #! /bin/sh -e |
| 2 | |
| 3 | prog=${0##*/} |
| 4 | fail () { echo >&2 "$prog: $1"; exit 2; } |
| 5 | usage () { echo "usage: $prog [CONF]"; } |
| 6 | |
| 7 | bogus=nil |
| 8 | while getopts "h" opt; do |
| 9 | case $opt in |
| 10 | h) usage; exit 0 ;; |
| 11 | *) bogus=t ;; |
| 12 | esac |
| 13 | done |
| 14 | shift $(( $OPTIND - 1 )) |
| 15 | case $# in 0) op=query ;; 1) op=set conf=$1 ;; *) bogus=t ;; esac |
| 16 | case $bogus in t) usage >&2; exit 2 ;; esac |
| 17 | |
| 18 | cd "$HOME/.disorder" |
| 19 | case $op in |
| 20 | query) |
| 21 | if ! [ -L passwd ]; then link=bogus |
| 22 | else link=$(readlink passwd) |
| 23 | fi |
| 24 | case $link in |
| 25 | passwd.*) conf=${link#passwd.} ;; |
| 26 | *) fail "\`~/.disorder/passwd' not a link to \`passwd.CONF'" ;; |
| 27 | esac |
| 28 | echo "$conf" |
| 29 | ;; |
| 30 | set) |
| 31 | if ! [ -f "passwd.$conf" ]; then fail "no config \`passwd.$conf'"; fi |
| 32 | ln -sf "passwd.$conf" passwd |
| 33 | ;; |
| 34 | esac |