Sysfunc Reference Guide

Print
Read : 4,579 times
(1 vote, average 5.00 out of 5)



This documentation is extracted from the sysfunc code.

It is re-generated and published for every sysfunc release (master branch). So, it always documents the latest release.


cfg_check

Aborts if the given parameter is not a valid one

Arguments

$1Parameter

Returns

Only if parameter is valid

Displays

If parameter is invalid, aborts with error message

cfg_display

Display the parameters along with their default and actual values

Arguments

None

Returns

0

Displays

Parameters

cfg_dump

Display parameters with actual value in raw format

Format of each line : <parameter><space><value>

The output of this function does not allow to say if a value is the default one or not.

Arguments

None

Returns

0

Displays

List of '<parameter><space><value>' lines

cfg_exists

Check that the given parameter is a valid one

Actually, parameter is valid if a default value is registered for this param.

Arguments

$1Parameter

Returns

0 if parameter exists, =!0 if not

Displays

nothing

cfg_get

Get parameter value

If parameter is set, returns set value. Else, returns default value.

Arguments

$1Parameter

Returns

Only if parameter is valid

Displays

Parameter value

cfg_get_default

Get parameter default value

Arguments

$1Parameter

Returns

Only if parameter is valid

Displays

Parameter default value

cfg_info

Display parameter information

Arguments

$*Optional. List of parameters. If empty, display every defined parameters

Returns

0

Displays

Parameters and related information

cfg_isset

Check if a parameter is explicitely set (not default)

Arguments

$1Parameter

Returns

0 if parameter is set (not default value), 1 if not set

Displays

nothing

cfg_list

List defined configuration parameters

Arguments

None

Returns

0

Displays

Defined parameters, one by line

cfg_set

Set an explicit parameter value

To reset a parameter to its default value, see cfg_unset

Arguments

$1Parameter
$2Value

Returns

Only if parameter is valid

Displays

Nothing

cfg_unset

Reset a parameter to its default value

Arguments

$1Parameter

Returns

Only if parameter is valid

Displays

Nothing

db_clear

Clear the whole database

Arguments

None

Returns

0

Displays

nothing

db_copy

Duplicate a variable (copy content)

If the source variable is not set, target is created with an empty value

Arguments

$1Source variable name
$2Target variable name

Returns

0

Displays

nothing

db_dump

Dump the database

Output format (each line) : <name><space><value><EOL>

The output is sorted alphabetically.

Arguments

None

Returns

0

Displays

DB content

db_expand

Replaces patterns in the form '{{%<variable name>%}}' by their value.

Allows nested substitutions (ex: {{%interface{{%hcfg:icount%}}/network%}}).

Patterns which do not correspond to an existing variable are replaced with an empty string.

Input: stdin, output: stdout.

Arguments

$1

Returns

0

Displays

Output

db_get

Get a variable value

If variable is not set, return an empty string (no error)

If global variable SF_DB_PATH contains '<stdin>', DB content is read from standard input.

Arguments

$1Variable name

Returns

0

Displays

Value or empty string if var not set

db_import

Import variables in dump format (one per line)

Lines are read from stdin

Arguments

None

Returns

0

Displays

nothing

db_isset

Check if a variable is set

If global variable SF_DB_PATH contains '<stdin>', DB content is read from standard input.

Arguments

$1Variable name

Returns

0 if variable is set, <> 0 if not

Displays

nothing

db_key

Build a key (regexp usable in grep) from a variable name

Arguments

$1Variable name

Returns

0

Displays

Key string

db_list

List DB keys alphabetically, one per line

Arguments

None

Returns

0

Displays

DB keys

db_normalize

Filter a name, leaving authorized chars only

Arguments

$1Variable name

Returns

0

Displays

Normalized name

db_rename

Rename a variable (keep content)

If the source variable is not set, target is created with an empty value

Arguments

$1Source variable name
$2Target variable name

Returns

0

Displays

nothing

db_set

Set a variable

Arguments

$1Variable name
$2Value

Returns

0

Displays

nothing

db_set_timestamp

Set a variable with the value returned by tm_now

Arguments

$1Variable name

Returns

0

Displays

nothing

db_unset

Unset a variable

No error if variable was not present in DB

Arguments

$*Variable names

Returns

0

Displays

nothing
This section contains functions to manipulate disks and block devices.

disk_category

Get category of content for a given disk device

Arguments

$1Device path

Returns

Always 0

Displays

'fs' if it is a filesystem 'swap' if it is a swap partition else, the type returned by disk_type()

disk_fs_size

Get the size of a file system (from device name)

File system can be mounted or not.

Note: In order to get the size of a mounted filesystem containing a given path, use fs_size.

Arguments

$1Device

Returns

0 if dev exists and contains a FS, else !=0.

Displays

FS size in bytes. If the device does not exist or does not contain a FS, displays nothing.

disk_normalize_device

Normalize a disk device name

After being normalized, device names can be compared.

Input can be in the form:

- /dev/<vg>/<lv> - /dev/mapper/... - /dev/<partition or disk> (as /dev/sda1) - LABEL=xxx - UUID=xxx

Output is in the form:

- /dev/<vg>/<lv> if LVM logical volume - /dev/<physical> if physical disk - Copy of input if input was not recognised

Arguments

$1Device name to normalize

Returns

0 if device exists, 1 if not

Displays

Normalized name if device exists, copy of input if not

disk_rescan

Scan and discover new SCSI devices

Calling program should wait between 5 and 10 seconds for new devices to be discovered.

Arguments

None

Returns

Always 0

Displays

Nothing

disk_type

Returns type of content for a given disk device

Arguments

$1Device path

Returns

Always 0

Displays

type returned by 'blkid' command

error

Displays an error message

If the SF_ERRLOG environment variable is set, it is supposed to contain a path. The error message will be appended to the file at this path. If the file does not exist, it will be created.

Arguments

$1 Message

Returns

Always 0

Displays

Error message

error_count

Display a count of errors detected so far

Arguments

None

Returns

Always 0

Displays

Error count

error_import

Import errors into the error system

This mechanism is generally used in conjunction with the $SF_ERRLOG variable. This variable is used to temporarily distract errors from the normal flow. Then, this function can be called to reinject errors into the default error repository.

Arguments

$1 Optional. File to import (1 error per line). If not set, takes input from stdin.

Returns

Always 0

Displays

Nothing

fatal

Displays an error message and aborts execution

Arguments

$1 message
$2 Optional. Exit code.

Returns

Does not return. Exits with the provided exit code if arg 2 set, with 1 if not.

Displays

Error and abort messages

show_errors

Display a list of errors detected so far

Arguments

None

Returns

Always 0

Displays

List of error messages, one by line

unsupported

Fatal error on unsupported feature

Call this function when a feature is not available on the current operating system (yet ?)

Arguments

$1 feature name

Returns

Does not return. Exits with code 2.

Displays

Error and abort messages

check_block

Replaces or prepends/appends a data block in a file

The block is composed of entire lines and is surrounded by special comment lines when inserted in the target file. These comment lines identify the data block and allow the function to be called several times on the same target file with different data blocks. The block identifier is the base name of the source path.

If the given block is not present in the target file, it is appended or prepended, depending on the flag argument. If the block is already present in the file (was inserted by a previous run of this function), its content is compared with the new data, and replaced if different. In this case, it is replaced at the exact location where the previous block lied.

If the target file exists, it is saved before being overwritten.

If the target path directory does not exist, it is created.

Arguments

$1If this arg starts with the '-' char, the data is to be read from stdin and the string after the '-' is the block identifier. If it does not start with '-', it is the path to the source file (containing the data to insert).
$2Target path
$3Optional. Target file mode.

Default=644

$4Optional. Flag. Set to 'prepend' to add data at the beginning of the file. Default mode: Append. Used only if data block is not already present in the file. Can be set to '' (empty string) to mean 'default mode'.
$5Optional. Comment character. This argument, if set, must contain only one character. This character will be used as first char when building the 'identifier' lines surrounding the data block. Default: '#'.

Returns

Always 0

Displays

Info msg

check_copy

Copy a file or the content of function's standard input to a target file

