| 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 | |
|---|
| 8 | use strict; |
|---|
| 9 | use File::Basename; |
|---|
| 10 | use File::Copy; |
|---|
| 11 | use ProjectBuilder::Base; |
|---|
| 12 | use ProjectBuilder::Conf; |
|---|
| 13 | |
|---|
| 14 | =pod |
|---|
| 15 | |
|---|
| 16 | =head1 NAME |
|---|
| 17 | |
|---|
| 18 | dploy-pxe-post - post install script for dploy-pxe |
|---|
| 19 | |
|---|
| 20 | =head1 DESCRIPTION |
|---|
| 21 | |
|---|
| 22 | This script has to be run to finish dploy-pxe istallation |
|---|
| 23 | |
|---|
| 24 | =head1 SYNOPSIS |
|---|
| 25 | |
|---|
| 26 | dploy-pxe-post |
|---|
| 27 | |
|---|
| 28 | =back |
|---|
| 29 | |
|---|
| 30 | No option nor parameter upported |
|---|
| 31 | |
|---|
| 32 | =head1 WEB SITES |
|---|
| 33 | |
|---|
| 34 | The 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 | |
|---|
| 38 | None exists for the moment. |
|---|
| 39 | |
|---|
| 40 | =head1 AUTHORS |
|---|
| 41 | |
|---|
| 42 | The dploy.org team L<http://trac.dploy.org/>. |
|---|
| 43 | |
|---|
| 44 | =head1 COPYRIGHT |
|---|
| 45 | |
|---|
| 46 | dploy.org is distributed under the GPL v2.0 license |
|---|
| 47 | described in the file C<COPYING> included with the distribution. |
|---|
| 48 | |
|---|
| 49 | =cut |
|---|
| 50 | |
|---|
| 51 | =over 4 |
|---|
| 52 | |
|---|
| 53 | change_parms is an internal function which changes the base default dir of the |
|---|
| 54 | tftp server with the one we want for dploy. |
|---|
| 55 | |
|---|
| 56 | =cut |
|---|
| 57 | |
|---|
| 58 | sub 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 | |
|---|
| 74 | my $proj = "PBPROJ"; |
|---|
| 75 | |
|---|
| 76 | pb_conf_init($proj); |
|---|
| 77 | pb_temp_init(); |
|---|
| 78 | pb_syntax_init("dploy-pxe-post\n"); |
|---|
| 79 | |
|---|
| 80 | # Give us the rights to modify the DHCP conf file |
|---|
| 81 | |
|---|
| 82 | # Get dploy account info |
|---|
| 83 | my $user = $proj; |
|---|
| 84 | my ($login,$pass,$uid,$gid,$gecos,$dir,$shell) = getpwnam($user) or die "$user not in passwd file"; |
|---|
| 85 | |
|---|
| 86 | # Include dploy in sudoers |
|---|
| 87 | my $found = 0; |
|---|
| 88 | open(SUDO,"/etc/sudoers") || die "Unable to read /etc/sudoers"; |
|---|
| 89 | while (<SUDO>) { |
|---|
| 90 | $found = 1 if ((/^$proj/) && (/\/bin\/umount/)); |
|---|
| 91 | } |
|---|
| 92 | close(SUDO); |
|---|
| 93 | |
|---|
| 94 | if ($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 | |
|---|
| 101 | pb_conf_add("PBCONF/dploy.conf"); |
|---|
| 102 | my ($pathpxe) = pb_conf_get("pathpxe"); |
|---|
| 103 | |
|---|
| 104 | # Create dir structure |
|---|
| 105 | foreach 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 |
|---|
| 112 | my $xin = ""; |
|---|
| 113 | $xin = "/etc/xinetd.d/tftp" if (! -f $xin); |
|---|
| 114 | $xin = "/etc/xinetd.d/tftpd" if (! -f $xin); |
|---|
| 115 | |
|---|
| 116 | open(XIN,$xin) || die "Unable to read $xin: $!"; |
|---|
| 117 | open(OUT,"> $ENV{'PBTMP'}/tftpd") || die "Unable to write $ENV{'PBTMP'}/tftpd: $!"; |
|---|
| 118 | while (<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 | } |
|---|
| 123 | close(XIN); |
|---|
| 124 | close(OUT); |
|---|
| 125 | move("$ENV{'PBTMP'}/tftpd",$xin); |
|---|
| 126 | |
|---|
| 127 | # Restart xinetd |
|---|
| 128 | pb_system("/etc/init.d/xinetd restart","Restarting xinetd"); |
|---|
| 129 | |
|---|
| 130 | # Restart Apache |
|---|
| 131 | pb_system("/etc/init.d/apache restart","Restarting Apache"); |
|---|
| 132 | |
|---|
| 133 | # PBHTTPDCONFDIR |
|---|
| 134 | # Prepare Apache conf for kickstart support for LinuxCOE |
|---|