source: devel/pb/contrib/pbsetupqemu @ 175

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

Adds some dependcies for rpm pkg

  • Property svn:executable set to *
File size: 6.6 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 "useradd pb -d /home/pb";
36}
37
38chdir "/home/pb";
39mkdir ".ssh",0700;
40system 'cp /tmp/pbkey .ssh/authorized_keys';
41chmod 0600,".ssh/authorized_keys";
42system 'chown -R pb:pb .ssh';
43
44# No passwd for pb only keys
45$file="/etc/shadow";
46open(PBFILE,$file) || die "Unable to open $file";
47open(PBOUT,"> $file.new") || die "Unable to open $file.new";
48while (<PBFILE>) {
49    s/^pb:\!\!:/pb:*:/;
50    print PBOUT $_;
51}
52close(PBFILE);
53close(PBOUT);
54rename("$file.new",$file);
55chmod 0640,$file;
56
57# Adapt sudoers
58$file="/etc/sudoers";
59$found = 0;
60open(PBFILE,$file) || die "Unable to open $file";
61open(PBOUT,"> $file.new") || die "Unable to open $file.new";
62while (<PBFILE>) {
63    $found = 1 if (/^pb   /);
64    s/Defaults[ \t]+requiretty//;
65    print PBOUT $_;
66}
67close(PBFILE);
68print PBOUT "pb   ALL=(ALL) NOPASSWD:ALL\n" if ( $found == 0 );
69close(PBOUT);
70rename("$file.new",$file);
71chmod 0440,$file;
72
73unlink "/tmp/pbkey";
74
75my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 
76
77# Get and install pb
78if ( $ddir eq "fedora" ) {
79    system "yum clean all";
80    system "yum update -y";
81    my $arch=`uname -m`;
82    my $opt = "";
83    chomp($arch);
84    if ($arch eq "x86_64") {
85        $opt="--exclude=*.i?86";
86    }
87
88    my $topbuilddir=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
89    chomp($topbuilddir);
90
91    my $p = `rpm -q afio`;
92    chomp($p);
93    if ($p !~ /^afio/) {
94        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";
95    }
96    $p = `rpm -q buffer`;
97    chomp($p);
98    if ($p !~ /^buffer/) {
99        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";
100    }
101    if ( $dver <= 4 ) {
102        # FC4 - AppConfig unavailable
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 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 ..";
104    } else {
105        # FC5/6/7
106        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";
107    }
108} 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"))) {
109    # Suppose pkg are installed already
110    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 .. ";
111} elsif ( $dfam eq "md" ) {
112    if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
113        # mondo not available
114        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";
115    } else {
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 mondo mkisofs cdrecord ntp-client perl-AppConfig perl-DateManip";
117    }
118} elsif ( $dfam eq "du" ) {
119    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";
120} elsif ( $dfam eq "gen" ) {
121    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";
122} else {
123    print "No pkg to install\n";
124}
125
126# Sync date
127system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
128
129# Patch AppConfig
130my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
131chomp($module);
132$found = 0;
133open(PBFILE,$module) || die "Unable to open $module";
134while (<PBFILE>) {
135    $found = 1 if (/Fix a bug if the variable is a hash/);
136}
137close(PBFILE);
138
139if ( $found == 0 ) {
140    chdir basename($module);
141    open(PBFILE,$module) || die "Unable to open $module";
142    my $module1 = $module."new";
143    open(PBOUT," > $module1") || die "Unable to open $module1";
144    while (<PBFILE>) {
145            s/^use AppConfig;/use AppConfig qw(:argcount);/;
146            if (/# variables prefixed '-' are reset to their default values/) {
147print PBOUT << 'EOF';
148                 # Fix a bug if the variable is a hash - 1 has been created as a key
149                 if ($nargs eq AppConfig::ARGCOUNT_HASH) {
150                     delete $state->{ VARIABLE }->{ $variable }{1};
151                 }
152
153EOF
154            }
155            print PBOUT "$_";
156    }
157    close(PBFILE);
158    close(PBOUT);
159    rename($module1,$module);
160}
161
162system "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 ..";
163
Note: See TracBrowser for help on using the repository browser.