The copy takes place only if the source and target files are different. If the target file is already existing, it is saved before being overwritten. If the target path directory does not exist, it is created.

Arguments

$1Source path. Special value: '-' means that data to copy is read from stdin, allowing to produce dynamic content without a temp file.
$2Target path
$3Optional. File creation mode. Default=644

Returns

Always 0

Displays

Info msg

check_line

Checks if a given line is contained in a file

Takes a pattern and a string as arguments. The first line matching the pattern is compared with the string. If they are different, the string argument replaces the line in the file. If they are the same, the file is left unchanged. If the pattern is not found, the string arg is appended to the file. If the file does not exist, it is created.

Arguments

$1File path
$2Pattern to search
$3Line string

Returns

Always 0

Displays

Info msg

check_link

Creates or modifies a symbolic link

The target is saved before being modified.

If the target path directory does not exist, it is created.

Arguments

$1Link target
$2Link path

Returns

Always 0

Displays

Info msg

chmod

Change the mode of a set of files/dirs

Arguments

$1mode as accepted by chmod
$2+List of paths

Returns

chmod status code

Displays

Nothing

chown

Change the owner of a set of files/dirs

Arguments

$1owner[:group]
$2+List of paths

Returns

chown status code

Displays

Nothing

comment_out

Comment lines in a file

The lines containing the (grep) pattern given in argument will be commented out by prefixing them with the comment string. If the pattern is not contained in the file, the file is left unchanged.

Arguments

$1File path
$2Pattern to search (grep regex syntax)
$3Optional. Comment prefix string. Default='#'
$4Number of lines to comment (''=all). Default: ''

Returns

Always 0

Displays

Info msg

contains_block

Checks if a file contains a block inserted by check_block

Arguments

$1The block identifier or source path
$2File path

Returns

0 if the block is in the file, !=0 if not.

Displays

Nothing

create_dir

Creates a directory

If the given path argument corresponds to an already existing file (any type except directory or symbolic link to a directory), the program aborts with a fatal error. If you want to avoid this (if you want to create the directory, even if something else is already existing in this path), call delete first. If the path given as arg contains a symbolic link pointing to an existing directory, it is left as-is.

Arguments

$1 Path
$2 Optional. Directory owner[:group]. Default: root
$3 Optional. Directory mode in a format accepted by chmod. Default: 755

Returns

Always 0

Displays

Info msg

delete

Recursively deletes a file or a directory

Returns without error if arg is a non-existent path

Arguments

$1 Path to delete

Returns

Always 0

Displays

Info msg

file_checksum

Compute the checksum of a file

Computed checksum depends on the OS and software available. It is prefixed with a string giving the format, followed by a ':' and the chacksum in readable form.

Possible format strings, in preference order: SHA1, MD5, CKS, SUM.

Generate a fatal error if none of these mechanisms is found.

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

Checksum, nothing if file does not exist.

file_group

Return group of a file (numeric)

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

File group in numeric form (nothing if file does not exist)

file_is_link

Portable way to check if a file is a symbolic link

Note: Don't use 'test -h' (not portable)

Arguments

$1Path

Returns

0 if file exists and is a symbolic link, 1 if not

Displays

Nothing

file_mode

Return mode of a file in octal

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

File mode (nothing if file does not exist)

file_mtime

Return last modification time of a file (Unix format)

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

File last modification time in Unix format (Seconds since Epoch), nothing if file does not exist.

file_owner

Return owner of a file (numeric)

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

File owner in numeric form (nothing if file does not exist)

file_readlink

Get the link target of a symbolic link

Arguments

$1Path

Returns

0 if file exists and is a symbolic link, 1 if not

Displays

Link target if file exists and is a symbolic link, nothing otherwise

file_realpath

Canonicalize a file path

The input path must correspond to an existing item (file or dir, any type) Every directories leading to the source item must be readable by the current user.

This function preserves the current directory.

Arguments

$1Path

Returns

0 if canonical path could be determined, 1 if not

Displays

Canonical path, nothing if path does not exist or access denied

file_size

Return size of a file (in bytes)

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

File size (in bytes), nothing if file does not exist.

file_type

Get the type of a file

