From 045043f0628db6c07176c8894e7be44da359e79c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 9 Dec 2014 17:00:13 +0100 Subject: [PATCH] Improving access mode, negatives, colorisation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The connection mode (server or direct) is now checked and set depending on an existing buxtond process. The numbers having negative values are now well handled. The colorized output is now filtered depending on being printing to a terminal or not. Change-Id: I66b18880f34d3c85f2f3d44c43412ef01fbf0767 Signed-off-by: José Bollo --- src/vconf-buxton-backup-mem-layer.sh | 18 +++++++++++++++--- src/vconf-buxton-init-from-vconf.sh | 28 ++++++++++++++++++++++++---- src/vconf-buxton-restore-mem-layer.sh | 18 +++++++++++++++--- src/vconf-buxton-tool.sh | 35 +++++++++++++++++++++++++++++------ 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/src/vconf-buxton-backup-mem-layer.sh b/src/vconf-buxton-backup-mem-layer.sh index 6fd13cf..4e8d7b9 100755 --- a/src/vconf-buxton-backup-mem-layer.sh +++ b/src/vconf-buxton-backup-mem-layer.sh @@ -14,9 +14,21 @@ groupmem=vconf groupdb=vconf label=User -reset=$(printf '\e[0m') -red=$(printf '\e[1;31m') -green=$(printf '\e[1;32m') +# +# prompting +# +if [[ -t 1 ]] +then + reset=$(printf '\e[0m') + red=$(printf '\e[1;31m') + yellow=$(printf '\e[1;33m') + green=$(printf '\e[1;32m') +else + reset= + red= + yellow= + green= +fi # # check that buxton service is available diff --git a/src/vconf-buxton-init-from-vconf.sh b/src/vconf-buxton-init-from-vconf.sh index 72e4b61..bf6d237 100755 --- a/src/vconf-buxton-init-from-vconf.sh +++ b/src/vconf-buxton-init-from-vconf.sh @@ -12,10 +12,21 @@ layer=base group=vconf label=User -reset=$(printf '\e[0m') -red=$(printf '\e[1;31m') -green=$(printf '\e[1;32m') - +# +# prompting +# +if [[ -t 1 ]] +then + reset=$(printf '\e[0m') + red=$(printf '\e[1;31m') + yellow=$(printf '\e[1;33m') + green=$(printf '\e[1;32m') +else + reset= + red= + yellow= + green= +fi # # create the default group for vconf @@ -43,6 +54,15 @@ else fi # +# Check existing root +# +if [[ ! -d $root ]] +then + echo "${green}No legacy vconf data.${reset}" + exit 0 +fi + +# # loop on keys of the vconf file system # find $root -type f | diff --git a/src/vconf-buxton-restore-mem-layer.sh b/src/vconf-buxton-restore-mem-layer.sh index 2a74517..389225a 100755 --- a/src/vconf-buxton-restore-mem-layer.sh +++ b/src/vconf-buxton-restore-mem-layer.sh @@ -14,9 +14,21 @@ groupdb=vconf groupmem=vconf label=User -reset=$(printf '\e[0m') -red=$(printf '\e[1;31m') -green=$(printf '\e[1;32m') +# +# prompting +# +if [[ -t 1 ]] +then + reset=$(printf '\e[0m') + red=$(printf '\e[1;31m') + yellow=$(printf '\e[1;33m') + green=$(printf '\e[1;32m') +else + reset= + red= + yellow= + green= +fi # # check that buxton service is available diff --git a/src/vconf-buxton-tool.sh b/src/vconf-buxton-tool.sh index 607a6c1..49e27f6 100755 --- a/src/vconf-buxton-tool.sh +++ b/src/vconf-buxton-tool.sh @@ -49,8 +49,9 @@ badargs() { # # calls to buxton # +buxmode=$(pgrep buxtond >/dev/null 2>&1 && echo -n -s || echo -n -d) buxton() { - buxtonctl "$@" + buxtonctl $buxmode -- "$@" } buxton_is_ready() { @@ -184,7 +185,14 @@ group=vconf layer_of_key() { case "$1/" in user/*) echo -n "user";; - memory/*) echo -n "temp";; + memory/*) + if [[ "$buxmode" = '-d' ]] + then + error "the layer temp isn't available in direct mode" + exit + fi + echo -n "temp" + ;; *) echo -n "base";; esac } @@ -238,6 +246,20 @@ setkey() { fi } +# calls getopt with negative numbers protection +mygetopt() { + local name="$exe $1" long="$2" short="$3" x= + shift 3 + eval set -- $( + for x; do + echo -n "'$x'" | + sed "s:\(.\)'\(.\):\\1\\\\'\\2:g ; s/^'\(-[0-9.]*\)'\$/'protect-sign:\1'/ ; s/^.*/& /" + done + ) + getopt -n "$name" -l "$long" -o "$short" -- "$@" | + sed "s/'protect-sign:/'/g" +} + # # ensure existing the group for vconf # @@ -248,7 +270,7 @@ doset() { local typ= name= layer= value= smack= force=false instal=false # scan arguments - eval set -- $(getopt -n "$exe set" -l force,install,type:,smack:,group:,user: -o fit:s:g:u: -- "$@") + eval set -- $(mygetopt set force,install,type:,smack:,group:,user: fit:s:g:u: "$@") while : do case "$1" in @@ -269,7 +291,7 @@ doset() { shift ;; -u|-g|--user|--group) - warning "option $1 $2 ignored!" + info "option $1 $2 ignored!" shift 2 ;; --) @@ -292,7 +314,8 @@ doset() { then if expr "$name" : memory/ >/dev/null then - setkey "$typ" "memory_init/$name" "$value" "$smack" + setkey "$typ" "memory_init/$name" "$value" "$smack" || exit + [[ "$buxmode" = -d ]] && exit else warning only keys beginning with memory/ are allowing option -i fi @@ -306,7 +329,7 @@ doget() { local name= layer= rec=false val= # scan arguments - eval set -- $(getopt -n "$exe get" -l recursive -o r -- "$@") + eval set -- $(mygetopt get recursive r "$@") if [[ "$1" = "-r" || "$1" = "--recursive" ]] then rec=true -- 2.7.4