<?php
/*
Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@version $Id: Setup.php,v 1.7 2004/04/06 14:45:16 ordnas Exp $
@copyright Copyright © 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
@license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
require_once 'Utils.php';
if(ZI_INIT_MODE != 'RE'){
require_once 'System.php';
}
class ZZOSS_InstallerSetup {
var $init_dir;
var $init_file;
var $data_dir;
/**
* Holds data dir parameter of all installer installations.
*/
var $inits = array();
var $error = '';
function ZZOSS_InstallerSetup($root)
{
// Set default data dir.
$this->init_dir = $root.DIRECTORY_SEPARATOR;
// Define the init file path. This file holds the info, where the data dir is located
// for every single installer installation.
$this->init_file = $this->init_dir.'.init';
// Retrieve init array.
if(file_exists($this->init_file)){
$this->inits = ZZOSS_InstallerUtils::unserializeFromFile($this->init_file);
}
}
function hasRoot()
{
return isset($this->inits['_root']);
}
function isInitiated()
{
$this->is_initiated = (isset($this->inits[getcwd()]) && is_writeable($this->inits[getcwd()]));
//var_dump($this->is_initiated);
return $this->is_initiated;
}
function isDataDir($dir)
{
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
$dir = $dir.DIRECTORY_SEPARATOR;
if(!strlen($dir)){
$this->error = 'No directory provided.';
return false;
}
// If the data dir is not the same as the directory where the init
// file resides, we do some more checks.
if($dir != $this->init_dir){
if(!is_dir($dir)){
$this->error = 'Directory does not exist: '.$dir;
return false;
}
if(!is_writeable($dir)){
$this->error = 'Cannot write to directory: '.$dir;
return false;
}
}
$this->init_dir = $dir;
return true;
}
function init()
{
if(!$id = count($this->inits)){
// Should not be the case, that it already exists,
// but we want to be sure...
$id = 1;
/*
if(is_dir($this->init_dir)){
System::rm(array('-rf',$this->init_dir));
}
*/
if(!System::mkdir(array('-p',$this->init_dir))){
$this->error = 'Cannot create directory: '.$this->init_dir;
return false;
}
$this->inits['_root'] = $this->init_dir;
// Write the .htaccess to the root data dir.
$fp = @fopen($this->init_dir.'.htaccess','w');
fputs($fp, 'deny from all');
fclose($fp);
}
if(!strlen($this->data_dir)){
$this->data_dir = $this->init_dir.$id.DIRECTORY_SEPARATOR;
}
if(!@System::mkdir(array('-p',$this->data_dir))){
$this->error = 'Cannot create directory: '.$this->data_dir;
return false;
}
$this->inits[getcwd()] = $this->data_dir;
// Write the init file.
ZZOSS_InstallerUtils::serializeToFile($this->init_file, $this->inits);
return true;
}
function rmDataDir()
{
if(is_dir($this->data_dir)){
System::rm(array('-rf', $this->data_dir));
}
unset($this->inits[getcwd()]);
ZZOSS_InstallerUtils::serializeToFile($this->init_file, $this->inits);
}
function resume()
{
$this->init();
}
function initData()
{
// Clean previous installations
if(is_dir($this->data_dir.'installer')){
System::rm(array('-rf', $this->data_dir.'installer'));
}
if(is_dir($this->data_dir.'distributions')){
System::rm(array('-rf', $this->data_dir.'distributions'));
}
if(is_dir($this->data_dir.'dev')){
System::rm(array('-rf', $this->data_dir.'dev'));
}
if(!mkdir($this->data_dir.'installer')){
$this->error = 'Cannot create directory: '.$this->data_dir.'installer';
return false;
}
@mkdir($this->data_dir.'distributions');
@mkdir($this->data_dir.'dev');
@mkdir($this->data_dir.'dev'.DIRECTORY_SEPARATOR.'distributions');
@mkdir($this->data_dir.'dev'.DIRECTORY_SEPARATOR.'installer');
return true;
}
function getDataDir()
{
return $this->init_dir;
}
function getInitFile()
{
return $this->init_file;
}
function getInstallerDataDir()
{
if(!strlen($this->data_dir)){
$this->inits = ZZOSS_InstallerUtils::unserializeFromFile($this->init_file);
if(isset($this->inits[getcwd()])){
$this->data_dir = $this->inits[getcwd()];
}
}
return $this->data_dir;
}
function getError()
{
return $this->error;
}
}
?>