Arguments

$1Path

Returns

0 if file exists, 1 if not

Displays

- Nothing if file does not exist, - R: Regular file, - L: Symbolic link, - D: Directory, - C: Character device - B: Block device - P: Named pipe (fifo)

find_executable

Find an executable file

Arguments

$1 Executable name
$2 Optional. List of directories to search (separated by ':' chars). If not set, use PATH

Returns

0 if executable was found, 1 if not

Displays

Absolute path if found, nothing if not found

rename_to_old

Renames a file to '<dir>/old.<filename>

### This function is deprecated. Please use save instead.

Arguments

$1 Path

Returns

Always 0

Displays

Info msg

sort_file

Sort a file in-place

Arguments

$1Path
$2-*Optional. Sort options

Returns

Sort return code

Displays

Info msg

uncomment

Uncomment lines in a file

The commented lines containing the (grep) pattern given in argument will be uncommented by removing the comment string. If the pattern is not contained in the file, the file is left unchanged.

Arguments

$1File path
$2Pattern to search (grep regex syntax)
$3Optional. Comment prefix string. Default='#'
$4Number of lines to uncomment (''=all). Default: ''

Returns

Always 0

Displays

Info msg

create_fs

Create a file system, mount it, and register it (mount at boot)

### This function is deprecated. Please use fs_create.

Refuses existing directory as mount point (security)

Arguments

$1Mount point
$2device path
$3Optional. FS type (if empty, default FS type for this OS)
$4Optional. Mount point directory owner[:group]

Returns

0 if no error, 1 on error

Displays

Info msg

create_lv_fs

Create a logical volume and a filesystem on it

### This function is deprecated. Please use fs_create_lv_fs ### Warning: Note that superseding function has argument 4 and 5 swapped (size and FS type).

Combines create_lv and fs_create

Arguments

$1Mount point (directory)
$2Logical volume name
$3Volume group name
$4File system type (optional. if empty, defaults to default FS type for this OS)
$5Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG.
$6Optional. Directory owner[:group]

Returns

0: OK, !=0: Error

Displays

Info msg

fs_create

Create a file system, mount it, and register it (mount at boot)

Refuses existing directory as mount point (security)

Arguments

$1Mount point
$2device path
$3Optional. FS type (if empty, default FS type for this OS)
$4Optional. Mount point directory owner[:group]

Returns

0 if no error, 1 on error

Displays

Info msg

fs_create_lv_fs

Create a logical volume and a filesystem on it

Combines create_lv and fs_create

Arguments

$1Mount point (directory)
$2Logical volume name
$3Volume group name
$4Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG.
$5Optional. File system type. Defaults to default FS type for this environment
$6Optional. Directory owner[:group]

Returns

0: OK, !=0: Error

Displays

Info msg

fs_default_type

Returns default FS type for current environment

Arguments

None

Returns

Always 0

Displays

Type

fs_device

Gets the device of the filesystem containing a given path

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

The normalized device of the filesystem containing the element

fs_extend

Extend a file system to a given size

Arguments

$1A path contained in the file system to extend
$2The new size in Mbytes, or the size to add if prefixed with a '+'

Returns

Always 0

Displays

Info msg

fs_is_mount_point

Checks if a directory is a file system mount point

A filesystem must be mounted on the directory for it to be recognized as a mount point.

Arguments

$1Directory to check

Returns

0 if true, !=0 if false

Displays

nothing

fs_mount_point

Gets the mount point of the filesystem containing a given path

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

The mount directory of the filesystem containing the element

fs_size

Get the size of the filesystem containing a given path

Note: This function is to be used for a mounted filesystem. In order to get the size of a file system contained in a given device (mounted or not), use disk_fs_size.

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

FS size in Mbytes

get_fs_device

Gets the device of the filesystem containing a given path

### This function is deprecated. Please use fs_device.

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

The normalized device of the filesystem containing the element

get_fs_mnt

Gets the mount point of the filesystem containing a given path

### This function is deprecated. Please use fs_mount_point.

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

The mount directory of the filesystem containing the element

get_fs_size

Get the size of the filesystem containing a given path

### This function is deprecated. Please use fs_size.

