#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2005,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)90   1.2   src/csm/install/setacls.perl, setup, csm_rfish, rfishs001b 3/17/05 13:30:36

use strict;
use locale;
BEGIN
  {
	# this enables us to redirect where it looks for other CSM files during development
	$::csmroot = $ENV{'CSM_ROOT'} ? $ENV{'CSM_ROOT'} : '/opt/csm';
	$::csmpm = "$::csmroot/pm";
	$::csmbin = "$::csmroot/bin";
  }
use lib $::csmpm;
require NodeUtils;
use Getopt::Long;

$ENV{'CT_MANAGEMENT_SCOPE'}=1;

#TODO: if this is used beyond HMC
#   --NLS Messages

Getopt::Long::Configure("bundling");    #allows short command line options to be grouped (e.g. -av)
if (
    !GetOptions(
                'version=s'            => \$::VERSION,
                'nodeid=s'            => \$::NODEID,
                'operations=s'            => \$::OPERATION,
               )
   )
  {
      print "Usage error: setacls --version version --nodeid nodeid --operation op hostnames\n";
      exit 1;
  }

my @hostnames;
foreach my $hostname (@ARGV){
    push @hostnames, "root\@$hostname";
}
$::NODEID = lc($::NODEID);
push @hostnames, "root\@$::NODEID";

#create stanza file
my @classes = ("IBM.hw_element", "IBM.hw_frame", "IBM.hw_manager", "IBM.hw_domain");
my @stfile;
foreach my $class (@classes){
    push @stfile, "\n$class";
    foreach my $name (@hostnames){
        push @stfile, "\n\t$name\t\*\trw // allow root\@MS read and write access";
    }
}
NodeUtils->runcmd("echo \"@stfile\" | /usr/sbin/rsct/install/bin/chrmcacl");
NodeUtils->runcmd("/usr/bin/refresh -s ctrmc");
