#!/bin/bash # ------- # File: llxcfg-uni # Description: LliureX client for uniconf # Author: Luis Antonio Garcia Gisbert # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e # variables # --------- # functions # --------- usage(){ CMD="$(basename "$0")" error_message \ "Usage: $CMD [options] {get|del|list|xlist|rlist|show|xshow|rshow} key\n\ $CMD [options] set key [value|-]\n\ options: -r HOST[:PORT]\n\ -c CUSTOM_MONIKER" exit 1 } error_message() { echo -e "$1" >&2 } # main # --------- UNICONFD_PORT=4111 UNICONFD_DEFAULT="/etc/default/uniconfd" [ ! -r "$UNICONFD_DEFAULT" ] || source "$UNICONFD_DEFAULT" case "$1" in -r) shift [ "$1" ] || usage UNIHOST="${1%:*}" if [ "$UNIHOST" != "$1" ] ; then UNIPORT="${1#*:}" else UNIPORT="$UNICONFD_PORT" fi UNICONF="tcp:$UNIHOST:$UNIPORT" shift ;; -c) UNICONF="$1" shift ;; *) UNICONF="$UNICONFD_MOUNTS" ;; esac if [ -z "$UNICONF" ] ; then error_message "Error: No mounts defined in UNICONF variable. Use -r|-c options" usage fi ACTION="$1" [ "$ACTION" ] || usage shift KEY="$1" [ "$KEY" ] || usage shift rc=0 export UNICONF case "$ACTION" in get|del) uni $ACTION "$KEY" || rc=$? ;; list) uni keys "$KEY" || rc=$? ;; xlist) uni xkeys "$KEY" || rc=$? ;; rlist) uni hkeys "$KEY" || rc=$? ;; show) uni dump "$KEY" || rc=$? ;; xshow) uni xdump "$KEY" || rc=$? ;; rshow) uni hdump "$KEY" || rc=$? ;; set) if [ -z "$1" -o "$1" = "-" ] ; then uni xset "$KEY" || rc=$? elif [ "$1" ] ; then uni set "$KEY" "$1" || rc=$? else usage fi ;; esac exit $rc