Arguments

$1Path (must correspond to an existing element)

Returns

Always 0

Displays

FS size in Mbytes

has_dedicated_fs

Checks if a directory is a file system mount point

### This function is deprecated. Please use fs_is_mount_point.

Arguments

$1Directory to check

Returns

0 if true, !=0 if false

Displays

nothing

set_fs_space

Extend a file system to a given size

### This function is deprecated. Please use fs_extend.

Arguments

$1A path contained in the file system to extend
$2The new size in Mbytes, or the size to add if prefixed with a '+'

Returns

Always 0

Displays

Info msg

ip4_is_valid_ip

Checks if the input string is a valid IP address

Arguments

$1IP address to check

Returns

0 if address is valid, !=0 if not

Displays

Nothing

ip4_network

Compute network from IP and netmask

Arguments

$1IP
$2Netmask

Returns

0

Displays

Network

ip4_validate_ip

Checks if the input string is a valid IP address and aborts if not

Arguments

$1IP address to check

Returns

only if address is valid

Displays

Nothing if OK. Error if not

krn_module_is_loaded

Check if a kernel module is loaded

Arguments

$1Module name

Returns

0 if module is loaded, 1 if not

Displays

Nothing

create_lv

Create a logical volume

Arguments

$1Logical volume name
$2Volume group name
$3Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG.

Returns

0: OK, !=0: Error

Displays

Info msg

create_vg

Create a volume group

Arguments

$1volume group name
$2PE size (including optional unit, default=Mb)
$3Device path, without the /dev prefix

Returns

0: OK, !=0: Error

Displays

Info msg

lv_exists

Checks if a given logical volume exists

Arguments

$1VG name
$2LV name

Returns

0 if it exists, 1 if not

Displays

Nothing

lv_to_vg

Returns the VG containing a given LV

Arguments

$1LV device path

Returns

Always 0

Displays

The containing VG name, or nothing if device is not a valid LV.

lvm_vg_free

Returns the available size in a VG (in Mb)

Arguments

$1VG name

Returns

Always 0

Displays

The available size in Mbytes. Nothing if VG does not exist.

vg_exists

Checks if a given volume group exists

Arguments

$1VG name

Returns

0 if it exists, 1 if not

Displays

Nothing

cleanup

Cleanup at exit

This function discards every allocated resources (tmp files,...)

Arguments

None

Returns

Always 0

Displays

nothing

exec_url

Retrieves executable data through an URL and executes it.

Supports any URL accepted by wget.

By default, the 'wget' command is used. If the $WGET environment variable is set, it is used instead (use, for instance, to specify a proxy or an alternate configuration file).

Arguments

$1 Url

Returns

the return code of the executed program

Displays

data displayed by the executed program

finish

Finish execution

This function discards every allocated resources (tmp files,...)

Arguments

$1Ooptional. Exit code. Default: 0

Returns

Never returns. Exits from program.

Displays

nothing

func_is_defined

Check if a shell function is defined

Arguments

$1Function name

Returns

0 if function is defined, 1 if not

Displays

Nothing

help

Display help

Arguments

None

Returns

No return

Displays

Help message

loaded

Checks if the library is already loaded

Of course, if it can run, the library is loaded. So, it always returns 0.

Allows to support the 'official' way to load sysfunc :

sf_loaded 2>/dev/null || . sysfunc.sh

Arguments

None

Returns

Always 0

Displays

Nothing

txt_cleanup

Uncomment and cleanup input stream

- changes tabs to spaces, - changes multiple blanks to one space, - removes leading and trailing blanks, - removes comments (starting with '#'), - removes blank lines

Arguments

$1Optional. File to read from. If not set, read from stdin

Returns

Always 0

Displays

the cleaned stream

version

Displays library version

Arguments

None

Returns

Always 0

Displays

Library version (string)

banner

Displays a 'banner' message

The message is displayed with an horizontal separator line above and below

Arguments

$1 message

Returns

Always 0

Displays

message

debug

Display debug message

If $sf_verbose_level >= 2, displays the message.

Arguments

$1 message

Returns

Always 0

Displays

message if verbose level set to debug (2) or more

