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

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

path for ntpdate

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