#!/bin/bash # ------- # File: llxcfg-dnsd # Description: LliureX DNS command line utility # Author: Luis Atonio 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 # --------- CPKGS="dns" # functions # --------- usage(){ CMD="$(basename "$0")" exit_message \ "Usage: $CMD {start|stop|restart|reload|allow|deny|info|listfiles|update|revert|cpkgs}\n\ $CMD grepinfo FIELD\n\ $CMD {addalias|delalias} HOSTNAME HOSTALIAS1 [ HOSTALIAS2 ... HOSTALIASN ]\n\ $CMD {listalias} HOSTNAME\n\ options: -u|--update" } exit_message() { echo -e "$1" >&2 exit 1 } test_hostname(){ [ -z "${1}" ] && exit_message "Missing hostname !!" return 0 } test_alias(){ [ -z "${1}" ] && exit_message "Missing aliases !!" return 0 } test_hostnum(){ [ -z "${1}" ] && exit_message "Invalid hostname !!" return 0 } # main # --------- LIB_FILE="/usr/share/lliurex/lliurex-srv-common/lliurex-netfuncs.sh" [ -e "$LIB_FILE" ] || exit_message "No se encuentra la libreria ${LIB_FILE}" . ${LIB_FILE} case "$1" in -u|--update) AUTOUPDATE="Y" shift ;; esac ACTION="$1" rc=0 case "$ACTION" in start|stop|restart|reload) llxcfg-cpkg invoke "$ACTION" $CPKGS || rc=$? exit $rc ;; cpkgs) for c in $CPKGS ; do echo $c done exit 0 ;; allow|deny|listfiles|update|revert|info) llxcfg-cpkg "$ACTION" $CPKGS || rc=$? exit $rc ;; grepinfo) [ "$2" ] || usage llxcfg-cpkg grepinfo "$2" $CPKGS || rc=$? exit $rc ;; addalias) HOST_NAME="$2" shift 2 HOST_ALIAS="$@" test_hostname "${HOST_NAME}" test_alias "${HOST_ALIAS}" HOST_NUM="`get_dhcp_host_num ${HOST_NAME}`" test_hostnum "${HOST_NUM}" add_dhcp_host_alias ${HOST_NUM} ${HOST_ALIAS} ;; delalias) HOST_NAME="$2" shift 2 HOST_ALIAS="$@" test_hostname "${HOST_NAME}" test_alias "${HOST_ALIAS}" HOST_NUM="`get_dhcp_host_num ${HOST_NAME}`" test_hostnum "${HOST_NUM}" del_dhcp_host_alias ${HOST_NUM} ${HOST_ALIAS} ;; listalias) HOST_NAME="$2" test_hostname "${HOST_NAME}" HOST_NUM="`get_dhcp_host_num ${HOST_NAME}`" test_hostnum "${HOST_NUM}" get_dhcp_host_alias ${HOST_NUM} ;; *) usage ;; esac [ -z "$AUTOUPDATE" ] || llxcfg-cpkg update $CPKGS || rc=$? exit $rc