[164] | 1 | #!/usr/bin/perl -w
|
---|
[153] | 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 | #
|
---|
[163] | 6 | # Needs to use root account to connect to the VM
|
---|
[153] | 7 |
|
---|
| 8 | # You need to specify here your local public SSH key used to access
|
---|
| 9 | # the pb account in the VM later on
|
---|
| 10 |
|
---|
[164] | 11 | use strict;
|
---|
| 12 | use File::Basename;
|
---|
| 13 | use ProjectBuilder::Distribution qw (pb_distro_init);
|
---|
[153] | 14 |
|
---|
[164] | 15 | my $file = "/tmp/pbkey";
|
---|
[153] | 16 |
|
---|
[164] | 17 | open(PBFILE,"> $file") || die "Unable to open $file";
|
---|
| 18 | 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";
|
---|
| 19 | close(PBFILE);
|
---|
| 20 | chmod 0644,$file;
|
---|
| 21 |
|
---|
| 22 | $file="/etc/passwd";
|
---|
| 23 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 24 | my $found = 0;
|
---|
| 25 | while (<PBFILE>) {
|
---|
| 26 | $found = 1 if (/^pb:/);
|
---|
| 27 | }
|
---|
| 28 | close(PBFILE);
|
---|
| 29 |
|
---|
| 30 | if ( $found == 0 ) {
|
---|
| 31 | if ( ! -d "/home" ) {
|
---|
| 32 | mkdir "/home";
|
---|
| 33 | }
|
---|
| 34 | system "useradd pb";
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[153] | 37 | # No passwd for pb only keys
|
---|
[164] | 38 | $file="/etc/shadow";
|
---|
| 39 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 40 | while (<PBFILE>) {
|
---|
| 41 | s/^pb:\!\!:/pb:*:/;
|
---|
| 42 | }
|
---|
| 43 | close(PBFILE);
|
---|
| 44 |
|
---|
[153] | 45 | # Adapt sudoers
|
---|
[164] | 46 | $file="/etc/sudoers";
|
---|
| 47 | $found = 0;
|
---|
| 48 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 49 | while (<PBFILE>) {
|
---|
| 50 | $found = 1 if (/^pb /);
|
---|
| 51 | }
|
---|
| 52 | close(PBFILE);
|
---|
[153] | 53 |
|
---|
[164] | 54 | if ( $found == 0 ) {
|
---|
| 55 | open(PBFILE,">> $file") || die "Unable to open $file";
|
---|
| 56 | print PBFILE "pb ALL=(ALL) NOPASSWD:ALL\n";
|
---|
| 57 | }
|
---|
[158] | 58 |
|
---|
[164] | 59 | system 'su - pb -c "mkdir -p .ssh ; chmod 700 .ssh ; cp /tmp/pbkey .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys"';
|
---|
| 60 | unlink "/tmp/pbkey";
|
---|
| 61 |
|
---|
| 62 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
| 63 |
|
---|
[158] | 64 | # Get and install pb
|
---|
[164] | 65 | if ( $ddir eq "fedora" ) {
|
---|
| 66 | system "yum clean all";
|
---|
| 67 | if ( $dver <= 4 ) {
|
---|
| 68 | # FC4
|
---|
| 69 | 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 ..";
|
---|
| 70 | } else {
|
---|
| 71 | # FC5/6/7
|
---|
| 72 | 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";
|
---|
| 73 | }
|
---|
| 74 | } elsif ( $dfam eq "md" ) {
|
---|
| 75 | 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";
|
---|
| 76 | } elsif ( $dfam eq "du" ) {
|
---|
| 77 | 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";
|
---|
| 78 | } elsif ( $dfam eq "gen" ) {
|
---|
| 79 | system "emerge neon newt slang autoconf automake subversion libtool gcc wget vim man groff lynx grub afio buffer mindi mondo-rescue cdrecord mkisofs";
|
---|
| 80 | } else {
|
---|
| 81 | print "No pkg to install\n";
|
---|
| 82 | }
|
---|
[158] | 83 |
|
---|
[164] | 84 | $file = "/tmp/pbpatch";
|
---|
| 85 | unlink $file;
|
---|
| 86 |
|
---|
| 87 | open(PBFILE,"> $file") || die "Unable to open $file";
|
---|
| 88 | print PBFILE << 'EOF';
|
---|
[163] | 89 | --- File.pm 2007-09-29 14:55:28.000000000 +0100
|
---|
| 90 | +++ File.pm.new 2007-09-29 14:55:44.000000000 +0100
|
---|
| 91 | @@ -15,7 +15,7 @@
|
---|
| 92 | package AppConfig::File;
|
---|
| 93 | use strict;
|
---|
| 94 | use warnings;
|
---|
[158] | 95 | -use AppConfig;
|
---|
| 96 | +use AppConfig qw(:argcount);
|
---|
| 97 | use AppConfig::State;
|
---|
[163] | 98 | our $VERSION = '1.65';
|
---|
| 99 |
|
---|
| 100 | @@ -208,6 +208,11 @@
|
---|
| 101 |
|
---|
| 102 | my $nargs = $state->_argcount($variable);
|
---|
| 103 |
|
---|
| 104 | + # Fix a bug if the variable is a hash - 1 has been created as a key
|
---|
| 105 | + if ($nargs eq AppConfig::ARGCOUNT_HASH) {
|
---|
| 106 | + delete $state->{ VARIABLE }->{ $variable }{1};
|
---|
| 107 | + }
|
---|
[158] | 108 | +
|
---|
[163] | 109 | # variables prefixed '-' are reset to their default values
|
---|
| 110 | if ($flag eq '-') {
|
---|
| 111 | $state->_default($variable);
|
---|
| 112 |
|
---|
[158] | 113 | EOF
|
---|
[164] | 114 | close(PBFILE);
|
---|
[158] | 115 |
|
---|
| 116 | # Patch AppConfig
|
---|
[164] | 117 | my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
|
---|
| 118 | chomp($module);
|
---|
| 119 | $found = 0;
|
---|
| 120 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
| 121 | while (<PBFILE>) {
|
---|
| 122 | $found = 1 if (/Fix a bug if the variable is a hash/);
|
---|
| 123 | }
|
---|
| 124 | close(PBFILE);
|
---|
[158] | 125 |
|
---|
[164] | 126 | if ( $found == 0 ) {
|
---|
| 127 | chdir basename($module);
|
---|
| 128 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
| 129 | my $module1 = $module."new";
|
---|
| 130 | open(PBOUT," > $module1") || die "Unable to open $module1";
|
---|
| 131 | while (<PBFILE>) {
|
---|
| 132 | s/^use AppConfig;/use AppConfig qw(:argcount);/;
|
---|
| 133 | if (/# variables prefixed '-' are reset to their default values/) {
|
---|
| 134 | print PBOUT << 'EOF';
|
---|
| 135 | # Fix a bug if the variable is a hash - 1 has been created as a key
|
---|
| 136 | if ($nargs eq AppConfig::ARGCOUNT_HASH) {
|
---|
| 137 | delete $state->{ VARIABLE }->{ $variable }{1};
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | EOF
|
---|
| 141 | }
|
---|
| 142 | print PBOUT "$_";
|
---|
| 143 | }
|
---|
| 144 | close(PBFILE);
|
---|
| 145 | close(PBOUT);
|
---|
| 146 | rename($module1,$module);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | 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 ..";
|
---|