lilalo
diff lm @ 40:5e5878bd1b20
Скрипты lm вынесены в отдельный файл l3config
author | devi |
---|---|
date | Tue Nov 22 22:47:47 2005 +0200 (2005-11-22) |
parents | 466bea239d25 |
children | 6452bfe549d1 |
line diff
1.1 --- a/lm Tue Nov 22 20:46:46 2005 +0200 1.2 +++ b/lm Tue Nov 22 22:47:47 2005 +0200 1.3 @@ -2,13 +2,15 @@ 1.4 1.5 1.6 use strict; 1.7 -use Inline::Files; 1.8 use Data::Dumper; 1.9 use Switch; 1.10 use XML::Simple; 1.11 use Getopt::Long; 1.12 use utf8; 1.13 1.14 +use lib "/usr/local/bin"; 1.15 +use l3config; 1.16 + 1.17 our $XMLClass; 1.18 our $XMLCourse; 1.19 our @Labs; 1.20 @@ -17,7 +19,7 @@ 1.21 our @SelectedMachines; # Machines list given as the command line argument 1.22 1.23 our $Config_File = "labmaker.conf"; 1.24 -our %Config = ( 1.25 +our %Config_ = ( 1.26 "show_host" => "no", 1.27 1.28 # Вспомогательные программы 1.29 @@ -85,7 +87,8 @@ 1.30 exit(0); 1.31 } 1.32 1.33 - load_config; 1.34 + init_config(); 1.35 + #load_config; 1.36 load_run; 1.37 load_scripts; 1.38 load_class; 1.39 @@ -126,10 +129,19 @@ 1.40 1.41 sub load_scripts 1.42 { 1.43 + print join " ", %Config; 1.44 + print "\n"; 1.45 + 1.46 + open (SCRIPTS, "$Config{l3scripts}") 1.47 + or die "Cant open l3scripts file: ".$Config{l3scripts}.": $!\n"; 1.48 + binmode SCRIPTS, ":utf8"; 1.49 local $/; 1.50 $_=<SCRIPTS>; 1.51 + close(SCRIPTS); 1.52 + 1.53 %Scripts = ("empty-element", split (/###(.*)\n/)); 1.54 delete($Scripts{"empty-element"}); 1.55 + 1.56 } 1.57 1.58 sub load_config 1.59 @@ -265,27 +277,39 @@ 1.60 my $command = shift; 1.61 my $arg = join " ", @_; 1.62 my $i=1; 1.63 + 1.64 + my %myenv = ( %Config, 1.65 + lab => $arg, 1.66 + center => $XMLClass->{"center"}, 1.67 + course => $XMLClass->{"course"}, 1.68 + date => $XMLClass->{"date"}, 1.69 + coursepath => $XMLCourse->{"path"}, 1.70 + ); 1.71 + 1.72 + if (grep { $_ eq "PRE-$command"} keys %Scripts) { 1.73 + $_=$Scripts{"PRE-$command"}; 1.74 + s/\$(\w+)/$myenv{$1}/ge; 1.75 + open(SHELL, "|/bin/sh -s"); 1.76 + binmode SHELL, ":utf8"; 1.77 + print SHELL $_; 1.78 + close (SHELL); 1.79 + } 1.80 + 1.81 + 1.82 for my $m (sort keys %Machines) { 1.83 if (!@SelectedMachines || grep $_ eq $i, @SelectedMachines) { 1.84 print "$m:\n" if $Config{"show_host"} =~ /y/i; 1.85 1.86 - my %myenv = ( %Config, 1.87 + %myenv = ( %myenv, 1.88 host => $m, 1.89 dirs => "/root /home/".$Machines{$m}->{"user"}, 1.90 lablogs => $Config{"path_lablogs"}."/". 1.91 $XMLClass->{"course"}."/". 1.92 $XMLClass->{"date"}."/". 1.93 "$m", 1.94 - lab => $arg, 1.95 - 1.96 email => $Machines{$m}->{"student"}->{"email"}, 1.97 company => $Machines{$m}->{"student"}->{"company"}, 1.98 - center => $XMLClass->{"center"}, 1.99 - course => $XMLClass->{"course"}, 1.100 - date => $XMLClass->{"date"}, 1.101 name => $Machines{$m}->{"name"}, 1.102 - coursepath => $XMLCourse->{"path"}, 1.103 - 1.104 ); 1.105 if (grep { $_ eq $command} keys %Scripts) { 1.106 $_=$Scripts{"$command"}; 1.107 @@ -306,6 +330,15 @@ 1.108 } 1.109 $i++; 1.110 } 1.111 + 1.112 + if (grep { $_ eq "POST-$command"} keys %Scripts) { 1.113 + $_=$Scripts{"POST-$command"}; 1.114 + s/\$(\w+)/$myenv{$1}/ge; 1.115 + open(SHELL, "|/bin/sh -s"); 1.116 + binmode SHELL, ":utf8"; 1.117 + print SHELL $_; 1.118 + close (SHELL); 1.119 + } 1.120 } 1.121 1.122 1.123 @@ -450,12 +483,7 @@ 1.124 sub print_usage_info 1.125 { 1.126 print "Usage:\n\n\t$0 [host-list] command\n"; 1.127 - while (<USAGE>) { 1.128 - print $_; 1.129 - } 1.130 -} 1.131 - 1.132 -__USAGE__ 1.133 + print <<'USAGE'; 1.134 1.135 Commands: 1.136 1.137 @@ -485,51 +513,7 @@ 1.138 If host list is not specified, 1.139 command is executed on all of the machines 1.140 1.141 +USAGE 1.142 +} 1.143 1.144 1.145 -__SCRIPTS__ 1.146 -###install 1.147 -cat $sshkey | $lmssh $ssh_user@$host /bin/sh -c '"mkdir -p ~/.ssh; cat >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"' 1.148 - 1.149 -###install-lm 1.150 -cat $lminstall | ssh $ssh_user@$host /bin/sh -s $dirs 1.151 -scp l3config.pm l3-agent $ssh_user@$host:/usr/local/bin 1.152 - 1.153 -###install-pm 1.154 -scp PM/* $ssh_user@$host:/tmp 1.155 -#ssh $ssh_user@$host 'cd /tmp; tar xfz Term-VT102*.gz; cd Term-VT102*[^z]; perl Makefile.PL; make ; make install' 1.156 -ssh $ssh_user@$host 'cd /tmp; tar xfz Text-Iconv*.gz; cd Text-Iconv*[^z]; perl Makefile.PL; make ; make install' 1.157 - 1.158 -###copy-lablogs 1.159 -for i in $dirs 1.160 -do 1.161 - mkdir -p $lablogs/${i##*/} 1.162 - scp -q $ssh_user@$host:${i}/.lilalo/* $lablogs/${i##*/} 1.163 -done 1.164 - 1.165 -###setlab 1.166 -for i in $dirs 1.167 -do 1.168 - echo $lab | ssh $ssh_user@$host "cat > "${i}"/.labmaker/lab" 1.169 -done 1.170 - 1.171 -###makeout 1.172 -common=$course-$date 1.173 -personal=$course-$date-$email 1.174 -mkdir -p $outpath/${common}/{Lablogs,Docs} 1.175 -mkdir -p $outpath/${personal}/{Course,Files} 1.176 -cd $outpath/${personal} 1.177 -ln -s ../${common}/Lablogs . 1.178 -ln -s ../${common}/Docs . 1.179 -cd ~- 1.180 -export UG_PERSONAL=$outpath/${personal}/Course 1.181 -export UG_CENTER="$center" 1.182 -export UG_COURSE="$course" 1.183 -export UG_DATE="$date" 1.184 -export UG_STUDENT="$name" 1.185 -export UG_COMPANY="$company" 1.186 -export UG_MAIL="$email" 1.187 -cd $coursepath; make personal; cd ~- 1.188 - 1.189 -###watch 1.190 -cat taillast.pl | ssh $ssh_user@$host perl - /root/.labmaker