Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Silent install a package on an instance from the command line in SugarCRM with this script
#!/usr/local/bin php
<?php
function usage()
{
print("usage: -i /path/to/instance -p /path/to/expanded/module -z /path/to/zipfile\n");
exit(1);
}
$opts = getopt('i:p:z:');
if (!$opts) usage();
$sugar_directory = array_key_exists('i', $opts) ? $opts['i'] : false;
$package_dir = array_key_exists('p', $opts) ? $opts['p'] : false;
$zip_file = array_key_exists('z', $opts) ? $opts['z'] : false;
if (!$sugar_directory || !$package_dir || !$zip_file) {
usage();
}
if ( function_exists('posix_getpwuid') ) {
$euinfo = posix_getpwuid(posix_geteuid());
$euser = $euinfo['name'];
$auser = exec("echo $(ps axho user,comm|grep -E \"httpd|apache\"|uniq|grep -v \"root\"|awk 'END {if ($1) print $1}')");
if ($euser != $auser ) {
error_log("Must be run as $auser! [not: $euser]");
usage();
}
}
if (!is_dir($package_dir)) {
error_log("Package directory isn't a directory");
exit(1);
}
if (!is_readable($zip_file)) {
error_log("Can't read zip file at $zip_file");
exit(1);
}
if (!chdir($sugar_directory)) {
error_log("Failed to chdir to $sugar_directory");
exit(1);
}
if (!is_readable($package_dir . '/manifest.php')) {
error_log("Package dir does not contain a readable manifest.php\n");
exit(1);
}
require_once($package_dir . '/manifest.php');
if (!is_array($manifest)) {
error_log("Sourced manifest but \$manifest was not set!\n");
exit(1);
}
if (!array_key_exists('name', $manifest) || $manifest['name'] == '') {
error_log("manifest doesn't specify a name!\n");
exit(1);
}
//initialize
if(!defined('sugarEntry')) define('sugarEntry', true);
require($sugar_directory.'/config.php');
require($sugar_directory.'/config_override.php');
require_once($sugar_directory.'/include/entryPoint.php');
require_once($sugar_directory.'/ModuleInstall/PackageManager/PackageManager.php');
$current_user = new User();
$current_user->retrieve("1"); // get the admin user, just in case
$current_user->is_admin = '1';
//initialize the module installer
// Use PackageManager instead of ModuleInstaller for extra pre-checks
$modInstaller = new PackageManager();
$modInstaller->silent = true; //shuts up the javscript progress bar
// Squelch some warnings
$GLOBALS[ 'app_list_strings' ][ 'moduleList' ] = Array();
// Check for already installed
$new_upgrade = new UpgradeHistory();
$new_upgrade->name = $manifest['name'];
if ($new_upgrade->checkForExisting($new_upgrade) !== null) {
error_log("Already installed.\n");
exit(0);
}
//start installation
echo "Patching $sugar_directory\n";
$modInstaller->performInstall($zip_file);
echo "Success!\n";
exit(0);
@rginnow
Copy link
Author

rginnow commented Sep 3, 2015

I believe this to be incompatible with Sugar 7.x. Will attempt to fix this.

@rginnow
Copy link
Author

rginnow commented Sep 8, 2015

With the past 2 revisions, this file has been tested & verified working with Sugar 7.5 Pro and Sugar 7.6 Enterprise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment