Compare commits

...

70 commits

Author SHA1 Message Date
Jan-Hendrik Frintrop
22b2fcf742 Change default deb package name (#19)
* Change default deb package name

Changed default deb package name to `"{$name}_{$version}_{$arch}.deb"` since this is what normally would be generated.

* Fix tests for default deb name

The tests with default package name still expected the old version of the name.

* Fixed tests

Tests tried to get the Control via `$this->getControl()` which obviously failed.
2017-07-18 12:07:15 +02:00
Walter Dal Mut
fe2ad18bb3 Merge pull request #18 from jhfrintrop/patch-6
Fix spacing in method names
2017-07-18 12:07:01 +02:00
Jan-Hendrik Frintrop
c2fa2ffd7f Fix setMaintainer (#14)
* Fix brackets of maintainer email

The email address of the maintainer must use angle brackes as per https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Maintainer
Also there should be a space between name and email.

* Use variable interpolation for maintainer name

Since you already use interpolation for maintainer email you can use it for name too.

* Fix default value for maintainer

The default value for the maintainer still had the square brackets.

* Fix tests for StandardFile

The tests still used square brackets.
2017-07-18 12:06:01 +02:00
Walter Dal Mut
eb7402f531 Merge pull request #17 from jhfrintrop/patch-5
Fix setReplaces
2017-07-18 12:05:32 +02:00
Walter Dal Mut
e5eac39aeb Merge pull request #16 from jhfrintrop/patch-4
Fix setProvides
2017-07-18 12:05:05 +02:00
Walter Dal Mut
0a7965ca27 Merge pull request #13 from jhfrintrop/patch-1
Fix setRecommends
2017-07-18 12:04:24 +02:00
Walter Dal Mut
c1db405718 Merge pull request #15 from jhfrintrop/patch-3
Fix setPriority
2017-07-18 12:03:53 +02:00
Jan-Hendrik Frintrop
9f73b61e7e Fix spacing in method names
Some method names were followed by spaces.
2017-07-18 09:14:45 +02:00
Jan-Hendrik Frintrop
f02de6e4f0 Fix setReplaces
`setReplaces` used `"Conflicts"` as key which should be `"Replaces"`.
2017-07-18 09:07:36 +02:00
Jan-Hendrik Frintrop
c31de5be5f Fix setProvides
Provided packages can also be a list of packages.
2017-07-18 09:05:56 +02:00
Jan-Hendrik Frintrop
26deac007c Fix setPriority
`setPriority` used `$this["Priority"]` as key which should be just `"Priority"`.
2017-07-18 09:03:50 +02:00
Jan-Hendrik Frintrop
9f0e89de59 Recommended packages can be a list
The field "Recommends" needs to accept a list of recommended packages.
2017-07-18 08:50:11 +02:00
Jan-Hendrik Frintrop
72f6bf643d Fix spelling mistake in property name
Property "Reccommends" does not exist.
It is "Recommends"
2017-07-18 08:46:05 +02:00
Walter Dal Mut
c5db10bb90 Merge pull request #12 from Tony133/master
Fix identation method
2017-06-27 19:30:58 +02:00
Tony133
5616cfaedd Fix identation 2017-06-27 15:10:25 +02:00
Walter Dal Mut
4733e927cb Merge pull request #11 from Tony133/master
Fix spaces
2017-06-27 11:00:36 +02:00
Tony133
7f65a0aa86 Fix indentation 2017-04-19 12:12:32 +02:00
Walter Dal Mut
ecc361aad0 Merge pull request #10 from DavidGoodwin/master
improve symlink copying
2016-06-21 14:50:09 +02:00
David Goodwin
d04b3e44fa don't continue and try to set permissions on a symlink - that'll be covered by something else in this package, or is outside our scope and part of the O/S or another package 2016-06-21 13:33:34 +01:00
David Goodwin
e5be8eac40 check retval from copy(src,dest) 2016-06-21 13:22:27 +01:00
David Goodwin
eafedc1c8f Fix indentation 2016-06-21 13:19:46 +01:00
Walter Dal Mut
56493c7991 Merge pull request #9 from ashleyfraser/symlinks
Added support for copying symbolic links
2016-06-14 19:17:30 +02:00
Ashley Fraser
84d9e7f8d7 Added support for copying symbolic links 2016-06-14 14:36:06 +02:00
Walter Dal Mut
25e3350670 Merge pull request #8 from utkuaydin/master
Minor correction in readme file
2015-07-06 15:40:03 +02:00
Utku Aydın
4d5ec6074e Minor correction in readme file 2015-07-06 16:23:39 +03:00
Walter Dal Mut
5ed71d2b1c Merge branch 'release/0.0.13' 2015-05-27 00:02:47 +02:00
Walter Dal Mut
0b11235a62 Bumped version 0.0.13 2015-05-27 00:02:33 +02:00
Walter Dal Mut
e05f29d86c Moved to a single changelog file 2015-05-26 10:35:00 +02:00
Walter Dal Mut
9ccde2227a Added functional test
* The packager will throws exceptions when the output folder exists
2015-05-26 10:23:25 +02:00
Walter Dal Mut
248c14d301 Merge tag '0.0.12' into develop
Fixes not empty output folder
2015-05-26 08:37:30 +02:00
Walter Dal Mut
03cd660ea0 Merge branch 'release/0.0.12' 2015-05-26 08:37:16 +02:00
Walter Dal Mut
e03d099610 Bumped version 0.0.12 2015-05-26 08:37:01 +02:00
Walter Dal Mut
101c0f7cd6 Merge pull request #7 from wapmorgan/master
Fix for incorrent errors about non-empty output directory
2015-05-26 08:35:35 +02:00
wapmorgan
0dc9ace168 Fix for incorrent errors about non-empty output directory 2015-05-26 04:55:20 +03:00
Walter Dal Mut
14f59088aa Merge tag '0.0.11' into develop
Added permission fix
2015-05-21 22:08:24 +02:00
Walter Dal Mut
f8cf01dd43 Merge branch 'release/0.0.11' 2015-05-21 22:08:10 +02:00
Walter Dal Mut
3fea36764b Bumped version 0.0.11 2015-05-21 22:07:43 +02:00
wapmorgan
b4f5905d72 Add preserving original file permissions 2015-05-21 22:05:51 +02:00
Walter Dal Mut
56acfbdff1 Merge pull request #6 from wapmorgan/master
Fix for binary files
2015-05-21 22:02:28 +02:00
wapmorgan
14d67be8d8 Add preserving original file permissions 2015-05-21 20:07:23 +03:00
Walter Dal Mut
592dd77f85 Added describe project link 2015-04-12 17:37:25 +02:00
Walter Dal Mut
df20d1654c Merge tag '0.0.10' into develop
Added getter for the output path
2015-04-12 13:13:39 +02:00
Walter Dal Mut
29a2ed1d46 Merge branch 'release/0.0.10' 2015-04-12 13:13:24 +02:00
Walter Dal Mut
fc0640f9bc Bumped version 0.0.10 2015-04-12 13:13:17 +02:00
Walter Dal Mut
5251337b38 Use getters for the output path 2015-04-12 13:12:26 +02:00
Walter Dal Mut
c52fb1b0ae Merge tag '0.0.9' into develop
New getter methods
2015-04-12 11:29:41 +02:00
Walter Dal Mut
b2fc4bef81 Merge branch 'release/0.0.9' 2015-04-12 11:29:36 +02:00
Walter Dal Mut
1b296a55ac Bumped version 0.0.9 2015-04-12 11:29:29 +02:00
Walter Dal Mut
664cff2bf0 Added getControl method
In order to retrive the actual control file i have added a new getter
method for the control file
2015-04-12 11:27:56 +02:00
Walter Dal Mut
037933215a Merge tag '0.0.8' into develop
Removed version from composer.json
2015-04-12 10:37:49 +02:00
Walter Dal Mut
dda9795e10 Merge branch 'release/0.0.8' 2015-04-12 10:37:32 +02:00
Walter Dal Mut
3a89e04031 Bumped version 0.0.8 2015-04-12 10:37:17 +02:00
Walter Dal Mut
3e297a6d9d Removed version property from composer 2015-04-12 10:36:11 +02:00
Walter Dal Mut
8ec88807eb Merge branch 'develop' 2014-12-04 08:03:19 +01:00
Walter Dal Mut
da685a0568 Updated change log 2014-12-04 08:03:11 +01:00
Walter Dal Mut
b34bc46a3e Merge branch 'develop' 2014-12-04 07:52:43 +01:00
Walter Dal Mut
adac0738cd Fixes missing autoloader class 2014-12-04 07:52:23 +01:00
Walter Dal Mut
2f6945a64d Merge branch 'develop' 2014-12-03 23:37:39 +01:00
Walter Dal Mut
f1849734cd Added travis-ci badge 2014-12-03 23:36:36 +01:00
Walter Dal Mut
70803c17a0 Removed IPacakger interface (not useful) 2014-12-03 23:33:41 +01:00
Walter Dal Mut
71be07b1fe Removed custom autoloader, use composer instead 2014-12-03 23:32:13 +01:00
Walter Dal Mut
95a7684787 Merge branch 'develop' 2014-12-03 23:26:42 +01:00
Walter Dal Mut
0c2ba5071d BC Break packager - Simplifies packager maintenance 2014-12-03 23:24:42 +01:00
Walter Dal Mut
f097b8cf31 Cover base configuration overwrite 2014-12-03 22:49:48 +01:00
Walter Dal Mut
529a529185 Cover filter out extra properties 2014-12-03 22:41:32 +01:00
Walter Dal Mut
0dfd236925 Removed window file new lines and extra spaces 2014-12-03 22:39:53 +01:00
Walter Dal Mut
dab5976eb3 Added standard control file test case 2014-12-03 22:38:07 +01:00
Walter Dal Mut
6e42141c12 Merge pull request #5 from gianarb/remove-empty-control-line
Fixed #4 It doesn't print line if control value is empty
2014-12-03 09:44:09 +01:00
Gianluca Arbezzano
485118b8f0 Fixed #4 It doesn't print line if control value is empty 2014-12-03 09:40:10 +01:00
Walter Dal Mut
979b114230 Bumped pear package version 2013-11-18 08:12:22 +01:00
15 changed files with 1396 additions and 249 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@ vendor
*.deb *.deb
src/*.tgz src/*.tgz
tags

11
.travis.yml Normal file
View 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
View 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

View file

@ -1,11 +1,28 @@
# Debian packager (PHP) # Debian packager (PHP)
* Develop: [![Build Status](https://travis-ci.org/wdalmut/php-deb-packager.svg?branch=develop)](https://travis-ci.org/wdalmut/php-deb-packager)
* Master : [![Build Status](https://travis-ci.org/wdalmut/php-deb-packager.svg?branch=master)](https://travis-ci.org/wdalmut/php-deb-packager)
A simple debian packager for PHP applications 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
<?php <?php
require_once 'wdm/debian/Autoloader.php'; require_once __DIR__ . '/vendor/autoload.php';
$control = new \wdm\debian\control\StandardFile(); $control = new \wdm\debian\control\StandardFile();
$control $control
@ -30,9 +47,16 @@ $packager->mount("/path/to/docs", "/usr/share/docs");
//Creates folders using mount points //Creates folders using mount points
$packager->run(); $packager->run();
//Creates the Debian package //Get the Debian package command
$packager->build(); echo $packager->build();
``` ```
**Create the Package**
```
$(php pack.php)
```
## Pre-Post scripts ## Pre-Post scripts
Optianally you can add script for different hooks Optianally you can add script for different hooks
@ -45,14 +69,14 @@ Optianally you can add script for different hooks
* Run pre package remove * Run pre package remove
* post-remove * post-remove
* Run post package remove * Run post package remove
Adding scripts Adding scripts
```php ```php
$packager->setPreInstallScript(__DIR__ . '/my-pre-install-script.sh'); $packager->setPreInstallScript(__DIR__ . '/my-pre-install-script.sh');
$packager->setPostInstallScript(__DIR__ . '/my-post-install-script.sh'); $packager->setPostInstallScript(__DIR__ . '/my-post-install-script.sh');
$packager->setPreRemoveScript(__DIR__ . '/my-pre-remove-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 See a script example
@ -67,4 +91,8 @@ echo "Goodbye Cruel World"
exit 0 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
View file

@ -0,0 +1 @@
0.0.13

View file

@ -1,10 +1,8 @@
{ {
"name": "wdalmut/php-deb-packager", "name": "wdalmut/php-deb-packager",
"description": "A simple debian packager for PHP applications", "description": "A simple debian packager for PHP applications",
"version":"0.0.3",
"type":"library", "type":"library",
"keywords":["deb","packager","ubuntu","php-deb"], "keywords":["deb","packager","ubuntu","php-deb", "debian"],
"time":"2012-07-31",
"license":"MIT", "license":"MIT",
"authors": [ "authors": [
{ {
@ -20,15 +18,13 @@
"require": { "require": {
"php": ">=5.3.3" "php": ">=5.3.3"
}, },
"require-dev": {
"phpunit/phpunit": "~4",
"mikey179/vfsStream": "1.4.*"
},
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"wdm": "src/" "wdm": ["src/", "tests/"]
} }
}, }
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wdalmut/php-deb-packager"
}
]
} }

1015
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
<?php <?php
require_once 'wdm/debian/Autoloader.php'; require_once __DIR__ . '/vendor/autoload.php';
$control = new \wdm\debian\control\StandardFile(); $control = new \wdm\debian\control\StandardFile();
$control $control
@ -23,5 +23,5 @@ $packager->mount(__DIR__ . "/../../diff", "/my-differ");
//Creates folders using mount points //Creates folders using mount points
$packager->run(); $packager->run();
//Creates the Debian package //Get the Debian package command
$packager->build(); echo $packager->build();

View file

@ -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>

View file

@ -1,4 +0,0 @@
<?php
require_once __DIR__ . '/IPackager.php';
require_once __DIR__ . '/Packager.php';
require_once __DIR__ . '/control/StandardFile.php';

View file

@ -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);
}

View file

@ -1,38 +1,10 @@
<?php <?php
namespace wdm\debian; namespace wdm\debian;
use RuntimeException;
use wdm\debian\control\StandardFile; 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 class Packager
implements IPackager
{ {
private $_control; private $_control;
private $_mountPoints = array(); private $_mountPoints = array();
@ -57,6 +29,16 @@ class Packager
return $this; return $this;
} }
/**
* Return the actual control file
*
* @return StandardFile
*/
public function getControl()
{
return $this->_control;
}
/** /**
* Pre install script * Pre install script
* *
@ -97,7 +79,15 @@ class Packager
$this->_postRM = $path; $this->_postRM = $path;
} }
/**
* @deprecated See addMount instead
*/
public function mount($sourcePath, $destinationPath) public function mount($sourcePath, $destinationPath)
{
return $this->addMount($sourcePath, $destinationPath);
}
public function addMount($sourcePath, $destinationPath)
{ {
$this->_mountPoints[$sourcePath] = $destinationPath; $this->_mountPoints[$sourcePath] = $destinationPath;
return $this; return $this;
@ -109,48 +99,54 @@ class Packager
return $this; return $this;
} }
public function getOutputPath()
{
return $this->_outputPath;
}
public function run() public function run()
{ {
if (file_exists($this->_outputPath)) { if (file_exists($this->getOutputPath())) {
$iterator = new \DirectoryIterator($this->_outputPath); $iterator = new \DirectoryIterator($this->getOutputPath());
foreach ($iterator as $path) { foreach ($iterator as $path) {
if ($path != '.' || $path != '..') { if ($path != '.' && $path != '..') {
echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL; throw new RuntimeException("OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!");
exit();
} }
} }
} }
mkdir($this->_outputPath, 0777); if (!file_exists($this->getOutputPath())) {
mkdir($this->getOutputPath(), 0777);
foreach ($this->_mountPoints as $path => $dest) {
$this->_pathToPath($path, $this->_outputPath . DIRECTORY_SEPARATOR . $dest);
} }
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) { if ($this->_preInst) {
$dest = $this->_outputPath . "/DEBIAN/preinst"; $dest = $this->getOutputPath() . "/DEBIAN/preinst";
$this->_copy($this->_preInst, $dest); $this->_copy($this->_preInst, $dest);
chmod($dest, 0755); chmod($dest, 0755);
} }
if ($this->_postInst) { if ($this->_postInst) {
$dest = $this->_outputPath . "/DEBIAN/postinst"; $dest = $this->getOutputPath() . "/DEBIAN/postinst";
$this->_copy($this->_postInst, $dest); $this->_copy($this->_postInst, $dest);
chmod($dest, 0755); chmod($dest, 0755);
} }
if ($this->_preRM) { if ($this->_preRM) {
$dest = $this->_outputPath . "/DEBIAN/prerm"; $dest = $this->getOutputPath() . "/DEBIAN/prerm";
$this->_copy($this->_preRM, $dest); $this->_copy($this->_preRM, $dest);
chmod($dest, 0755); chmod($dest, 0755);
} }
if ($this->_postRM) { if ($this->_postRM) {
$dest = $this->_outputPath . "/DEBIAN/postrm"; $dest = $this->getOutputPath() . "/DEBIAN/postrm";
$this->_copy($this->_postRM, $dest); $this->_copy($this->_postRM, $dest);
chmod($dest, 0755); chmod($dest, 0755);
} }
@ -183,17 +179,32 @@ class Packager
if (!file_exists($destFolder)) { if (!file_exists($destFolder)) {
mkdir($destFolder, 0777, true); 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) public function build($debPackageName = false)
{ {
if (!$debPackageName) { 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;
} }
} }

View file

@ -1,12 +1,12 @@
<?php <?php
namespace wdm\debian\control; namespace wdm\debian\control;
/** /**
* *
* Representation of Standard control file for Debian packages * Representation of Standard control file for Debian packages
* *
* @author Walter Dal Mut * @author Walter Dal Mut
* @package * @package
* @license MIT * @license MIT
* *
* Copyright (C) 2012 Corley S.R.L. * 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 * 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 * of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions: * so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
@ -33,159 +33,165 @@ class StandardFile
implements \ArrayAccess implements \ArrayAccess
{ {
private $_keys = array( private $_keys = array(
'Package' => '', 'Package' => false,
'Version' => '0.1', 'Version' => '0.1',
"Section" => "web", "Section" => "web",
"Priority" => "optional", "Priority" => "optional",
"Architecture" => "all", "Architecture" => "all",
"Essential" => "no", "Essential" => "no",
"Depends" => "", "Depends" => false,
"Pre-Depends" => "", "Pre-Depends" => false,
"Recommends" => "", "Recommends" => false,
"Suggests" => "", "Suggests" => false,
"Installed-Size" => 1024, "Installed-Size" => 1024,
"Maintainer" => "name [email]", "Maintainer" => "name <email>",
"Conflicts" => "", "Conflicts" => false,
"Replaces" => "", "Replaces" => false,
"Provides" => "your-company", "Provides" => "your-company",
"Description" => "Your description" "Description" => "Your description"
); );
public function setPackageName($name) public function setPackageName($name)
{ {
return $this->_setProperty("Package", $name); return $this->_setProperty("Package", $name);
} }
public function setVersion($version) public function setVersion($version)
{ {
return $this->_setProperty("Version", $version); return $this->_setProperty("Version", $version);
} }
public function setSection($section) public function setSection($section)
{ {
return $this->_setProperty("Section", $section); return $this->_setProperty("Section", $section);
} }
public function setPriority($priority) public function setPriority($priority)
{ {
return $this->_setProperty($this["Priority"], $priority); return $this->_setProperty("Priority", $priority);
} }
public function setArchitecture($arch) public function setArchitecture($arch)
{ {
return $this->_setProperty("Architecture", $arch); return $this->_setProperty("Architecture", $arch);
} }
public function setEssential($essential) public function setEssential($essential)
{ {
return $this->_setProperty("Essential", $essential); return $this->_setProperty("Essential", $essential);
} }
public function setDepends($depends) public function setDepends($depends)
{ {
return $this->_setProperty("Depends", $this->_transformList($depends)); return $this->_setProperty("Depends", $this->_transformList($depends));
} }
public function setPreDepends($depends) public function setPreDepends($depends)
{ {
return $this->_setProperty("Pre-Depends", $this->_transformList($depends)); return $this->_setProperty("Pre-Depends", $this->_transformList($depends));
} }
public function setRecommends($depends) public function setRecommends($depends)
{ {
return $this->_setProperty("Reccommends", $depends); return $this->_setProperty("Recommends", $this->_transformList($depends));
} }
public function setSuggests($depends) public function setSuggests($depends)
{ {
return $this->_setProperty("Suggests", $this->_transformList($depends)); return $this->_setProperty("Suggests", $this->_transformList($depends));
} }
public function setInstalledSize($size) public function setInstalledSize($size)
{ {
return $this->_setProperty("Installed-Size", $size); return $this->_setProperty("Installed-Size", $size);
} }
public function setMaintainer($maintainer, $email = false) public function setMaintainer($maintainer, $email = false)
{ {
$email = ($email) ? $email : "---"; $email = ($email) ? $email : "---";
return $this->_setProperty("Maintainer", $maintainer . "[{$email}]"); return $this->_setProperty("Maintainer", "{$maintainer} <{$email}>");
} }
public function setConflicts($conflicts) public function setConflicts($conflicts)
{ {
return $this->_setProperty("Conflicts", $this->_transformList($conflicts)); return $this->_setProperty("Conflicts", $this->_transformList($conflicts));
} }
public function setReplaces($replaces) public function setReplaces($replaces)
{ {
return $this->_setProperty("Conflicts", $this->_transformList($replaces)); return $this->_setProperty("Replaces", $this->_transformList($replaces));
} }
public function setProvides($provides) public function setProvides($provides)
{ {
return $this->_setProperty("Provides", $provides); return $this->_setProperty("Provides", $this->_transformList($provides));
} }
public function setDescription($description) public function setDescription($description)
{ {
return $this->_setProperty("Description", $description); return $this->_setProperty("Description", $description);
} }
private function _transformList($depends) private function _transformList($depends)
{ {
if (is_array($depends)) { if (is_array($depends)) {
$depends = implode(", ", $depends); $depends = implode(", ", $depends);
} else { } else {
$depends = $depends; $depends = $depends;
} }
return $depends; return $depends;
} }
private function _setProperty($key, $value) private function _setProperty($key, $value)
{ {
$this[$key] = $value; $this[$key] = $value;
return $this; 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)) { if ($this->offsetExists($offset)) {
return $this->_keys[$offset]; return $this->_keys[$offset];
} else { } else {
return null; 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)) { if ($this->offsetExists($offset)) {
unset($this->_keys[$offset]); unset($this->_keys[$offset]);
} }
} }
/** /**
* Control file string representation. * Control file string representation.
* *
* @return string The control file * @return string The control file
*/ */
public function __toString() public function __toString()
{ {
$control = ''; $control = '';
foreach ($this->_keys as $key => $value) { foreach ($this->_keys as $key => $value) {
$control .= "{$key}: {$value}" . PHP_EOL; if ($value) {
$control .= "{$key}: {$value}" . PHP_EOL;
}
} }
return $control; return $control;
} }
} }

View 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);
}
}

View 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);
}
}