Compare commits
70 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 |
15 changed files with 1396 additions and 249 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -7,3 +7,5 @@ vendor
|
|||
*.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
|
||||
|
||||
40
README.md
40
README.md
|
|
@ -1,11 +1,28 @@
|
|||
# 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
|
||||
|
|
@ -30,9 +47,16 @@ $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
|
||||
|
|
@ -45,14 +69,14 @@ Optianally you can add script for different hooks
|
|||
* 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->setPreRemoveScript(__DIR__ . '/my-post-remove-script.sh');
|
||||
$packager->setPostRemoveScript(__DIR__ . '/my-post-remove-script.sh');
|
||||
```
|
||||
|
||||
See a script example
|
||||
|
|
@ -67,4 +91,8 @@ 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
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
{
|
||||
"name": "wdalmut/php-deb-packager",
|
||||
"description": "A simple debian packager for PHP applications",
|
||||
"version":"0.0.3",
|
||||
"type":"library",
|
||||
"keywords":["deb","packager","ubuntu","php-deb"],
|
||||
"time":"2012-07-31",
|
||||
"keywords":["deb","packager","ubuntu","php-deb", "debian"],
|
||||
"license":"MIT",
|
||||
"authors": [
|
||||
{
|
||||
|
|
@ -20,15 +18,13 @@
|
|||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4",
|
||||
"mikey179/vfsStream": "1.4.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"wdm": "src/"
|
||||
"wdm": ["src/", "tests/"]
|
||||
}
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/wdalmut/php-deb-packager"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
||||
|
|
@ -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,62 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<package packagerversion="1.8.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
|
||||
http://pear.php.net/dtd/tasks-1.0.xsd
|
||||
http://pear.php.net/dtd/package-2.0
|
||||
http://pear.php.net/dtd/package-2.0.xsd">
|
||||
<name>Corley_Deb_Packager</name>
|
||||
<channel>pear.corley.it</channel>
|
||||
<summary>Corley DEB packager.</summary>
|
||||
<description>
|
||||
This library provides mechanisms for generate valid .deb files useful
|
||||
for software distribution for GNU/Linux Debian based systems.
|
||||
</description>
|
||||
<lead>
|
||||
<name>Walter Dal Mut</name>
|
||||
<user>wdalmut</user>
|
||||
<email>walter.dalmut at corley.it</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<contributor>
|
||||
<name>Gabriele Mittica</name>
|
||||
<user>gmittica</user>
|
||||
<email>gabriele.mittica at corley.it</email>
|
||||
<active>yes</active>
|
||||
</contributor>
|
||||
<date>2012-06-04</date>
|
||||
<time>12:46:12</time>
|
||||
<version>
|
||||
<release>0.0.2</release>
|
||||
<api>0.0.2</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT</license>
|
||||
<notes>In this release the first proposal.</notes>
|
||||
<contents>
|
||||
<dir name="" baseinstalldir="/">
|
||||
<dir name="wdm">
|
||||
<dir name="debian">
|
||||
<dir name="control">
|
||||
<file role="php" name="StandardFile.php" />
|
||||
</dir>
|
||||
<file role="php" name="Autoloader.php" />
|
||||
<file role="php" name="IPackager.php" />
|
||||
<file role="php" name="Packager.php" />
|
||||
</dir>
|
||||
</dir>
|
||||
</dir>
|
||||
</contents>
|
||||
<dependencies>
|
||||
<required>
|
||||
<php>
|
||||
<min>5.3.3</min>
|
||||
</php>
|
||||
<pearinstaller>
|
||||
<min>1.4.0</min>
|
||||
</pearinstaller>
|
||||
</required>
|
||||
</dependencies>
|
||||
<phprelease />
|
||||
</package>
|
||||
|
|
@ -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,38 +1,10 @@
|
|||
<?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
|
||||
{
|
||||
private $_control;
|
||||
private $_mountPoints = array();
|
||||
|
|
@ -57,6 +29,16 @@ class Packager
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the actual control file
|
||||
*
|
||||
* @return StandardFile
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->_control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre install script
|
||||
*
|
||||
|
|
@ -97,7 +79,15 @@ class Packager
|
|||
$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;
|
||||
|
|
@ -109,48 +99,54 @@ class Packager
|
|||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mkdir($this->_outputPath, 0777);
|
||||
|
||||
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);
|
||||
foreach ($this->_mountPoints as $path => $dest) {
|
||||
$this->_pathToPath($path, $this->getOutputPath() . DIRECTORY_SEPARATOR . $dest);
|
||||
}
|
||||
|
||||
file_put_contents($this->_outputPath . "/DEBIAN/control", (string)$this->_control);
|
||||
mkdir($this->getOutputPath() . "/DEBIAN", 0777);
|
||||
|
||||
file_put_contents($this->getOutputPath() . "/DEBIAN/control", (string)$this->_control);
|
||||
|
||||
if ($this->_preInst) {
|
||||
$dest = $this->_outputPath . "/DEBIAN/preinst";
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/preinst";
|
||||
$this->_copy($this->_preInst, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_postInst) {
|
||||
$dest = $this->_outputPath . "/DEBIAN/postinst";
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/postinst";
|
||||
$this->_copy($this->_postInst, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_preRM) {
|
||||
$dest = $this->_outputPath . "/DEBIAN/prerm";
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/prerm";
|
||||
$this->_copy($this->_preRM, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
||||
if ($this->_postRM) {
|
||||
$dest = $this->_outputPath . "/DEBIAN/postrm";
|
||||
$dest = $this->getOutputPath() . "/DEBIAN/postrm";
|
||||
$this->_copy($this->_postRM, $dest);
|
||||
chmod($dest, 0755);
|
||||
}
|
||||
|
|
@ -183,17 +179,32 @@ class Packager
|
|||
if (!file_exists($destFolder)) {
|
||||
mkdir($destFolder, 0777, true);
|
||||
}
|
||||
copy($source, $dest);
|
||||
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;
|
||||
$command = "dpkg -b {$this->getOutputPath()} {$debPackageName}";
|
||||
|
||||
echo $command;
|
||||
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