#!/usr/bin/perl -w # Script to be used as pbscript to create a potentialy # missing pb account on the QEMU VM, and adds it to sudo # # Needs to use root account to connect to the VM # You need to specify here your local public SSH key used to access # the pb account in the VM later on use strict; use File::Basename; use ProjectBuilder::Distribution qw (pb_distro_init); my $file = "/tmp/pbkey"; open(PBFILE,"> $file") || die "Unable to open $file"; print 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"; close(PBFILE); chmod 0644,$file; $file="/etc/passwd"; open(PBFILE,$file) || die "Unable to open $file"; my $found = 0; while () { $found = 1 if (/^pb:/); } close(PBFILE); if ( $found == 0 ) { if ( ! -d "/home" ) { mkdir "/home"; } system "useradd pb"; } # No passwd for pb only keys $file="/etc/shadow"; open(PBFILE,$file) || die "Unable to open $file"; while () { s/^pb:\!\!:/pb:*:/; } close(PBFILE); # Adapt sudoers $file="/etc/sudoers"; $found = 0; open(PBFILE,$file) || die "Unable to open $file"; while () { $found = 1 if (/^pb /); } close(PBFILE); if ( $found == 0 ) { open(PBFILE,">> $file") || die "Unable to open $file"; print PBFILE "pb ALL=(ALL) NOPASSWD:ALL\n"; } system 'su - pb -c "mkdir -p .ssh ; chmod 700 .ssh ; cp /tmp/pbkey .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys"'; unlink "/tmp/pbkey"; my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); # Get and install pb if ( $ddir eq "fedora" ) { system "yum clean all"; if ( $dver <= 4 ) { # FC4 system "yum -y 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 ; 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 .."; } else { # FC5/6/7 system "yum -y install neon newt-devel slang-devel autoconf automake libtool gcc rpm-build wget vim gcc-c++ docbook-utils-pdf ImageMagick man patch cdrecord mkisofs perl-AppConfig perl-DateManip"; } } elsif ( $dfam eq "md" ) { system "urpmi --auto-select neon newt-devel slang-devel glibc-static-devel autoconf automake libtool gcc rpm-build wget gcc-c++ docbook-utils-pdf ImageMagick man patch mindi mondo mkisofs cdrecord perl-AppConfig perl-DateManip"; } elsif ( $dfam eq "du" ) { 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 libncurses5-dev"; } elsif ( $dfam eq "gen" ) { system "emerge neon newt slang autoconf automake subversion libtool gcc wget vim man groff lynx grub afio buffer mindi mondo-rescue cdrecord mkisofs"; } else { print "No pkg to install\n"; } $file = "/tmp/pbpatch"; unlink $file; open(PBFILE,"> $file") || die "Unable to open $file"; print PBFILE << 'EOF'; --- File.pm 2007-09-29 14:55:28.000000000 +0100 +++ File.pm.new 2007-09-29 14:55:44.000000000 +0100 @@ -15,7 +15,7 @@ package AppConfig::File; use strict; use warnings; -use AppConfig; +use AppConfig qw(:argcount); use AppConfig::State; our $VERSION = '1.65'; @@ -208,6 +208,11 @@ my $nargs = $state->_argcount($variable); + # Fix a bug if the variable is a hash - 1 has been created as a key + if ($nargs eq AppConfig::ARGCOUNT_HASH) { + delete $state->{ VARIABLE }->{ $variable }{1}; + } + # variables prefixed '-' are reset to their default values if ($flag eq '-') { $state->_default($variable); EOF close(PBFILE); # Patch AppConfig my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`; chomp($module); $found = 0; open(PBFILE,$module) || die "Unable to open $module"; while () { $found = 1 if (/Fix a bug if the variable is a hash/); } close(PBFILE); if ( $found == 0 ) { chdir basename($module); open(PBFILE,$module) || die "Unable to open $module"; my $module1 = $module."new"; open(PBOUT," > $module1") || die "Unable to open $module1"; while () { s/^use AppConfig;/use AppConfig qw(:argcount);/; if (/# variables prefixed '-' are reset to their default values/) { print PBOUT << 'EOF'; # Fix a bug if the variable is a hash - 1 has been created as a key if ($nargs eq AppConfig::ARGCOUNT_HASH) { delete $state->{ VARIABLE }->{ $variable }{1}; } EOF } print PBOUT "$_"; } close(PBFILE); close(PBOUT); rename($module1,$module); } system "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 ..";