#!/usr/bin/env perl
#  
# dcreal-conf.pl :
#   電脳サーバ用資源ファイルを作成する
# Copyright (C) GFD_Dennou_Club, 2001-.  All rights reserved.
#
#  ●Usage : dcreal-conf.pl
#
#  ●作成されるファイル
#
#    hogehoge/	           : 作業ディレクトリ. 
#             dcreal.conf  : 設定ファイル
#
# 履歴  2003/09/11 杉山耕一朗
#       2006/04/04 森川靖大   メッセージを表示するよう改造
#
######################################################################
#Jcode.pm モジュールの読み込み
use Jcode; 
use File::Basename;

# 設定ファイルの読み込み
$CONF = 'dcreal.conf'; 
while (@ARGV) {
    last unless ($ARGV[0] =~ /^-/);
    $_ = shift;                           
    if (/^-c/) { $CONF = shift; next; }; 
    die "unknown option $_";
}
require "$CONF";

#日付取得
$t = time unless defined $t;
($sec, $min, $hour, $day, $mon, $year) = gmtime($t);
$time = sprintf("%04d/%02d/%02d", $year+1900, $mon+1, $day);

#ユーザ名取得
@PASSWD = getpwuid($<); 
$NAME = $PASSWD[0];
system ("gate-user-show $NAME > tmp.txt "); 
if (-f "/usr/local/bin/gate-user-show"){
    open (GATE, "tmp.txt");
    while (<GATE>) {
	chomp($_); 
	if ($_ =~ /^kname/){
	    @NAMES = split(/: /, $_);
	    $NAME = $NAMES[1];
	}
    }
    close(GATE);    
    system ("rm tmp.txt");
#    print "$NAME"; 
}else{
    @NAMES = split(/,/, $NAME); 
    $NAME = @NAMES[0];
    print "$NAME \n";
}

#WEB 用 SIGEN ファイル作成
print "Making SIGEN files ../$WEBDIR.SIGEN";
open (WEB, ">../$WEBDIR.SIGEN");
print WEB <<EOW
Subject:\t Web サーバ用ディレクトリ
Maintainer:\t $NAME
Update:\t\t $time
Description:\t このディレクトリは Web サーバに置かれるべき資源を
\t\t 格納しています. Web サーバと Real サーバを別々に
\t\t もつ場合はこのディレクトリと src ディレクトリを 
\t\t Web サーバに移動して下さい. 
\t\t このディレクトリ内の資源は自動生成されたものです.

履歴
\t $time $NAME

EOW
    ;
close(WEB);
print " ... done.\n";


#REAL 用 SIGEN ファイル作成
print "Making SIGEN files ../$RMDIR.SIGEN";
open (RM, ">../$RMDIR.SIGEN");
print RM <<EOR
Subject:\t Real サーバ用ディレクトリ
Maintainer:\t $NAME
Update:\t\t $time
Description:\t このディレクトリは Real サーバに置かれるべき資源を
\t\t 格納しています. 
\t\t このディレクトリ内の資源は自動生成されたものです.
\t\t Web サーバと Real サーバを別々に
\t\t もつ場合はこのディレクトリと src ディレクトリを 
\t\t Real サーバに移動して下さい. 

履歴
\t $time $NAME
EOR
    ;
close(WEB);
print " ... done.\n";


#SRC 用 SIGEN ファイル作成
print "Making SIGEN files ../$SRC.SIGEN";
open (SRC, ">../$SRC.SIGEN");
print SRC <<EOS
Subject:\t オリジナル資源ディレクトリ
Maintainer:\t $NAME
Update:\t\t $time
Description:\t このディレクトリは資源を公開するのに必要となる
\t\t ソースファイルを格納しています. 
\t\t このディレクトリ中身は絶対に消去しないで下さい. 

履歴
\t $time $NAME

EOS
    ;
close(SRC);
print " ... done.\n";


print basename($0) . ": Successful \n";
