[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
|
---|
[166] | 5 |
|
---|
| 6 | # Needs to be extented with the pb Distribution.pm module at the end externally
|
---|
[153] | 7 | #
|
---|
[163] | 8 | # Needs to use root account to connect to the VM
|
---|
[153] | 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 |
|
---|
[164] | 13 | use strict;
|
---|
| 14 | use File::Basename;
|
---|
[153] | 15 |
|
---|
[164] | 16 | my $file = "/tmp/pbkey";
|
---|
[153] | 17 |
|
---|
[164] | 18 | open(PBFILE,"> $file") || die "Unable to open $file";
|
---|
| 19 | 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";
|
---|
| 20 | close(PBFILE);
|
---|
| 21 | chmod 0644,$file;
|
---|
| 22 |
|
---|
| 23 | $file="/etc/passwd";
|
---|
| 24 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 25 | my $found = 0;
|
---|
| 26 | while (<PBFILE>) {
|
---|
| 27 | $found = 1 if (/^pb:/);
|
---|
| 28 | }
|
---|
| 29 | close(PBFILE);
|
---|
| 30 |
|
---|
| 31 | if ( $found == 0 ) {
|
---|
| 32 | if ( ! -d "/home" ) {
|
---|
| 33 | mkdir "/home";
|
---|
| 34 | }
|
---|
[176] | 35 | system "groupadd pb";
|
---|
[179] | 36 | system "useradd pb -g pb -m -d /home/pb";
|
---|
[164] | 37 | }
|
---|
| 38 |
|
---|
[171] | 39 | chdir "/home/pb";
|
---|
| 40 | mkdir ".ssh",0700;
|
---|
| 41 | system 'cp /tmp/pbkey .ssh/authorized_keys';
|
---|
| 42 | chmod 0600,".ssh/authorized_keys";
|
---|
| 43 | system 'chown -R pb:pb .ssh';
|
---|
| 44 |
|
---|
[153] | 45 | # No passwd for pb only keys
|
---|
[164] | 46 | $file="/etc/shadow";
|
---|
| 47 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
[166] | 48 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
[164] | 49 | while (<PBFILE>) {
|
---|
| 50 | s/^pb:\!\!:/pb:*:/;
|
---|
[166] | 51 | print PBOUT $_;
|
---|
[164] | 52 | }
|
---|
| 53 | close(PBFILE);
|
---|
[166] | 54 | close(PBOUT);
|
---|
| 55 | rename("$file.new",$file);
|
---|
[167] | 56 | chmod 0640,$file;
|
---|
[164] | 57 |
|
---|
[153] | 58 | # Adapt sudoers
|
---|
[164] | 59 | $file="/etc/sudoers";
|
---|
| 60 | $found = 0;
|
---|
| 61 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
[166] | 62 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
[164] | 63 | while (<PBFILE>) {
|
---|
| 64 | $found = 1 if (/^pb /);
|
---|
[166] | 65 | s/Defaults[ \t]+requiretty//;
|
---|
| 66 | print PBOUT $_;
|
---|
[164] | 67 | }
|
---|
| 68 | close(PBFILE);
|
---|
[169] | 69 | print PBOUT "pb ALL=(ALL) NOPASSWD:ALL\n" if ( $found == 0 );
|
---|
[166] | 70 | close(PBOUT);
|
---|
| 71 | rename("$file.new",$file);
|
---|
[167] | 72 | chmod 0440,$file;
|
---|
[153] | 73 |
|
---|
[164] | 74 | unlink "/tmp/pbkey";
|
---|
| 75 |
|
---|
| 76 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
[176] | 77 | print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
|
---|
[164] | 78 |
|
---|
[158] | 79 | # Get and install pb
|
---|
[164] | 80 | if ( $ddir eq "fedora" ) {
|
---|
| 81 | system "yum clean all";
|
---|
[169] | 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 | }
|
---|
[171] | 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 | }
|
---|
[164] | 103 | if ( $dver <= 4 ) {
|
---|
[171] | 104 | # FC4 - AppConfig unavailable
|
---|
[169] | 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 ..";
|
---|
[164] | 106 | } else {
|
---|
| 107 | # FC5/6/7
|
---|
[169] | 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";
|
---|
[164] | 109 | }
|
---|
[181] | 110 | } elsif (($ddir eq "suse") && (($dver eq "10.2") || ($dver eq "10.3"))) {
|
---|
| 111 | system "yast2 -i 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";
|
---|
| 112 | } 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"))) {
|
---|
[175] | 113 | # Suppose pkg are installed already
|
---|
| 114 | 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 .. ";
|
---|
[164] | 115 | } elsif ( $dfam eq "md" ) {
|
---|
[175] | 116 | if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
|
---|
[171] | 117 | # mondo not available
|
---|
| 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 mkisofs cdrecord ntp-client perl-AppConfig perl-DateManip";
|
---|
| 119 | } else {
|
---|
| 120 | 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";
|
---|
| 121 | }
|
---|
[164] | 122 | } elsif ( $dfam eq "du" ) {
|
---|
[166] | 123 | 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";
|
---|
[164] | 124 | } elsif ( $dfam eq "gen" ) {
|
---|
[166] | 125 | 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";
|
---|
[164] | 126 | } else {
|
---|
| 127 | print "No pkg to install\n";
|
---|
| 128 | }
|
---|
[158] | 129 |
|
---|
[171] | 130 | # Sync date
|
---|
| 131 | system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
|
---|
| 132 |
|
---|
[158] | 133 | # Patch AppConfig
|
---|
[164] | 134 | my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
|
---|
| 135 | chomp($module);
|
---|
| 136 | $found = 0;
|
---|
| 137 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
| 138 | while (<PBFILE>) {
|
---|
| 139 | $found = 1 if (/Fix a bug if the variable is a hash/);
|
---|
| 140 | }
|
---|
| 141 | close(PBFILE);
|
---|
[158] | 142 |
|
---|
[164] | 143 | if ( $found == 0 ) {
|
---|
| 144 | chdir basename($module);
|
---|
| 145 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
| 146 | my $module1 = $module."new";
|
---|
| 147 | open(PBOUT," > $module1") || die "Unable to open $module1";
|
---|
| 148 | while (<PBFILE>) {
|
---|
| 149 | s/^use AppConfig;/use AppConfig qw(:argcount);/;
|
---|
| 150 | if (/# variables prefixed '-' are reset to their default values/) {
|
---|
| 151 | print PBOUT << 'EOF';
|
---|
| 152 | # Fix a bug if the variable is a hash - 1 has been created as a key
|
---|
| 153 | if ($nargs eq AppConfig::ARGCOUNT_HASH) {
|
---|
| 154 | delete $state->{ VARIABLE }->{ $variable }{1};
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | EOF
|
---|
| 158 | }
|
---|
| 159 | print PBOUT "$_";
|
---|
| 160 | }
|
---|
| 161 | close(PBFILE);
|
---|
| 162 | close(PBOUT);
|
---|
| 163 | rename($module1,$module);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | 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 ..";
|
---|
[166] | 167 |
|
---|