#!/usr/bin/perl -w
# $Id$
# This script (sophomorix-samba) is maintained by Rüdiger Beck
# It is Free Software (License GPLv3)
# If you find errors, contact the author
# jeffbeck@web.de  or  jeffbeck@gmx.de



# Bibliotheken
use strict;
use Sophomorix::SophomorixConfig;
use Sophomorix::SophomorixBase;
use Getopt::Long;
Getopt::Long::Configure ("bundling");

my @arguments = @ARGV;

&log_script_start(@arguments);

# ===========================================================================
# get servername
# ==========================================================================
my $servername="";

my $servername_debconf=&get_debconf_value("linuxmuster-base", "servername",0);
# process debconf data
if ($servername_debconf ne 0){
    # from debconf
    $servername=$servername_debconf;    
    print "   Servername from debconf     :   $servername \n";
} else {
    # from config file
    $servername=$Conf::smb_netbios_name;
    print "   Servername from sophomorix.conf :   $servername \n";
}



# ===========================================================================
# netlogon-scripte erstellen
# ==========================================================================

&patch_netlogon("login.bat");



&log_script_end(@arguments);




# ===========================================================================
# sub
# ==========================================================================

sub patch_netlogon {
    my ($template) = @_;
    # target file
    my $login_path="${DevelConf::devel_netlogon_path}/$template";
    # add the .template
    $template=$template.".template";
    my $template_path="${DevelConf::devel_netlogon_template}/$template";
    my $tmp=$template_path."-tmp";

    open(TEMPLATE, "<$template_path");
    open(TMP, ">$tmp");
    print TMP "rem Do not edit! Auto-generated by sophomorix-samba \cM\cJ";
     while (<TEMPLATE>) {
        chomp();
        if(/^\###/){next;} # Bei 3-fachen Kommentarzeichen aussteigen
        if(not /^\#/){ 
            # ersetzte netbios name
       #     s/\$smb_netbios_name/$Conf::smb_netbios_name/g;
            s/\@\@servername\@\@/$Conf::smb_netbios_name/g;
        }
        #mac
        #print TMP "$_\l\r";
        #windows
        print TMP "$_\cM\cJ";
        # linux
        #print TMP "$_\n";
     }
     close(TEMPLATE);
     close(TMP);
     system("mv $tmp $login_path");
}





