source: ProjectBuilder/devel/pb/contrib/pbsetupqemu@ 166

Last change on this file since 166 was 166, checked in by Bruno Cornec, 17 years ago

Attempt ro remove a pb on recent bash version (maybe)

  • Property svn:executable set to *
File size: 4.8 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";
36}
37
38# No passwd for pb only keys
39$file="/etc/shadow";
40open(PBFILE,$file) || die "Unable to open $file";
41open(PBOUT,"> $file.new") || die "Unable to open $file.new";
42while (<PBFILE>) {
43 s/^pb:\!\!:/pb:*:/;
44 print PBOUT $_;
45}
46close(PBFILE);
47close(PBOUT);
48rename("$file.new",$file);
49
50# Adapt sudoers
51$file="/etc/sudoers";
52$found = 0;
53open(PBFILE,$file) || die "Unable to open $file";
54open(PBOUT,"> $file.new") || die "Unable to open $file.new";
55while (<PBFILE>) {
56 $found = 1 if (/^pb /);
57 s/Defaults[ \t]+requiretty//;
58 print PBOUT $_;
59}
60close(PBFILE);
61print PBFILE "pb ALL=(ALL) NOPASSWD:ALL\n" if ( $found == 0 );
62close(PBOUT);
63rename("$file.new",$file);
64
65system 'su - pb -c "mkdir -p .ssh ; chmod 700 .ssh ; cp /tmp/pbkey .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys"';
66unlink "/tmp/pbkey";
67
68my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
69
70# Get and install pb
71if ( $ddir eq "fedora" ) {
72 system "yum clean all";
73 if ( $dver <= 4 ) {
74 # FC4
75 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 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 ..";
76 } else {
77 # FC5/6/7
78 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 ntp perl-AppConfig perl-DateManip";
79 }
80} elsif ( $dfam eq "md" ) {
81 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 ntp-client perl-AppConfig perl-DateManip";
82} elsif ( $dfam eq "du" ) {
83 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";
84} elsif ( $dfam eq "gen" ) {
85 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";
86} else {
87 print "No pkg to install\n";
88}
89
90# Patch AppConfig
91my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
92chomp($module);
93$found = 0;
94open(PBFILE,$module) || die "Unable to open $module";
95while (<PBFILE>) {
96 $found = 1 if (/Fix a bug if the variable is a hash/);
97}
98close(PBFILE);
99
100if ( $found == 0 ) {
101 chdir basename($module);
102 open(PBFILE,$module) || die "Unable to open $module";
103 my $module1 = $module."new";
104 open(PBOUT," > $module1") || die "Unable to open $module1";
105 while (<PBFILE>) {
106 s/^use AppConfig;/use AppConfig qw(:argcount);/;
107 if (/# variables prefixed '-' are reset to their default values/) {
108print PBOUT << 'EOF';
109 # Fix a bug if the variable is a hash - 1 has been created as a key
110 if ($nargs eq AppConfig::ARGCOUNT_HASH) {
111 delete $state->{ VARIABLE }->{ $variable }{1};
112 }
113
114EOF
115 }
116 print PBOUT "$_";
117 }
118 close(PBFILE);
119 close(PBOUT);
120 rename($module1,$module);
121}
122
123system "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 ..";
124
Note: See TracBrowser for help on using the repository browser.