source: devel/pb/contrib/pbsetupqemu @ 311

Last change on this file since 311 was 311, checked in by Bruno Cornec, 12 years ago

Used devel version for VM management

  • Property svn:executable set to *
File size: 6.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$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 "groupadd pb";
36    system "useradd pb -g pb -m -d /home/pb";
37}
38
39# For root
40mkdir ".ssh",0700;
41system 'cp /tmp/pbkey .ssh/authorized_keys';
42chmod 0600,".ssh/authorized_keys";
43
44# For pb
45chdir "/home/pb";
46mkdir ".ssh",0700;
47system 'cp /tmp/pbkey .ssh/authorized_keys';
48chmod 0600,".ssh/authorized_keys";
49system 'chown -R pb:pb .ssh';
50
51# No passwd for pb only keys
52$file="/etc/shadow";
53open(PBFILE,$file) || die "Unable to open $file";
54open(PBOUT,"> $file.new") || die "Unable to open $file.new";
55while (<PBFILE>) {
56    s/^pb:\!\!:/pb:*:/;
57    s/^pb:\!:/pb:*:/;   #SLES 9 e.g.
58    print PBOUT $_;
59}
60close(PBFILE);
61close(PBOUT);
62rename("$file.new",$file);
63chmod 0640,$file;
64
65# pb has to be added to portage group on gentoo
66
67unlink "/tmp/pbkey";
68
69my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 
70print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
71
72# Get and install pb
73if ( $ddir eq "fedora" ) {
74    system "yum clean all";
75    system "yum update -y";
76    my $arch=`uname -m`;
77    my $opt = "";
78    chomp($arch);
79    if ($arch eq "x86_64") {
80        $opt="--exclude=*.i?86";
81    }
82
83    #my $topbuilddir=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
84    #chomp($topbuilddir);
85
86    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 sudo perl-DateManip perl-ExtUtils-MakeMaker";
87} 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"))) {
88    # Suppose pkg are installed already
89    system "rpm -e lsb 2>&1 > /dev/null";
90    system "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 .. ";
91} elsif ($ddir eq "suse") { 
92    # New OpenSuSE
93    system "export TERM=linux ; liste=\"\" ; for i in neon newt-devel slang-devel autoconf automake libtool make gcc wget gcc-c++ docbook-utils ImageMagick man patch mkisofs sudo perl-DateManip perl-File-HomeDir xntp; do rpm -q \$i 1> /dev/null 2> /dev/null ; if [ \$\? != 0 ]; then liste=\"\$liste \$i\"; fi; done; echo \"Liste: \$liste\" ; if [ \"\$liste\" != \"\" ]; then yast2 -i \$liste ; fi";
94} elsif ( $dfam eq "md" ) {
95    if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
96        # mondo not available
97        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 sudo man patch mkisofs cdrecord ntp-client perl-DateManip";
98    } else {
99        system "urpmi.update -a ; urpmi --auto neon newt-devel slang-devel glibc-static-devel autoconf automake libtool gcc rpm-build wget gcc-c++ sudo docbook-utils-pdf ImageMagick man patch mondo mkisofs cdrecord ntp-client perl-DateManip";
100    }
101} elsif ( $dfam eq "du" ) {
102    if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
103        system "apt-get update; apt-get -y install autoconf automake libtool g++ wget patch mondo groff imagemagick docbook-utils docbook2x docbook-to-man ssh dpkg-dev sudo debian-builder dh-make fakeroot libnewt-dev ntpdate libncurses5-dev libdate-manip-perl";
104    } elsif (( $dver eq "7.10" ) && ($ddir eq "ubuntu")) {
105        system "apt-get update; apt-get -y install autoconf automake libtool g++ wget patch groff imagemagick docbook-utils docbook2x docbook-to-man openssh-server dpkg-dev sudo debian-builder dh-make fakeroot libnewt-dev ntpdate libncurses5-dev libdate-manip-perl wodim genisoimage afio buffer";
106    } else  {
107        system "apt-get update; apt-get -y install autoconf automake libtool g++ wget patch mondo groff imagemagick docbook-utils docbook2x docbook-to-man openssh-server dpkg-dev sudo debian-builder dh-make fakeroot libnewt-dev ntpdate libncurses5-dev libdate-manip-perl";
108    }
109} elsif ( $dfam eq "gen" ) {
110        #system "emerge -u system ; emerge neon newt slang autoconf automake subversion libtool gcc wget vim man groff lynx grub afio buffer sudo ntp DateManip";
111} else {
112    print "No pkg to install\n";
113}
114
115# Adapt sudoers
116$file="/etc/sudoers";
117open(PBFILE,$file) || die "Unable to open $file";
118open(PBOUT,"> $file.new") || die "Unable to open $file.new";
119while (<PBFILE>) {
120    next if (/^pb   /);
121    s/Defaults[ \t]+requiretty//;
122    print PBOUT $_;
123}
124close(PBFILE);
125print PBOUT "pb   ALL=(ALL) NOPASSWD:ALL\n";
126close(PBOUT);
127rename("$file.new",$file);
128chmod 0440,$file;
129
130# Suse wants sudoers as 640
131if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
132    chmod 0640,$file;
133}
134
135# Sync date
136system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
137
138system "rm -rf project-builder-* ; wget --passive-ftp 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 ..";
139
Note: See TracBrowser for help on using the repository browser.