Compare commits
83 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22b2fcf742 | ||
|
|
fe2ad18bb3 | ||
|
|
c2fa2ffd7f | ||
|
|
eb7402f531 | ||
|
|
e5eac39aeb | ||
|
|
0a7965ca27 | ||
|
|
c1db405718 | ||
|
|
9f73b61e7e | ||
|
|
f02de6e4f0 | ||
|
|
c31de5be5f | ||
|
|
26deac007c | ||
|
|
9f0e89de59 | ||
|
|
72f6bf643d | ||
|
|
c5db10bb90 | ||
|
|
5616cfaedd | ||
|
|
4733e927cb | ||
|
|
7f65a0aa86 | ||
|
|
ecc361aad0 | ||
|
|
d04b3e44fa | ||
|
|
e5be8eac40 | ||
|
|
eafedc1c8f | ||
|
|
56493c7991 | ||
|
|
84d9e7f8d7 | ||
|
|
25e3350670 | ||
|
|
4d5ec6074e | ||
|
|
5ed71d2b1c | ||
|
|
0b11235a62 | ||
|
|
e05f29d86c | ||
|
|
9ccde2227a | ||
|
|
248c14d301 | ||
|
|
03cd660ea0 | ||
|
|
e03d099610 | ||
|
|
101c0f7cd6 | ||
|
|
0dc9ace168 | ||
|
|
14f59088aa | ||
|
|
f8cf01dd43 | ||
|
|
3fea36764b | ||
|
|
b4f5905d72 | ||
|
|
56acfbdff1 | ||
|
|
14d67be8d8 | ||
|
|
592dd77f85 | ||
|
|
df20d1654c | ||
|
|
29a2ed1d46 | ||
|
|
fc0640f9bc | ||
|
|
5251337b38 | ||
|
|
c52fb1b0ae | ||
|
|
b2fc4bef81 | ||
|
|
1b296a55ac | ||
|
|
664cff2bf0 | ||
|
|
037933215a | ||
|
|
dda9795e10 | ||
|
|
3a89e04031 | ||
|
|
3e297a6d9d | ||
|
|
8ec88807eb | ||
|
|
da685a0568 | ||
|
|
b34bc46a3e | ||
|
|
adac0738cd | ||
|
|
2f6945a64d | ||
|
|
f1849734cd | ||
|
|
70803c17a0 | ||
|
|
71be07b1fe | ||
|
|
95a7684787 | ||
|
|
0c2ba5071d | ||
|
|
f097b8cf31 | ||
|
|
529a529185 | ||
|
|
0dfd236925 | ||
|
|
dab5976eb3 | ||
|
|
6e42141c12 | ||
|
|
485118b8f0 | ||
|
|
979b114230 | ||
|
|
f05b914d41 | ||
|
|
659ee4d90b | ||
|
|
c4351d8218 | ||
|
|
d027d9e275 | ||
|
|
6a8bc31126 | ||
|
|
2881c02a6f | ||
|
|
6169031c80 | ||
|
|
382c97eee7 | ||
|
|
8a34d98a65 | ||
|
|
e705d0fe8c | ||
|
|
0b5e388aa1 | ||
|
|
2f2524f496 | ||
|
|
a72b9490cc |
14 changed files with 1560 additions and 196 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -1,3 +1,11 @@
|
|||
.project
|
||||
.buildpath
|
||||
.settings
|
||||
|
||||
vendor
|
||||
*.phar
|
||||
*.deb
|
||||
|
||||
src/*.tgz
|
||||
|
||||
tags
|
||||
|
|
|
|||
11
.travis.yml
Normal file
11
.travis.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
language: php
|
||||
php:
|
||||
- 5.6
|
||||
- 5.5
|
||||
- 5.4
|
||||
- 5.3
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
||||
script: vendor/bin/phpunit tests
|
||||
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# 0.0.13
|
||||
|
||||
## BC Breaks
|
||||
|
||||
* The packager will throws a RuntimeException if the output folder already
|
||||
exists and it is not empty.
|
||||
|
||||
# 0.0.10
|
||||
|
||||
## BC Breaks
|
||||
|
||||
## Deprecations
|
||||
|
||||
* Method `mount` will be replaced by method `addMount` in the future
|
||||
|
||||
# 0.0.4
|
||||
|
||||
## BC Breaks
|
||||
|
||||
* Build will returns the dpkg command instead print it to the user
|
||||
* Removed internal autoloader -> use composer as a default
|
||||
|
||||
73
README.md
73
README.md
|
|
@ -1,20 +1,37 @@
|
|||
# Debian packager (PHP)
|
||||
|
||||
* Develop: [](https://travis-ci.org/wdalmut/php-deb-packager)
|
||||
* Master : [](https://travis-ci.org/wdalmut/php-deb-packager)
|
||||
|
||||
A simple debian packager for PHP applications
|
||||
|
||||
Get composer:
|
||||
|
||||
```
|
||||
curl -sS http://getcomposer.org/installer | php
|
||||
```
|
||||
|
||||
Install dependencies and autoloader
|
||||
|
||||
```
|
||||
php composer.phar install
|
||||
```
|
||||
|
||||
Use it:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require_once 'wdm/debian/Autoloader.php';
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$control = new \wdm\debian\control\StandardFile();
|
||||
$control
|
||||
->setPackage("my-package-name")
|
||||
->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.")
|
||||
->setProvides("my-package-name")
|
||||
->setDescription("My software description");
|
||||
;
|
||||
|
||||
|
|
@ -30,6 +47,52 @@ $packager->mount("/path/to/docs", "/usr/share/docs");
|
|||
//Creates folders using mount points
|
||||
$packager->run();
|
||||
|
||||
//Creates the Debian package
|
||||
$packager->build();
|
||||
//Get the Debian package command
|
||||
echo $packager->build();
|
||||
```
|
||||
|
||||
**Create the Package**
|
||||
|
||||
```
|
||||
$(php pack.php)
|
||||
```
|
||||
|
||||
## Pre-Post scripts
|
||||
|
||||
Optianally you can add script for different hooks
|
||||
|
||||
* pre-install
|
||||
* Run pre install
|
||||
* post-install
|
||||
* Run post install
|
||||
* pre-remove
|
||||
* Run pre package remove
|
||||
* post-remove
|
||||
* Run post package remove
|
||||
|
||||
Adding scripts
|
||||
|
||||
```php
|
||||
$packager->setPreInstallScript(__DIR__ . '/my-pre-install-script.sh');
|
||||
$packager->setPostInstallScript(__DIR__ . '/my-post-install-script.sh');
|
||||
$packager->setPreRemoveScript(__DIR__ . '/my-pre-remove-script.sh');
|
||||
$packager->setPostRemoveScript(__DIR__ . '/my-post-remove-script.sh');
|
||||
```
|
||||
|
||||
See a script example
|
||||
|
||||
```shell
|
||||
#!/bin/sh
|
||||
#postinst script for upcloo
|
||||
|
||||
set -e
|
||||
|
||||
echo "Goodbye Cruel World"
|
||||
|
||||
exit 0
|
||||
```
|
||||
|
||||
## Use Yaml files instead the library directly
|
||||
|
||||
Just take a look to [wdalmut/php-deb-describe](https://github.com/wdalmut/php-deb-describe)
|
||||
|
||||
|
|
|
|||
1
VERSION
Normal file
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.0.13
|
||||
30
composer.json
Normal file
30
composer.json
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "wdalmut/php-deb-packager",
|
||||
"description": "A simple debian packager for PHP applications",
|
||||
"type":"library",
|
||||
"keywords":["deb","packager","ubuntu","php-deb", "debian"],
|
||||
"license":"MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name":"Walter Dal Mut",
|
||||
"email":"walter.dalmut@gmail.com",
|
||||
"homepage":"http://walterdalmut.com",
|
||||
"role":"Developer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"email":"walter.dalmut@gmail.com"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4",
|
||||
"mikey179/vfsStream": "1.4.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"wdm": ["src/", "tests/"]
|
||||
}
|
||||
}
|
||||
}
|
||||
1015
composer.lock
generated
Normal file
1015
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once 'wdm/debian/Autoloader.php';
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$control = new \wdm\debian\control\StandardFile();
|
||||
$control
|
||||
|
|
@ -9,7 +9,7 @@ $control
|
|||
->setDepends(array("php5", "php5-cli", "php5-xsl"))
|
||||
->setInstalledSize(4096)
|
||||
->setMaintainer("Walter Dal Mut", "walter.dalmut@corley.it")
|
||||
->setProvides("Corley S.r.l.")
|
||||
->setProvides("my-package-name")
|
||||
->setDescription("My software description");
|
||||
;
|
||||
|
||||
|
|
@ -23,5 +23,5 @@ $packager->mount(__DIR__ . "/../../diff", "/my-differ");
|
|||
//Creates folders using mount points
|
||||
$packager->run();
|
||||
|
||||
//Creates the Debian package
|
||||
$packager->build();
|
||||
//Get the Debian package command
|
||||
echo $packager->build();
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/IPackager.php';
|
||||
require_once __DIR__ . '/Packager.php';
|
||||
require_once __DIR__ . '/control/StandardFile.php';
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?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);
|
||||
}
|
||||
|
|
@ -1,86 +1,162 @@
|
|||
<?php
|
||||
<?php
|
||||
namespace wdm\debian;
|
||||
|
||||
use RuntimeException;
|
||||
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
|
||||
class Packager
|
||||
{
|
||||
private $_control;
|
||||
private $_mountPoints = array();
|
||||
private $_outputPath;
|
||||
|
||||
|
||||
private $_preInst;
|
||||
private $_postInst;
|
||||
private $_preRM;
|
||||
private $_postRM;
|
||||
|
||||
/**
|
||||
* Set the control file
|
||||
*
|
||||
* This file contains the base package information
|
||||
*
|
||||
* @param StandardFile $control
|
||||
* @return \wdm\debian\Packager
|
||||
*/
|
||||
public function setControl(StandardFile $control)
|
||||
{
|
||||
$this->_control = $control;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the actual control file
|
||||
*
|
||||
* @return StandardFile
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->_control;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See addMount instead
|
||||
*/
|
||||
public function mount($sourcePath, $destinationPath)
|
||||
{
|
||||
return $this->addMount($sourcePath, $destinationPath);
|
||||
}
|
||||
|
||||
public function addMount($sourcePath, $destinationPath)
|
||||
{
|
||||
$this->_mountPoints[$sourcePath] = $destinationPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setOutputPath($path)
|
||||
{
|
||||
$this->_outputPath = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getOutputPath()
|
||||
{
|
||||
return $this->_outputPath;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (file_exists($this->_outputPath)) {
|
||||
$iterator = new \DirectoryIterator($this->_outputPath);
|
||||
if (file_exists($this->getOutputPath())) {
|
||||
$iterator = new \DirectoryIterator($this->getOutputPath());
|
||||
foreach ($iterator as $path) {
|
||||
if ($path != '.' || $path != '..'); {
|
||||
echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL;
|
||||
exit();
|
||||
if ($path != '.' && $path != '..') {
|
||||
throw new RuntimeException("OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_mountPoints as $path => $dest) {
|
||||
$this->_pathToPath($path, $this->_outputPath . DIRECTORY_SEPARATOR . $dest);
|
||||
|
||||
if (!file_exists($this->getOutputPath())) {
|
||||
mkdir($this->getOutputPath(), 0777);
|
||||
}
|
||||
|
||||
mkdir($this->_outputPath . "/DEBIAN", 0777);
|
||||
file_put_contents($this->_outputPath . "/DEBIAN/control", (string)$this->_control);
|
||||
|
||||
|
||||
foreach ($this->_mountPoints as $path => $dest) {
|
||||
$this->_pathToPath($path, $this->getOutputPath() . DIRECTORY_SEPARATOR . $dest);
|
||||
}
|
||||
|
||||
mkdir($this->getOutputPath() . "/DEBIAN", 0777);
|
||||
|
||||
file_put_contents($this->getOutputPath() . "/DEBIAN/control", (string)$this->_control);
|
||||
|
||||
if ($this->_preInst) {
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/preinst";
|
||||
$this->_copy($this->_preInst, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_postInst) {
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/postinst";
|
||||
$this->_copy($this->_postInst, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_preRM) {
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/prerm";
|
||||
$this->_copy($this->_preRM, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_postRM) {
|
||||
$dest = $this->getOutputPath() . "/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 != '..') {
|
||||
|
|
@ -91,29 +167,44 @@ 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);
|
||||
}
|
||||
copy($source, $dest);
|
||||
$destFolder = dirname($dest);
|
||||
if (!file_exists($destFolder)) {
|
||||
mkdir($destFolder, 0777, true);
|
||||
}
|
||||
if (is_link($source)) {
|
||||
symlink(readlink($source), $dest);
|
||||
return; // don't set perms on symlink targets
|
||||
} else {
|
||||
if (!copy($source, $dest)) {
|
||||
echo "Error: failed to copy: $source -> $dest \m";
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (fileperms($source) != fileperms($dest)) {
|
||||
chmod($dest, fileperms($source));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function build($debPackageName = false)
|
||||
{
|
||||
if (!$debPackageName) {
|
||||
$debPackageName = basename($this->_outputPath . ".deb");
|
||||
$control = $this->getControl();
|
||||
$name = $control['Package'];
|
||||
$version = $control['Version'];
|
||||
$arch = $control['Architecture'];
|
||||
$debPackageName = "{$name}_{$version}_{$arch}.deb";
|
||||
}
|
||||
|
||||
$command = "dpkg -b {$this->_outputPath} {$debPackageName}" . PHP_EOL;
|
||||
|
||||
echo $command;
|
||||
|
||||
$command = "dpkg -b {$this->getOutputPath()} {$debPackageName}";
|
||||
|
||||
return $command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
<?php
|
||||
namespace wdm\debian\control;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Representation of Standard control file for Debian packages
|
||||
*
|
||||
* @author Walter Dal Mut
|
||||
* @package
|
||||
* @package
|
||||
* @license MIT
|
||||
*
|
||||
* Copyright (C) 2012 Corley S.R.L.
|
||||
|
|
@ -17,7 +17,7 @@ namespace wdm\debian\control;
|
|||
* 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.
|
||||
*
|
||||
|
|
@ -33,159 +33,165 @@ class StandardFile
|
|||
implements \ArrayAccess
|
||||
{
|
||||
private $_keys = array(
|
||||
'Package' => '',
|
||||
'Package' => false,
|
||||
'Version' => '0.1',
|
||||
"Section" => "web",
|
||||
"Priority" => "optional",
|
||||
"Architecture" => "all",
|
||||
"Essential" => "no",
|
||||
"Depends" => "",
|
||||
"Pre-Depends" => "",
|
||||
"Recommends" => "",
|
||||
"Suggests" => "",
|
||||
"Depends" => false,
|
||||
"Pre-Depends" => false,
|
||||
"Recommends" => false,
|
||||
"Suggests" => false,
|
||||
"Installed-Size" => 1024,
|
||||
"Maintainer" => "name [email]",
|
||||
"Conflicts" => "",
|
||||
"Replaces" => "",
|
||||
"Maintainer" => "name <email>",
|
||||
"Conflicts" => false,
|
||||
"Replaces" => false,
|
||||
"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);
|
||||
return $this->_setProperty("Priority", $priority);
|
||||
}
|
||||
|
||||
|
||||
public function setArchitecture($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 setRecommends($depends)
|
||||
{
|
||||
return $this->_setProperty("Recommends", $this->_transformList($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, $email = false)
|
||||
{
|
||||
$email = ($email) ? $email : "---";
|
||||
return $this->_setProperty("Maintainer", $maintainer . "[{$email}]");
|
||||
return $this->_setProperty("Maintainer", "{$maintainer} <{$email}>");
|
||||
}
|
||||
|
||||
|
||||
public function setConflicts($conflicts)
|
||||
{
|
||||
return $this->_setProperty("Conflicts", $this->_transformList($conflicts));
|
||||
}
|
||||
|
||||
|
||||
public function setReplaces($replaces)
|
||||
{
|
||||
return $this->_setProperty("Conflicts", $this->_transformList($replaces));
|
||||
return $this->_setProperty("Replaces", $this->_transformList($replaces));
|
||||
}
|
||||
|
||||
|
||||
public function setProvides($provides)
|
||||
{
|
||||
return $this->_setProperty("Provides", $provides);
|
||||
return $this->_setProperty("Provides", $this->_transformList($provides));
|
||||
}
|
||||
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
return $this->_setProperty("Description", $description);
|
||||
}
|
||||
|
||||
|
||||
private function _transformList($depends)
|
||||
{
|
||||
if (is_array($depends)) {
|
||||
$depends = implode(", ", $depends);
|
||||
} else {
|
||||
$depends = $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) {
|
||||
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) {
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if (!$this->offsetExists($offset)) {
|
||||
throw new \InvalidArgumentException("Invalid property '{$offset}' 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;
|
||||
if ($value) {
|
||||
$control .= "{$key}: {$value}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $control;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
105
tests/wdm/debian/PackagerTest.php
Normal file
105
tests/wdm/debian/PackagerTest.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
namespace wdm\debian;
|
||||
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
class PackagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->object = new Packager();
|
||||
}
|
||||
|
||||
public function testRetrieveTheBuildCommand()
|
||||
{
|
||||
$this->object->setOutputPath("/tmp");
|
||||
|
||||
$this->assertEquals("dpkg -b /tmp my.deb", $this->object->build("my.deb"));
|
||||
}
|
||||
|
||||
public function testRetriveControlFile()
|
||||
{
|
||||
$control = new control\StandardFile();
|
||||
$this->object->setControl($control);
|
||||
|
||||
$this->assertSame($control, $this->object->getControl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException RuntimeException
|
||||
* @expectedExceptionMessage OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!
|
||||
*/
|
||||
public function testOutputFolderIsNotEmpty()
|
||||
{
|
||||
$root = vfsStream::setup('root');
|
||||
|
||||
mkdir(vfsStream::url('root/tmp'));
|
||||
file_put_contents(vfsStream::url('root/tmp/ciao.txt'), "ciao");
|
||||
|
||||
$this->object->setOutputPath(vfsStream::url('root/tmp'));
|
||||
|
||||
$control = new control\StandardFile();
|
||||
$this->object->setControl($control);
|
||||
|
||||
$this->object->run();
|
||||
}
|
||||
|
||||
public function testOutputFolderExistsButIsEmpty()
|
||||
{
|
||||
$root = vfsStream::setup('root');
|
||||
|
||||
mkdir(vfsStream::url('root/tmp'));
|
||||
|
||||
$this->object->setOutputPath(vfsStream::url('root/tmp'));
|
||||
|
||||
$control = new control\StandardFile();
|
||||
$this->object->setControl($control);
|
||||
|
||||
$this->object->run();
|
||||
$command = $this->object->build();
|
||||
|
||||
$control = $this->object->getControl();
|
||||
$name = $control['Package'];
|
||||
$version = $control['Version'];
|
||||
$arch = $control['Architecture'];
|
||||
$debPackageName = "{$name}_{$version}_{$arch}.deb";
|
||||
|
||||
$this->assertEquals("dpkg -b vfs://root/tmp {$debPackageName}", $command);
|
||||
}
|
||||
|
||||
public function testCreateDebWhenOutputFolderIsMissing()
|
||||
{
|
||||
$root = vfsStream::setup('root');
|
||||
|
||||
$this->object->setOutputPath(vfsStream::url('root/tmp'));
|
||||
|
||||
$control = new control\StandardFile();
|
||||
$this->object->setControl($control);
|
||||
|
||||
$this->object->run();
|
||||
$command = $this->object->build();
|
||||
|
||||
$control = $this->object->getControl();
|
||||
$name = $control['Package'];
|
||||
$version = $control['Version'];
|
||||
$arch = $control['Architecture'];
|
||||
$debPackageName = "{$name}_{$version}_{$arch}.deb";
|
||||
|
||||
$this->assertEquals("dpkg -b vfs://root/tmp {$debPackageName}", $command);
|
||||
}
|
||||
|
||||
public function testCreateDebPackageWithAnotherName()
|
||||
{
|
||||
$root = vfsStream::setup('root');
|
||||
|
||||
$this->object->setOutputPath(vfsStream::url('root/tmp'));
|
||||
|
||||
$control = new control\StandardFile();
|
||||
$this->object->setControl($control);
|
||||
|
||||
$this->object->run();
|
||||
$command = $this->object->build("myname.deb");
|
||||
|
||||
$this->assertEquals("dpkg -b vfs://root/tmp myname.deb", $command);
|
||||
}
|
||||
}
|
||||
73
tests/wdm/debian/control/StandardFileTest.php
Normal file
73
tests/wdm/debian/control/StandardFileTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
namespace wdm\debian\control;
|
||||
|
||||
class StandardFileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $object;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->object = new StandardFile();
|
||||
}
|
||||
|
||||
public function testMinimumFile()
|
||||
{
|
||||
$conf = (string)$this->object;
|
||||
|
||||
$expected = <<<OEF
|
||||
Version: 0.1
|
||||
Section: web
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Essential: no
|
||||
Installed-Size: 1024
|
||||
Maintainer: name <email>
|
||||
Provides: your-company
|
||||
Description: Your description
|
||||
|
||||
OEF;
|
||||
$this->assertEquals($expected, $conf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid property 'MyPersonalSection' for this control file.
|
||||
*/
|
||||
public function testFilterMissingOrInvalidProperties()
|
||||
{
|
||||
$this->object["MyPersonalSection"] = "Test";
|
||||
}
|
||||
|
||||
public function testOverwriteConfiguration()
|
||||
{
|
||||
$this->object["Version"] = "1.0.1";
|
||||
$this->object["Section"] = "Software";
|
||||
$this->object["Priority"] = "security";
|
||||
$this->object["Architecture"] = "x86";
|
||||
$this->object["Essential"] = "yes";
|
||||
$this->object["Installed-Size"] = "2048";
|
||||
$this->object["Maintainer"] = "Walter Dal Mut <walter.dalmut at gmail dot com>";
|
||||
$this->object["Provides"] = "Corley SRL";
|
||||
$this->object["Description"] = "My Desc";
|
||||
$this->object["Depends"] = "php5-cli";
|
||||
$this->object["Recommends"] = "php5-curl";
|
||||
|
||||
$conf = (string)$this->object;
|
||||
|
||||
$expected = <<<OEF
|
||||
Version: 1.0.1
|
||||
Section: Software
|
||||
Priority: security
|
||||
Architecture: x86
|
||||
Essential: yes
|
||||
Depends: php5-cli
|
||||
Recommends: php5-curl
|
||||
Installed-Size: 2048
|
||||
Maintainer: Walter Dal Mut <walter.dalmut at gmail dot com>
|
||||
Provides: Corley SRL
|
||||
Description: My Desc
|
||||
|
||||
OEF;
|
||||
$this->assertEquals($expected, $conf);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue