Script Index


function explode()

Parameters:

Description

Turns a string into an array. Each element of the array is separated in the string by the delimiter. Note: The array you want the fields put into must be declared before you call this function.

EXAMPLE
my_array=()
explode "a_string_to_explode" "_" "my_array"
echo my_array[*]
Produces "a" "string" "to" "explode".


function real_sedit()

Parameters:

Type

API

Description

First argument is a sed command. Second argument is a file. sedit performs the sed command on the file, modifiying the original file. For example,
sedit "s/foo/bar/g" /tmp/somefile
will replace all occurances of foo with bar in /tmp/somefile. This function is often used in spells to make changes to source files before compiling. See the sed man page for more information.


function isdigit()

Parameters:

Returns:

Type

API

Description

Argument is a string to check if the string contains all digits or not


function isalpha()

Parameters:

Returns:

Type

API

Description

Argument is a string to check if it contains all chars a-zA-Z


function real_query()

Parameters:

Returns:

Type

API

Description

Asks the user a yes/no question. First argument is the question to ask, second argument is the default answer. If a timeout occurs before the question is answered, the given default answer is applied. Pressing spacebar or enter applies the default answer immediatelly without waiting for timeout. Returns true or false based on the answer given.


function real_query_string()

Parameters:

Returns:

Description

Asks user for string, with default answer and timeout (like query)


function real_message()

Parameters:

Stdout

message

Type

API

Description

echo's the given arguments if SILENT is not set.


function error_message()

Parameters:

Stderr

message

Stdout

message

Type

Private

Description

echo's the given arguments if SILENT is not set.


function debug()

Parameters:

Description

Enters a debug message if the type of debug message != 'no' The 'type' is usually the name of the file the debug statement comes from. i.e. DEBUG_liblock, DEBUG_libsorcery, DEBUG_cast etc.


function progress_spinner()

Parameters:

Stdout

progress spinner

Description

Displays progress spinner like the one in fsck.


function progress_bar()

Parameters:

Description

Displays progress bar in the form of [----> ] 100%
Or just a dot in the dot format


function clear_line()

Parameters:

Stdout

Clear line

Description

Clears the current line and puts the cursor at the begining of it.


function sound()

Parameters:

Globals

SOUND

Description

Plays a given soundfile if sounds are on and the file exists in the chosen theme.


function edit_file()

Parameters:

Description

Runs the editor given by EDITOR on the file given in the first argument. If EDITOR is not set, "nano -w" is used.


function esc_str()

Parameters:

Stdout

escaped string

Description

Adds escape sequences to strings for special characters. Does NOT escape the string ".*". Used for putting escape sequences in regexp strings that should be treated literaly.


function esc_provider_str()

Parameters:

Description

esc_str with a minor modification used for escaping provider queries, where only the provider name needs to be escaped. Does NOT escape strings matching ".*(.*".


function consolidate_params()

Parameters:

Description

Properly quotes and backquotes parameters so they can be passed through su at the start of many sorcery commands Expected usage is: PARAMS=$(consolidate_params "$@") su -c "$0 $PARAMS" root


function get_basenames()

Parameters:

Stdin

directories.

Stdout

directories' basenames

Description

Takes newline separated list of directories and outputs their base names.


function get_dirnames()

Parameters:

Stdin

directories.

Stdout

directories' basenames

Description

Takes newline separated list of pathnames and outputs their directory names.


function ensure_dir()

Parameters:

Returns:

Stderr

error if the input is not a directory, but something else

Description

Checks whether the passed directory exists and if not, tries to create it, first checking if it already exists as something else.


function iterate()

Parameters:

Stdin

is used when $3 isn't given.

Description

$3 is optional, when it isn't used, stdin is used and only the first letter in $2 is used. Note, using stdin can have odd side effects when your function uses read and stdin itself. Special vars: BREAK: Use this to break out of the loop prematurely, also causes a return of 1. If the function returns the value of the last return Notes: In stdin mode, if the string does not terminate with the delimiter, the last token will be ignored.


function select_list()

Parameters:

Description

gives the user some nice select list and puts the selected item in return_var


function select_list_sub()

Parameters:

Description

Common code for select_list and select_provider The user should have already printed out the menu, this handles getting a valid answer from the user.


function set_term_title()

Parameters:

Description

sets the terminal title if TERM=xterm|rxvt or the window title if TERM=screen


function real_list_remove()

Parameters:

Description

Removes from the list string(s). Strings are kept to be unique and are separated by spaces


function real_list_add()

Parameters:

Description

Puts in the list string(s). Strings are kept to be unique and are separated by spaces


function real_list_find()

Parameters:

Description

return 0 at least one element is in list return 1 none of supplied elements is not in list Finds if at least one of the given elements is in the string. They can be delimited by spaces, tabs or newlines. The search elements must not contain any of these or they won't match. The matching is exact, regular expressions and globbing patterns are not supported. Warning, this function takes a real string, not a variable name as other list_* functions. Use the ${var[*]} form when passing arrays


function real_persistent_read()

Parameters:

Description

finds the persistent var for spell and sets variable name to the value of the variable to read


function real_persistent_add()

Parameters:

Description

Adds variable names to the list of persistent variables


function real_persistent_remove()

Parameters:

Description

Removes variable names from the list of persistent variables


function real_persistent_load()

Parameters:

Description

Loads persistent variables stored in file "$SPELL_CONFIG"


function real_persistent_save()

Parameters:

Description

Saves variables marked as persistent to file "$SPELL_CONFIG". The File is completely overwritten. Also unsets all persistent variables


function real_persistent_clear()

Parameters:

Description

