self.outf.write('@reboot %s %s %s' % (run_as, script_path,
parameters.text))
+class cmd_add_startup(Command):
+ """Adds VGP Startup Script Group Policy to the sysvol
+
+This command adds a startup script policy to the sysvol.
+
+Example:
+samba-tool gpo manage scripts startup add {31B2F340-016D-11D2-945F-00C04FB984F9} test_script.sh '-n'
+ """
+
+ synopsis = "%prog <gpo> <script> [args] [run_as] [options]"
+
+ takes_optiongroups = {
+ "sambaopts": options.SambaOptions,
+ "versionopts": options.VersionOptions,
+ "credopts": options.CredentialsOptions,
+ }
+
+ takes_options = [
+ Option("-H", "--URL", help="LDB URL for database or target server", type=str,
+ metavar="URL", dest="H"),
+ Option("--run-once", dest="run_once", default=False, action='store_true',
+ help="Whether to run the script only once"),
+ ]
+
+ takes_args = ["gpo", "script", "args?", "run_as?"]
+
+ def run(self, gpo, script, args=None, run_as=None, run_once=None,
+ H=None, sambaopts=None, credopts=None, versionopts=None):
+ pass
+
class cmd_startup(SuperCommand):
"""Manage Startup Scripts Group Policy Objects"""
subcommands = {}
subcommands["list"] = cmd_list_startup()
+ subcommands["add"] = cmd_add_startup()
class cmd_scripts(SuperCommand):
"""Manage Scripts Group Policy Objects"""
from configparser import ConfigParser
from io import StringIO
import xml.etree.ElementTree as etree
+from tempfile import NamedTemporaryFile
+from time import sleep
source_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../.."))
os.environ["PASSWORD"]))
self.assertNotIn(openssh, out, 'The test entry was still found!')
+ def test_startup_script_add(self):
+ lp = LoadParm()
+ fname = None
+ with NamedTemporaryFile() as f:
+ fname = os.path.basename(f.name)
+ f.write(b'#!/bin/sh\necho $@ hello world')
+ f.flush()
+ (result, out, err) = self.runsublevelcmd("gpo", ("manage",
+ "scripts", "startup",
+ "add"), self.gpo_guid,
+ f.name, "'-n'", "-H",
+ "ldap://%s" %
+ os.environ["SERVER"],
+ "-U%s%%%s" %
+ (os.environ["USERNAME"],
+ os.environ["PASSWORD"]))
+ self.assertCmdSuccess(result, out, err, 'Script add failed')
+
+ script_path = '\\'.join(['\\', lp.get('realm').lower(), 'Policies',
+ self.gpo_guid, 'MACHINE\\VGP\\VTLA\\Unix',
+ 'Scripts\\Startup', fname])
+ entry = '@reboot root %s -n' % script_path
+ (result, out, err) = self.runsublevelcmd("gpo", ("manage", "scripts",
+ "startup", "list"),
+ self.gpo_guid, "-H",
+ "ldap://%s" %
+ os.environ["SERVER"],
+ "-U%s%%%s" %
+ (os.environ["USERNAME"],
+ os.environ["PASSWORD"]))
+ self.assertIn(entry, out, 'The test entry was not found!')
+ local_path = lp.get('path', 'sysvol')
+ local_script_path = os.path.join(local_path, lp.get('realm').lower(),
+ 'Policies', self.gpo_guid,
+ 'Machine/VGP/VTLA/Unix',
+ 'Scripts/Startup', fname)
+ self.assertTrue(os.path.exists(local_script_path),
+ 'The test script was not uploaded to the sysvol')
+
def test_startup_script_list(self):
lp = LoadParm()
lp.load(os.environ['SERVERCONFFILE'])