diff --git a/plugins/dynamix.docker.manager/include/DockerClient.php b/plugins/dynamix.docker.manager/include/DockerClient.php index 4008da194..d752aa869 100644 --- a/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/plugins/dynamix.docker.manager/include/DockerClient.php @@ -33,28 +33,8 @@ if (!isset($eth0) && is_file("/usr/local/emhttp/state/network.ini")) { extract(parse_ini_file('/usr/local/emhttp/state/network.ini',true)); } -$docker_cfg_defaults = [ - "DOCKER_ENABLED" => "no", - "DOCKER_OPTS" => "--storage-driver=btrfs", - "DOCKER_IMAGE_SIZE" => "20", - "DOCKER_IMAGE_FILE" => "/mnt/user/system/docker/docker.img", - "DOCKER_APP_CONFIG_PATH" => "/mnt/user/appdata/", - "DOCKER_APP_UNRAID_PATH" => "" -]; -$dockercfg = $docker_cfg_defaults; - -// Docker configuration file - create if needed -$docker_cfgfile = "/boot/config/docker.cfg"; -if (!file_exists($docker_cfgfile)) { - $tmp = ''; - foreach ($docker_cfg_defaults as $key => $value) $tmp .= "$key=\"$value\"\n"; - file_put_contents($docker_cfgfile, $tmp); -} else { - $docker_cfg_existing = parse_ini_file($docker_cfgfile); - if (!empty($docker_cfg_existing)) { - $dockercfg = array_merge($docker_cfg_defaults, $docker_cfg_existing); - } -} +// Docker configuration file - guaranteed to exist +$dockercfg = parse_ini_file("/boot/config/docker.cfg"); ###################################### ## DOCKERTEMPLATES CLASS ## diff --git a/plugins/dynamix.docker.manager/scripts/dockerconfig.php b/plugins/dynamix.docker.manager/scripts/dockerconfig.php new file mode 100755 index 000000000..d90c537d8 --- /dev/null +++ b/plugins/dynamix.docker.manager/scripts/dockerconfig.php @@ -0,0 +1,37 @@ +#!/usr/bin/php + + "no", + "DOCKER_IMAGE_FILE" => "/mnt/user/system/docker/docker.img", + "DOCKER_IMAGE_SIZE" => "20", + "DOCKER_APP_CONFIG_PATH" => "/mnt/user/appdata/", + "DOCKER_APP_UNRAID_PATH" => "/mnt/user/" +]; + +$cfg_new = $cfg_defaults; +if (file_exists($cfgfile)) { + $cfg_old = parse_ini_file($cfgfile); + if (!empty($cfg_old)) { + $cfg_new = array_merge($cfg_defaults, $cfg_old); + if (empty(array_diff($cfg_new, $cfg_old))) + unset($cfg_new); + } +} +if ($cfg_new) { + foreach ($cfg_new as $key => $value) $tmp .= "$key=\"$value\"\n"; + file_put_contents($cfgfile, $tmp); +} +?> diff --git a/plugins/dynamix.vm.manager/classes/libvirt_helpers.php b/plugins/dynamix.vm.manager/classes/libvirt_helpers.php index a7f4ea416..9e3c59577 100644 --- a/plugins/dynamix.vm.manager/classes/libvirt_helpers.php +++ b/plugins/dynamix.vm.manager/classes/libvirt_helpers.php @@ -428,34 +428,11 @@ ] ]; - $domain_cfg_defaults = [ - "SERVICE" => "disable", - "DEBUG" => "no", - "DOMAINDIR" => "/mnt/user/domains/", - "MEDIADIR" => "/mnt/user/isos/", - "VIRTIOISO" => "", - "BRNAME" => "", - "VMSTORAGEMODE" => "auto", - "IMAGE_FILE" => "/mnt/user/system/libvirt/libvirt.img", - "IMAGE_SIZE" => "1" - ]; - $domain_cfg = $domain_cfg_defaults; - - // Create domain config if needed + // Read configuration file (guaranteed to exist) $domain_cfgfile = "/boot/config/domain.cfg"; - if (!file_exists($domain_cfgfile)) { - $tmp = ''; - foreach ($domain_cfg_defaults as $key => $value) $tmp .= "$key=\"$value\"\n"; - file_put_contents($domain_cfgfile, $tmp); - } else { - // This will clean any ^M characters (\r) caused by windows from the config file - shell_exec("sed -i 's!\r!!g' '$domain_cfgfile'"); - - $domain_cfg_existing = parse_ini_file($domain_cfgfile); - if (!empty($domain_cfg_existing)) { - $domain_cfg = array_merge($domain_cfg_defaults, $domain_cfg_existing); - } - } + // This will clean any ^M characters (\r) caused by windows from the config file + shell_exec("sed -i 's!\r!!g' '$domain_cfgfile'"); + $domain_cfg = parse_ini_file($domain_cfgfile); if ($domain_cfg['DEBUG'] != "yes") { error_reporting(0); @@ -1054,4 +1031,4 @@ ]; } -?> \ No newline at end of file +?> diff --git a/plugins/dynamix.vm.manager/scripts/libvirtconfig.php b/plugins/dynamix.vm.manager/scripts/libvirtconfig.php new file mode 100755 index 000000000..9c070ea14 --- /dev/null +++ b/plugins/dynamix.vm.manager/scripts/libvirtconfig.php @@ -0,0 +1,41 @@ +#!/usr/bin/php + + "disable", + "IMAGE_FILE" => "/mnt/user/system/libvirt/libvirt.img", + "IMAGE_SIZE" => "1", + "DEBUG" => "no", + "DOMAINDIR" => "/mnt/user/domains/", + "MEDIADIR" => "/mnt/user/isos/", + "VIRTIOISO" => "", + "BRNAME" => "br0", + "VMSTORAGEMODE" => "auto" +]; + +$cfg_new = $cfg_defaults; +if (file_exists($cfgfile)) { + $cfg_old = parse_ini_file($cfgfile); + if (!empty($cfg_old)) { + $cfg_new = array_merge($cfg_defaults, $cfg_old); + if (empty(array_diff($cfg_new, $cfg_old))) + unset($cfg_new); + } +} +if ($cfg_new) { + foreach ($cfg_new as $key => $value) $tmp .= "$key=\"$value\"\n"; + file_put_contents($cfgfile, $tmp); +} +?> diff --git a/plugins/dynamix/dynamix.plg b/plugins/dynamix/dynamix.plg index 5c7401c20..bb2178d4b 100644 --- a/plugins/dynamix/dynamix.plg +++ b/plugins/dynamix/dynamix.plg @@ -3,8 +3,8 @@ - - + + ]>