msg

Displays a message (string)

If the $sf_noexec environment variable is set, prefix the message with '(n)'

Arguments

$1 message

Returns

Always 0

Displays

Message

msg1

Displays a message prefixed with spaces

Arguments

$1 message

Returns

Always 0

Displays

message prefixed with spaces

msg_section

Displays a 'section' message

This is a message prefixed with a linefeed and some hyphens. To be used as paragraph/section title.

Arguments

$1 message

Returns

Always 0

Displays

Message

newline

Display a new line

Arguments

None

Returns

Always 0

Displays

new line

separator

Displays a separator line

Arguments

None

Returns

Always 0

Displays

separator line

trace

Display trace message

If the $sf_verbose environment variable is set or $sf_verbose_level >= 1, displays the message.

Arguments

$1 message

Returns

Always 0

Displays

message if verbose mode is active, nothing if not

warning

Displays a warning message

Arguments

$1 message

Returns

Always 0

Displays

Warning message

ask

Ask a question to the user

Arguments

$1 Question

Returns

Always 0

Displays

message to stderr, answer to stdout

yn_question

Asks a 'yes/no' question, gets answer, and return yes/no code

Works at least for questions in english, french, and german : Accepts 'Y', 'O', and 'J' for 'yes' (upper or lowercase), and anything different is considered as 'no'

If the $sf_forceyes environment variable is set, the user is not asked and the 'yes' code is returned.

Arguments

$1 Question string

Returns

0 for 'yes', 1 for 'no'

Displays

Question and typed answer if $sf_forceyes not set, nothing if $sf_forceyes is set.

dns_addr_to_name

Resolves an IP address through the DNS

If the address cannot be resolved, displays nothing

Arguments

$1IP address
$2Optional. DNS server to ask

Returns

Always 0

Displays

Host name as returned by the DNS or nothing if address could not be resolved.

dns_name_to_addr

Resolves a host name through the DNS

If the name cannot be resolved, displays nothing

Arguments

$1Host name to resolve
$2Optional. DNS server to ask

Returns

Always 0

Displays

IP address as returned by the DNS or nothing if name could not be resolved.

domain_part

Suppresses the host name part from a FQDN

Displays the input string without the beginning up to and including the first '.'.

Arguments

$1Input FQDN

Returns

Always 0

Displays

truncated string

host_part

Extracts a hostname from an FQDN

Removes everything from the first dot up to the end of the string

Arguments

$1Input FQDN

Returns

Always 0

Displays

truncated string

primary_ip_address

Get the primary address of the system

This is an arbitrary choice, such as the address assigned to the first network nterface. Feel free to improve !

Arguments

None

Returns

Always 0

Displays

IP address or nothing if no address was found

compute_os_id

Alias of os_id

### This function is deprecated. Please use os_id

Arguments

None

Returns

Always 0

Displays

OS ID string

find_posix_shell

Find a Posix-compatible shell on the current host

Search a bash shell first, then ksh

Arguments

None

Returns

Always 0

Displays

Shell path if found, nothing if not found

os_arch

Display the current OS architecture (aka 'hardware platform')

Arguments

None

Returns

0

Displays

OS distrib

os_distrib

Display the current OS distribution

Arguments

None

Returns

0

Displays

OS distrib

os_family

Display the current OS family (Linux, SunOS,...)

Arguments

None

Returns

0

Displays

OS distrib

os_id

Computes and displays a string defining the curent system environment

The displayed string is a combination of the OS name, version, system architecture and may also depend on other parameters like, for instance, the RedHat ES/AS branches. It is an equivalent of the 'channel' concept used by RedHat. I personnally call it 'OS ID' for 'OS IDentifier' and use it in every script where I need a single string to identify the system environment the script is currently running on.

If the current system is not recognized, the program aborts.

By convention, environments recognized by this function support the rest of the library.

**Contributors welcome !** Feel free to enhance this function with additional recognized systems, especially with other Linux distros, and send me your patches.

Arguments

None

Returns

Always 0

Displays

OS ID string

os_version

Display the current OS version

Arguments

None

Returns

0

Displays

OS distrib

