
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
$1 | Parameter |
Returns
Only if parameter is validDisplays
If parameter is invalid, aborts with error messagecfg_display
Display the parameters along with their default and actual values
Arguments
None
Returns
0Displays
Parameterscfg_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
0Displays
List of '<parameter><space><value>' linescfg_exists
Check that the given parameter is a valid one
Actually, parameter is valid if a default value is registered for this param.
Arguments
$1 | Parameter |
Returns
0 if parameter exists, =!0 if notDisplays
nothingcfg_get
Get parameter value
If parameter is set, returns set value. Else, returns default value.
Arguments
$1 | Parameter |
Returns
Only if parameter is validDisplays
Parameter valuecfg_get_default
Get parameter default value
Arguments
$1 | Parameter |
Returns
Only if parameter is validDisplays
Parameter default valuecfg_info
Display parameter information
Arguments
$* | Optional. List of parameters. If empty, display every defined parameters |
Returns
0Displays
Parameters and related informationcfg_isset
Check if a parameter is explicitely set (not default)
Arguments
$1 | Parameter |
Returns
0 if parameter is set (not default value), 1 if not setDisplays
nothingcfg_list
List defined configuration parameters
Arguments
None
Returns
0Displays
Defined parameters, one by linecfg_set
Set an explicit parameter value
To reset a parameter to its default value, see cfg_unset
Arguments
$1 | Parameter |
$2 | Value |
Returns
Only if parameter is validDisplays
Nothingcfg_unset
Reset a parameter to its default value
Arguments
$1 | Parameter |
Returns
Only if parameter is validDisplays
Nothingdb_clear
Clear the whole database
Arguments
None
Returns
0Displays
nothingdb_copy
Duplicate a variable (copy content)
If the source variable is not set, target is created with an empty value
Arguments
$1 | Source variable name |
$2 | Target variable name |
Returns
0Displays
nothingdb_dump
Dump the database
Output format (each line) : <name><space><value><EOL>
The output is sorted alphabetically.
Arguments
None
Returns
0Displays
DB contentdb_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
0Displays
Outputdb_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
$1 | Variable name |
Returns
0Displays
Value or empty string if var not setdb_import
Import variables in dump format (one per line)
Lines are read from stdin
Arguments
None
Returns
0Displays
nothingdb_isset
Check if a variable is set
If global variable SF_DB_PATH contains '<stdin>', DB content is read from standard input.
Arguments
$1 | Variable name |
Returns
0 if variable is set, <> 0 if notDisplays
nothingdb_key
Build a key (regexp usable in grep) from a variable name
Arguments
$1 | Variable name |
Returns
0Displays
Key stringdb_list
List DB keys alphabetically, one per line
Arguments
None
Returns
0Displays
DB keysdb_normalize
Filter a name, leaving authorized chars only
Arguments
$1 | Variable name |
Returns
0Displays
Normalized namedb_rename
Rename a variable (keep content)
If the source variable is not set, target is created with an empty value
Arguments
$1 | Source variable name |
$2 | Target variable name |
Returns
0Displays
nothingdb_set
Set a variable
Arguments
$1 | Variable name |
$2 | Value |
Returns
0Displays
nothingdb_set_timestamp
Set a variable with the value returned by tm_now
Arguments
$1 | Variable name |
Returns
0Displays
nothingdb_unset
Unset a variable
No error if variable was not present in DB
Arguments
$* | Variable names |
Returns
0Displays
nothingThis section contains functions to manipulate disks and block devices.
disk_category
Get category of content for a given disk device
Arguments
$1 | Device path |
Returns
Always 0Displays
'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
$1 | Device |
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
$1 | Device name to normalize |
Returns
0 if device exists, 1 if notDisplays
Normalized name if device exists, copy of input if notdisk_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 0Displays
Nothingdisk_type
Returns type of content for a given disk device
Arguments
$1 | Device path |
Returns
Always 0Displays
type returned by 'blkid' commanderror
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 0Displays
Error messageerror_count
Display a count of errors detected so far
Arguments
None
Returns
Always 0Displays
Error counterror_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 0Displays
Nothingfatal
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 messagesshow_errors
Display a list of errors detected so far
Arguments
None
Returns
Always 0Displays
List of error messages, one by lineunsupported
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 messagescheck_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
$1 | If 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). |
$2 | Target path |
$3 | Optional. Target file mode.
Default=644 |
$4 | Optional. 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'. |
$5 | Optional. 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 0Displays
Info msgcheck_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
$1 | Source path. Special value: '-' means that data to copy is read from stdin, allowing to produce dynamic content without a temp file. |
$2 | Target path |
$3 | Optional. File creation mode. Default=644 |
Returns
Always 0Displays
Info msgcheck_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
$1 | File path |
$2 | Pattern to search |
$3 | Line string |
Returns
Always 0Displays
Info msgcheck_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
$1 | Link target |
$2 | Link path |
Returns
Always 0Displays
Info msgchmod
Change the mode of a set of files/dirs
Arguments
$1 | mode as accepted by chmod |
$2+ | List of paths |
Returns
chmod status codeDisplays
Nothingchown
Change the owner of a set of files/dirs
Arguments
$1 | owner[:group] |
$2+ | List of paths |
Returns
chown status codeDisplays
Nothingcomment_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
$1 | File path |
$2 | Pattern to search (grep regex syntax) |
$3 | Optional. Comment prefix string. Default='#' |
$4 | Number of lines to comment (''=all). Default: '' |
Returns
Always 0Displays
Info msgcontains_block
Checks if a file contains a block inserted by check_block
Arguments
$1 | The block identifier or source path |
$2 | File path |
Returns
0 if the block is in the file, !=0 if not.Displays
Nothingcreate_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 0Displays
Info msgdelete
Recursively deletes a file or a directory
Returns without error if arg is a non-existent path
Arguments
$1 | Path to delete |
Returns
Always 0Displays
Info msgfile_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
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
Checksum, nothing if file does not exist.file_group
Return group of a file (numeric)
Arguments
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
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
$1 | Path |
Returns
0 if file exists and is a symbolic link, 1 if notDisplays
Nothingfile_mode
Return mode of a file in octal
Arguments
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
File mode (nothing if file does not exist)file_mtime
Return last modification time of a file (Unix format)
Arguments
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
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
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
File owner in numeric form (nothing if file does not exist)file_readlink
Get the link target of a symbolic link
Arguments
$1 | Path |
Returns
0 if file exists and is a symbolic link, 1 if notDisplays
Link target if file exists and is a symbolic link, nothing otherwisefile_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
$1 | Path |
Returns
0 if canonical path could be determined, 1 if notDisplays
Canonical path, nothing if path does not exist or access deniedfile_size
Return size of a file (in bytes)
Arguments
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
File size (in bytes), nothing if file does not exist.file_type
Get the type of a file
Arguments
$1 | Path |
Returns
0 if file exists, 1 if notDisplays
- 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 notDisplays
Absolute path if found, nothing if not foundrename_to_old
Renames a file to '<dir>/old.<filename>
### This function is deprecated. Please use save instead.
Arguments
$1 | Path |
Returns
Always 0Displays
Info msgsort_file
Sort a file in-place
Arguments
$1 | Path |
$2-* | Optional. Sort options |
Returns
Sort return codeDisplays
Info msguncomment
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
$1 | File path |
$2 | Pattern to search (grep regex syntax) |
$3 | Optional. Comment prefix string. Default='#' |
$4 | Number of lines to uncomment (''=all). Default: '' |
Returns
Always 0Displays
Info msgcreate_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
$1 | Mount point |
$2 | device path |
$3 | Optional. FS type (if empty, default FS type for this OS) |
$4 | Optional. Mount point directory owner[:group] |
Returns
0 if no error, 1 on errorDisplays
Info msgcreate_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
$1 | Mount point (directory) |
$2 | Logical volume name |
$3 | Volume group name |
$4 | File system type (optional. if empty, defaults to default FS type for this OS) |
$5 | Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG. |
$6 | Optional. Directory owner[:group] |
Returns
0: OK, !=0: ErrorDisplays
Info msgfs_create
Create a file system, mount it, and register it (mount at boot)
Refuses existing directory as mount point (security)
Arguments
$1 | Mount point |
$2 | device path |
$3 | Optional. FS type (if empty, default FS type for this OS) |
$4 | Optional. Mount point directory owner[:group] |
Returns
0 if no error, 1 on errorDisplays
Info msgfs_create_lv_fs
Create a logical volume and a filesystem on it
Combines create_lv and fs_create
Arguments
$1 | Mount point (directory) |
$2 | Logical volume name |
$3 | Volume group name |
$4 | Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG. |
$5 | Optional. File system type. Defaults to default FS type for this environment |
$6 | Optional. Directory owner[:group] |
Returns
0: OK, !=0: ErrorDisplays
Info msgfs_default_type
Returns default FS type for current environment
Arguments
None
Returns
Always 0Displays
Typefs_device
Gets the device of the filesystem containing a given path
Arguments
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
The normalized device of the filesystem containing the elementfs_extend
Extend a file system to a given size
Arguments
$1 | A path contained in the file system to extend |
$2 | The new size in Mbytes, or the size to add if prefixed with a '+' |
Returns
Always 0Displays
Info msgfs_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
$1 | Directory to check |
Returns
0 if true, !=0 if falseDisplays
nothingfs_mount_point
Gets the mount point of the filesystem containing a given path
Arguments
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
The mount directory of the filesystem containing the elementfs_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
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
FS size in Mbytesget_fs_device
Gets the device of the filesystem containing a given path
### This function is deprecated. Please use fs_device.
Arguments
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
The normalized device of the filesystem containing the elementget_fs_mnt
Gets the mount point of the filesystem containing a given path
### This function is deprecated. Please use fs_mount_point.
Arguments
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
The mount directory of the filesystem containing the elementget_fs_size
Get the size of the filesystem containing a given path
### This function is deprecated. Please use fs_size.
Arguments
$1 | Path (must correspond to an existing element) |
Returns
Always 0Displays
FS size in Mbyteshas_dedicated_fs
Checks if a directory is a file system mount point
### This function is deprecated. Please use fs_is_mount_point.
Arguments
$1 | Directory to check |
Returns
0 if true, !=0 if falseDisplays
nothingset_fs_space
Extend a file system to a given size
### This function is deprecated. Please use fs_extend.
Arguments
$1 | A path contained in the file system to extend |
$2 | The new size in Mbytes, or the size to add if prefixed with a '+' |
Returns
Always 0Displays
Info msgip4_is_valid_ip
Checks if the input string is a valid IP address
Arguments
$1 | IP address to check |
Returns
0 if address is valid, !=0 if notDisplays
Nothingip4_network
Compute network from IP and netmask
Arguments
$1 | IP |
$2 | Netmask |
Returns
0Displays
Networkip4_validate_ip
Checks if the input string is a valid IP address and aborts if not
Arguments
$1 | IP address to check |
Returns
only if address is validDisplays
Nothing if OK. Error if notkrn_module_is_loaded
Check if a kernel module is loaded
Arguments
$1 | Module name |
Returns
0 if module is loaded, 1 if notDisplays
Nothingcreate_lv
Create a logical volume
Arguments
$1 | Logical volume name |
$2 | Volume group name |
$3 | Size (Default: megabytes, optional suffixes: [kmgt]. Special value: 'all' takes the whole free size in the VG. |
Returns
0: OK, !=0: ErrorDisplays
Info msgcreate_vg
Create a volume group
Arguments
$1 | volume group name |
$2 | PE size (including optional unit, default=Mb) |
$3 | Device path, without the /dev prefix |
Returns
0: OK, !=0: ErrorDisplays
Info msglv_exists
Checks if a given logical volume exists
Arguments
$1 | VG name |
$2 | LV name |
Returns
0 if it exists, 1 if notDisplays
Nothinglv_to_vg
Returns the VG containing a given LV
Arguments
$1 | LV device path |
Returns
Always 0Displays
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
$1 | VG name |
Returns
Always 0Displays
The available size in Mbytes. Nothing if VG does not exist.vg_exists
Checks if a given volume group exists
Arguments
$1 | VG name |
Returns
0 if it exists, 1 if notDisplays
Nothingcleanup
Cleanup at exit
This function discards every allocated resources (tmp files,...)
Arguments
None
Returns
Always 0Displays
nothingexec_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 programDisplays
data displayed by the executed programfinish
Finish execution
This function discards every allocated resources (tmp files,...)
Arguments
$1 | Ooptional. Exit code. Default: 0 |
Returns
Never returns. Exits from program.Displays
nothingfunc_is_defined
Check if a shell function is defined
Arguments
$1 | Function name |
Returns
0 if function is defined, 1 if notDisplays
Nothinghelp
Display help
Arguments
None
Returns
No returnDisplays
Help messageloaded
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 0Displays
Nothingtxt_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
$1 | Optional. File to read from. If not set, read from stdin |
Returns
Always 0Displays
the cleaned streamversion
Displays library version
Arguments
None
Returns
Always 0Displays
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 0Displays
messagedebug
Display debug message
If $sf_verbose_level >= 2, displays the message.
Arguments
$1 | message |
Returns
Always 0Displays
message if verbose level set to debug (2) or moremsg
Displays a message (string)
If the $sf_noexec environment variable is set, prefix the message with '(n)'
Arguments
$1 | message |
Returns
Always 0Displays
Messagemsg1
Displays a message prefixed with spaces
Arguments
$1 | message |
Returns
Always 0Displays
message prefixed with spacesmsg_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 0Displays
Messagenewline
Display a new line
Arguments
None
Returns
Always 0Displays
new lineseparator
Displays a separator line
Arguments
None
Returns
Always 0Displays
separator linetrace
Display trace message
If the $sf_verbose environment variable is set or $sf_verbose_level >= 1, displays the message.
Arguments
$1 | message |
Returns
Always 0Displays
message if verbose mode is active, nothing if notwarning
Displays a warning message
Arguments
$1 | message |
Returns
Always 0Displays
Warning messageask
Ask a question to the user
Arguments
$1 | Question |
Returns
Always 0Displays
message to stderr, answer to stdoutyn_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
$1 | IP address |
$2 | Optional. DNS server to ask |
Returns
Always 0Displays
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
$1 | Host name to resolve |
$2 | Optional. DNS server to ask |
Returns
Always 0Displays
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
$1 | Input FQDN |
Returns
Always 0Displays
truncated stringhost_part
Extracts a hostname from an FQDN
Removes everything from the first dot up to the end of the string
Arguments
$1 | Input FQDN |
Returns
Always 0Displays
truncated stringprimary_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 0Displays
IP address or nothing if no address was foundcompute_os_id
Alias of os_id
### This function is deprecated. Please use os_id
Arguments
None
Returns
Always 0Displays
OS ID stringfind_posix_shell
Find a Posix-compatible shell on the current host
Search a bash shell first, then ksh
Arguments
None
Returns
Always 0Displays
Shell path if found, nothing if not foundos_arch
Display the current OS architecture (aka 'hardware platform')
Arguments
None
Returns
0Displays
OS distribos_distrib
Display the current OS distribution
Arguments
None
Returns
0Displays
OS distribos_family
Display the current OS family (Linux, SunOS,...)
Arguments
None
Returns
0Displays
OS distribos_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 0Displays
OS ID stringos_version
Display the current OS version
Arguments
None
Returns
0Displays
OS distribpoweroff
Shutdown and poweroff the host
Arguments
None
Returns
does not returnDisplays
nothingreboot
Shutdown and restart the host
Arguments
None
Returns
does not returnDisplays
nothingshutdown
Shutdown and halt the host
Arguments
None
Returns
does not returnDisplays
nothingThis 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 0Displays
Nothingsave
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 0Displays
Info msgsoft_available_version
Get the available version of an upgradeable package
Arguments
$1 | Software name |
Returns
0 if an update is available, 1 if not installed, 2 if up-to-dateDisplays
Available version if one exists, nothing if notsoft_clean_cache
Clean the software installation cache
Arguments
None
Returns
Always 0Displays
Nothingsoft_exists
Check if software exists (installed or available for installation)
Arguments
$1 | Software name |
Returns
0 if software exists, 1 if notDisplays
Nothingsoft_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 0Displays
Info msgsoft_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 0Displays
Info msgsoft_is_installed
Check if a software is installed
Arguments
$1 | Software name |
Returns
0 if software is installed, 1 if not.Displays
Nothingsoft_is_up_to_date
Check if a software is installed and the latest version
Arguments
$1 | Software name |
Returns
0 if software is up-to-date, 1 if not installed, 2 if upgradeable.Displays
Nothingsoft_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
$1 | Software name |
Returns
0 if the software is upgradeable, !=0 if not.Displays
Nothingsoft_list
List installed software
Returns a sorted list of installed software
Linux output: (name-version-release.arch)
Arguments
None
Returns
Always 0Displays
software listsoft_reinstall
Reinstall software(s), even at same version
Arguments
$* | Software name(s) |
Returns
Always 0Displays
Info msgsoft_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 0Displays
Info msgsoft_repo_list
List defined software repository names
Arguments
None
Returns
Always 0Displays
List of software repositories, one per linesoft_uninstall
Uninstall software(s) (including dependencies)
Nothing is done for softwares which are not present on the host.
Arguments
$* | Software name(s) |
Returns
Always 0Displays
Info msgsoft_version
get version of an installed software
Arguments
$1 | Software 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 0Displays
Stringsvc_disable
Disable service start/stop at system boot/shutdown
Arguments
$* | Service names |
Returns
Always 0Displays
Info msgsvc_enable
Enable service start/stop at system boot/shutdown
Arguments
$* | Service names |
Returns
Always 0Displays
Info msgsvc_install
Install a service script (script to start/stop a service)
Arguments
$1 | Source script |
$2 | Service name |
Returns
Always 0Displays
Info msgsvc_is_enabled
Check if a service is enabled on boot
On Linux, check for current runlevel. On Solaris, check for level 3.
Arguments
$1 | Service name |
Returns
0 if enabled, 1 if diasabled, 2 if not installedDisplays
Nothingsvc_is_installed
Check if a service script is installed
Arguments
$1 | Service name |
Returns
0 is installed, 1 if notDisplays
Nothingsvc_is_up
Check if a service is running
Arguments
$1 | Service name |
Returns
0 if service is running, 1 if stopped, 2 if not installedDisplays
Nothingsvc_script
Display the full path of the script corresponding to a given service
Arguments
$1 | Service name |
Returns
Always 0Displays
Script pathsvc_start
Start a service
'noexec' does not disable starting/stopping services.
Arguments
$1 | Service name |
Returns
Return code from script executionDisplays
Output from service scriptsvc_stop
Stop a service
'noexec' does not disable starting/stopping services.
Arguments
$1 | Service name |
Returns
Return code from script executionDisplays
Output from service scriptsvc_uninstall
Uninstall a service script (script to start/stop a service)
Arguments
$1 | Service name |
Returns
Always 0Displays
Info msgtm_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
0Displays
Time stringtm_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
$1 | Optional. 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 stringtm_timestamp
Display Unix current time (Seconds since Epoch)
Arguments
None
Returns
0Displays
Time stringget_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 0Displays
An unused temporary pathtmpdir
Creates an empty temporary dir and returns its path
Arguments
None
Returns
Always 0Displays
Temporary dir pathtmpfile
Creates an empty temporary file and returns its path
Arguments
None
Returns
Always 0Displays
Temporary file pathcreate_group
Create a user group
Arguments
$1 | Group name |
$2 | Group Id |
Returns
Status from system commandDisplays
Info msgcreate_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
$1 | User name |
$2 | uid |
$3 | gid |
$4 | description (gecos) |
$5 | home dir (can be '' for '/none') |
$6 | Additional groups (separated with ',') |
$7 | encrypted password (Linux) |
$8 | encrypted password (HP-UX & SunOS) |
$9 | encrypted password (AIX) |
Returns
Always 0Displays
Info msgdelete_group
Remove a group
Arguments
$1 | Group name |
Returns
Status from system commandDisplays
nothingdelete_user
Remove a user account
Arguments
$1 | User name |
Returns
Status from system commandDisplays
nothingset_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
$1 | Username |
$2 | Encrypted password |
$3 | File path |
Returns
Always 0Displays
Nothingset_passwd_aix
Set an AIX password
TODO: Unify with other supported OS
Arguments
$1 | Username |
$2 | Encrypted password |
Returns
Always 0Displays
nothinguser_exists
Checks if a given user exists on the system
Arguments
$1 | User name to check |
Returns
0 if user exists; != 0 if notDisplays
nothinguser_gid
Return GID of a given user
Arguments
$1 | User name |
Returns
0 if user exists, 1 if notDisplays
Primary GID if user exists, nothing if notuser_uid
Return UID of a given user
Arguments
$1 | User name |
Returns
0 if user exists, 1 if notDisplays
UID if user exists, nothing if notvm_host_is_vmware
Check if we are on a VMware host
Arguments
None
Returns
0 if VMware, 1 if notDisplays
Nothing- ask
- banner
- cfg_check
- cfg_display
- cfg_dump
- cfg_exists
- cfg_get
- cfg_get_default
- cfg_info
- cfg_isset
- cfg_list
- cfg_set
- cfg_unset
- check_block
- check_copy
- check_line
- check_link
- chmod
- chown
- cleanup
- comment_out
- compute_os_id
- contains_block
- create_dir
- create_fs
- create_group
- create_lv
- create_lv_fs
- create_user
- create_vg
- db_clear
- db_copy
- db_dump
- db_expand
- db_get
- db_import
- db_isset
- db_key
- db_list
- db_normalize
- db_rename
- db_set
- db_set_timestamp
- db_unset
- debug
- delete
- delete_group
- delete_user
- disk_category
- disk_fs_size
- disk_normalize_device
- disk_rescan
- disk_type
- dns_addr_to_name
- dns_name_to_addr
- domain_part
- error
- error_count
- error_import
- exec_url
- fatal
- file_checksum
- file_group
- file_is_link
- file_mode
- file_mtime
- file_owner
- file_readlink
- file_realpath
- file_size
- file_type
- find_executable
- find_posix_shell
- finish
- fs_create
- fs_create_lv_fs
- fs_default_type
- fs_device
- fs_extend
- fs_is_mount_point
- fs_mount_point
- fs_size
- func_is_defined
- get_fs_device
- get_fs_mnt
- get_fs_size
- get_tmp
- has_dedicated_fs
- help
- host_part
- ip4_is_valid_ip
- ip4_network
- ip4_validate_ip
- krn_module_is_loaded
- loaded
- lv_exists
- lv_to_vg
- lvm_vg_free
- msg
- msg1
- msg_section
- newline
- os_arch
- os_distrib
- os_family
- os_id
- os_version
- poweroff
- primary_ip_address
- reboot
- rename_to_old
- sav_zap
- save
- separator
- set_fs_space
- set_passwd
- set_passwd_aix
- show_errors
- shutdown
- soft_available_version
- soft_clean_cache
- soft_exists
- soft_install
- soft_install_upgrade
- soft_is_installed
- soft_is_up_to_date
- soft_is_upgradeable
- soft_list
- soft_reinstall
- soft_remove
- soft_repo_list
- soft_uninstall
- soft_version
- sort_file
- svc_base
- svc_disable
- svc_enable
- svc_install
- svc_is_enabled
- svc_is_installed
- svc_is_up
- svc_script
- svc_start
- svc_stop
- svc_uninstall
- tm_date
- tm_now
- tm_timestamp
- tmpdir
- tmpfile
- trace
- txt_cleanup
- uncomment
- unsupported
- user_exists
- user_gid
- user_uid
- version
- vg_exists
- vm_host_is_vmware
- warning
- yn_question