Compare commits

...

35 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
11 changed files with 211 additions and 60 deletions

View file

@ -1,5 +0,0 @@
# BC Breaks
# Deprecations
* Method `mount` will be replaced by method `addMount` in the future

View file

@ -1,4 +0,0 @@
# BC Breaks
* Build will returns the dpkg command instead print it to the user
* Removed internal autoloader -> use composer as a default

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

@ -76,7 +76,7 @@ Adding scripts
$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

View file

@ -1 +1 @@
0.0.11
0.0.13

View file

@ -19,7 +19,8 @@
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4"
"phpunit/phpunit": "~4",
"mikey179/vfsStream": "1.4.*"
},
"autoload": {
"psr-0": {

92
composer.lock generated
View file

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "42aa3f85b9b2e12726c3a920256505a0",
"hash": "452e33232d90b29107daa9bb4740b3ea",
"packages": [],
"packages-dev": [
{
@ -61,6 +61,44 @@
],
"time": "2014-10-13 12:58:55"
},
{
"name": "mikey179/vfsStream",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "61b12172292cf539685507aa65b076c1530e83c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/61b12172292cf539685507aa65b076c1530e83c1",
"reference": "61b12172292cf539685507aa65b076c1530e83c1",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/",
"time": "2014-09-14 10:18:53"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.4",
@ -112,16 +150,16 @@
},
{
"name": "phpspec/prophecy",
"version": "1.4.0",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5"
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5",
"reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"shasum": ""
},
"require": {
@ -168,20 +206,20 @@
"spy",
"stub"
],
"time": "2015-03-27 19:31:25"
"time": "2015-04-27 22:15:08"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.16",
"version": "2.0.17",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c"
"reference": "c4e8e7725e351184a76544634855b8a9c405a6e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/934fd03eb6840508231a7f73eb8940cf32c3b66c",
"reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c4e8e7725e351184a76544634855b8a9c405a6e3",
"reference": "c4e8e7725e351184a76544634855b8a9c405a6e3",
"shasum": ""
},
"require": {
@ -230,7 +268,7 @@
"testing",
"xunit"
],
"time": "2015-04-11 04:35:00"
"time": "2015-05-25 05:11:59"
},
{
"name": "phpunit/php-file-iterator",
@ -418,16 +456,16 @@
},
{
"name": "phpunit/phpunit",
"version": "4.6.4",
"version": "4.6.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "163232991e652e6efed2f8470326fffa61e848e2"
"reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/163232991e652e6efed2f8470326fffa61e848e2",
"reference": "163232991e652e6efed2f8470326fffa61e848e2",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25",
"reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25",
"shasum": ""
},
"require": {
@ -486,7 +524,7 @@
"testing",
"xunit"
],
"time": "2015-04-11 05:23:21"
"time": "2015-05-25 05:18:18"
},
{
"name": "phpunit/phpunit-mock-objects",
@ -916,17 +954,17 @@
},
{
"name": "symfony/yaml",
"version": "v2.6.6",
"version": "v2.6.7",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "174f009ed36379a801109955fc5a71a49fe62dd4"
"reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/174f009ed36379a801109955fc5a71a49fe62dd4",
"reference": "174f009ed36379a801109955fc5a71a49fe62dd4",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/f157ab074e453ecd4c0fa775f721f6e67a99d9e2",
"reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2",
"shasum": ""
},
"require": {
@ -951,18 +989,18 @@
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2015-03-30 15:54:10"
"homepage": "https://symfony.com",
"time": "2015-05-02 15:18:45"
}
],
"aliases": [],

View file

@ -1,6 +1,7 @@
<?php
namespace wdm\debian;
use RuntimeException;
use wdm\debian\control\StandardFile;
class Packager
@ -108,14 +109,15 @@ class Packager
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->getOutputPath(), 0777);
if (!file_exists($this->getOutputPath())) {
mkdir($this->getOutputPath(), 0777);
}
foreach ($this->_mountPoints as $path => $dest) {
$this->_pathToPath($path, $this->getOutputPath() . DIRECTORY_SEPARATOR . $dest);
@ -177,15 +179,28 @@ class Packager
if (!file_exists($destFolder)) {
mkdir($destFolder, 0777, true);
}
copy($source, $dest);
if (fileperms($source) != fileperms($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->getOutputPath() . ".deb");
$control = $this->getControl();
$name = $control['Package'];
$version = $control['Version'];
$arch = $control['Architecture'];
$debPackageName = "{$name}_{$version}_{$arch}.deb";
}
$command = "dpkg -b {$this->getOutputPath()} {$debPackageName}";

View file

@ -44,7 +44,7 @@ class StandardFile
"Recommends" => false,
"Suggests" => false,
"Installed-Size" => 1024,
"Maintainer" => "name [email]",
"Maintainer" => "name <email>",
"Conflicts" => false,
"Replaces" => false,
"Provides" => "your-company",
@ -68,7 +68,7 @@ class StandardFile
public function setPriority($priority)
{
return $this->_setProperty($this["Priority"], $priority);
return $this->_setProperty("Priority", $priority);
}
public function setArchitecture($arch)
@ -93,7 +93,7 @@ class StandardFile
public function setRecommends($depends)
{
return $this->_setProperty("Reccommends", $depends);
return $this->_setProperty("Recommends", $this->_transformList($depends));
}
public function setSuggests($depends)
@ -109,7 +109,7 @@ class StandardFile
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)
@ -119,12 +119,12 @@ class StandardFile
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)
@ -149,11 +149,13 @@ class StandardFile
return $this;
}
public function offsetExists ($offset) {
public function offsetExists($offset)
{
return array_key_exists($offset, $this->_keys);
}
public function offsetGet ($offset) {
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
return $this->_keys[$offset];
} else {
@ -161,14 +163,16 @@ class StandardFile
}
}
public function offsetSet ($offset, $value) {
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) {
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
unset($this->_keys[$offset]);
}
@ -183,7 +187,7 @@ class StandardFile
{
$control = '';
foreach ($this->_keys as $key => $value) {
if($value){
if ($value) {
$control .= "{$key}: {$value}" . PHP_EOL;
}
}

View file

@ -1,6 +1,8 @@
<?php
namespace wdm\debian;
use org\bovigo\vfs\vfsStream;
class PackagerTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
@ -22,4 +24,82 @@ class PackagerTest extends \PHPUnit_Framework_TestCase
$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

@ -21,7 +21,7 @@ Priority: optional
Architecture: all
Essential: no
Installed-Size: 1024
Maintainer: name [email]
Maintainer: name <email>
Provides: your-company
Description: Your description
@ -46,7 +46,7 @@ OEF;
$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["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";
@ -63,7 +63,7 @@ Essential: yes
Depends: php5-cli
Recommends: php5-curl
Installed-Size: 2048
Maintainer: Walter Dal Mut [walter.dalmut at gmail dot com]
Maintainer: Walter Dal Mut <walter.dalmut at gmail dot com>
Provides: Corley SRL
Description: My Desc