From 9f7295397c2e5597e5895c2c6ddf9cf772d702f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Fri, 5 Dec 2014 15:47:41 +0100 Subject: [PATCH] Improved packaging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commits has 2 main goals: - Allow to provide vconf, vconf-devel, vconf-keys-devel for solving issue when building. - that done, error came because the vconftool replacement coulded not run without a server buxton what is a problem at build time. Thus the tool is replaced using an agnostic tool written in bash. There is an issue with that current version: it provides a package that it also obsoletes. This issue will be fixed soon. Change-Id: I9ea93d61cfe12fa23448fd6367d372cc7bbf55d9 Signed-off-by: José Bollo --- CMakeLists.txt | 4 +- packaging/vconf-buxton.spec | 14 +- src/CMakeLists.txt | 5 +- src/vconf-buxton-tool.c | 262 --------------------------- src/vconf-buxton-tool.sh | 420 ++++++++++++++++++++++++++++++++++++++++++++ src/vconf-buxton.pc.in | 1 + 6 files changed, 433 insertions(+), 273 deletions(-) delete mode 100644 src/vconf-buxton-tool.c create mode 100755 src/vconf-buxton-tool.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index d12070d..b510b72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ SET(EXEC_PREFIX "\${prefix}") SET(LIBDIR ${LIB_INSTALL_DIR}) SET(INCLUDEDIR "\${prefix}/include/vconf") SET(VERSION_MAJOR 0) -SET(VERSION_MINOR 1) +SET(VERSION_MINOR 3) SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.0") SET(BINDIR "${PREFIX}/bin") SET(SYSTEMDDIR "lib/systemd/system") @@ -18,7 +18,7 @@ SET(SRCS vconf-buxton.c) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 vconf-internal-keys libbuxton) +pkg_check_modules(pkgs REQUIRED glib-2.0 vconf-internal-keys buxton) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/vconf-buxton.spec b/packaging/vconf-buxton.spec index e611274..30186c8 100644 --- a/packaging/vconf-buxton.spec +++ b/packaging/vconf-buxton.spec @@ -11,7 +11,7 @@ Name: vconf-buxton Summary: Configuration system library -Version: 0.1 +Version: 0.3 Release: 1 Group: System/Libraries License: Apache-2.0 @@ -21,9 +21,12 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(libbuxton) +BuildRequires: pkgconfig(buxton) BuildRequires: pkgconfig(vconf-internal-keys) Obsoletes: vconf +Obsoletes: vconf-devel +Obsoletes: vconf-keys-devel +Provides: vconf %description Configuration system library having vconf API and buxton backend @@ -31,9 +34,9 @@ Configuration system library having vconf API and buxton backend %package devel Summary: Vconf-buxton (devel) Requires: %{name} = %{version}-%{release} -Requires: vconf-buxton = %{version}-%{release} -Requires: vconf-buxton-keys-devel = %{version}-%{release} +Requires: %{name}-keys-devel = %{version}-%{release} Obsoletes: vconf-devel +Provides: vconf-devel %description devel Vconf library (devel) @@ -41,9 +44,10 @@ Vconf library (devel) %package keys-devel Summary: Vconf-buxton (devel) Requires: %{name} = %{version}-%{release} -Requires: vconf-buxton = %{version}-%{release} Requires: vconf-internal-keys-devel Obsoletes: vconf-keys-devel +Obsoletes: vconf-devel +Provides: vconf-keys-devel %description keys-devel Vconf key management header files diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5c141c..aab4f8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,17 +19,14 @@ SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${VERSION}) TARGET_LINK_LIBRARIES(${LIBNAME} ${glib_pkg_LDFLAGS} ${pkgs_LDFLAGS}) -ADD_EXECUTABLE(${TOOLNAME} vconf-buxton-tool.c) -TARGET_LINK_LIBRARIES(${TOOLNAME} ${pkgs_LDFLAGS} ${glib_pkg_LDFLAGS} ${LIBNAME}) - CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${LIBNAME}.pc @ONLY) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LIBNAME}.pc") INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIB_INSTALL_DIR}) -INSTALL(TARGETS ${TOOLNAME} DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/src/vconf-buxton-init-from-vconf.sh DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/src/vconf-buxton-restore-mem-layer.sh DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/src/vconf-buxton-backup-mem-layer.sh DESTINATION bin) +INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/src/vconf-buxton-tool.sh DESTINATION bin RENAME ${TOOLNAME}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/vconf-buxton.h DESTINATION include/vconf) INSTALL(FILES ${CMAKE_SOURCE_DIR}/src/vconf-buxton-keys.h DESTINATION include/vconf) diff --git a/src/vconf-buxton-tool.c b/src/vconf-buxton-tool.c deleted file mode 100644 index 8303911..0000000 --- a/src/vconf-buxton-tool.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * Copyright (C) 2014 Intel Corporation - * - * Author: José Bollo - * Author: Hakjoo Ko - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include "vconf-buxton.h" -#include "log.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -enum -{ - VCONFTOOL_TYPE_NO = 0x00, - VCONFTOOL_TYPE_STRING, - VCONFTOOL_TYPE_INT, - VCONFTOOL_TYPE_DOUBLE, - VCONFTOOL_TYPE_BOOL -}; - -static char *guid = NULL; -static char *uid = NULL; -static char *vconf_type = NULL; -static int is_recursive = FALSE; -static int is_initialization = FALSE; -static int is_forced = FALSE; -static int get_num = 0; - -static GOptionEntry entries[] = { - {"type", 't', 0, G_OPTION_ARG_STRING, &vconf_type, "type of value", - "int|bool|double|string"}, - {"recursive", 'r', 0, G_OPTION_ARG_NONE, &is_recursive, - "retrieve keys recursively", NULL}, - {"guid", 'g', 0, G_OPTION_ARG_STRING, &guid, "group permission", NULL}, - {"uid", 'u', 0, G_OPTION_ARG_STRING, &uid, "user permission", NULL}, - {"initialization", 'i', 0, G_OPTION_ARG_NONE, &is_initialization, - "memory backend initialization", NULL}, - {"force", 'f', 0, G_OPTION_ARG_NONE, &is_forced, - "overwrite vconf values by force", NULL}, - {NULL} -}; - -static void get_operation (const char *input); -static void print_keylist (keylist_t * keylist); - -static char usage[] = - "Usage:\n" - "\n" - "[Set vconf value]\n" - " %1$s set -t \n" - " =int|bool|double|string\n" - "\n" - " Ex) %1$s set -t string db/testapp/key1 \"This is test\" \n" - "\n" - " \n" - " any option is ignored! (compatibility)\n" - "\n" - "[Get vconf value]\n" - " %1$s get \n" - "\n" - " \n" - " -r : retrieve all keys included in sub-directorys \n" - " Ex) %1$s get db/testapp/key1\n" - " %1$s get db/testapp/\n" - "\n" - "[Unset vconf value]\n" - " %1$s unset \n" - "\n" " Ex) %1$s unset db/testapp/key1\n" "\n" - "\n" - "[Set vconf label (Smack)]\n" - " %1$s label \n" - "\n" " Ex) %1$s label db/testapp/key1 User::Share\n" "\n"; - -static void -print_help (const char *cmd) -{ - fprintf (stderr, usage, cmd); -} - -static int -check_type (void) -{ - if (vconf_type) - { - if (!strncasecmp (vconf_type, "int", 3)) - return VCONFTOOL_TYPE_INT; - else if (!strncasecmp (vconf_type, "string", 6)) - return VCONFTOOL_TYPE_STRING; - else if (!strncasecmp (vconf_type, "double", 6)) - return VCONFTOOL_TYPE_DOUBLE; - else if (!strncasecmp (vconf_type, "bool", 4)) - return VCONFTOOL_TYPE_BOOL; - } - return VCONFTOOL_TYPE_NO; -} - -int -main (int argc, char **argv) -{ - int set_type; - - GError *error = NULL; - GOptionContext *context; - - context = g_option_context_new ("- vconf library tool"); - g_option_context_add_main_entries (context, entries, NULL); - g_option_context_set_help_enabled (context, FALSE); - g_option_context_set_ignore_unknown_options (context, TRUE); - - if (!g_option_context_parse (context, &argc, &argv, &error)) - { - g_print ("option parsing failed: %s\n", error->message); - exit (1); - } - - if (argc < 2) - { - print_help (argv[0]); - return 1; - } - - if (!strcmp (argv[1], "set")) - { - set_type = check_type (); - if (argc < 4 || !set_type) - { - print_help (argv[0]); - return 1; - } - - switch (set_type) - { - case VCONFTOOL_TYPE_STRING: - vconf_set_str (argv[2], argv[3]); - break; - case VCONFTOOL_TYPE_INT: - vconf_set_int (argv[2], atoi (argv[3])); - break; - case VCONFTOOL_TYPE_DOUBLE: - vconf_set_dbl (argv[2], atof (argv[3])); - break; - case VCONFTOOL_TYPE_BOOL: - vconf_set_bool (argv[2], !!atoi (argv[3])); - break; - default: - fprintf (stderr, "never reach"); - exit (1); - } - - } - else if (!strcmp (argv[1], "get")) - { - if (argv[2]) - get_operation (argv[2]); - else - print_help (argv[0]); - } - else if (!strcmp (argv[1], "unset")) - { - if (argv[2]) - vconf_unset (argv[2]); - else - print_help (argv[0]); - } - else if (!strcmp (argv[1], "label")) - { - if (argv[2] && argv[3]) - vconf_set_label (argv[2], argv[3]); - else - print_help (argv[0]); - } - else - fprintf (stderr, "%s is a invalid command\n", argv[1]); - return 0; -} - -static void -get_operation (const char *input) -{ - keylist_t *keylist; - - keylist = vconf_keylist_new (); - if (is_recursive) - { - vconf_scan (keylist, input, VCONF_GET_KEY_REC); - } - else - { - vconf_keylist_add_null (keylist, input); - vconf_refresh (keylist); - } - vconf_keylist_sort (keylist); - print_keylist (keylist); - if (!get_num) - printf ("No data\n"); - vconf_keylist_free (keylist); -} - -static void -print_keylist (keylist_t * keylist) -{ - keynode_t *node; - - vconf_keylist_rewind (keylist); - while ((node = vconf_keylist_nextnode (keylist))) - { - switch (vconf_keynode_get_type (node)) - { - case VCONF_TYPE_INT: - printf ("%s, value = %d (int)\n", - vconf_keynode_get_name (node), - vconf_keynode_get_int (node)); - get_num++; - break; - case VCONF_TYPE_BOOL: - printf ("%s, value = %d (bool)\n", - vconf_keynode_get_name (node), - vconf_keynode_get_bool (node)); - get_num++; - break; - case VCONF_TYPE_DOUBLE: - printf ("%s, value = %f (double)\n", - vconf_keynode_get_name (node), - vconf_keynode_get_dbl (node)); - get_num++; - break; - case VCONF_TYPE_STRING: - printf ("%s, value = %s (string)\n", - vconf_keynode_get_name (node), - vconf_keynode_get_str (node)); - get_num++; - break; - default: - break; - } - } -} diff --git a/src/vconf-buxton-tool.sh b/src/vconf-buxton-tool.sh new file mode 100755 index 0000000..a418253 --- /dev/null +++ b/src/vconf-buxton-tool.sh @@ -0,0 +1,420 @@ +#!/bin/bash +# +# This script emulate the behaviour of vconftool +# +# author: jose.bollo@open.eurogiciel.org + +verbose=false +quiet=false + +# +# prompting +# +if tty --silent +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 + +info() { + $verbose && echo "${green}$*${reset}" + return 0 +} + +warning() { + $quiet || echo "${yellow}WARNING: $*${reset}" + return 0 +} + +error() { + $quiet || echo "${red}ERROR: $*${reset}" >&2 + return 1 +} + +badargs() { + error "bad arguments" + exit +} + +# +# calls to buxton +# +buxton() { + buxtonctl "$@" +} + +buxton_is_ready() { + buxton check > /dev/null +} + +buxton_has_group() { + local layer="$1" group="$2" + buxton list-groups "${layer}" 2>/dev/null | + grep -q "found group ${group}\$" +} + +buxton_has_key() { + local layer="$1" group="$2" name="$3" + buxton list-keys "${layer}" "${group}" 2>/dev/null | + grep -q "found key ${name}\$" +} + +buxton_make_group() { + local layer="$1" group="$2" + if buxton create-group "$layer" "$group" > /dev/null + then + info "group $group succesfully created for layer $layer" + else + error "can not create group $group for layer $layer" + fi +} + +buxton_get_label() { + if [[ $# -eq 2 ]] + then + local layer="$1" group="$2" result= + if ! result=$(buxton get-label "$layer" "$group" 2> /dev/null | + grep "\[$layer] $group:(null) - " | + sed 's:.* - ::') + then + error "can not get the label $label of group $group of layer $layer" + elif [[ -z "$result" ]] + then + error "invalid label gotten for group $group of layer $layer" + else + echo -n "$result" + fi + else + local layer="$1" group="$2" name="$3" result= + if ! result=$(buxton get-label "$layer" "$group" "$name" 2> /dev/null | + grep "\[$layer] $group:$name - " | + sed 's:.* - ::') + then + error "can not get the label $label of key $name in group $group of layer $layer" + elif [[ -z "$result" ]] + then + error "invalid label gotten for key $name in group $group of layer $layer" + else + echo -n "$result" + fi + fi +} + +buxton_set_label() { + if [[ $# -eq 3 ]] + then + local layer="$1" group="$2" label="$3" + if ! buxton set-label "$layer" "$group" "$label" > /dev/null + then + error "can not set label $label to group $group of layer $layer" + elif [[ "$label" != "$(buxton_get_label "$layer" "$group")" ]] + then + error "check failed when setting label $label to group $group of layer $layer" + else + info "label $label set to group $group of layer $layer" + fi + else + local layer="$1" group="$2" name="$3" label="$4" + if ! buxton set-label "$layer" "$group" "$name" "$label" > /dev/null + then + error "can not set label $label to key $name in group $group of layer $layer" + elif [[ "$label" != "$(buxton_get_label "$layer" "$group" "$name")" ]] + then + error "check failed when setting label $label to key $name in group $group of layer $layer" + else + info "label $label set to key $name in group $group of layer $layer" + fi + fi +} + +buxton_ensure_group() { + local layer="$1" group="$2" label="$3" + if buxton_has_group "$layer" "$group" + then + info "group $group exists in layer $layer" + else + buxton_make_group "$layer" "$group" || return + fi + [[ -z "$label" ]] || buxton_set_label "$layer" "$group" "$label" +} + +buxton_ensure_ready() { + if ! buxton_is_ready + then + error "can not connect to buxton service" + exit + fi +} + +buxton_unset() { + local layer="$1" group="$2" name="$3" + + # unset the value + if ! buxton_has_key "$layer" "$group" "$name" + then + info "key $name in group $group of layer $layer is already unset" + elif ! buxton "unset-value" "$layer" "$group" "$name" > /dev/null + then + error "can not unset key $name in group $group of layer $layer" + elif buxton_has_key "$layer" "$group" "$name" + then + error "check failed when unsetting key $name in group $group of layer $layer" + else + info "key $name in group $group of layer $layer is unset" + fi + exit +} + +############################################################################################# + +group=vconf + + +# get the layer of the key +layer_of_key() { + case "$1/" in + user/*) echo -n "user";; + memory/*) echo -n "temp";; + *) echo -n "base";; + esac +} + +# get the standard value +stdval() { + local typ="$1" val="$2" + case "$typ:${val,,}" in + bool:0|bool:false|bool:off) echo -n "false";; + bool:1|bool:true|bool:on) echo -n "true";; + *) echo -n "$val";; + esac +} + +# get buxton-type from vconf-type +v2btype() { + case "${1,,}" in + int) echo -n "int32";; + string) echo -n "string";; + double) echo -n "double";; + bool) echo -n "bool";; + *) error "unknown vconf-type $1"; exit;; + esac +} + +# get vconf-type from buxton-type +b2vtype() { + case "${1,,}" in + int32) echo -n "int";; + string) echo -n "string";; + double) echo -n "double";; + bool) echo -n "bool";; + *) error "unknown buxton-type $1"; exit;; + esac +} + +# +# ensure existing the group for vconf +# +buxton_ensure_group "base" "$group" || exit + +# set the value +doset() { + local typ= name= layer= value= smack= force=false + + # scan arguments + while [[ $# -ne 0 ]] + do + case "$1" in + -t|--type) + [[ $# -ge 2 && -z "$typ" ]] || badargs + typ="$2" + shift 2 + ;; + -s|--smack) + [[ $# -ge 2 && -z "$smack" ]] || badargs + smack="$2" + shift 2 + ;; + -f|--force) + force=true + shift + ;; + -i|--install) + warning "option $1 ignored!" + shift + ;; + -u|-g|--user|--group) + [[ $# -ge 2 ]] || badargs + warning "option $1 $2 ignored!" + shift 2 + ;; + *) + [[ $# -ge 2 && -z "$name" ]] || badargs + name="$1" + value="$2" + shift 2 + ;; + esac + done + [[ -n "$typ" && -n "$name" ]] || badargs + + # process + layer="$(layer_of_key "$name")" + typ="$(v2btype "$typ")" + value="$(stdval "$typ" "$value")" + + if buxton "set-$typ" "$layer" "$group" "$name" "$value" > /dev/null + then + info "key $name in group $group of layer $layer set to $typ: $value" + else + error "can not set key $name in group $group of layer $layer with $typ: $value" + fi + exit +} + +# get the value +doget() { + local name= layer= rec=false val= + + # scan arguments + while [[ $# -ne 0 ]] + do + case "$1" in + -r|--recursive) + rec=true + shift + ;; + *) + [[ $# -eq 1 && -n "$1" ]] || badargs + name="$1" + shift + ;; + esac + done + [[ -n "$name" ]] || badargs + + # process + layer="$(layer_of_key "$name")" + if $rec + then + set -- $(buxton list-keys "$layer" "$group" "$name" 2> /dev/null | + grep "found key" | + sed 's:.* ::') + else + set -- "$name" + fi + for name + do + val="$(buxton get "$layer" "$group" "$name" 2> /dev/null | + grep "\[$layer] $group:$name = " | + sed 's/.* = // ; s/^int32:/int:/ ; s/^\(.*\): \(.*\)$/\2 (\1)/')" + if [[ -z "$val" ]] + then + error "key $name not found in group $group of layer $layer" + else + echo "$name, value = $val" + fi + done + exit +} + +# unset the value +dounset() { + local name= layer= + + # scan arguments + [[ $# -eq 1 && -n "$name" ]] || badargs + name="$1" + layer="$(layer_of_key "$name")" + + # process + buxton_unset "$layer" "$group" "$name" + exit +} + +# set the label +dolabel() { + local name= smack= layer= + + # scan arguments + [[ $# -eq 2 && -n "$name" && -n "$smack" ]] || badargs + name="$1" + smack="$2" + layer="$(layer_of_key "$name")" + + # process + buxton_set_label "$layer" "$group" "$name" + exit +} + + + + + + +exe="$(basename "$0")" +cmd="${1,,}" +shift + +case "${cmd}" in +-v|--verbose) verbose=true; cmd="${1,,}"; shift;; +-q|--quiet) quiet=true; cmd="${1,,}"; shift;; +esac + +case "${cmd}" in +get) doget "$@";; +set) doset "$@";; +unset) dounset "$@";; +label) dolabel "$@";; +help|-h|--help) cat << EOC + +Usage: $exe [-v|--verbose|-q|--quiet] command ... + +Command set: set a value (create or update) + + $exe set -t + + = int | bool | double | string + + + + -u, --user ignored! (compatibility) + -g, --group ignored! (compatibility) + -i, --install ignored! (compatibility) + -s, --smack