poweroff

Shutdown and poweroff the host

Arguments

None

Returns

does not return

Displays

nothing

reboot

Shutdown and restart the host

Arguments

None

Returns

does not return

Displays

nothing

shutdown

Shutdown and halt the host

Arguments

None

Returns

does not return

Displays

nothing
This feature is still under development: so far, only regular files and symbolic links are supported. Other file types are ignored and not saved.

sav_zap

Delete eveything that was saved on this host

Arguments

None

Returns

Always 0

Displays

Nothing

save

Saves a file

No action if the **$sf_nosave** environment variable is set to a non-empty string.

If the input arg is the path of an existing regular file or symbolic link, the file is saved.

If the file cannot be saved (copy or dir creation failure), a fatal error is raised and the program is aborted.

Arguments

$1 Path. Beware! Arg can contain any char (including blanks)

Returns

Always 0

Displays

Info msg

soft_available_version

Get the available version of an upgradeable package

Arguments

$1Software name

Returns

0 if an update is available, 1 if not installed, 2 if up-to-date

Displays

Available version if one exists, nothing if not

soft_clean_cache

Clean the software installation cache

Arguments

None

Returns

Always 0

Displays

Nothing

soft_exists

Check if software exists (installed or available for installation)

Arguments

$1Software name

Returns

0 if software exists, 1 if not

Displays

Nothing

soft_install

Install software(s) if not already present on the host

If a software is installed but not up to date, it is not upgraded.

Arguments

$*Software name(s)

Returns

Always 0

Displays

Info msg

soft_install_upgrade

Install or upgrade software(s)

For each of the software names supplied as arguments :

- if the software is not installed, install it, - if the software is installed and upgradeable, upgrade it, - if the software is up-to-date, do nothing.

Arguments

$*Software name(s)

Returns

Always 0

Displays

Info msg

soft_is_installed

Check if a software is installed

Arguments

$1Software name

Returns

0 if software is installed, 1 if not.

Displays

Nothing

soft_is_up_to_date

Check if a software is installed and the latest version

Arguments

$1Software name

Returns

0 if software is up-to-date, 1 if not installed, 2 if upgradeable.

Displays

Nothing

soft_is_upgradeable

Check if a newer version of a software is available

Note : if the software is not installed, it is not considered as upgradeable

Arguments

$1Software name

Returns

0 if the software is upgradeable, !=0 if not.

Displays

Nothing

soft_list

List installed software

Returns a sorted list of installed software

Linux output: (name-version-release.arch)

Arguments

None

Returns

Always 0

Displays

software list

soft_reinstall

Reinstall software(s), even at same version

Arguments

$*Software name(s)

Returns

Always 0

Displays

Info msg

soft_remove

Uninstall software(s) (ignoring and bypassing dependencies)

Nothing is done for softwares which are not present on the host.

Arguments

$*Software name(s)

Returns

Always 0

Displays

Info msg

soft_repo_list

List defined software repository names

Arguments

None

Returns

Always 0

Displays

List of software repositories, one per line

soft_uninstall

Uninstall software(s) (including dependencies)

Nothing is done for softwares which are not present on the host.

Arguments

$*Software name(s)

Returns

Always 0

Displays

Info msg

soft_version

get version of an installed software

Arguments

$1Software name

Returns

0 if software is installed, 1 otherwise.

Displays

Software version (nothing if soft is not installed)

svc_base

Display the base directory of service scripts

Arguments

None

Returns

Always 0

Displays

String

svc_disable

Disable service start/stop at system boot/shutdown

Arguments

$*Service names

Returns

Always 0

Displays

Info msg

svc_enable

Enable service start/stop at system boot/shutdown

Arguments

$*Service names

Returns

Always 0

Displays

Info msg

svc_install

Install a service script (script to start/stop a service)

Arguments

$1Source script
$2Service name

Returns

Always 0

Displays

Info msg

svc_is_enabled

Check if a service is enabled on boot

On Linux, check for current runlevel. On Solaris, check for level 3.

Arguments

$1Service name

Returns

0 if enabled, 1 if diasabled, 2 if not installed

Displays

Nothing

svc_is_installed

