source: devel/dploy-pxe/bin/dploy-pxe-post @ 69

Revision 69, 3.0 KB checked in by bruno, 4 years ago (diff)

change_parms is now returning a string so that it works in the s/e and does the right job for string substitution hopefully

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2#
3# dploy-pxe post install script
4#
5# Copyright B. Cornec & G. Renaud HP 2008
6# Provided under the GPL v2
7
8use strict;
9use File::Basename;
10use File::Copy;
11use ProjectBuilder::Base;
12use ProjectBuilder::Conf;
13
14=pod
15
16=head1 NAME
17
18dploy-pxe-post - post install script for dploy-pxe
19
20=head1 DESCRIPTION
21
22This script has to be run to finish dploy-pxe istallation
23
24=head1 SYNOPSIS
25
26dploy-pxe-post
27
28=back
29
30No option nor parameter upported
31
32=head1 WEB SITES
33
34The main Web site of the project is available at L<http://www.dploy.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.dploy.org/>.
35
36=head1 USER MAILING LIST
37
38None exists for the moment.
39
40=head1 AUTHORS
41
42The dploy.org team L<http://trac.dploy.org/>.
43
44=head1 COPYRIGHT
45
46dploy.org is distributed under the GPL v2.0 license
47described in the file C<COPYING> included with the distribution.
48
49=cut
50
51=over 4
52
53change_parms is an internal function which changes the base default dir of the
54tftp server with the one we want for dploy.
55
56=cut
57
58sub change_parms() {
59       
60        my ($s1, $s2, $params) = @_;
61        my $ret = "\n";
62
63        $ret .= "### Modified by dploy.org\n";
64        $ret .= "### original: server_args$s1=$s2$params\n";
65        my $dir = dirname($pathpxe->{$proj});
66        my $nparams = $params;
67        $nparams =~ s/-s\s+\S+/-s $dir/;
68        $ret .= "server_args$s1=$s2$nparams\n";
69        print "Changing tftpd args from $parms to $nparams\n";
70        return($ret);
71}
72
73
74my $proj = "PBPROJ";
75
76pb_conf_init($proj);
77pb_temp_init();
78pb_syntax_init("dploy-pxe-post\n");
79
80# Give us the rights to modify the DHCP conf file
81
82# Get dploy account info
83my $user = $proj;
84my ($login,$pass,$uid,$gid,$gecos,$dir,$shell) = getpwnam($user) or die "$user not in passwd file";
85
86# Include dploy in sudoers
87my $found = 0;
88open(SUDO,"/etc/sudoers") || die "Unable to read /etc/sudoers";
89while (<SUDO>) {
90        $found = 1 if ((/^$proj/) && (/\/bin\/umount/));
91}
92close(SUDO);
93
94if ($found == 0) {
95        open(SUDO,">> /etc/sudoers") || die "Unable to write /etc/sudoers";
96    print SUDO "$proj ALL=NOPASSWD: /bin/mount -o loop ?*\n";
97    print SUDO "$proj ALL=NOPASSWD: /bin/umount ?*\n";
98        close(SUDO);
99}
100
101pb_conf_add("PBCONF/dploy.conf");
102my ($pathpxe) = pb_conf_get("pathpxe");
103
104# Create dir structure
105foreach my $d ("$pathpxe->{$proj}", "$pathpxe->{$proj}/../linuxcoe", "$pathpxe->{$proj}/../mondorescue") {
106        pb_mkdir_p($d) if ( not -d $d);
107        chown $uid,$gid,$d;
108        chmod 0755,$d;
109}
110
111# Adapt tftp xinetd conf file
112my $xin = "";
113$xin = "/etc/xinetd.d/tftp" if (! -f $xin);
114$xin = "/etc/xinetd.d/tftpd" if (! -f $xin);
115
116open(XIN,$xin)  || die "Unable to read $xin: $!";
117open(OUT,"> $ENV{'PBTMP'}/tftpd")  || die "Unable to write $ENV{'PBTMP'}/tftpd: $!";
118while (<XIN>) {
119        s/disable(\s*)=(\s*)yes/disable$1=$2no/;
120        s/server_args(\s*)=(\s*)(.*)/change_parms($1,$2,$3)/e;
121        print OUT;
122}
123close(XIN);
124close(OUT);
125move("$ENV{'PBTMP'}/tftpd",$xin);
126
127# Restart xinetd
128pb_system("/etc/init.d/xinetd restart","Restarting xinetd");
129
130# Restart Apache
131pb_system("/etc/init.d/apache restart","Restarting Apache");
132
133# PBHTTPDCONFDIR
134# Prepare Apache conf for kickstart support for LinuxCOE
Note: See TracBrowser for help on using the repository browser.