Skip to content

Commit

Permalink
Fixed set internal param for Fedora 16 (#764)
Browse files Browse the repository at this point in the history
Signed-off-by: William Leonard <william.leonard@lxcenter.org>
  • Loading branch information
shazarlx committed Dec 20, 2011
1 parent 9decff9 commit 05e46d6
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 32 deletions.
28 changes: 28 additions & 0 deletions hypervm/bin/xen-dists/fedora-16.conf
@@ -0,0 +1,28 @@
# Copyright (C) 2000-2006 SWsoft. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# This configuration file is meant to be used with
# the Fedora distribution kit.
#

ADD_IP=redhat-add_ip.sh
DEL_IP=redhat-del_ip.sh
SET_HOSTNAME=redhat-set_hostname.sh
SET_DNS=set_dns.sh
SET_USERPASS=set_userpass.sh
SET_UGID_QUOTA=set_ugid_quota.sh
POST_CREATE=postcreate.sh
STARTUP_SCRIPT=systemd
97 changes: 65 additions & 32 deletions hypervm/httpdocs/lib/vps/driver/vps__xenlib.php
Expand Up @@ -1646,54 +1646,87 @@ function setInternalParam($mountpoint)
$setuserpass = $result['SET_USERPASS'];
$ipdel = $result['DEL_IP'];

$name = createTempDir("$mountpoint/tmp", "xen-scripts");
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $name);
if ($this->main->networkgateway) {
$gw = $this->main->networkgateway;
} else {
$gw = os_get_network_gateway();
}

$gwn = strtil($gw, ".") . ".0";

$basepath = strfrom($name, $mountpoint);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\nsource /$basepath/$ipdel\n");
$delipstring = "IPDELALL=yes chroot $mountpoint bash /$basepath/tmpfile.sh";
$hostname = $this->main->hostname;
if (!$hostname) { $hostname = os_get_hostname(); }

if ($this->main->networkgateway) {
$gw = $this->main->networkgateway;
} else {
$gw = os_get_network_gateway();
}
if ($result['STARTUP_SCRIPT'] != "systemd"){
$name = createTempDir("$mountpoint/tmp", "xen-scripts");
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $name);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $name);

log_shell($delipstring);
system($delipstring);
$basepath = strfrom($name, $mountpoint);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\nsource /$basepath/$ipdel\n");
$delipstring = "IPDELALL=yes chroot $mountpoint bash /$basepath/tmpfile.sh";

$gwn = strtil($gw, ".") . ".0";
putenv("VE_STATE=stopped");
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$ipadd\n");
$string = "IPDELALL=yes MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($delipstring);
log_shell(system($delipstring,$ret1).":return $ret1");

log_shell($string);
system($string);
putenv("VE_STATE=stopped");
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$ipadd\n");
$string = "IPDELALL=yes MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn chroot $mountpoint bash /$basepath/tmpfile.sh";

$hostname = $this->main->hostname;
if (!$hostname) { $hostname = os_get_hostname(); }
log_shell($string);
log_shell(system($string,$ret1).":return $ret1");

lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$sethostname\n");
$string = "HOSTNM=$hostname chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
system($string);
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$sethostname\n");
$string = "HOSTNM=$hostname chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
log_shell(system($string,$ret1).":return $ret1");

if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
$rootpass = "root:{$this->main->rootpassword}";
lfile_put_contents("$name/tmpfile.sh", "source /$basepath/functions\n source /$basepath/$setuserpass\n");
$string = "USERPW=$rootpass chroot $mountpoint bash /$basepath/tmpfile.sh";
log_shell($string);
system($string);
log_shell(system($string));
}

lxfile_rm_rec($name);
}
else if ($result['STARTUP_SCRIPT'] == "systemd"){
$script_dir = createTempDir("$mountpoint", "hypervm-runonce");
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipadd", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$sethostname", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$setuserpass", $script_dir);
lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$ipdel", $script_dir);
$basepath = strfrom($script_dir, $mountpoint);
$startupdir = "lib/systemd/system";
$startupscript = "fedora-startup.service";
$ro_a = "#!/bin/bash\n";
$ro_b = "source $basepath/functions\n";
$ro_c = "(";
$ro_d = "IPDELALL=yes source $basepath/$ipdel";
$ro_e = " & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK=$main_netmask MAIN_IP_ADDRESS=$main_ip IP_ADDR=\"$iplist\" NETWORK_GATEWAY=$gw NETWORK_GATEWAY_NET=$gwn source $basepath/$ipadd";
$ro_f = " & HOSTNM=$hostname source $basepath/$sethostname";
$ro_g = ")\n";
if (($this->main->subaction === 'rebuild') || ($this->main->dbaction === 'add') || ($this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword)) {
$rootpass = "root:{$this->main->rootpassword}";
$ro_g = " & USERPW=$rootpass source $basepath/$setuserpass)\n";
}
$ro_h = "service fedora-startup disable\nrm -f /$startupdir/$startupscript\nrm -rf $basepath";
lfile_put_contents("$script_dir/hypervm-runonce.sh", $ro_a.$ro_b.$ro_c.$ro_d.$ro_e.$ro_f.$ro_g.$ro_h);

lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/$startupscript", "$mountpoint/$startupdir");
lfile_put_contents("$mountpoint/$startupdir/$startupscript",
lfile_get_contents("$mountpoint/$startupdir/$startupscript").
"ExecStart=$basepath/hypervm-runonce.sh\n");
system("ln -s /lib/systemd/system/fedora-startup.service $mountpoint/etc/systemd/system/multi-user.target.wants/fedora-startup.service");
system("chmod 755 $script_dir/hypervm-runonce.sh");
}


lxfile_rm_rec($name);

if ($this->main->nameserver) {
$nlist = explode(" ", $this->main->nameserver);
$nstring = null;
Expand Down

0 comments on commit 05e46d6

Please sign in to comment.