Check if a service script is installed

Arguments

$1Service name

Returns

0 is installed, 1 if not

Displays

Nothing

svc_is_up

Check if a service is running

Arguments

$1Service name

Returns

0 if service is running, 1 if stopped, 2 if not installed

Displays

Nothing

svc_script

Display the full path of the script corresponding to a given service

Arguments

$1Service name

Returns

Always 0

Displays

Script path

svc_start

Start a service

'noexec' does not disable starting/stopping services.

Arguments

$1Service name

Returns

Return code from script execution

Displays

Output from service script

svc_stop

Stop a service

'noexec' does not disable starting/stopping services.

Arguments

$1Service name

Returns

Return code from script execution

Displays

Output from service script

svc_uninstall

Uninstall a service script (script to start/stop a service)

Arguments

$1Service name

Returns

Always 0

Displays

Info msg

tm_date

Display current date as 'DD-Mmm-YYYY'

Local time is the default. If the SF_TM_UTC environment variable is set to a non empty value, UTC time is displayed. This will change date if time is near midnight and local/utc times correspond to different dates.

Arguments

None

Returns

0

Displays

Time string

tm_now

Display normalized time string for current time (local or UTC)

Local time is the default. If the SF_TM_UTC environment variable is set to a non empty value, UTC time is displayed.

Default format: DD-Mmm-YYYY HH:MM:SS (<Unix time>)

Arguments

$1Optional. Date format (without the leading '+'). See date(1) man page for more details on macros supported in format string.

Returns

date command return code (!=0 if syntax error in format)

Displays

Time string

tm_timestamp

Display Unix current time (Seconds since Epoch)

Arguments

None

Returns

0

Displays

Time string

get_tmp

Returns an unused temporary path

### This function is deprecated. Please use tmpfile or tmpdir instead

The returned path can then be used to create a directory or a file.

Arguments

None

Returns

Always 0

Displays

An unused temporary path

tmpdir

Creates an empty temporary dir and returns its path

Arguments

None

Returns

Always 0

Displays

Temporary dir path

tmpfile

Creates an empty temporary file and returns its path

Arguments

None

Returns

Always 0

Displays

Temporary file path

create_group

Create a user group

Arguments

$1Group name
$2Group Id

Returns

Status from system command

Displays

Info msg

create_user

Create a user

To set the login shell, initialize the CREATE_USER_SHELL variable before calling the function.

For accounts with no access allowed (blocked accounts), $7, $8, and $9 are not set.

Arguments

$1User name
$2uid
$3gid
$4description (gecos)
$5home dir (can be '' for '/none')
$6Additional groups (separated with ',')
$7encrypted password (Linux)
$8encrypted password (HP-UX & SunOS)
$9encrypted password (AIX)

Returns

Always 0

Displays

Info msg

delete_group

Remove a group

Arguments

$1Group name

Returns

Status from system command

Displays

nothing

delete_user

Remove a user account

Arguments

$1User name

Returns

Status from system command

Displays

nothing

set_passwd

Change a user's password

Works on HP-UX, Solaris, and Linux.

Replaces an encrypted passwd in /etc/passwd or /etc/shadow.

TODO: Unify with AIX and autodetect the file to use (passwd/shadow)

Arguments

$1Username
$2Encrypted password
$3File path

Returns

Always 0

Displays

Nothing

set_passwd_aix

Set an AIX password

TODO: Unify with other supported OS

Arguments

$1Username
$2Encrypted password

Returns

Always 0

Displays

nothing

user_exists

Checks if a given user exists on the system

Arguments

$1User name to check

Returns

0 if user exists; != 0 if not

Displays

nothing

user_gid

Return GID of a given user

Arguments

$1User name

Returns

0 if user exists, 1 if not

Displays

Primary GID if user exists, nothing if not

user_uid

Return UID of a given user

Arguments

$1User name

Returns

0 if user exists, 1 if not

Displays

UID if user exists, nothing if not

vm_host_is_vmware

Check if we are on a VMware host

Arguments

None

Returns

0 if VMware, 1 if not

Displays

Nothing
 
Joomla SEO powered by JoomSEF