source: devel/pb/contrib/pbsetupqemu @ 200

Last change on this file since 200 was 200, checked in by Bruno Cornec, 13 years ago

More fixes for handling creation/destruction of VMs
SuSE 10.0 forces bz2 files (not more recent versions)

  • Property svn:executable set to *
File size: 6.9 KB
Line 
1#!/usr/bin/perl -w
2
3# Script to be used as pbscript to create a potentialy
4# missing pb account on the QEMU VM, and adds it to sudo
5
6# Needs to be extented with the pb Distribution.pm module at the end externally
7#
8# Needs to use root account to connect to the VM
9
10# You need to specify here your local public SSH key used to access
11# the pb account in the VM later on
12
13use strict;
14use File::Basename;
15
16my $file = "/tmp/pbkey";
17
18open(PBFILE,"> $file") || die "Unable to open $file";
19print PBFILE "ssh-dss AAAAB3NzaC1kc3MAAACBAMC06bNLMu8ZBJv3Hi77+fi+GUhtQScIbGKru86C/IP27EjrmYhPVccbu8kpX6SDHIouhpZ00gaefP3zHjLUmPKlXkMNUNjxx5JNLPoHhSIuUvoSTNoh9gsi31abAvzbW+RNer7rvBJO4ytNJRdsuNxBwqjxK04JEmatds+aKTQjAAAAFQDHaNmIuvYZ0RtNBVe+tzTzxxCQmQAAAIA4o89Xob2VBRtQKBjmWVAuTS14qiqnQUPNloaRkM+r2odI+NJDFc+WXOIG9QAPKKt1jvFOBOX9Mu3/xwiDLnAGhxud98FoyHevSpIWUld7rG4j1aww1WxolFWY/iPyAvDDMW3iysCoqQeSOlpRd9Mz/dq6/P/VcizhdGOKyc3JBgAAAIAA1eY+BoneiQ/tQ8j3GYbMTu6U7VzZ2OaoVeQn4NtZmPl+ZeQIj83nFpo99mYCbaBPqnZToERndl+ljp/JX5pamwj6RcLIDCyiB6MXLbQSWj0goegU1htp5aMd3NcyR2Jy8gCnf0QjDr7j23Q+CFGExtRb/nsDmaG5W9D6QSWQ/g== bruno\@victoria\n";
20close(PBFILE);
21chmod 0644,$file;
22
23$file="/etc/passwd";
24open(PBFILE,$file) || die "Unable to open $file";
25my $found = 0;
26while (<PBFILE>) {
27    $found = 1 if (/^pb:/);
28}
29close(PBFILE);
30
31if ( $found == 0 ) {
32    if ( ! -d "/home" ) {
33        mkdir "/home";
34    }
35    system "groupadd pb";
36    system "useradd pb -g pb -m -d /home/pb";
37}
38
39chdir "/home/pb";
40mkdir ".ssh",0700;
41system 'cp /tmp/pbkey .ssh/authorized_keys';
42chmod 0600,".ssh/authorized_keys";
43system 'chown -R pb:pb .ssh';
44
45# No passwd for pb only keys
46$file="/etc/shadow";
47open(PBFILE,$file) || die "Unable to open $file";
48open(PBOUT,"> $file.new") || die "Unable to open $file.new";
49while (<PBFILE>) {
50    s/^pb:\!\!:/pb:*:/;
51    s/^pb:\!:/pb:*:/;   #SLES 9 e.g.
52    print PBOUT $_;
53}
54close(PBFILE);
55close(PBOUT);
56rename("$file.new",$file);
57chmod 0640,$file;
58
59# Adapt sudoers
60$file="/etc/sudoers";
61$found = 0;
62open(PBFILE,$file) || die "Unable to open $file";
63open(PBOUT,"> $file.new") || die "Unable to open $file.new";
64while (<PBFILE>) {
65    $found = 1 if (/^pb   /);
66    s/Defaults[ \t]+requiretty//;
67    print PBOUT $_;
68}
69close(PBFILE);
70print PBOUT "pb   ALL=(ALL) NOPASSWD:ALL\n" if ( $found == 0 );
71close(PBOUT);
72rename("$file.new",$file);
73chmod 0440,$file;
74
75unlink "/tmp/pbkey";
76
77my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 
78# Suse wants sudoers as 640
79if (($ddir eq "sles") || ($ddir eq "suse")) {
80    chmod 0640,$file;
81}
82print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
83
84# Get and install pb
85if ( $ddir eq "fedora" ) {
86    system "yum clean all";
87    system "yum update -y";
88    my $arch=`uname -m`;
89    my $opt = "";
90    chomp($arch);
91    if ($arch eq "x86_64") {
92        $opt="--exclude=*.i?86";
93    }
94
95    my $topbuilddir=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
96    chomp($topbuilddir);
97
98    if ( $dver <= 4 ) {
99        # FC4 - AppConfig unavailable
100        system "yum -y $opt install neon newt-devel slang-devel autoconf automake libtool gcc rpm-build wget gcc-c++ docbook-utils-pdf ImageMagick man patch cdrecord mkisofs perl-DateManip ntp sudo ; rm -rf AppConfig-* ; wget http://search.cpan.org/CPAN/authors/id/A/AB/ABW/AppConfig-1.66.tar.gz ; tar xvfz AppConfig-1.66.tar.gz ; cd AppConfig* ; perl Makefile.PL ; make ; make install ; cd ..";
101    } else {
102        # FC5/6/7
103        system "yum -y $opt install neon newt-devel slang-devel autoconf automake libtool gcc rpm-build wget gcc-c++ docbook-utils-pdf ImageMagick man patch cdrecord mkisofs ntp sudo perl-AppConfig perl-DateManip";
104    }
105} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || (($ddir eq "mandrake") && ($dver eq "10.1"))) {
106    # Suppose pkg are installed already
107    system "rpm -e lsb 2>&1 > /dev/null";
108    system "rm -rf AppConfig-* ; wget http://search.cpan.org/CPAN/authors/id/A/AB/ABW/AppConfig-1.66.tar.gz ; tar xvfz AppConfig-1.66.tar.gz ; cd AppConfig* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf DateManip* ; wget http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.46.tar.gz ; tar xvfz Date-Manip-5.46.tar.gz ; cd Date-Manip* ; perl Makefile.PL ; make ; make install ; cd .. ";
109} elsif ($ddir eq "suse") { 
110    # New OpenSuSE
111    system "export TERM=linux ; liste=\"\" ; for i in neon newt-devel slang-devel autoconf automake libtool gcc wget gcc-c++ docbook-utils ImageMagick man patch mkisofs sudo perl-DateManip perl-AppConfig perl-File-HomeDir xntp; do rpm -q \$i 1> /dev/null 2> /dev/null ; if [ \$\? != 0 ]; then liste=\"\$liste \$i\"; fi; done; echo \"Liste: \$liste\" ; if [ \"\$liste\" != \"\" ]; then yast2 -i \$liste ; fi";
112} elsif ( $dfam eq "md" ) {
113    if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
114        # mondo not available
115        system "urpmi.update -a ; urpmi --auto neon newt-devel slang-devel glibc-static-devel autoconf automake libtool gcc rpm-build wget gcc-c++ docbook-utils-pdf ImageMagick sudo man patch mkisofs cdrecord ntp-client perl-AppConfig perl-DateManip";
116    } else {
117        system "urpmi.update -a ; urpmi --auto neon newt-devel slang-devel glibc-static-devel autoconf automake libtool gcc rpm-build wget gcc-c++ docbook-utils-pdf ImageMagick man patch mondo mkisofs cdrecord ntp-client perl-AppConfig perl-DateManip";
118    }
119} elsif ( $dfam eq "du" ) {
120    system "apt-get update; apt-get -y install autoconf automake libtool g++ wget patch mondo groff imagemagick docbook-utils docbook2x docbook-to-man openssh-server dpkg-dev sudo debian-builder dh-make fakeroot libnewt-dev ntpdate libncurses5-dev libdate-manip-perl libappconfig-perl";
121} elsif ( $dfam eq "gen" ) {
122    system "emerge neon newt slang autoconf automake subversion libtool gcc wget vim man groff lynx grub afio buffer mindi mondo-rescue cdrecord mkisofs ntp-client";
123} else {
124    print "No pkg to install\n";
125}
126
127# Sync date
128system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
129
130# Patch AppConfig
131my $module=`find /usr/*/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
132chomp($module);
133$found = 0;
134open(PBFILE,$module) || die "Unable to open $module";
135while (<PBFILE>) {
136    $found = 1 if (/Fix a bug if the variable is a hash/);
137}
138close(PBFILE);
139
140if ( $found == 0 ) {
141    chdir basename($module);
142    open(PBFILE,$module) || die "Unable to open $module";
143    my $module1 = $module."new";
144    open(PBOUT," > $module1") || die "Unable to open $module1";
145    while (<PBFILE>) {
146            s/^use AppConfig;/use AppConfig qw(:argcount);/;
147            if (/# variables prefixed '-' are reset to their default values/) {
148print PBOUT << 'EOF';
149                 # Fix a bug if the variable is a hash - 1 has been created as a key
150                 if ($nargs eq AppConfig::ARGCOUNT_HASH) {
151                     delete $state->{ VARIABLE }->{ $variable }{1};
152                 }
153
154EOF
155            }
156            print PBOUT "$_";
157    }
158    close(PBFILE);
159    close(PBOUT);
160    rename($module1,$module);
161}
162
163system "rm -rf project-builder-* ; wget ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; tar xvfz project-builder-latest.tar.gz ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd ..";
164
Note: See TracBrowser for help on using the repository browser.