#!/usr/bin/env php | +-----------------------------------------------------------------------+ */ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; if (!function_exists('exec')) { rcube::raise_error("PHP exec() function is required. Check disable_functions in php.ini.", false, true); } $cfgfile = INSTALL_PATH . 'jsdeps.json'; $SOURCES = json_decode(file_get_contents($cfgfile), true); if (empty($SOURCES['dependencies'])) { rcube::raise_error("ERROR: Failed to read dependencies list from $cfgfile", false, true); } $CURL = trim(`which curl`); $WGET = trim(`which wget`); $UNZIP = trim(`which unzip`); $FILEINFO = trim(`which file`); if (($CACHEDIR = getenv("CACHEDIR")) && is_writeable($CACHEDIR)) { // use $CACHEDIR } 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 $LICENSES = array(); $LICENSES['MIT'] = << $dest) { echo "Installing $sourcedir/$src into $destdir/$dest\n"; // make sure the destination's parent directory exists if (strpos($dest, '/') !== false) { $parentdir = dirname($destdir . '/' . $dest); if (!is_dir($parentdir)) { mkdir($parentdir, 0775, true); } } // avoid copying source directory as a child into destination if (is_dir($sourcedir . '/' . $src) && is_dir($destdir . '/' . $dest)) { exec(sprintf('rm -rf %s/%s', $destdir, $dest)); } exec(sprintf('mv -f %s/%s %s/%s', $sourcedir, $src, $destdir, $dest), $out, $retval); if ($retval !== 0) { rcube::raise_error("Failed to move $src into $destdir/$dest; " . join('; ' . $out)); } } // remove temp extraction dir exec('rm -rf ' . $extract); } // extract the archive into the destination directory else { echo "Extracting zip archive into $destdir\n"; exec(sprintf('%s -o %s -d %s', $UNZIP, escapeshellarg($srcfile), $destdir), $out, $retval); if ($retval !== 0) { rcube::raise_error("Failed to unzip $srcfile; " . join('; ' . $out)); } } // remove some files from the destination if (!empty($package['omit'])) { foreach ((array)$package['omit'] as $glob) { exec(sprintf('rm -rf %s/%s', $destdir, escapeshellarg($glob))); } } // prepend license header to extracted files if (!empty($package['addlicense'])) { foreach ((array)$package['addlicense'] as $filename) { $pkg = $package; $pkg['dest'] = $package['dest'] . '/' . $filename; compose_destfile($pkg, $destdir . '/' . $filename); } } } /** * Delete the package destination file/dir */ function delete_destfile($package) { $destdir = INSTALL_PATH . ($package['rm'] ?: $package['dest']); if (file_exists($destdir)) { if (PHP_OS === 'Windows') { exec(sprintf("rd /s /q %s", escapeshellarg($destdir))); } else { exec(sprintf("rm -rf %s", escapeshellarg($destdir))); } } } //////////////// Execution $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'])) { $package['name'] = $package['lib']; } if ($WHAT && $package['lib'] !== $WHAT) { continue; } if ($args['delete']) { delete_destfile($package); continue; } if ($args['get']) { $srcfile = fetch_from_source($package, $useCache, $filetype); } else { $srcfile = extract_filetype($package, $filetype); } if (!empty($package['sha1']) && ($sum = sha1_file($srcfile)) !== $package['sha1']) { rcube::raise_error("Incorrect sha1 sum of $srcfile. Expected: {$package['sha1']}, got: $sum", false, true); } if ($args['extract']) { echo "Installing {$package['name']}...\n"; if ($filetype === 'zip') { extract_zipfile($package, $srcfile); } else { compose_destfile($package, $srcfile); } echo "Done.\n"; } }