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

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

Support global filter gfiles (taken before package specific ones)

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