snappymail/release.php

198 lines
6 KiB
PHP
Raw Normal View History

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
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
$rollup = trim(`which rollup`);
if (!$rollup) {
exit('rollup not installed, run as root: npm install --global rollup');
}
$options = getopt('', ['aur','docker']);
// 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");
2020-08-10 19:47:48 +08:00
$package = json_decode(file_get_contents('package.json'));
$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");
echo "\x1b[33;1m === Gulp === \x1b[0m\n";
2020-08-10 18:43:02 +08:00
passthru($gulp, $return_var);
if ($return_var) {
exit("gulp failed with error code {$return_var}\n");
}
/*
passthru("{$rollup} -c", $return_var);
if ($return_var) {
exit("rollup failed with error code {$return_var}\n");
}
*/
$cmddir = escapeshellcmd(__DIR__) . '/snappymail/v/0.0.0/static';
2020-09-23 21:12:22 +08:00
if ($gzip = trim(`which gzip`)) {
echo "\x1b[33;1m === Gzip *.js and *.css === \x1b[0m\n";
2020-09-23 21:12:22 +08:00
passthru("{$gzip} -k --best {$cmddir}/js/*.js");
passthru("{$gzip} -k --best {$cmddir}/js/min/*.js");
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-24 06:09:54 +08:00
if ($brotli = trim(`which brotli`)) {
echo "\x1b[33;1m === Brotli *.js and *.css === \x1b[0m\n";
2020-09-23 21:12:22 +08:00
passthru("{$brotli} -k --best {$cmddir}/js/*.js");
passthru("{$brotli} -k --best {$cmddir}/js/min/*.js");
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');
2020-08-24 06:09:54 +08:00
}
2020-08-10 19:47:48 +08:00
// Temporary rename folder to speed up PharData
//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
@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
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);
$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);
//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
}
}
if ($options['docker']) {
$tar->buildFromDirectory('./snappymail/', "@v/{$package->version}@");
} else {
$tar->buildFromDirectory('./', "@snappymail/v/{$package->version}@");
}
2020-08-10 19:47:48 +08:00
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');
//$zip->addFile('data/EMPTY');
//$tar->addFile('data/EMPTY');
2020-08-10 19:47:48 +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);
$index = str_replace('source', 'community', $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
$zip->addFile('README.md');
$tar->addFile('README.md');
$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);
echo "{$zip_destination} created\n{$tar_destination}.gz created\n";
// Arch User Repository
if ($options['aur']) {
/*
file_put_contents('arch/.SRCINFO', 'pkgbase = snappymail
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
b2sums = ?
b2sums = e020b2d4bc694ca056f5c15b148c69553ab610b5e1789f52543aa65e098f8097a41709b5b0fc22a6a01088a9d3f14d623b1b6e9ae2570acd4f380f429301c003
b2sums = 2536e11622895322cc752c6b651811b2122d3ae60099fe609609d7b45ba1ed00ea729c23f344405078698d161dbf9bcaffabf8eff14b740acdce3c681c513318
pkgname = snappymail
');
*/
}
// Docker build
else if ($options['docker']) {
echo "\x1b[33;1m === Docker === \x1b[0m\n";
copy($zip_destination, "./.docker/release/snappymail-{$package->version}.zip");
if ($docker) {
passthru("{$docker} build " . __DIR__ . "/.docker/release/ --build-arg FILES_ZIP={$zip_destination} -t snappymail:{$package->version}");
} else {
echo "Docker not installed!\n";
}
}