composer script section os.dependent composer script section os.dependent shell shell

composer script section os.dependent


Simplest solution is using PHP itself I reckon:

{ ...  "scripts": {    "post-update-cmd": "php -r chmod('../log', 0777);"  }}

This requires the php binary to be in your PATH (or similar) on Linux/OSX/Windows.

Ps: I can't recall for sure, but I believe path should be relative to where your composer.json is, so you may have to adjust the above path accordingly.


Possible solution is to move post update command into the hook and perform all necessary check for operating system there.In your composer:

{ ...  "scripts": {    "post-update-cmd": "Hooks\MyHook::checkOS()"  }, "autoload": {    "psr-0": {        "Hooks": "src/"    } }

}

Than create class that will handle your logic:

...class MyHook(){ public static function checkOS(){  // 1 - get operating system  // 2 - is chmod exist? execute chmod -R 777 ../log}}


Thanks to @alcohol for pointing me tothe right direction.Simple solution:

"scripts": {  "post-update-cmd": "php post-update-cmd.php"}

post-update-cmd.php:

#!/bin/php<?phpini_set('register_argc_argv', 0);if (!isset($argc) || is_null($argc)) die('CLI only');$log_dir = dirname(dirname(__FILE__)). DIRECTORY_SEPARATOR . 'log';if( strpos(strtolower(php_uname('s')), 'win') === false ) {    exec("mkdir -p $log_dir && chmod -R 777 $log_dir");} else { // Windows !    if( !file_exists($log_dir) ) {        exec("mkdir $log_dir");    }    echo "WinOS - no chmod available\n";}echo "Finished\n";