From 659ee4d90b9a7ba8ae66d29ee780483647d7e61c Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Mon, 18 Nov 2013 08:03:46 +0100 Subject: [PATCH] [BUGFIX] missing out folder creation --- .gitignore | 4 ++ composer.json | 6 +- src/wdm/debian/Packager.php | 106 ++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index b036e5c..67cac47 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ .buildpath .settings +vendor +*.phar +*.deb + src/*.tgz diff --git a/composer.json b/composer.json index 672f53f..bc11f4b 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,9 @@ "php": ">=5.3.3" }, "autoload": { - "psr-0": ["src/"] + "psr-0": { + "wdm": "src/" + } }, "repositories": [ { @@ -29,4 +31,4 @@ "url": "https://github.com/wdalmut/php-deb-packager" } ] -} \ No newline at end of file +} diff --git a/src/wdm/debian/Packager.php b/src/wdm/debian/Packager.php index 8a5024f..3299e22 100644 --- a/src/wdm/debian/Packager.php +++ b/src/wdm/debian/Packager.php @@ -1,14 +1,14 @@ -_control = $control; return $this; } - + /** * Pre install script - * + * * @param string $path The absolute path of your pre-install script */ public function setPreInstallScript($path) { $this->_preInst = $path; } - + /** * Post install script - * + * * @param string $path The absolute path of your post-install script */ public function setPostInstallScript($path) { $this->_postInst = $path; } - + /** * Pre remove script - * + * * @param string $path The absolute path of your pre-remove script */ public function setPreRemoveScript($path) { $this->_preRM = $path; } - + /** * Post remove script - * + * * @param string $path The absolute path of your post-remove script */ public function setPostRemoveScript($path) { $this->_postRM = $path; } - + public function mount($sourcePath, $destinationPath) { $this->_mountPoints[$sourcePath] = $destinationPath; return $this; } - + public function setOutputPath($path) { $this->_outputPath = $path; return $this; } - + public function run() { if (file_exists($this->_outputPath)) { $iterator = new \DirectoryIterator($this->_outputPath); foreach ($iterator as $path) { - if ($path != '.' || $path != '..'); { + if ($path != '.' || $path != '..') { echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL; exit(); } } } - + + mkdir($this->_outputPath, 0777); + foreach ($this->_mountPoints as $path => $dest) { $this->_pathToPath($path, $this->_outputPath . DIRECTORY_SEPARATOR . $dest); } - - mkdir($this->_outputPath . "/DEBIAN", 0777); - + + mkdir($this->_outputPath . "/DEBIAN", 0777); + file_put_contents($this->_outputPath . "/DEBIAN/control", (string)$this->_control); - + if ($this->_preInst) { $dest = $this->_outputPath . "/DEBIAN/preinst"; $this->_copy($this->_preInst, $dest); chmod($dest, 0755); } - + if ($this->_postInst) { - $dest = $this->_outputPath . "/DEBIAN/postinst"; - $this->_copy($this->_postInst, $dest); + $dest = $this->_outputPath . "/DEBIAN/postinst"; + $this->_copy($this->_postInst, $dest); chmod($dest, 0755); } - + if ($this->_preRM) { - $dest = $this->_outputPath . "/DEBIAN/prerm"; - $this->_copy($this->_preRM, $dest); + $dest = $this->_outputPath . "/DEBIAN/prerm"; + $this->_copy($this->_preRM, $dest); chmod($dest, 0755); } - + if ($this->_postRM) { - $dest = $this->_outputPath . "/DEBIAN/postrm"; - $this->_copy($this->_postRM, $dest); + $dest = $this->_outputPath . "/DEBIAN/postrm"; + $this->_copy($this->_postRM, $dest); chmod($dest, 0755); } - + return $this; } - - private function _pathToPath($path, $dest) + + private function _pathToPath($path, $dest) { - if (is_dir($path)) { + if (is_dir($path)) { $iterator = new \DirectoryIterator($path); foreach ($iterator as $element) { if ($element != '.' && $element != '..') { @@ -169,29 +171,29 @@ class Packager $this->_copy($fullPath, $dest . DIRECTORY_SEPARATOR . $element); } } - } - } else if (is_file($path)) { - $this->_copy($path, $dest); + } + } else if (is_file($path)) { + $this->_copy($path, $dest); } } - - private function _copy($source, $dest) + + private function _copy($source, $dest) { - $destFolder = dirname($dest); - if (!file_exists($destFolder)) { - mkdir($destFolder, 0777, true); - } + $destFolder = dirname($dest); + if (!file_exists($destFolder)) { + mkdir($destFolder, 0777, true); + } copy($source, $dest); } - + public function build($debPackageName = false) { if (!$debPackageName) { $debPackageName = basename($this->_outputPath . ".deb"); } - + $command = "dpkg -b {$this->_outputPath} {$debPackageName}" . PHP_EOL; - + echo $command; } -} \ No newline at end of file +}