lilalo
changeset 40:5e5878bd1b20
Скрипты lm вынесены в отдельный файл l3config
author | devi |
---|---|
date | Tue Nov 22 22:47:47 2005 +0200 (2005-11-22) |
parents | aa788e638a9d |
children | 6452bfe549d1 |
files | l3config.pm l3scripts lm |
line diff
1.1 --- a/l3config.pm Tue Nov 22 22:45:45 2005 +0200 1.2 +++ b/l3config.pm Tue Nov 22 22:47:47 2005 +0200 1.3 @@ -124,6 +124,8 @@ 1.4 "lmssh" => "./lm-ssh", 1.5 "lminstall" => "./lm-install", 1.6 "ssh_user" => "root", 1.7 + 1.8 + "l3scripts" => "l3scripts", 1.9 1.10 ); 1.11
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/l3scripts Tue Nov 22 22:47:47 2005 +0200 2.3 @@ -0,0 +1,63 @@ 2.4 +###install 2.5 +cat $sshkey | $lmssh $ssh_user@$host /bin/sh -c '"mkdir -p ~/.ssh; cat >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"' 2.6 + 2.7 +###install-lm 2.8 +cat $lminstall | ssh $ssh_user@$host /bin/sh -s $dirs 2.9 +scp l3config.pm l3-agent $ssh_user@$host:/usr/local/bin 2.10 + 2.11 +###install-pm 2.12 +scp PM/* $ssh_user@$host:/tmp 2.13 +ssh $ssh_user@$host 'cd /tmp; tar xfz Term-VT102*.gz; cd Term-VT102*[^z]; perl Makefile.PL; make ; make install' 2.14 +#ssh $ssh_user@$host 'cd /tmp; tar xfz Text-Iconv*.gz; cd Text-Iconv*[^z]; perl Makefile.PL; make ; make install' 2.15 + 2.16 +###copy-lablogs 2.17 +for i in $dirs 2.18 +do 2.19 + mkdir -p $lablogs/${i##*/} 2.20 + scp -q $ssh_user@$host:${i}/.lilalo/* $lablogs/${i##*/} 2.21 +done 2.22 + 2.23 +###setlab 2.24 +for i in $dirs 2.25 +do 2.26 + echo $lab | ssh $ssh_user@$host "cat > "${i}"/.labmaker/lab" 2.27 +done 2.28 + 2.29 +###makeout 2.30 +common=$course-$date 2.31 +personal=$course-$date-$email 2.32 +mkdir -p $outpath/${common}/{Lablogs,Docs} 2.33 +mkdir -p $outpath/${personal}/{Course,Files} 2.34 +cd $outpath/${personal} 2.35 +ln -s ../${common}/Lablogs . 2.36 +ln -s ../${common}/Docs . 2.37 +cd ~- 2.38 +export UG_PERSONAL=$outpath/${personal}/Course 2.39 +export UG_CENTER="$center" 2.40 +export UG_COURSE="$course" 2.41 +export UG_DATE="$date" 2.42 +export UG_STUDENT="$name" 2.43 +export UG_COMPANY="$company" 2.44 +export UG_MAIL="$email" 2.45 +cd $coursepath; make personal; cd ~- 2.46 + 2.47 +###POST-makeout 2.48 +rm -rf /tmp/$course-$date 2.49 +mkdir /tmp/$course-$date 2.50 +find $outpath/*$date* -name \*.pdf -exec cp {} /tmp/$course-$date/ \; 2.51 +cd /tmp 2.52 +zip -r $course-$date.zip $course-$date 2.53 +mv $course-$date.zip /var/www/tmp/ 2.54 +mutt -s 'Сгенерированы методички' imchubin\@mail.ru <<LETTER 2.55 +Сгенерированы методички для курса $course, который начинается $date. 2.56 + 2.57 +Архив файлов для печати можно получить по адресу: 2.58 +http://chub.in/tmp/$course-$date.zip 2.59 +Архив будет доступен по этому адресу в течение трех дней. 2.60 + 2.61 +-- 2.62 +WBR,i.m.chubin 2.63 +LETTER 2.64 + 2.65 +###watch 2.66 +cat taillast.pl | ssh $ssh_user@$host perl - /root/.labmaker
3.1 --- a/lm Tue Nov 22 22:45:45 2005 +0200 3.2 +++ b/lm Tue Nov 22 22:47:47 2005 +0200 3.3 @@ -2,13 +2,15 @@ 3.4 3.5 3.6 use strict; 3.7 -use Inline::Files; 3.8 use Data::Dumper; 3.9 use Switch; 3.10 use XML::Simple; 3.11 use Getopt::Long; 3.12 use utf8; 3.13 3.14 +use lib "/usr/local/bin"; 3.15 +use l3config; 3.16 + 3.17 our $XMLClass; 3.18 our $XMLCourse; 3.19 our @Labs; 3.20 @@ -17,7 +19,7 @@ 3.21 our @SelectedMachines; # Machines list given as the command line argument 3.22 3.23 our $Config_File = "labmaker.conf"; 3.24 -our %Config = ( 3.25 +our %Config_ = ( 3.26 "show_host" => "no", 3.27 3.28 # Вспомогательные программы 3.29 @@ -85,7 +87,8 @@ 3.30 exit(0); 3.31 } 3.32 3.33 - load_config; 3.34 + init_config(); 3.35 + #load_config; 3.36 load_run; 3.37 load_scripts; 3.38 load_class; 3.39 @@ -126,10 +129,19 @@ 3.40 3.41 sub load_scripts 3.42 { 3.43 + print join " ", %Config; 3.44 + print "\n"; 3.45 + 3.46 + open (SCRIPTS, "$Config{l3scripts}") 3.47 + or die "Cant open l3scripts file: ".$Config{l3scripts}.": $!\n"; 3.48 + binmode SCRIPTS, ":utf8"; 3.49 local $/; 3.50 $_=<SCRIPTS>; 3.51 + close(SCRIPTS); 3.52 + 3.53 %Scripts = ("empty-element", split (/###(.*)\n/)); 3.54 delete($Scripts{"empty-element"}); 3.55 + 3.56 } 3.57 3.58 sub load_config 3.59 @@ -265,27 +277,39 @@ 3.60 my $command = shift; 3.61 my $arg = join " ", @_; 3.62 my $i=1; 3.63 + 3.64 + my %myenv = ( %Config, 3.65 + lab => $arg, 3.66 + center => $XMLClass->{"center"}, 3.67 + course => $XMLClass->{"course"}, 3.68 + date => $XMLClass->{"date"}, 3.69 + coursepath => $XMLCourse->{"path"}, 3.70 + ); 3.71 + 3.72 + if (grep { $_ eq "PRE-$command"} keys %Scripts) { 3.73 + $_=$Scripts{"PRE-$command"}; 3.74 + s/\$(\w+)/$myenv{$1}/ge; 3.75 + open(SHELL, "|/bin/sh -s"); 3.76 + binmode SHELL, ":utf8"; 3.77 + print SHELL $_; 3.78 + close (SHELL); 3.79 + } 3.80 + 3.81 + 3.82 for my $m (sort keys %Machines) { 3.83 if (!@SelectedMachines || grep $_ eq $i, @SelectedMachines) { 3.84 print "$m:\n" if $Config{"show_host"} =~ /y/i; 3.85 3.86 - my %myenv = ( %Config, 3.87 + %myenv = ( %myenv, 3.88 host => $m, 3.89 dirs => "/root /home/".$Machines{$m}->{"user"}, 3.90 lablogs => $Config{"path_lablogs"}."/". 3.91 $XMLClass->{"course"}."/". 3.92 $XMLClass->{"date"}."/". 3.93 "$m", 3.94 - lab => $arg, 3.95 - 3.96 email => $Machines{$m}->{"student"}->{"email"}, 3.97 company => $Machines{$m}->{"student"}->{"company"}, 3.98 - center => $XMLClass->{"center"}, 3.99 - course => $XMLClass->{"course"}, 3.100 - date => $XMLClass->{"date"}, 3.101 name => $Machines{$m}->{"name"}, 3.102 - coursepath => $XMLCourse->{"path"}, 3.103 - 3.104 ); 3.105 if (grep { $_ eq $command} keys %Scripts) { 3.106 $_=$Scripts{"$command"}; 3.107 @@ -306,6 +330,15 @@ 3.108 } 3.109 $i++; 3.110 } 3.111 + 3.112 + if (grep { $_ eq "POST-$command"} keys %Scripts) { 3.113 + $_=$Scripts{"POST-$command"}; 3.114 + s/\$(\w+)/$myenv{$1}/ge; 3.115 + open(SHELL, "|/bin/sh -s"); 3.116 + binmode SHELL, ":utf8"; 3.117 + print SHELL $_; 3.118 + close (SHELL); 3.119 + } 3.120 } 3.121 3.122 3.123 @@ -450,12 +483,7 @@ 3.124 sub print_usage_info 3.125 { 3.126 print "Usage:\n\n\t$0 [host-list] command\n"; 3.127 - while (<USAGE>) { 3.128 - print $_; 3.129 - } 3.130 -} 3.131 - 3.132 -__USAGE__ 3.133 + print <<'USAGE'; 3.134 3.135 Commands: 3.136 3.137 @@ -485,51 +513,7 @@ 3.138 If host list is not specified, 3.139 command is executed on all of the machines 3.140 3.141 +USAGE 3.142 +} 3.143 3.144 3.145 -__SCRIPTS__ 3.146 -###install 3.147 -cat $sshkey | $lmssh $ssh_user@$host /bin/sh -c '"mkdir -p ~/.ssh; cat >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"' 3.148 - 3.149 -###install-lm 3.150 -cat $lminstall | ssh $ssh_user@$host /bin/sh -s $dirs 3.151 -scp l3config.pm l3-agent $ssh_user@$host:/usr/local/bin 3.152 - 3.153 -###install-pm 3.154 -scp PM/* $ssh_user@$host:/tmp 3.155 -#ssh $ssh_user@$host 'cd /tmp; tar xfz Term-VT102*.gz; cd Term-VT102*[^z]; perl Makefile.PL; make ; make install' 3.156 -ssh $ssh_user@$host 'cd /tmp; tar xfz Text-Iconv*.gz; cd Text-Iconv*[^z]; perl Makefile.PL; make ; make install' 3.157 - 3.158 -###copy-lablogs 3.159 -for i in $dirs 3.160 -do 3.161 - mkdir -p $lablogs/${i##*/} 3.162 - scp -q $ssh_user@$host:${i}/.lilalo/* $lablogs/${i##*/} 3.163 -done 3.164 - 3.165 -###setlab 3.166 -for i in $dirs 3.167 -do 3.168 - echo $lab | ssh $ssh_user@$host "cat > "${i}"/.labmaker/lab" 3.169 -done 3.170 - 3.171 -###makeout 3.172 -common=$course-$date 3.173 -personal=$course-$date-$email 3.174 -mkdir -p $outpath/${common}/{Lablogs,Docs} 3.175 -mkdir -p $outpath/${personal}/{Course,Files} 3.176 -cd $outpath/${personal} 3.177 -ln -s ../${common}/Lablogs . 3.178 -ln -s ../${common}/Docs . 3.179 -cd ~- 3.180 -export UG_PERSONAL=$outpath/${personal}/Course 3.181 -export UG_CENTER="$center" 3.182 -export UG_COURSE="$course" 3.183 -export UG_DATE="$date" 3.184 -export UG_STUDENT="$name" 3.185 -export UG_COMPANY="$company" 3.186 -export UG_MAIL="$email" 3.187 -cd $coursepath; make personal; cd ~- 3.188 - 3.189 -###watch 3.190 -cat taillast.pl | ssh $ssh_user@$host perl - /root/.labmaker