#!/bin/bash
# ***** BEGIN LICENSE BLOCK *****
# * Copyright (C) 2009  Konstantin A. Baev <kipruss@etersoft.ru>, Etersoft
# *
# * 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.
# ***** END LICENSE BLOCK *****

if [ -f /etc/eterscripts.conf ] ; then
  . /etc/eterscripts.conf
else
  echo 'Ошибка! Не найден конфигурационный файл /etc/eterscripts.conf'
  exit 1
fi

. shell-ini-config
. shell-quote
. shell-error

[ -w "$smb_conf" ] || fatal "Конфигурационный файл самбы $smb_conf не доступен на запись или отсутствует"

. $DATADIR/smbconf_functions.sh

case "$1" in
    normalize)
        [ "$#" -eq 1 ] || fatal 'Usage: smbconf normalize'
        normalize_conf
        ;;
    print)
        [ "$#" -eq 1 ] || fatal 'Usage: smbconf print'
        print_conf
        ;;
    restart)
        [ "$#" -eq 1 ] || fatal 'Usage: smbconf restart'
        service smb restart
        ;;
    share)
        case "$2" in
            list)
                [ "$#" -eq 2 ] || fatal 'Usage: smbconf share list'
                list_share
                ;;
            print)
                [ "$#" -eq 3 ] || fatal 'Usage: smbconf share print {<share_name>|global}'
                print_share "$3"
                ;;
            add)
                [ "$#" -eq 3 ] || fatal 'Usage: smbconf share add <share_name>'
                add_share "$3"
                ;;
            rename)
                [ "$#" -eq 4 ] || fatal 'Usage: smbconf share rename <share_oldname> <share_newname>'
                rename_share "$3" "$4"
                ;;
            delete)
                [ "$#" -eq 3 ] || fatal 'Usage: smbconf share delete <share_name>'
                del_share "$3"
                ;;
            *)
                fatal 'Usage: smbconf share {list|print|add|rename|delete}'
        esac
        ;;
    param)
        case "$2" in
            get)
                [ "$#" -eq 4 ] || fatal 'Usage: smbconf param get {<share_name>|global} <param_name>'
                get_param "$3" "$4"
                ;;
            set)
                [ "$#" -eq 5 ] || fatal 'Usage: smbconf param set {<share_name>|global} <param_name> <param_value>'
                set_param "$3" "$4" "$5"
                ;;
            delete)
                [ "$#" -eq 4 ] || fatal 'Usage: smbconf param delete {<share_name>|global} <param_name>'
                del_param "$3" "$4"
                ;;
            *)
                fatal 'Usage: smbconf param {get|set|delete}'
        esac
        ;;
    add_sharebase)
        [ "$#" -eq 1 ] || fatal 'Usage: smbconf add_sharebase'
        add_sharebase sharebase
        ;;
    client)
        [ "$#" -ge 2 -a "$#" -le 3 ] || fatal 'Usage: smbconf client <server_name> [<share_name>]'
        client_setup "$2" "$3"
        ;;
    *)
        fatal 'Usage: smbconf {normalize|print|restart|share|param|client}'
esac

