commit ebd84de51af4000a8c9e3c5d7a33012e5ed5ceca Author: Walter Dal Mut Date: Sat Jun 2 14:10:08 2012 +0200 Added base diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf36c9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.project +.buildpath +.settings diff --git a/README.md b/README.md new file mode 100644 index 0000000..08b0c58 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Debian packager 4 PHP + +A simple debian packager for PHP applications + +```php +setPackage("my-package-name") + ->setVersion("0.1.1"); + ->setDepends(array("php5", "php5-cli", "php5-xsl")); + ->setInstalledSize(4096) + ->setMaintainer("Walter Dal Mut", "walter.dalmut@corley.it"); + ->setProvides("Corley S.r.l."); + ->setDescription("My software description"); +; + +$packager = new \wdm\debian\Packager(); + +$packager->setOutputPath("/path/to/out"); +$packager->setControl($control); + +$packager->mount("/path/to/source-conf", "/etc/my-sw"); +$packager->mount("/path/to/exec", "/usr/bin/my-sw"); +$packager->mount("/path/to/docs", "/usr/share/docs"); + +//Creates folders using mount points +$packager->run(); + +//Creates the Debian package +$packager->build(); +``` \ No newline at end of file diff --git a/src/example.php b/src/example.php new file mode 100644 index 0000000..4dc8cc1 --- /dev/null +++ b/src/example.php @@ -0,0 +1,27 @@ +setPackageName("my-package-name") + ->setVersion("0.1.1") + ->setDepends(array("php5", "php5-cli", "php5-xsl")) + ->setInstalledSize(4096) + ->setMaintainer("Walter Dal Mut", "walter.dalmut@corley.it") + ->setProvides("Corley S.r.l.") + ->setDescription("My software description"); +; + +$packager = new \wdm\debian\Packager(); + +$packager->setOutputPath(__DIR__ . "/out"); +$packager->setControl($control); + +$packager->mount(__DIR__ . "/../../diff", "/my-differ"); + +//Creates folders using mount points +$packager->run(); + +//Creates the Debian package +$packager->build(); \ No newline at end of file diff --git a/src/wdm/debian/Autoloader.php b/src/wdm/debian/Autoloader.php new file mode 100644 index 0000000..8b0d270 --- /dev/null +++ b/src/wdm/debian/Autoloader.php @@ -0,0 +1,4 @@ +_control = $control; + return $this; + } + + 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 != '..'); { + echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL; + exit(); + } + } + } + + foreach ($this->_mountPoints as $path => $dest) { + $this->_pathToPath($path, $this->_outputPath . DIRECTORY_SEPARATOR . $dest); + } + + mkdir($this->_outputPath . "/DEBIAN", 0777); + file_put_contents($this->_outputPath . "/DEBIAN/control", (string)$this->_control); + + return $this; + } + + private function _pathToPath($path, $dest) + { + if (is_dir($path)) { + $iterator = new \DirectoryIterator($path); + foreach ($iterator as $element) { + if ($element != '.' && $element != '..') { + $fullPath = $path . DIRECTORY_SEPARATOR . $element; + if (is_dir($fullPath)) { + $this->_pathToPath($fullPath, $dest . DIRECTORY_SEPARATOR . $element); + } else { + $this->_copy($fullPath, $dest . DIRECTORY_SEPARATOR . $element); + } + } + } + } else if (is_file($path)) { + $this->_copy($path, $dest); + } + } + + private function _copy($source, $dest) + { + $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 diff --git a/src/wdm/debian/control/StandardFile.php b/src/wdm/debian/control/StandardFile.php new file mode 100644 index 0000000..2fa9b60 --- /dev/null +++ b/src/wdm/debian/control/StandardFile.php @@ -0,0 +1,190 @@ + '', + 'Version' => '0.1', + "Section" => "web", + "Priority" => "optional", + "Architecture" => "all", + "Essential" => "no", + "Depends" => "", + "Pre-Depends" => "", + "Recommends" => "", + "Suggests" => "", + "Installed-Size" => 1024, + "Maintainer" => "name [email]", + "Conflicts" => "", + "Replaces" => "", + "Provides" => "your-company", + "Description" => "Your description" + ); + + public function setPackageName($name) + { + return $this->_setProperty("Package", $name); + } + + public function setVersion($version) + { + return $this->_setProperty("Version", $version); + } + + public function setSection($section) + { + return $this->_setProperty("Section", $section); + } + + public function setPriority($priority) + { + return $this->_setProperty($this["Priority"], $priority); + } + + public function setArchitectur($arch) + { + return $this->_setProperty("Architecture", $arch); + } + + public function setEssential($essential) + { + return $this->_setProperty("Essential", $essential); + } + + public function setDepends($depends) + { + return $this->_setProperty("Depends", $this->_transformList($depends)); + } + + public function setPreDepends($depends) + { + return $this->_setProperty("Pre-Depends", $this->_transformList($depends)); + } + + public function setRecommends($depends) + { + return $this->_setProperty("Reccommends", $depends); + } + + public function setSuggests($depends) + { + return $this->_setProperty("Suggests", $this->_transformList($depends)); + } + + public function setInstalledSize($size) + { + return $this->_setProperty("Installed-Size", $size); + } + + public function setMaintainer($maintainer) + { + return $this->_setProperty("Maintainer", $maintainer); + } + + public function setConflicts($conflicts) + { + return $this->_setProperty("Conflicts", $this->_transformList($conflicts)); + } + + public function setReplaces($replaces) + { + return $this->_setProperty("Conflicts", $this->_transformList($replaces)); + } + + public function setProvides($provides) + { + return $this->_setProperty("Provides", $provides); + } + + public function setDescription($description) + { + return $this->_setProperty("Description", $description); + } + + private function _transformList($depends) + { + if (is_array($depends)) { + $depends = implode(", ", $depends); + } else { + $depends = $depends; + } + + return $depends; + } + + private function _setProperty($key, $value) + { + $this[$key] = $value; + return $this; + } + + public function offsetExists ($offset) { + return array_key_exists($offset, $this->_keys); + } + + public function offsetGet ($offset) { + if ($this->offsetExists($offset)) { + return $this->_keys[$offset]; + } else { + return null; + } + } + + public function offsetSet ($offset, $value) { + if (!$this->offsetExists($offset)) { + throw new \Exception("Invalid property for this control file."); + } + $this->_keys[$offset] = $value; + } + + public function offsetUnset ($offset) { + if ($this->offsetExists($offset)) { + unset($this->_keys[$offset]); + } + } + + /** + * Control file string representation. + * + * @return string The control file + */ + public function __toString() + { + $control = ''; + foreach ($this->_keys as $key => $value) { + $control .= "{$key}: {$value}" . PHP_EOL; + } + + return $control; + } +} \ No newline at end of file