Unsets all persistent variables. Mainly usable as replacement of persistent_save for functions which can be called by nonroot users ( for example from 'gaze what' )


function config_get_option()

Parameters:

Returns:

Description

Retrieves setting from $SPELL_CONFIG file and optionally sets user supplied variable. Function is here to make possible changes to config system easy, since all other functions are using this function and are not working with variables directly


function config_get_last_option()

Parameters:

Returns:

Description

Get value of a persistent variable from the previous cast when there is a -r. The persistent data moves to a seperate directory when cast -r is run, this makes the new persistent config clean but allows us to provide the user defaults from the last cast.


function config_set_option()

Parameters:

Description

Stores string to given variable and makes the variable persistent Function is here to make possible changes to config system easy, since all other functions are using this function and are not working with variables directly


function real_config_query()

Parameters:

Returns:

Description

Asks user for string, with default answer and timeout (like query) Return variable is also marked as persistent


function real_config_query_option()

Parameters:

Returns:

Description

Asks user for string, with default answer and timeout (like query) The string is added to the variable If you want to use empty string, place there dummy string and remove it later by list_remove function. Also for one config variable, all option_yes and option_no have to be different. Return variable is also marked as persistent


function real_config_query_string()

Parameters:

Returns:

Description

Asks user for string, with default answer and timeout (like query) Return variable is also marked as persistent


function real_config_query_list()

Parameters:

Returns:

Description

Asks user for string, with numbered possibilities listed Return variable is also marked as persistent


function real_get_source_nums()

Parameters:

Description

Output a list of source numbers associated with the current spell. This is the number portion of SOURCE[[:digit:]], eg '', "2", "3", etc. A prefix may be given and it will be prepended to each result value.


function misc_is_function()

Parameters:

Returns:

Description

misc_is_function Returns true if input argument is the name of an existing function, false otherwise.


function remove_files_and_dirs()

Parameters:

Description

Remove files listed and any directories which become empty after subsequent file removal.


function mk_tmp_dirs()

Parameters:

Description

Safely creates $TMP_DIR and exports the variable so we can use it even in subprocesses called through make.


function smgl_which()

Parameters:

Description

'which' is not in basesystem, heres our own simple version of it it should be just as fast as the real one. Marches through $PATH looking for the executable specified


function find_make()

Parameters:

Description

Finds the make command and complains if its missing (shouldnt ever happen)


function cleanup_tmp_dir()

Parameters:


function is_sorcery_var()

Parameters:

Returns:

Description

This function will probably need to be updated as sorcery variables come in and out of flux, the variables listed are roughly defined as things defined at the point in which a spell file is run, and when it is not run in a seperate subshell, note that the build phase of cast is seperate from the frontend, so a spell could technically modify something like "SPELLS" and not have a major problem. However the philosophy is to not discriminate about what sorcery variables are technically okay to use in what files and ones that arent, instead we'll treat all usages of sorcery variables equally. The rules are of course subject to change without warning and its just easier to be consistent, also theres a good chance that if a variable is safe in some circumstances and not others, and one uses it where its safe, someone will forget and start using it in places that arent safe...


function complain_sorcery_var()

Parameters:

stdout

Complain vehemently that a variable name is used by sorcery and the user should file a bug because a spell is using the variable


function set_architecture()

Parameters:

Description

Sets the SPECFILE glocal variable and the SMGL_COMPAT_ARCHS global array SPECFILE contains the compiler and other arch specifications SMGL_COMPAT_ARCHS is an array that holds architectures which are compatible with the desired architecture. The desired architecture is determined as follows:

1) If function is gien an argument, the argument is used, or
2) If cross-install is on, the TARGET architecture is used, or
3) The local ARCHITECTURE is used
The least specific arch is in SMGL_COMPAT_ARCHS[0], SMGL_COMPAT_ARCHS[1] is more specific, et cetera. For example: desired architecture="athlon-xp" might result in: SPECFILE=/usr/share/archspecs/ia32/amd/athlon-xp SMGL_COMPAT_ARCHS=("ia32" "amd" "athlon-xp") ARCHITECTURE is also modified to be an array, the reverse of SMGL_COMPAT_ARCHS. The result is an array from most specific arch to least specific. $ARCHITECTURE does not change meaning since $A == ${A[0]}.


function define_functions()

Parameters:

Description

Creates functions with identical bodies. It is useful if you need to override a bunch of functions which have already been defined.


function upvar()

Parameters:

Description

Set variable by name, useful for setting variables that were passed by reference. Example:

function uber() {
local x
unter x 5
echo $x
}
function unter() {
local var=$1 y=$2
read -p "enter value (default $2)" y
upvar $var $y
}


function awkuniq()

Parameters:

Description

Like uniq, but doesnt require a sorted list, implemented in awk.


function smgl_dirname()

Parameters:

Description

Dirname written in bash, optionally uses an upvar (making it forkless).


function smgl_basename()

Parameters:

Description

basename written in bash, optionally uses upvar (making it forkless). Does not have ability to remove file extension like the real basename.


function envar_prepend_path()

Parameters:

Stdout

new path

Description

TODO: remove grimoire functions libgcc gcc_prepend_path and use this one


function append_to_notice_log()

Parameters:

Description

Appends the input to the notice log, prepending the spell name as a title, appending a newline and teeing the input back unchanged.


function log_failure_reason()

Parameters:

Description

Appends the failure reason (input) to a log for use in displaying the final FAILED_LIST and the activity log


function get_failure_reason()

Parameters:

Description

Checks if there is an entry for the spell in the failure_reason_log If there is one, set the upvar to the reason


function show_file()

Parameters:

Description

Checks if the file is compressed and displays it


/var/lib/sorcery/modules/libmisc

This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this software; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

License