YaST2 Developers Documentation: SCR System agent functions



SCR System agent functions

Execute (.target.bash, string command, map environment) -> integer
Execute (.target.bash_background, string command, map environment) -> integer
Execute (.target.bash_output, string command, map environment) -> map

Runs a bash command. The command is stated as string. The map variables can be used to give initial environment definitions to the target. The keys have to be strings, the values can be of any type. If you use string values, the strings may _not_ contain single quotes. Escape them with double backqoute, if you need them. This is subject to change.

The return value will be either an integer with the exitcode of the shell script or a map:

$[
"exit" : <integer>, //exitcode from shell script
"stdout" : <string>, //stdout of the command
"stderr" : <string> //stderr of the command ]

Example:

Execute (.target.bash, "/bin/touch $FILE ; exit 5", $["FILE":"/somedir/somefile"]) -> 5
Example:
Execute (.target.bash_output, "/bin/touch $FILE ; exit 5", $["FILE":"/somedir/somefile"]) -> $[ "exit" : 5, "stdout" : "", "stderr" : ""]

Execute (.target.bash_input, string command, string input) -> integer

Note: Function has only one used within YaST2 and is subject to sudden change or removal.

Read (.target.byte, string filename) -> byteblock

Opens a binary file and reads its contents into a single byteblock.

Write (.target.byte, string filename, byteblock) -> boolean

Write a byteblock into a file.

Execute (.target.control.printer_reset, string device) -> boolean

Reset the given printer (trigger ioctl)

The return value is true or false, depending of the success

Read (.target.dir, string path) -> list
Read (.target.dir, [string path, list default]) -> list

Reads a directory. Returns a list of strings, one string for each file contained in the directory path is pointing to. The entries '.' and '..' are NOT returned. Returns nil and doesn't log an error, if path does not point to a readable directory. If a default value is given, this is returned if path isn't accessible.

Example:

Read (.target.dir, "/proc/self") -> [ "cmdline", "cwd", "environ", ... ]

Execute (.target.insmod, string module, string options) -> boolean

Load module in target system.

The return value is true or false, depending of the success.

Example:

Execute (.target.insmod, "a_module", "an option")

Execute (.target.kill, integer pid [, integer signal]) -> boolean

Kill process with signal (SIGTERM if not specified).

The return value is true or false, depending of the success.

Example:

Execute (.target.kill, 1, 9)

Read (.target.lstat, string filename) -> map

Return a map with file information (see stat(2)). If the file does not exist return an empty map.

Execute (.target.mkdir, string path <, integer mode>)) -> boolean

Creates a directory and all its parents, if necessary. All created elements will have mode 0755 if mode is omitted.

The return value is true or false, depending of the success, ie if the directory exists afterwards.

Example:

Execute (.target.mkdir, "/var/adm/mount")

Execute (.target.modprobe, string module, string options) -> boolean

Load module in target system.

The return value is true or false, depending of the success.

Example:

Execute (.target.modprobe, "a_module", "an option")

Execute (.target.mount, [ string device, string mountpoint <, string logfile>], [, string options])) -> boolean

Mounts a (block) device at a mountpoint. If logfile is given, the stderr of the mount cmd will be appended to this file

The return value is true or false, depending of the success

Example:

Execute (.target.mount, ["/dev/fd0", "/floppy"], "-t msdos")
Example:
Execute (.target.mount, ["/dev/fd0", "/floppy", "/var/log/y2mountlog"], "-t msdos")

Write (.target.passwd.<name>, string cryptval) -> bool

.passwd can be used to set or modify the encrypted password of an already existing user in /etc/passwd and /etc/shadow.

This call returns true on success and false, if it fails.

Example:

Write (.target.passwd.root, crypt (a_passwd))

Execute (.target.remove, string file) -> boolean

Remove a file.

The return value is true or false depending on the success.

Example:

Execute (.target.remove, "/tmp/xyz")

Read (.target.size, string filename) -> integer

return current size of file returns -1 if the file does not exist

Execute (.target.smbmount, [ string server_and_dir, string mountpoint <, string logfile>], [, string options])) -> boolean

Mounts a SMB share at a mountpoint. if logfile is given, the stderr of the mount cmd will be appended to this file

The return value is true or false, depending of the success

Example:

Execute (.target.smbmount, ["//windows/crap", "/crap"], "-o guest")
Example:
Execute (.target.smbmount, ["//smb/share", "/smbshare", "/var/log/y2mountlog"])

Read (.target.stat, string filename) -> map

Return a map with file information (see stat(2)). If the file does not exist return an empty map.

Read (.target.string, string filename) -> string

Opens an Ascii file and reads the contents to a single string. Newlines are preserved.

Example:

Read (.target.string, "/some/file") -> "a contents"

Write (.target.string, string filename, string value) -> boolean

Writes the string value into a file. If the file already exists, the existing file is overwritten. The return value is true, if the file has been written successfully.

Execute (.target.symlink, string oldpath, string newpath) -> boolean

Creates a symbolic link named newpath which contains the string oldpath.

Symbolic links are interpreted at run-time as if the con­ tents of the link had been substituted into the path being followed to find a file or directory.

The return value is true or false, depending of the success.

Example:

Execute (.target.symlink, "/lib/YaST2", "Y2")

Read (.target.symlink, string filename) -> string

Returns the content of the symbolic link filename. If the filename does not exist or is no symbolic link, nil is returned and an error logged.

Example:

Read (.target.symlink, "/var/X11R6/bin/X")

Read (.target.tmpdir) -> string

Returns the (instance specific) directory for storing temporary files. The directory (and its contents) will be removed by the SystemAgent destructor (usually when yast2 exits)

Example:

Read (.target.tmpdir) -> "/some/temp/dir"

Execute (.target.umount, string mountpoint) -> boolean

Unmounts a (block) device at a mountpoint.

The return value is true or false, depending of the success.

Example:

Execute (.target.umount, "/floppy")

Read (.target.yast2, string filename) -> any
Read (.target.yast2, string filename, [any default = nil]) -> any

Opens a file that must be in YCP syntax and contain exactly one value, parses that file and returns the parsed value. Returns default, if the file didn't exist, was not readable or did not contain a valid YCP value.

The purpose of this function is to load data located in ydatadir. The data may also be located in any of the paths in source/core/liby2/src/pathsearch.cc appended by "data/". The filename must be relative to one of those paths.

A warning in the log is omitted if a default value is given.

Read (.target.ycp, string filename) -> any
Read (.target.ycp, string filename, [any default = nil]) -> any

Opens a file that must be in YCP syntax and contain exactly one value, parses that file and returns the parsed value. Returns 'default', if the file didn't exist, was not readable or didn't not contain a valid YCP value. A warning in the log is omitted if a default value is given.

Write (.target.ycp, string filename, any value) -> boolean

Opens a file for writing and prints the value value in YCP syntax to that file. Returns true, if the file has been written, false otherwise. The newly created file gets the mode 0644 minus umask. Furthermore any missing directory in the pathname filename is created automatically.

Write (.target.ycp, [ string filename, integer mode], any value) -> boolean

Opens a file for writing and prints the value value in YCP syntax to that file. Returns true, if the file has been written, false otherwise. The newly created file gets the mode mode minus umask. Furthermore any missing directory in the pathname filename is created automatically.


YaST2 Developers Documentation: SCR System agent functions