Page 1 of 1

Best way to patch apps after an update?

Posted: Mon Oct 15, 2012 9:21 am
by interfaSys
I couldn't find a way to call a script (shell or php) in the documentation, so I guess we have to rewrite scripts for Installatron using internal commands such as chmod, chown, etc., but what would be the best way to patch applications via the patch command?

Re: Best way to patch apps after an update?

Posted: Mon Oct 15, 2012 9:43 am
by Phil
Hello,

The context for this is an app package?

We generally recommend our ''_exec_script'' command for this. For example:

Code: Select all

$this->_exec_script('<?php

shell_exec('.var_export("touch ". escapeshellarg("$this->path/somefile"),true).');

');


If there are any questions let us know. If you can provide the exact command, I'll provide the exact code that should be used.

Thanks,
Phil

Re: Best way to patch apps after an update?

Posted: Tue Oct 16, 2012 7:00 am
by interfaSys
Hello Phil,

Yes, the context is an app package.
"$this->_exec_script" is not documented on http://installatron.com/developer/apps, but I'm guessing it can be used anywhere?

I'd like to patch wordpress after every update. I would be manually running something like:

Code: Select all

patch -p1 < patch.diff


So, would something like this work?

Code: Select all

<?php
class i_installer_customcode   
{   
       function init()
       {
               $this->registerCustomCode("wordpress", "all", "install", "last", "process", "wordpressinstall");
       }

       function wordpressinstall($o)
       {
            $o->cp("/home/installatronpatches/wordpress.diff", "$o->path/wordpress.diff");
            $o->_exec_script('<?php
               shell_exec('.var_export("patch ". escapeshellarg("-p1 < $o->path/wordpress.diff"),true).');
            ');   
       }
}
?>


Have you given some thoughts about allowing users to easily patch the apps? Not sure how popular this would be as only advanced users would want to automatically customize their apps.
Each app could have an optional patch file being applied to it and there would need to be a dry run first.

Re: Best way to patch apps after an update?

Posted: Tue Oct 16, 2012 9:16 pm
by Phil
Hello,

This custom code will execute that patch file on install and upgrade:

Code: Select all

<?php
class i_installer_customcode   
{   
       function init()
       {
               $this->registerCustomCode("wordpress", "all", "install", "last", "process", "wordpressinstall");
               $this->registerCustomCode("wordpress", "all", "upgrade", "last", "process", "wordpressinstall");
       }

       function wordpressinstall($o)
       {
            $o->cp("/home/installatronpatches/wordpress.diff", "$o->path/wordpress.diff");
            $o->_exec_script('<?php
               shell_exec('.var_export("patch -p1 < ".escapeshellarg("$o->path/wordpress.diff"),true).');
            ');
       }
}
?>


App customizations can be used to generically apply a patch file for every app (when the patch file exists). For example:

Code: Select all

<?php
class i_installer_customcode   
{   
       function init()
       {
               $this->registerCustomCode("all", "all", "install", "last", "process", "appdiff");
               $this->registerCustomCode("all", "all", "upgrade", "last", "process", "appdiff");
       }

       function appdiff($o)
       {
              if (!$o->exists("/home/installatronpatches/".$o->install->ini["installer"].".diff"))
              {
                     return;
              }

              $o->cp("/home/installatronpatches/".$o->install->ini["installer"].".diff", "$o->path/diff");
              $o->_exec_script('<?php
               shell_exec('.var_export("patch -p1 < ".escapeshellarg("$o->path/diff"),true).');
              ');
       }
}
?>


If there are any questions let us know.

Thanks,
Phil

Re: Best way to patch apps after an update?

Posted: Wed Oct 17, 2012 10:25 am
by interfaSys
Great tip about how to automatically patch apps, thank you Phil.

Re: Best way to patch apps after an update?

Posted: Thu Oct 18, 2012 10:24 am
by interfaSys
Quick question (haven't checked the docs). Is it possible to apply custom codes to certain resellers or groups of resellers?

Re: Best way to patch apps after an update?

Posted: Fri Oct 19, 2012 12:46 pm
by Phil
Hello,

For security reasons it's not possible for resellers to save their own custom code. However, the admin can save custom code that applies to a reseller.

For example:

Code: Select all

<?php
class i_installer_customcode   
{   
       function init()
       {
               $this->registerCustomCode("all", "all", "install", "last", "process", "appdiff");
               $this->registerCustomCode("all", "all", "upgrade", "last", "process", "appdiff");
       }

       function appdiff($o)
       {
              // handle reseller1 differently
              if ( $o->owner["parent"] === "reseller1" )
              {
                     return;
              }

              if (!$o->exists("/home/installatronpatches/".$o->install->ini["installer"].".diff"))
              {
                     return;
              }

              $o->cp("/home/installatronpatches/".$o->install->ini["installer"].".diff", "$o->path/diff");
              $o->_exec_script('<?php
               shell_exec('.var_export("patch -p1 < ".escapeshellarg("$o->path/diff"),true).');
              ');
       }
}
?>


Thanks,
Phil

Re: Best way to patch apps after an update?

Posted: Sat Oct 20, 2012 5:09 am
by interfaSys
Ah, great, thank you Phil.