=== modified file 'bin/confz' --- bin/confz 2014-06-19 17:46:31 +0000 +++ bin/confz 2014-06-19 16:58:23 +0000 @@ -7,10 +7,9 @@ typeset -gA vars vars_prev typeset -ga do_command -typeset -g confz_indent check_only verbose +typeset -g confz_indent check_only -: ${check_only:=0} -: ${verbose:=0} +check_only=0 # helper that prints out error message and exits die() { @@ -39,29 +38,6 @@ "$@" || die "command failed with error $?: ${(q)@}" } -# trace-printing helper for setting $vars values -setvar() { - if (($verbose)); then - print -r - "$confz_indent$fg[cyan]$1$fg[default]=${(qqq)2}" - fi - vars[$1]=$2 -} - -# set $vars parameter if it's empty (ie. set default value) -defvar() { - [[ -z $1 ]] && setvar $1 $2 -} - -# check if variables are nonempty -checkvars() { - local var - local -a empty - for var in "$@"; do - [[ -z $vars[$var] ]] && empty+=( $var ) - done - (( $#empty )) && die "required parameters are empty: ${(q)empty}" -} - # autoload all relevant functions and run confz_*_init confz_load() { local func @@ -110,10 +86,10 @@ # parse variable assignments while (( $# )); do case $1 in - (:*) setvar ${1#:} ${vars_prev[${1#:}]};; + (:*) vars[${1#:}]=${vars_prev[${1#:}]};; (%*=*) lift[${${1#%}%%=*}]=${${1#%}#*=};; (%*) lift[${1#%}]=${1#%};; - (*=*) setvar ${1%%=*} ${1#*=};; + (*=*) vars[${1%%=*}]=${1#*=};; (--) shift; break;; (*) die "$name: unrecognised argument: ${(qqq)1}";; esac @@ -146,15 +122,15 @@ # restore $do_command do_command=( "${do_command_prev[@]}" ) + # lift %variables from calee to caller + for outer inner in ${(kv)lift}; do + vars_prev[$outer]=${vars[$inner]} + done + # restore old $vars and put calee's $vars into $vars_prev vars_switch=( "${(kv)vars[@]}" ) vars=( "${(kv)vars_prev[@]}" ) vars_prev=( "${(kv)vars_switch[@]}" ) - - # lift %variables from calee to caller - for outer inner in ${(kv)lift}; do - setvar $outer ${vars_prev[$inner]} - done } # "dependency" that represents toplevel and gets it's deps out of argv === modified file 'zsh-functions/confz_fs_init' --- zsh-functions/confz_fs_init 2014-06-19 17:46:31 +0000 +++ zsh-functions/confz_fs_init 2014-06-19 17:03:14 +0000 @@ -7,17 +7,16 @@ # configure LVM2 logical volume confz_logical_volume_check() { - defvar vg_name $DEFAULT_VG - [[ -n ${vars[vg_name]} ]] || \ + [[ -n ${vars[vg_name]:=$DEFAULT_VG} ]] || \ die "$0: DEFAULT_VG is unset and no 'vg_name' was passed" - defvar size $DEFAULT_VOLUME_SIZE - [[ -n ${vars[size]} ]] || \ + [[ -n ${vars[size]:=$DEFAULT_VOLUME_SIZE} ]] || \ die "$0: DEFAULT_VOLUME_SIZE is unset and no 'size' was passed" - checkvars lv_name + [[ -n ${vars[lv_name]} ]] || \ + die "$0: no 'lv_name' was passed" - setvar device /dev/mapper/$vars[vg_name]-$vars[lv_name] + vars[device]=/dev/mapper/$vars[vg_name]-$vars[lv_name] do_command=( lvcreate @@ -32,11 +31,14 @@ # create filesystem on block device confz_filesystem_check() { - defvar filesystem $DEFAULT_FS - [[ -n ${vars[filesystem]} ]] || \ + [[ -n ${vars[device]} ]] || \ + die "$0: no 'device' was passed" + + [[ -n ${vars[filesystem]:=$DEFAULT_FS} ]] || \ die "$0: DEFAULT_FS is unset and no 'filesystem' was passed" - checkvars label device filesystem + [[ -n ${vars[label]} ]] || \ + die "$0: no 'label' was passed" [[ -b ${vars[device]} ]] || \ die "$0: not a block device: ${(qqq)vars[device]}" @@ -67,9 +69,20 @@ # put mountpoint for device into /etc/fstab confz_fstab_check() { - checkvars device mountpoint filesystem opts - defvar dump 0 - defvar pass 2 + [[ -n ${vars[device]} ]] || \ + die "$0: no 'device' was passed" + + [[ -n ${vars[mountpoint]} ]] || \ + die "$0: no 'mountpoint' was passed" + + [[ -n ${vars[filesystem]} ]] || \ + die "$0: no 'filesystem' was passed" + + [[ -n ${vars[opts]} ]] || \ + die "$0: no 'opts' was passed" + + : ${vars[dump]:=0} + : ${vars[pass]:=2} local device mountpoint filesystem opts dump pass sed '/^[ \t]*#/d;s/#.*//;s/[ \t]\+/ /g' /etc/fstab | \ @@ -108,7 +121,11 @@ # make device mounted on mountpoint confz_mounted_check() { - checkvars device mountpoint + [[ -n ${vars[device]} ]] || \ + die "$0: no 'device' was passed" + + [[ -n ${vars[mountpoint]} ]] || \ + die "$0: no 'mountpoint' was passed" grep -q "^${vars[device]} ${vars[mountpoint]} " /proc/mounts } @@ -121,10 +138,18 @@ # create LVM2 logical volume, and make sure it's in fstab and mounted confz_mounted_volume_check() { - checkvars lv_name opts label - defvar filesystem xfs - defvar opts noatime - defvar label $vars[lv_name] + [[ -n ${vars[lv_name]} ]] || \ + die "$0: no 'lv_name' was passed" + + [[ -n ${vars[mountpoint]} ]] || \ + die "$0: no 'mountpoint' was passed" + + [[ -n ${vars[size]} ]] || \ + die "$0: no 'size' was passed" + + : ${vars[filesystem]:=xfs} + : ${vars[opts]:=noatime} + : ${vars[label]:=${vars[lv_name]}} require logical_volume %device :vg_name :size :lv_name require filesystem :device :label :filesystem === modified file 'zsh-functions/confz_vserver_init' --- zsh-functions/confz_vserver_init 2014-06-19 17:46:31 +0000 +++ zsh-functions/confz_vserver_init 2014-06-19 17:06:09 +0000 @@ -38,8 +38,8 @@ [[ -n ${vars[source]} ]] || \ die "$0: no 'source' was passed" - setvar etcdir /etc/vservers/${vars[name]} - setvar vdir /vservers/${vars[name]} + vars[etcdir]=/etc/vservers/${vars[name]} + vars[vdir]=/vservers/${vars[name]} local ctx ret ret=1