source: devel/pb/contrib/pbsetupqemu @ 176

Last change on this file since 176 was 176, checked in by bruno, 12 years ago

Add pbdistrocheck do the set of tools
perl 5.8.0 only is required (instead of 5.8.4) if AppConfig? is provided (to be checked ?)

  • Property svn:executable set to *
File size: 6.7 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 -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    print PBOUT $_;
52}
53close(PBFILE);
54close(PBOUT);
55rename("$file.new",$file);
56chmod 0640,$file;
57
58# Adapt sudoers
59$file="/etc/sudoers";
60$found = 0;
61open(PBFILE,$file) || die "Unable to open $file";
62open(PBOUT,"> $file.new") || die "Unable to open $file.new";
63while (<PBFILE>) {
64    $found = 1 if (/^pb   /);
65    s/Defaults[ \t]+requiretty//;
66    print PBOUT $_;
67}
68close(PBFILE);
69print PBOUT "pb   ALL=(ALL) NOPASSWD:ALL\n" if ( $found == 0 );
70close(PBOUT);
71rename("$file.new",$file);
72chmod 0440,$file;
73
74unlink "/tmp/pbkey";
75
76my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 
77print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
78
79# Get and install pb
80if ( $ddir eq "fedora" ) {
81    system "yum clean all";
82    system "yum update -y";
83    my $arch=`uname -m`;
84    my $opt = "";
85    chomp($arch);
86    if ($arch eq "x86_64") {
87        $opt="--exclude=*.i?86";
88    }
89
90    my $topbuilddir=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
91    chomp($topbuilddir);
92
93    my $p = `rpm -q afio`;
94    chomp($p);
95    if ($p !~ /^afio/) {
96        system "rm -f afio-* ; wget ftp://ftp.mondorescue.org/src/afio-2.4.7-1.src.rpm ; rpm -ivh afio-2.4.7-1.src.rpm ; rpmbuild -ba $topbuilddir/SPECS/afio.spec ; chmod 644 $topbuilddir/RPMS/*/*.rpm";
97    }
98    $p = `rpm -q buffer`;
99    chomp($p);
100    if ($p !~ /^buffer/) {
101        system "rm -f buffer-* ; wget ftp://ftp.mondorescue.org/src/buffer-1.19-1.src.rpm ; rpm -ivh buffer-1.19-1.src.rpm ; rpmbuild -ba $topbuilddir/SPECS/buffer.spec ; chmod 644 $topbuilddir/RPMS/*/*.rpm";
102    }
103    if ( $dver <= 4 ) {
104        # FC4 - AppConfig unavailable
105        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 ; 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 ..";
106    } else {
107        # FC5/6/7
108        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 perl-AppConfig perl-DateManip";
109    }
110} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.2"))) || (($ddir eq "mandrake") && ($dver eq "10.1"))) {
111    # Suppose pkg are installed already
112    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 .. ";
113} elsif ( $dfam eq "md" ) {
114    if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
115        # mondo not available
116        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 mkisofs cdrecord ntp-client perl-AppConfig perl-DateManip";
117    } else {
118        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";
119    }
120} elsif ( $dfam eq "du" ) {
121    system "apt-get install autoconf automake libtool g++ wget patch mondo groff imagemagick docbook-utils docbook2x docbook-to-man openssh-server dpkg-dev debian-builder dh-make fakeroot libnewt-dev ntp-client libncurses5-dev";
122} elsif ( $dfam eq "gen" ) {
123    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";
124} else {
125    print "No pkg to install\n";
126}
127
128# Sync date
129system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
130
131# Patch AppConfig
132my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
133chomp($module);
134$found = 0;
135open(PBFILE,$module) || die "Unable to open $module";
136while (<PBFILE>) {
137    $found = 1 if (/Fix a bug if the variable is a hash/);
138}
139close(PBFILE);
140
141if ( $found == 0 ) {
142    chdir basename($module);
143    open(PBFILE,$module) || die "Unable to open $module";
144    my $module1 = $module."new";
145    open(PBOUT," > $module1") || die "Unable to open $module1";
146    while (<PBFILE>) {
147            s/^use AppConfig;/use AppConfig qw(:argcount);/;
148            if (/# variables prefixed '-' are reset to their default values/) {
149print PBOUT << 'EOF';
150                 # Fix a bug if the variable is a hash - 1 has been created as a key
151                 if ($nargs eq AppConfig::ARGCOUNT_HASH) {
152                     delete $state->{ VARIABLE }->{ $variable }{1};
153                 }
154
155EOF
156            }
157            print PBOUT "$_";
158    }
159    close(PBFILE);
160    close(PBOUT);
161    rename($module1,$module);
162}
163
164system "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 ..";
165
Note: See TracBrowser for help on using the repository browser.