Added base
This commit is contained in:
commit
ebd84de51a
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.project
|
||||
.buildpath
|
||||
.settings
|
33
README.md
Normal file
33
README.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Debian packager 4 PHP
|
||||
|
||||
A simple debian packager for PHP applications
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$control = new \wdm\debian\control\StandardFile();
|
||||
$control
|
||||
->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();
|
||||
```
|
27
src/example.php
Normal file
27
src/example.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
require_once 'wdm/debian/Autoloader.php';
|
||||
|
||||
$control = new \wdm\debian\control\StandardFile();
|
||||
$control
|
||||
->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();
|
4
src/wdm/debian/Autoloader.php
Normal file
4
src/wdm/debian/Autoloader.php
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/IPackager.php';
|
||||
require_once __DIR__ . '/Packager.php';
|
||||
require_once __DIR__ . '/control/StandardFile.php';
|
57
src/wdm/debian/IPackager.php
Normal file
57
src/wdm/debian/IPackager.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
namespace wdm\debian;
|
||||
|
||||
use wdm\debian\control\StandardFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* Packager interface
|
||||
*
|
||||
* @author Walter Dal Mut
|
||||
* @package
|
||||
* @license MIT
|
||||
*
|
||||
* Copyright (C) 2012 Corley S.R.L.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
interface IPackager
|
||||
{
|
||||
public function setControl(StandardFile $control);
|
||||
public function mount($sourcePath, $destinationPath);
|
||||
|
||||
/**
|
||||
* Output path
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
public function setOutputPath($path);
|
||||
|
||||
/**
|
||||
* Create folder structures
|
||||
*
|
||||
* @return IPackager
|
||||
*/
|
||||
public function run();
|
||||
|
||||
/**
|
||||
* Build the package
|
||||
*/
|
||||
public function build($debPackageName = false);
|
||||
}
|
119
src/wdm/debian/Packager.php
Normal file
119
src/wdm/debian/Packager.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
namespace wdm\debian;
|
||||
|
||||
use wdm\debian\control\StandardFile;
|
||||
|
||||
/**
|
||||
*
|
||||
* Main packager
|
||||
*
|
||||
* @author Walter Dal Mut
|
||||
* @package
|
||||
* @license MIT
|
||||
*
|
||||
* Copyright (C) 2012 Corley S.R.L.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
class Packager
|
||||
implements IPackager
|
||||
{
|
||||
private $_control;
|
||||
private $_mountPoints = array();
|
||||
private $_outputPath;
|
||||
|
||||
public function setControl(StandardFile $control)
|
||||
{
|
||||
$this->_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;
|
||||
}
|
||||
}
|
190
src/wdm/debian/control/StandardFile.php
Normal file
190
src/wdm/debian/control/StandardFile.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
namespace wdm\debian\control;
|
||||
|
||||
/**
|
||||
*
|
||||
* Representation of Standard control file for Debian packages
|
||||
*
|
||||
* @author Walter Dal Mut
|
||||
* @package
|
||||
* @license MIT
|
||||
*
|
||||
* Copyright (C) 2012 Corley S.R.L.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
class StandardFile
|
||||
implements \ArrayAccess
|
||||
{
|
||||
private $_keys = array(
|
||||
'Package' => '',
|
||||
'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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue