confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

commit 350b4a15f91cf9045e85b7d4b30e920977437cd7
parent 255766dfbd225c8ac4022ed8ee306996030b1cee
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Thu, 26 Jun 2014 20:23:05 +0200

check for variables being defined instead of being empty
Diffstat:
Mbin/confz | 4++--
Mzsh-functions/confz_fs_init | 9+++------
Mzsh-functions/confz_vserver_init | 2+-
3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/bin/confz b/bin/confz @@ -50,7 +50,7 @@ setvar() { # set $vars parameter if it's empty (ie. set default value) defvar() { - if ! (($+vars[$1])) || [[ -z $vars[$1] ]]; then + if ! (($+vars[$1])); then setvar $1 $2 fi } @@ -60,7 +60,7 @@ checkvars() { local var local -a empty for var in "$@"; do - if ! (($+vars[$var])) || [[ -z $vars[$var] ]]; then + if ! (($+vars[$var])); then empty+=( $var ) fi done diff --git a/zsh-functions/confz_fs_init b/zsh-functions/confz_fs_init @@ -7,12 +7,10 @@ # 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 @@ -33,8 +31,7 @@ confz_logical_volume_check() { # create filesystem on block device confz_filesystem_check() { - defvar filesystem ${DEFAULT_FS:-} - [[ -n ${vars[filesystem]} ]] || \ + [[ -n ${vars[filesystem]:=${DEFAULT_FS}} ]] || \ die "$0: DEFAULT_FS is unset and no 'filesystem' was passed" checkvars label device filesystem diff --git a/zsh-functions/confz_vserver_init b/zsh-functions/confz_vserver_init @@ -78,7 +78,7 @@ confz_vserver_started_check() { vserver --silent -- $vars[name] running || return $? local context_id context_id=$(</etc/vservers/$vars[name]/run) - if [[ -z $vars[context_id] ]]; then + if ! (($+vars[context_id])); then vars[context_id]=$context_id elif (( $vars[context_id] != $context_id )); then die "vserver ${(qqq)name} running under context id $context_id, expected $vars[context_id]"