From 3f6ca2cffc1e2081bfc5e112475883e513ac3ed5 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 20 Aug 2017 19:30:44 +0200 Subject: [PATCH] Add --get and --extract arguments and CACHEDIR env-variable support to install-jsdeps.sh (#5882) --- CHANGELOG | 1 + bin/install-jsdeps.sh | 92 ++++++++++++++++++++++++++++--------------- 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 44cdbb423..7319df35c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Add --get and --extract arguments and CACHEDIR env-variable support to install-jsdeps.sh (#5882) - Update to jquery-minicolors 2.2.6 - Support _filter and _scope as GET arguments for opening mail UI (#5825) - Support for IMAP folders that cannot contain both folders and messages (#5057) diff --git a/bin/install-jsdeps.sh b/bin/install-jsdeps.sh index a88a34a25..0e5145607 100755 --- a/bin/install-jsdeps.sh +++ b/bin/install-jsdeps.sh @@ -33,26 +33,20 @@ if (empty($SOURCES['dependencies'])) { die("ERROR: Failed to read sources from " . INSTALL_PATH . "jsdeps.json\n"); } -$CURL = trim(`which curl`); -$WGET = trim(`which wget`); -$UNZIP = trim(`which unzip`); +$CURL = trim(`which curl`); +$WGET = trim(`which wget`); +$UNZIP = trim(`which unzip`); $FILEINFO = trim(`which file`); -if (empty($UNZIP)) { - die("ERROR: Required program 'unzip' not found\n"); +if (($CACHEDIR = getenv("CACHEDIR")) && is_writeable($CACHEDIR)) { + // use $CACHEDIR } -if (empty($FILEINFO)) { - die("ERROR: Required program 'file' not found\n"); -} -if (empty($CURL) && empty($WGET)) { - die("ERROR: Required program 'wget' or 'curl' not found\n"); -} - -$CACHEDIR = sys_get_temp_dir(); - -if (is_writeable(INSTALL_PATH . 'temp/js_cache') || @mkdir(INSTALL_PATH . 'temp/js_cache', 0774, true)) { +else if (is_writeable(INSTALL_PATH . 'temp/js_cache') || @mkdir(INSTALL_PATH . 'temp/js_cache', 0774, true)) { $CACHEDIR = INSTALL_PATH . 'temp/js_cache'; } +else { + $CACHEDIR = sys_get_temp_dir(); +} //////////////// License definitions @@ -116,13 +110,16 @@ EOL; */ function fetch_from_source($package, $useCache = true, &$filetype = null) { - global $CURL, $WGET, $FILEINFO, $CACHEDIR; + global $CURL, $WGET; - $filetype = pathinfo($package['url'], PATHINFO_EXTENSION) ?: 'tmp'; - $cache_file = $CACHEDIR . '/' . $package['lib'] . '-' . $package['version'] . '.' . $filetype; + $cache_file = extract_filetype($package, $filetype); if (!is_readable($cache_file) || !$useCache) { - echo "Fetching $package[url]\n"; + if (empty($CURL) && empty($WGET)) { + die("ERROR: Required program 'wget' or 'curl' not found\n"); + } + + echo "Fetching {$package['url']}\n"; if ($CURL) exec(sprintf('%s -s %s -o %s', $CURL, escapeshellarg($package['url']), $cache_file), $out, $retval); @@ -134,8 +131,21 @@ function fetch_from_source($package, $useCache = true, &$filetype = null) } } - if (!empty($package['sha1']) && ($sum = sha1_file($cache_file)) !== $package['sha1']) { - die("ERROR: Incorrect sha1 sum of $cache_file. Expected: $package[sha1], got: $sum\n"); + return $cache_file; +} + +/** + * Returns package source file location and type + */ +function extract_filetype($package, &$filetype = null) +{ + global $FILEINFO, $CACHEDIR; + + $filetype = pathinfo($package['url'], PATHINFO_EXTENSION) ?: 'tmp'; + $cache_file = $CACHEDIR . '/' . $package['lib'] . '-' . $package['version'] . '.' . $filetype; + + if (empty($FILEINFO)) { + die("ERROR: Required program 'file' not found\n"); } // detect downloaded/cached file type @@ -193,6 +203,10 @@ function extract_zipfile($package, $srcfile) { global $UNZIP, $CACHEDIR; + if (empty($UNZIP)) { + die("ERROR: Required program 'unzip' not found\n"); + } + $destdir = INSTALL_PATH . $package['dest']; if (!is_dir($destdir)) { mkdir($destdir, 0774, true); @@ -295,9 +309,14 @@ function delete_destfile($package) //////////////// Execution -$args = rcube_utils::get_opt(array('f' => 'force:bool', 'd' => 'delete:bool')) - + array('force' => false, 'delete' => false); +$args = rcube_utils::get_opt(array('f' => 'force:bool', 'd' => 'delete:bool', 'g' => 'get:bool', 'e' => 'extract:bool')) + + array('force' => false, 'delete' => false, 'get' => false, 'extract' => false); $WHAT = $args[0]; +$useCache = !$args['force'] && !$args['get']; + +if (!$args['get'] && !$args['extract'] && !$args['delete']) { + $args['get'] = $args['extract'] = 1; +} foreach ($SOURCES['dependencies'] as $package) { if (!isset($package['name'])) { @@ -313,16 +332,27 @@ foreach ($SOURCES['dependencies'] as $package) { continue; } - echo "Installing $package[name]...\n"; - - $srcfile = fetch_from_source($package, !$args['force'], $filetype); - - if ($filetype === 'zip') { - extract_zipfile($package, $srcfile); + if ($args['get']) { + $srcfile = fetch_from_source($package, $useCache, $filetype); } else { - compose_destfile($package, $srcfile); + $srcfile = extract_filetype($package, $filetype); } - echo "Done.\n\n"; + if (!empty($package['sha1']) && ($sum = sha1_file($srcfile)) !== $package['sha1']) { + die("ERROR: Incorrect sha1 sum of $srcfile. Expected: {$package['sha1']}, got: $sum\n"); + } + + if ($args['extract']) { + echo "Installing {$package['name']}...\n"; + + if ($filetype === 'zip') { + extract_zipfile($package, $srcfile); + } + else { + compose_destfile($package, $srcfile); + } + + echo "Done.\n"; + } }