2020-09-11 23:16:11 +08:00
|
|
|
#!/usr/bin/php
|
2020-08-10 18:43:02 +08:00
|
|
|
<?php
|
|
|
|
chdir(__DIR__);
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2022-11-25 16:56:26 +08:00
|
|
|
$options = getopt('', ['aur','docker','plugins','set-version','skip-gulp','debian','nextcloud','sign','cpanel']);
|
2021-02-10 16:50:20 +08:00
|
|
|
|
|
|
|
if (isset($options['plugins'])) {
|
2022-02-07 19:29:19 +08:00
|
|
|
require(__DIR__ . '/build/plugins.php');
|
2021-02-10 16:50:20 +08:00
|
|
|
}
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$gulp = trim(`which gulp`);
|
|
|
|
if (!$gulp) {
|
|
|
|
exit('gulp not installed, run as root: npm install --global gulp-cli');
|
|
|
|
}
|
2020-08-10 19:47:48 +08:00
|
|
|
|
|
|
|
$package = json_decode(file_get_contents('package.json'));
|
|
|
|
|
2021-10-22 04:45:15 +08:00
|
|
|
/**
|
|
|
|
* Update files that contain version
|
|
|
|
*/
|
|
|
|
// cloudron
|
|
|
|
$file = __DIR__ . '/integrations/cloudron/Dockerfile';
|
2021-10-22 04:48:06 +08:00
|
|
|
file_put_contents($file, preg_replace('/VERSION=[0-9.]+/', "VERSION={$package->version}", file_get_contents($file)));
|
2021-10-22 04:45:15 +08:00
|
|
|
$file = __DIR__ . '/integrations/cloudron/DESCRIPTION.md';
|
|
|
|
file_put_contents($file, preg_replace('/<upstream>[^<]*</', "<upstream>{$package->version}<", file_get_contents($file)));
|
|
|
|
// docker
|
|
|
|
$file = __DIR__ . '/.docker/release/files/usr/local/include/application.ini';
|
|
|
|
file_put_contents($file, preg_replace('/current = "[0-9.]+"/', "current = \"{$package->version}\"", file_get_contents($file)));
|
|
|
|
// nextcloud
|
2021-08-17 21:14:55 +08:00
|
|
|
$file = __DIR__ . '/integrations/nextcloud/snappymail/appinfo/info.xml';
|
|
|
|
file_put_contents($file, preg_replace('/<version>[^<]*</', "<version>{$package->version}<", file_get_contents($file)));
|
2021-10-22 04:45:15 +08:00
|
|
|
// virtualmin
|
|
|
|
$file = __DIR__ . '/integrations/virtualmin/snappymail.pl';
|
|
|
|
file_put_contents($file, preg_replace('/return \\( "[0-9]+\\.[0-9]+\\.[0-9]+" \\)/', "return ( \"{$package->version}\" )", file_get_contents($file)));
|
|
|
|
|
2021-09-01 18:21:08 +08:00
|
|
|
if (isset($options['set-version'])) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arch User Repository
|
|
|
|
// https://aur.archlinux.org/packages/snappymail/
|
|
|
|
$options['aur'] = isset($options['aur']);
|
|
|
|
|
|
|
|
// Docker build
|
|
|
|
$docker = trim(`which docker`);
|
|
|
|
$options['docker'] = isset($options['docker']) || (!$options['aur'] && $docker && strtoupper(readline("Build Docker image? (Y/N): ")) === "Y");
|
2021-08-17 21:14:55 +08:00
|
|
|
|
2021-02-02 23:36:40 +08:00
|
|
|
$destPath = "build/dist/releases/webmail/{$package->version}/";
|
|
|
|
is_dir($destPath) || mkdir($destPath, 0777, true);
|
|
|
|
|
|
|
|
$zip_destination = "{$destPath}snappymail-{$package->version}.zip";
|
|
|
|
$tar_destination = "{$destPath}snappymail-{$package->version}.tar";
|
2020-08-10 19:47:48 +08:00
|
|
|
|
|
|
|
@unlink($zip_destination);
|
|
|
|
@unlink($tar_destination);
|
|
|
|
@unlink("{$tar_destination}.gz");
|
|
|
|
|
2021-11-01 07:35:59 +08:00
|
|
|
if (!isset($options['skip-gulp'])) {
|
|
|
|
echo "\x1b[33;1m === Gulp === \x1b[0m\n";
|
|
|
|
passthru($gulp, $return_var);
|
|
|
|
if ($return_var) {
|
|
|
|
exit("gulp failed with error code {$return_var}\n");
|
|
|
|
}
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2021-11-01 07:35:59 +08:00
|
|
|
$cmddir = escapeshellcmd(__DIR__) . '/snappymail/v/0.0.0/static';
|
2020-09-23 21:12:22 +08:00
|
|
|
|
2021-11-01 07:35:59 +08:00
|
|
|
if ($gzip = trim(`which gzip`)) {
|
|
|
|
echo "\x1b[33;1m === Gzip *.js and *.css === \x1b[0m\n";
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/js/*.js");
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/js/min/*.js");
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/css/admin*.css");
|
|
|
|
passthru("{$gzip} -k --best {$cmddir}/css/app*.css");
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/boot.js.gz');
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/min/boot.min.js.gz');
|
|
|
|
}
|
2020-08-12 06:25:36 +08:00
|
|
|
|
2021-11-01 07:35:59 +08:00
|
|
|
if ($brotli = trim(`which brotli`)) {
|
|
|
|
echo "\x1b[33;1m === Brotli *.js and *.css === \x1b[0m\n";
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/js/*.js");
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/js/min/*.js");
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/css/admin*.css");
|
|
|
|
passthru("{$brotli} -k --best {$cmddir}/css/app*.css");
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/boot.js.br');
|
|
|
|
unlink(__DIR__ . '/snappymail/v/0.0.0/static/js/min/boot.min.js.br');
|
|
|
|
}
|
|
|
|
}
|
2021-06-11 02:36:57 +08:00
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
// Temporary rename folder to speed up PharData
|
2020-10-15 22:21:52 +08:00
|
|
|
//if (!rename('snappymail/v/0.0.0', "snappymail/v/{$package->version}")){
|
|
|
|
if (!rename('snappymail/v/0.0.0', "snappymail/v/{$package->version}")) {
|
|
|
|
exit('Failed to temporary rename snappymail/v/0.0.0');
|
2020-08-10 19:47:48 +08:00
|
|
|
}
|
|
|
|
register_shutdown_function(function(){
|
|
|
|
// Rename folder back to original
|
2020-10-15 22:21:52 +08:00
|
|
|
@rename("snappymail/v/{$GLOBALS['package']->version}", 'snappymail/v/0.0.0');
|
2020-08-10 19:47:48 +08:00
|
|
|
});
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2021-02-02 23:36:40 +08:00
|
|
|
echo "\x1b[33;1m === Zip/Tar === \x1b[0m\n";
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip = new ZipArchive();
|
2020-08-10 19:47:48 +08:00
|
|
|
if (!$zip->open($zip_destination, ZIPARCHIVE::CREATE)) {
|
|
|
|
exit("Failed to create {$zip_destination}");
|
2020-08-10 18:43:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar = new PharData($tar_destination);
|
|
|
|
|
2020-10-15 22:21:52 +08:00
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('snappymail/v'), RecursiveIteratorIterator::SELF_FIRST);
|
2020-08-10 18:43:02 +08:00
|
|
|
foreach ($files as $file) {
|
|
|
|
$file = str_replace('\\', '/', $file);
|
2020-11-26 22:10:43 +08:00
|
|
|
//echo "{$file}\n";
|
2020-08-10 18:43:02 +08:00
|
|
|
// Ignore "." and ".." folders
|
2020-08-10 19:47:48 +08:00
|
|
|
if (!in_array(substr($file, strrpos($file, '/')+1), array('.', '..'))) {
|
|
|
|
if (is_dir($file)) {
|
|
|
|
$zip->addEmptyDir($file);
|
|
|
|
} else if (is_file($file)) {
|
|
|
|
$zip->addFile($file);
|
|
|
|
}
|
2020-08-10 18:43:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:58:20 +08:00
|
|
|
if ($options['docker']) {
|
|
|
|
$tar->buildFromDirectory('./snappymail/', "@v/{$package->version}@");
|
|
|
|
} else {
|
|
|
|
$tar->buildFromDirectory('./', "@snappymail/v/{$package->version}@");
|
|
|
|
}
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2022-10-09 02:46:09 +08:00
|
|
|
//$zip->addFile('cli/upgrade.sh');
|
|
|
|
//$tar->addFile('cli/upgrade.sh');
|
|
|
|
|
2020-11-03 23:22:26 +08:00
|
|
|
$zip->addFile('data/.htaccess');
|
|
|
|
$tar->addFile('data/.htaccess');
|
2020-09-26 18:25:57 +08:00
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip->addFromString('data/VERSION', $package->version);
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->addFromString('data/VERSION', $package->version);
|
|
|
|
|
2020-11-03 23:22:26 +08:00
|
|
|
$zip->addFile('data/README.md');
|
|
|
|
$tar->addFile('data/README.md');
|
|
|
|
|
2021-02-02 23:36:40 +08:00
|
|
|
if ($options['aur']) {
|
|
|
|
$data = '<?php
|
|
|
|
function __get_custom_data_full_path()
|
|
|
|
{
|
|
|
|
return \'/var/lib/snappymail\';
|
|
|
|
}
|
|
|
|
';
|
|
|
|
$zip->addFromString('include.php', $data);
|
|
|
|
$tar->addFromString('include.php', $data);
|
|
|
|
} else {
|
|
|
|
$zip->addFile('_include.php');
|
|
|
|
$tar->addFile('_include.php');
|
|
|
|
}
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2020-09-23 20:49:43 +08:00
|
|
|
$zip->addFile('.htaccess');
|
|
|
|
$tar->addFile('.htaccess');
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$index = file_get_contents('index.php');
|
|
|
|
$index = str_replace('0.0.0', $package->version, $index);
|
|
|
|
$zip->addFromString('index.php', $index);
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->addFromString('index.php', $index);
|
2020-08-10 18:43:02 +08:00
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
$zip->addFile('README.md');
|
|
|
|
$tar->addFile('README.md');
|
|
|
|
|
2020-11-24 00:13:38 +08:00
|
|
|
$data = file_get_contents('dev/serviceworker.js');
|
|
|
|
//$data = file_get_contents('snappymail/v/0.0.0/static/js/min/serviceworker.min.js');
|
|
|
|
$zip->addFromString('serviceworker.js', $data);
|
|
|
|
$tar->addFromString('serviceworker.js', $data);
|
|
|
|
|
2020-08-10 18:43:02 +08:00
|
|
|
$zip->close();
|
|
|
|
|
2020-08-10 19:47:48 +08:00
|
|
|
$tar->compress(Phar::GZ);
|
|
|
|
unlink($tar_destination);
|
2022-02-16 23:55:56 +08:00
|
|
|
$tar_destination .= '.gz';
|
2020-08-10 19:47:48 +08:00
|
|
|
|
2022-02-16 23:55:56 +08:00
|
|
|
echo "{$zip_destination} created\n{$tar_destination} created\n";
|
2020-11-26 22:13:55 +08:00
|
|
|
|
2022-10-11 17:52:48 +08:00
|
|
|
if (isset($options['nextcloud'])) {
|
|
|
|
require(__DIR__ . '/build/nextcloud.php');
|
|
|
|
}
|
|
|
|
|
2022-11-25 16:56:26 +08:00
|
|
|
if (isset($options['cpanel'])) {
|
|
|
|
require(__DIR__ . '/build/cpanel.php');
|
|
|
|
}
|
|
|
|
|
2022-01-11 06:00:27 +08:00
|
|
|
rename("snappymail/v/{$package->version}", 'snappymail/v/0.0.0');
|
|
|
|
|
2022-04-14 05:52:21 +08:00
|
|
|
file_put_contents("{$destPath}core.json", '{
|
|
|
|
"version": "'.$package->version.'",
|
|
|
|
"file": "../latest.tar.gz",
|
|
|
|
"warnings": []
|
|
|
|
}');
|
|
|
|
|
2021-02-02 23:36:40 +08:00
|
|
|
// Arch User Repository
|
|
|
|
if ($options['aur']) {
|
2021-09-23 22:11:51 +08:00
|
|
|
// extension_loaded('blake2')
|
|
|
|
if (!function_exists('b2sum') && $b2sum = trim(`which b2sum`)) {
|
|
|
|
function b2sum($file) {
|
|
|
|
$file = escapeshellarg($file);
|
|
|
|
exec("b2sum --binary {$file} 2>&1", $output, $exitcode);
|
|
|
|
$output = explode(' ', implode("\n", $output));
|
|
|
|
return $output[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$b2sums = function_exists('b2sum') ? [
|
2022-02-16 23:55:56 +08:00
|
|
|
b2sum($tar_destination),
|
2022-01-11 06:05:09 +08:00
|
|
|
b2sum(__DIR__ . '/build/arch/snappymail.sysusers'),
|
|
|
|
b2sum(__DIR__ . '/build/arch/snappymail.tmpfiles')
|
2021-09-23 22:11:51 +08:00
|
|
|
] : [];
|
|
|
|
|
2022-01-11 06:05:09 +08:00
|
|
|
file_put_contents('build/arch/.SRCINFO', 'pkgbase = snappymail
|
2021-02-02 23:36:40 +08:00
|
|
|
pkgdesc = modern PHP webmail client
|
|
|
|
pkgver = '.$package->version.'
|
|
|
|
pkgrel = 1
|
|
|
|
url = https://github.com/the-djmaze/snappymail
|
|
|
|
arch = any
|
|
|
|
license = AGPL3
|
|
|
|
makedepends = php
|
|
|
|
makedepends = nodejs
|
|
|
|
makedepends = yarn
|
|
|
|
makedepends = gulp
|
|
|
|
depends = php-fpm
|
|
|
|
optdepends = mariadb: storage backend for contacts
|
|
|
|
optdepends = php-pgsql: storage backend for contacts
|
|
|
|
optdepends = php-sqlite: storage backend for contacts
|
|
|
|
source = snappymail-'.$package->version.'.tar.gz::https://github.com/the-djmaze/snappymail/archive/v'.$package->version.'.tar.gz
|
|
|
|
source = snappymail.sysusers
|
|
|
|
source = snappymail.tmpfiles
|
2021-09-20 15:19:23 +08:00
|
|
|
b2sums = '.implode("\n b2sums = ", $b2sums).'
|
2021-02-02 23:36:40 +08:00
|
|
|
|
|
|
|
pkgname = snappymail
|
|
|
|
');
|
2021-09-23 22:11:51 +08:00
|
|
|
|
2022-01-11 06:05:09 +08:00
|
|
|
$file = __DIR__ . '/build/arch/PKGBUILD';
|
2021-09-20 15:19:23 +08:00
|
|
|
if (is_file($file)) {
|
|
|
|
$PKGBUILD = file_get_contents($file);
|
|
|
|
$PKGBUILD = preg_replace('/pkgver=[0-9.]+/', "pkgver={$package->version}", $PKGBUILD);
|
|
|
|
$PKGBUILD = preg_replace('/b2sums=\\([^)]+\\)/s', "b2sums=('".implode("'\n '", $b2sums)."')", $PKGBUILD);
|
|
|
|
file_put_contents($file, $PKGBUILD);
|
|
|
|
}
|
2021-02-02 23:36:40 +08:00
|
|
|
}
|
2022-01-11 06:00:27 +08:00
|
|
|
// Debian Repository
|
|
|
|
else if (isset($options['debian'])) {
|
2022-02-19 03:28:40 +08:00
|
|
|
require(__DIR__ . '/build/deb.php');
|
2022-01-11 06:00:27 +08:00
|
|
|
}
|
2020-11-26 22:13:55 +08:00
|
|
|
// Docker build
|
2021-02-02 23:36:40 +08:00
|
|
|
else if ($options['docker']) {
|
|
|
|
echo "\x1b[33;1m === Docker === \x1b[0m\n";
|
2022-05-19 04:34:08 +08:00
|
|
|
$zip_filename = "snappymail-{$package->version}.zip";
|
|
|
|
copy($zip_destination, "./.docker/release/{$zip_filename}");
|
2021-02-02 23:36:40 +08:00
|
|
|
if ($docker) {
|
2022-05-19 04:35:06 +08:00
|
|
|
passthru("{$docker} build --pull " . __DIR__ . "/.docker/release/ --build-arg FILES_ZIP={$zip_filename} -t snappymail:{$package->version}");
|
2021-02-02 23:36:40 +08:00
|
|
|
} else {
|
|
|
|
echo "Docker not installed!\n";
|
2020-11-26 22:13:55 +08:00
|
|
|
}
|
2020-12-01 01:58:20 +08:00
|
|
|
}
|
2022-02-28 18:35:29 +08:00
|
|
|
|
|
|
|
if (isset($options['sign'])) {
|
|
|
|
echo "\x1b[33;1m === PGP Sign === \x1b[0m\n";
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '.escapeshellarg($tar_destination), $return_var);
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '.escapeshellarg($zip_destination), $return_var);
|
2022-10-11 17:52:48 +08:00
|
|
|
if (isset($options['nextcloud'])) {
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '
|
|
|
|
.escapeshellarg("{$destPath}snappymail-{$package->version}-nextcloud.tar.gz"), $return_var);
|
|
|
|
}
|
2022-02-28 18:35:29 +08:00
|
|
|
if (isset($options['debian'])) {
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --armor --detach-sign '
|
|
|
|
. escapeshellarg(__DIR__ . "/build/dist/releases/webmail/{$package->version}/" . basename(DEB_DEST_DIR.'.deb')), $return_var);
|
2022-03-10 20:53:28 +08:00
|
|
|
// https://github.com/the-djmaze/snappymail/issues/185#issuecomment-1059420588
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --digest-algo SHA512 --clearsign --output '
|
|
|
|
. escapeshellarg(__DIR__ . "/build/dist/releases/webmail/{$package->version}/InRelease") . ' '
|
|
|
|
. escapeshellarg(__DIR__ . "/build/dist/releases/webmail/{$package->version}/Release"), $return_var);
|
|
|
|
passthru('gpg --local-user 1016E47079145542F8BA133548208BA13290F3EB --digest-algo SHA512 -abs --output '
|
|
|
|
. escapeshellarg(__DIR__ . "/build/dist/releases/webmail/{$package->version}/Release.gpg") . ' '
|
|
|
|
. escapeshellarg(__DIR__ . "/build/dist/releases/webmail/{$package->version}/Release"), $return_var);
|
2022-02-28 18:35:29 +08:00
|
|
|
}
|
|
|
|
}
|