Best way to patch apps after an update?

SDK Docs: http://installatron.com/developer/apps
SDK GUI Editor: http://installatron.com/editor
Post Reply
interfaSys
Posts: 78
Joined: Thu Jan 05, 2012 10:56 am

Best way to patch apps after an update?

Post by interfaSys » Mon Oct 15, 2012 9:21 am

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?
Olivier
interfaSys
Web, mobile, hosting product and service development experts

Phil
Staff
Posts: 490
Joined: Tue Jun 19, 2007 6:06 am

Re: Best way to patch apps after an update?

Post by Phil » Mon Oct 15, 2012 9:43 am

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
Phillip Stier
Installatron Co-Founder

interfaSys
Posts: 78
Joined: Thu Jan 05, 2012 10:56 am

Re: Best way to patch apps after an update?

Post by interfaSys » Tue Oct 16, 2012 7:00 am

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.
Olivier
interfaSys
Web, mobile, hosting product and service development experts

Phil
Staff
Posts: 490
Joined: Tue Jun 19, 2007 6:06 am

Re: Best way to patch apps after an update?

Post by Phil » Tue Oct 16, 2012 9:16 pm

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
Phillip Stier
Installatron Co-Founder

interfaSys
Posts: 78
Joined: Thu Jan 05, 2012 10:56 am

Re: Best way to patch apps after an update?

Post by interfaSys » Wed Oct 17, 2012 10:25 am

Great tip about how to automatically patch apps, thank you Phil.
Olivier
interfaSys
Web, mobile, hosting product and service development experts

interfaSys
Posts: 78
Joined: Thu Jan 05, 2012 10:56 am

Re: Best way to patch apps after an update?

Post by interfaSys » Thu Oct 18, 2012 10:24 am

Quick question (haven't checked the docs). Is it possible to apply custom codes to certain resellers or groups of resellers?
Olivier
interfaSys
Web, mobile, hosting product and service development experts

Phil
Staff
Posts: 490
Joined: Tue Jun 19, 2007 6:06 am

Re: Best way to patch apps after an update?

Post by Phil » Fri Oct 19, 2012 12:46 pm

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
Phillip Stier
Installatron Co-Founder

interfaSys
Posts: 78
Joined: Thu Jan 05, 2012 10:56 am

Re: Best way to patch apps after an update?

Post by interfaSys » Sat Oct 20, 2012 5:09 am

Ah, great, thank you Phil.
Olivier
interfaSys
Web, mobile, hosting product and service development experts

Post Reply