#!/usr/bin/env php | +-----------------------------------------------------------------------+ */ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; if (!function_exists('exec')) { die("PHP exec() function is required. Check disable_functions in php.ini\n"); } $SOURCES = json_decode(file_get_contents(INSTALL_PATH . 'jsdeps.json'), true); 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`); $FILEINFO = trim(`which file`); if (empty($UNZIP)) { die("ERROR: Required program 'unzip' not found\n"); } 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)) { $CACHEDIR = INSTALL_PATH . 'temp/js_cache'; } //////////////// License definitions $LICENSES = array(); $LICENSES['MIT'] = << $dest) { echo "Installing files $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, 0774, 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) { echo "ERROR: Failed to move $src into $destdir/$dest; " . join('; ' . $out) . "\n"; } } // 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) { echo "ERROR: Failed to unzip $srcfile; " . join('; ' . $out) . "\n"; } } // 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')) + array('force' => false, 'delete' => false); $WHAT = $args[0]; 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; } echo "Installing $package[name]...\n"; $srcfile = fetch_from_source($package, !$args['force'], $filetype); if ($filetype === 'zip') { extract_zipfile($package, $srcfile); } else { compose_destfile($package, $srcfile); } echo "Done.\n\n"; }