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

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

export TZ also
Still better example script in perl

  • Property svn:executable set to *
File size: 5.4 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 use root account to connect to the VM
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
11use strict;
12use File::Basename;
13use ProjectBuilder::Distribution qw (pb_distro_init);
14
15my $file = "/tmp/pbkey";
16
17open(PBFILE,"> $file") || die "Unable to open $file";
18print 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";
19close(PBFILE);
20chmod 0644,$file;
21
22$file="/etc/passwd";
23open(PBFILE,$file) || die "Unable to open $file";
24my $found = 0;
25while (<PBFILE>) {
26 $found = 1 if (/^pb:/);
27}
28close(PBFILE);
29
30if ( $found == 0 ) {
31 if ( ! -d "/home" ) {
32 mkdir "/home";
33 }
34 system "useradd pb";
35}
36
37# No passwd for pb only keys
38$file="/etc/shadow";
39open(PBFILE,$file) || die "Unable to open $file";
40while (<PBFILE>) {
41 s/^pb:\!\!:/pb:*:/;
42}
43close(PBFILE);
44
45# Adapt sudoers
46$file="/etc/sudoers";
47$found = 0;
48open(PBFILE,$file) || die "Unable to open $file";
49while (<PBFILE>) {
50 $found = 1 if (/^pb /);
51}
52close(PBFILE);
53
54if ( $found == 0 ) {
55 open(PBFILE,">> $file") || die "Unable to open $file";
56 print PBFILE "pb ALL=(ALL) NOPASSWD:ALL\n";
57}
58
59system 'su - pb -c "mkdir -p .ssh ; chmod 700 .ssh ; cp /tmp/pbkey .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys"';
60unlink "/tmp/pbkey";
61
62my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
63
64# Get and install pb
65if ( $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}
83
84$file = "/tmp/pbpatch";
85unlink $file;
86
87open(PBFILE,"> $file") || die "Unable to open $file";
88print PBFILE << 'EOF';
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;
95-use AppConfig;
96+use AppConfig qw(:argcount);
97 use AppConfig::State;
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+ }
108+
109 # variables prefixed '-' are reset to their default values
110 if ($flag eq '-') {
111 $state->_default($variable);
112
113EOF
114close(PBFILE);
115
116# Patch AppConfig
117my $module=`find /usr/lib/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
118chomp($module);
119$found = 0;
120open(PBFILE,$module) || die "Unable to open $module";
121while (<PBFILE>) {
122 $found = 1 if (/Fix a bug if the variable is a hash/);
123}
124close(PBFILE);
125
126if ( $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/) {
134print 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
140EOF
141 }
142 print PBOUT "$_";
143 }
144 close(PBFILE);
145 close(PBOUT);
146 rename($module1,$module);
147}
148
149system "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 ..";
Note: See TracBrowser for help on using the repository browser.