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 |
|
---|
13 | use strict;
|
---|
14 | use File::Basename;
|
---|
15 |
|
---|
16 | my $file = "/tmp/pbkey";
|
---|
17 |
|
---|
18 | open(PBFILE,"> $file") || die "Unable to open $file";
|
---|
19 | print 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";
|
---|
20 | close(PBFILE);
|
---|
21 | chmod 0644,$file;
|
---|
22 |
|
---|
23 | $file="/etc/passwd";
|
---|
24 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
25 | my $found = 0;
|
---|
26 | while (<PBFILE>) {
|
---|
27 | $found = 1 if (/^pb:/);
|
---|
28 | }
|
---|
29 | close(PBFILE);
|
---|
30 |
|
---|
31 | if ( $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
|
---|
40 | mkdir ".ssh",0700;
|
---|
41 | system 'cp /tmp/pbkey .ssh/authorized_keys';
|
---|
42 | chmod 0600,".ssh/authorized_keys";
|
---|
43 |
|
---|
44 | # For pb
|
---|
45 | chdir "/home/pb";
|
---|
46 | mkdir ".ssh",0700;
|
---|
47 | system 'cp /tmp/pbkey .ssh/authorized_keys';
|
---|
48 | chmod 0600,".ssh/authorized_keys";
|
---|
49 | system 'chown -R pb:pb .ssh';
|
---|
50 |
|
---|
51 | # No passwd for pb only keys
|
---|
52 | $file="/etc/shadow";
|
---|
53 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
54 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
55 | while (<PBFILE>) {
|
---|
56 | s/^pb:\!\!:/pb:*:/;
|
---|
57 | s/^pb:\!:/pb:*:/; #SLES 9 e.g.
|
---|
58 | print PBOUT $_;
|
---|
59 | }
|
---|
60 | close(PBFILE);
|
---|
61 | close(PBOUT);
|
---|
62 | rename("$file.new",$file);
|
---|
63 | chmod 0640,$file;
|
---|
64 |
|
---|
65 | unlink "/tmp/pbkey";
|
---|
66 |
|
---|
67 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
68 | print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
|
---|
69 |
|
---|
70 | # Get and install pb
|
---|
71 | if ( $ddir eq "fedora" ) {
|
---|
72 | system "yum clean all";
|
---|
73 | system "yum update -y";
|
---|
74 | my $arch=`uname -m`;
|
---|
75 | my $opt = "";
|
---|
76 | chomp($arch);
|
---|
77 | if ($arch eq "x86_64") {
|
---|
78 | $opt="--exclude=*.i?86";
|
---|
79 | }
|
---|
80 |
|
---|
81 | #my $topbuilddir=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
|
---|
82 | #chomp($topbuilddir);
|
---|
83 |
|
---|
84 | if ( $dver <= 4 ) {
|
---|
85 | # FC4 - AppConfig unavailable
|
---|
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 perl-DateManip ntp sudo ; rm -rf AppConfig-* ; 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 ..";
|
---|
87 | } else {
|
---|
88 | # FC5/6/7
|
---|
89 | 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-AppConfig perl-DateManip";
|
---|
90 | }
|
---|
91 | } 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"))) {
|
---|
92 | # Suppose pkg are installed already
|
---|
93 | system "rpm -e lsb 2>&1 > /dev/null";
|
---|
94 | system "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 .. ; 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 .. ";
|
---|
95 | } elsif ($ddir eq "suse") {
|
---|
96 | # New OpenSuSE
|
---|
97 | 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-AppConfig 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";
|
---|
98 | } elsif ( $dfam eq "md" ) {
|
---|
99 | if (( $dver eq "2006.0" ) || ( $dver eq "10.2" )) {
|
---|
100 | # mondo not available
|
---|
101 | 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-AppConfig perl-DateManip";
|
---|
102 | } else {
|
---|
103 | 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-AppConfig perl-DateManip";
|
---|
104 | }
|
---|
105 | } elsif ( $dfam eq "du" ) {
|
---|
106 | if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
|
---|
107 | 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 libappconfig-perl";
|
---|
108 | } elsif (( $dver eq "7.10" ) && ($ddir eq "ubuntu")) {
|
---|
109 | 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 libappconfig-perl wodim genisoimage afio buffer";
|
---|
110 | } else {
|
---|
111 | 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 libappconfig-perl";
|
---|
112 | }
|
---|
113 | } elsif ( $dfam eq "gen" ) {
|
---|
114 | #system "emerge -u system ; emerge neon newt slang autoconf automake subversion libtool gcc wget vim man groff lynx grub afio buffer sudo ntp AppConfig DateManip";
|
---|
115 | } else {
|
---|
116 | print "No pkg to install\n";
|
---|
117 | }
|
---|
118 |
|
---|
119 | # Adapt sudoers
|
---|
120 | $file="/etc/sudoers";
|
---|
121 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
122 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
123 | while (<PBFILE>) {
|
---|
124 | next if (/^pb /);
|
---|
125 | s/Defaults[ \t]+requiretty//;
|
---|
126 | print PBOUT $_;
|
---|
127 | }
|
---|
128 | close(PBFILE);
|
---|
129 | print PBOUT "pb ALL=(ALL) NOPASSWD:ALL\n";
|
---|
130 | close(PBOUT);
|
---|
131 | rename("$file.new",$file);
|
---|
132 | chmod 0440,$file;
|
---|
133 |
|
---|
134 | # Suse wants sudoers as 640
|
---|
135 | if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
|
---|
136 | chmod 0640,$file;
|
---|
137 | }
|
---|
138 |
|
---|
139 | # Sync date
|
---|
140 | system "/usr/sbin/ntpdate ntp.home.musique-ancienne.org";
|
---|
141 |
|
---|
142 | # Patch AppConfig
|
---|
143 | my $module=`find /usr/*/perl5 -type f -name File.pm | grep AppConfig/File.pm`;
|
---|
144 | chomp($module);
|
---|
145 | $found = 0;
|
---|
146 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
147 | while (<PBFILE>) {
|
---|
148 | $found = 1 if (/Fix a bug if the variable is a hash/);
|
---|
149 | }
|
---|
150 | close(PBFILE);
|
---|
151 |
|
---|
152 | if ( $found == 0 ) {
|
---|
153 | chdir basename($module);
|
---|
154 | open(PBFILE,$module) || die "Unable to open $module";
|
---|
155 | my $module1 = $module."new";
|
---|
156 | open(PBOUT," > $module1") || die "Unable to open $module1";
|
---|
157 | while (<PBFILE>) {
|
---|
158 | s/^use AppConfig;/use AppConfig qw(:argcount);/;
|
---|
159 | if (/# variables prefixed '-' are reset to their default values/) {
|
---|
160 | print PBOUT << 'EOF';
|
---|
161 | # Fix a bug if the variable is a hash - 1 has been created as a key
|
---|
162 | if ($nargs eq AppConfig::ARGCOUNT_HASH) {
|
---|
163 | delete $state->{ VARIABLE }->{ $variable }{1};
|
---|
164 | }
|
---|
165 |
|
---|
166 | EOF
|
---|
167 | }
|
---|
168 | print PBOUT "$_";
|
---|
169 | }
|
---|
170 | close(PBFILE);
|
---|
171 | close(PBOUT);
|
---|
172 | rename($module1,$module);
|
---|
173 | }
|
---|
174 |
|
---|
175 | system "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 ..";
|
---|
176 |
|
---|