#!/usr/bin/perl
#
# $Header: //sapdb/V76/develop/sys/src/install/perl/packages/syncman/instsyncman#3 $
# $DateTime: 2003/09/16 10:21:43 $
# $Change: 51992 $
#
# Desc:

import SAPDB::Install::StdIO;
import SAPDB::Install::System;
import SAPDB::Install::Registry;
import SAPDB::Install::Tools;
import SAPDB::Install::SetUser;
import SAPDB::Install::Cwd;
import SAPDB::Install::Values;

$path{'name'} = 'syncman path';

$path{'opt'}='syncmanpath=s';
$path{'list'} = 'syncman.lst';
$path{'update'}=0;


$usage= " [-syncmanpath <instpath>]";
$usage_desc = "\t-syncmanpath <instpath>\tsyncman installation directory\n";
                  


@paths = (\%path);
$main_path=\%path;
$skip=0;
@opts=();

local ($data,$prog);


sub preinstall{
	($data,$prog)=readIndepPath();
	$prog =~ /\S/ or $prog = $SAPDB::Install::Values::indep_prog_path;
	$data =~ /\S/ or $data = $SAPDB::Install::Values::indep_data_path;
	$prog =~ /\S/ or print2stderr("independent program path not found\n") and diesoft($SAPDB::Install::Values::diemsg);
	$path{'default'} = $prog;
	$path{'value'}=$prog unless ($SAPDB::Install::StartInstall::opt_relocate);  
	return 1;
}
 

sub postprepare{
	return 1;
}

# we overwrite here the syncman start scripts in '<indepprogpath>/bin'
# and '<indepprogpath>/app/syncman/example' to call the generic python wrapper.
# for win, it looks like(w/o the leading '#', of course):
#
#@echo off
#"<indepprogpath>\bin\x_python" "<pythonscriptpath>\syncman_caller.py" <basename> %*
#
#
# for unix this is:
# 
##!/bin/sh
#"<indepprogpath>/bin/x_python" "<pythonscriptpath>/syncman_caller.py" <basename> $*
#
#
# <basename> is one of {'msgserver','syncservice','syncmangui','syncmanacc', 'syncmanjconf', 'createexampletables', 'createxampledatabases'}.
#
sub postinstall{
	my @basenames;
        my $myprog=$prog;
	my $mydata=$data;
	if($^O=~/mswin/i){
		$cmd=".cmd";
                $scripthead='@echo off';
                $args='%*';
                $sep="\\";
                $lineend="\r\n";
                $myprog=~s/\//\\/g;
                $mydata=~s/\//\\/g;
	}
	else{
		$cmd="";
                $scripthead='#!/bin/sh';
                $args='$*';
                $sep="/";
                $lineend="\n";
	}
        @basenames  = ('msgserver','syncservice','syncmangui','syncmanacc', 'syncmanjconf'); # these go into <indepprog>/bin
        my $syncmaninst=$myprog.$sep.'app'.$sep.'syncman';
        my $relsyncmaninst='app'.$sep.'syncman';
	my $syncmanextern=$mydata.$sep.'app'.$sep.'syncman'.$sep.'extern';
	foreach my $base (@basenames){
		my $longfile=$myprog.$sep.'bin'.$sep.$base.$cmd;
                my $rellongfile='bin'.$sep.$base.$cmd;
                open(FD,">$longfile") or $SAPDB::Install::Values::log->SetMsg("WRN:cannot create syncman starter script file \"$longfile\"\n");
                print FD $scripthead.$lineend;
                print FD "\"".$myprog.$sep.'bin'.$sep.'x_python'."\"".' '."\"".$syncmaninst.$sep.'syncman_caller.py'."\"".' '.$base.' '.$args.$lineend;
                close(FD);
	        unless ($^O =~ /mswin/i){
		    chmod (0555, $longfile);
		    chown ($packobj->UID, $packobj->GID, $longfile);
	        }
                $packobj->RegData->updateMd5Sum($rellongfile); # register checksums for generated files 
                $SAPDB::Install::Values::log->SetMsg("MSG: file \"$longfile\" generated by installer\n");
	}
        @examplebasenames  = ('createexampletables', 'createexampledatabases'); # these go into <indepprog>/app/syncman/example
	foreach my $ebase (@examplebasenames){
		my $elongfile=$syncmaninst.$sep.'example'.$sep.$ebase.$cmd;
                my $relelongfile=$relsyncmaninst.$sep.'example'.$sep.$ebase.$cmd;
                open(FD,">$elongfile") or $SAPDB::Install::Values::log->SetMsg("WRN:cannot create syncman starter script file \"$elongfile\"\n");
                print FD $scripthead.$lineend;
                print FD "\"".$myprog.$sep.'bin'.$sep.'x_python'."\"".' '."\"".$syncmaninst.$sep.'syncman_caller.py'."\"".' '.$ebase.' '.$args.$lineend;
                close(FD);
	        unless ($^O =~ /mswin/i){
		    chmod (0555, $elongfile);
		    chown ($packobj->UID, $packobj->GID, $elongfile);
	        }
                $packobj->RegData->updateMd5Sum($relelongfile); # register checksums for generated files 
                $SAPDB::Install::Values::log->SetMsg("MSG: file \"$elongfile\" generated by installer\n");
	}
	makedir($syncmanextern,0770,$packobj->UID,$packobj->GID);
        $SAPDB::Install::Values::log->SetMsg("MSG: directory \"$syncmanextern\" generated by installer\n");
	return 1;    
}



sub registerWin{
	return 1;
}
	

sub registerUX{
	return 1;
}


*register =           $^O =~ /^MsWin/i ? \&registerWin :
        \&registerUX;




sub unregisterWin{
	return 1;
}

sub unregisterUX{
	return 1;
}


*unregister =           $^O =~ /^MsWin/i ? \&unregisterWin :
        \&unregisterUX;


sub preuninstall{
	return 1;
}

sub postuninstall{
	return 1;	
}

1;
                                                                                                         
