Run command supports shell scripts
authorFrederic Massart <fred@moodle.com>
Wed, 24 Jul 2013 05:48:47 +0000 (13:48 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 24 Jul 2013 05:48:54 +0000 (13:48 +0800)
lib/scripts.py
scripts/README.md

index 4d16660..6811efb 100644 (file)
@@ -24,6 +24,7 @@ http://github.com/FMCorz/mdk
 
 import os
 import shutil
+import stat
 from tools import process
 from config import Conf
 from exceptions import ScriptNotFound, ConflictInScriptName, UnsupportedScript
@@ -33,7 +34,7 @@ C = Conf()
 
 class Scripts(object):
 
-    _supported = ['php']
+    _supported = ['php', 'sh']
     _dirs = None
     _list = None
 
@@ -129,6 +130,14 @@ class Scripts(object):
             cmd = '%s %s' % (C.get('php'), dest)
             result = process(cmd, cwd=path, **cmdkwargs)
             os.remove(dest)
+        elif cli.endswith('.sh'):
+            dest = os.path.join(path, 'mdkscriptrun.sh')
+            shutil.copyfile(cli, dest)
+            os.chmod(dest, stat.S_IRUSR | stat.S_IXUSR)
+
+            cmd = '%s' % (dest)
+            result = process(cmd, cwd=path, **cmdkwargs)
+            os.remove(dest)
         else:
             raise UnsupportedScript('Script not supported')
 
index 39ebc05..ba4cd29 100644 (file)
@@ -12,6 +12,10 @@ Formats
 
 PHP scripts will be executed from the web directory of an instance. They will be executed as any other CLI script.
 
+### Shell
+
+Shell scripts will be executed from the web directory of an instance. They will be made executable and run on their own. If you need to access information about the instance from within the shell script, retrieve it using `mdk info`.
+
 Directories
 -----------