Script Index


/var/lib/sorcery/modules/libapi

This library contains all sorcery functions which a spell may use. If the function isn't listed here, it may disapear without warning. If you use a funtion which isn't listed here, you'd better have a good reason. Better yet, raise a bug on the topic and the needed function will probably get added.

NOTE

This library must not contain any logic. It is simply a set of wrapper functions.

Synopsis

Defines the Spell-Sorcery Interface


function acquire_src()

Parameters:

See

var.lib.sorcery.modules.libsummon.html for more details.

Type

API

params

Number portion of SOURCE[[:digit:]], eg '', "2", "3", etc.

Description

Get a particular source, check first in $SOURCE_CACHE and respect FORCE_DOWNLOAD. Calls download_src if the file must be downloaded.


function config_query()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
config_query DETAILED "Detailed questions ?" n; then
if [ $DETAILED == y ]; then
....
fi
echo The reply for last question was: $DETAILED


function config_query_list()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
config_query_list COLOR "What color ?" "red" "white" "blue"
echo Your color is $COLOR


function config_query_option()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

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

Example 1:
config_query_option OPT "Use X ?" y "--with-x" "--without-x"
config_query_option OPT "Use jpeg ?" y "--with-jpeg" "--do-not-use-jpeg"
echo All selected options together: $OPT
Example 2:
CONFIGURE:
config_query_option ASK "Use X11 ?" y --with-x11 EMPTY1
config_query_option ASK "Use Alsa ?" y --with-alsa EMPTY2
BUILD:
local TEMP="$ASK"
list_remove TEMP EMPTY1 EMPTY2
./configure $TEMP
...


function config_query_string()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
config_query_string REAL_NAME "What is your real name ?" "nobody"
echo Hi $REAL_NAME


function conflicts()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

If the default answer is anything other than 'y' then 'n' is assumed. returns the given spellname if it is installed


function default_sorcery_build()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Used if no BUILD script is found for a spell Default build for BUILD_API==1 is:

./configure --build=$BUILD ## --prefix=/usr ## --sysconfdir=/etc ## --localstatedir=/var ## $OPTS &&
make &&
prepare_install &&
make install
Default build for BUILD_API==2 is:
./configure --build=$BUILD ## --prefix=/usr ## --sysconfdir=/etc ## --localstatedir=/var ## $OPTS &&
make


function default_sorcery_download()

Parameters:

See

var.lib.sorcery.modules.libsummon.html for more details.

Type

API

Description

Default download code, downloads each SOURCE[[:digit:]]*


function default_sorcery_install()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==2 Used if no INSTALL script is found. Default install is:

make install


function default_sorcery_install_extras()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==2 Installs configuration files and documentation.


function default_sorcery_post_build()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==1 Installs configuration files and documentation. Stops installwatch. Used if no POST_BUILD script is found for a spell. equivalent to default_sorcery_post_install in BUILD_API==2


function default_sorcery_post_install()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==2 Puts the spell at the root of the stage root so manipulation of the installed files can happen


function default_sorcery_transfer()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==2 Transfers the files from the stage area to the system. Default is transfer_staged_spell


function default_sorcery_pre_build()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Creates the source directory and unpacks the source package into it. Used if no PRE_BUILD script is found for a spell.


function default_sorcery_pre_install()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Only defined for BUILD_API==2 Used if no PRE_INSTALL script is found. Default pre_install is:

prepare_install


function depends()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

Denotes that a spell requires another spell to work.


function devoke_installwatch()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API

Description

Stops using installwatch


function devoke_stage_root()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API

Description

Stops using stage root


function download_src()

Parameters:

See

var.lib.sorcery.modules.libsummon.html for more details.

Type

API

params

Number portion of SOURCE[[:digit:]], eg '', "2", "3", etc.

Description

Download a file. If the source is a file tree (eg from cvs or svn) then if there is an existing tarball, it will be unpacked, updated and repackaged as a tar.bz2. If the source is a simple file it will be downloaded as usual.


function force_depends()

Parameters:

Type

API

Description

Causes a dependent spell to be recast when it might not otherwise be. This is intended to be called on an already enabled dependency. It can be thought of as an inverse of up_trigger (although it is *not* a trigger).

Example 1:
depends foo &&
force_depends foo
Example 2:
optional_depends foo --enable-foo --disable-foo "for foo support" &&
if is_depends_enabled $SPELL foo; then
force_depends foo
fi


function gather_docs()

Parameters:

See

var.lib.sorcery.modules.build_api.common.html for more details.

Type

API

Description

Gathers all documentation files from source archive and installs them as part of the spell


function get_source_nums()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Type

API

params

String to prefix on the results.

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 get_spell_provider()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API

stdout

the provider name(s)

Description

info from the committed ($DEPENDS_STATUS) database. If the uncommited db doesnt exist (maybe we're not casting) use DEPENDS_STATUS instead.


function guess_compressor()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Stdout

compressor

Type

API

Description

Guesses what program was used to compress a file Return value is always success due to `file' workings


function handle_changed_config()

Parameters:

See

var.lib.sorcery.modules.libresurrect.html for more details.

Type

API

Description

Present the user with the following menu (0) trash $to and install over it (1) backup $to to $to.$savetime, install the new file in its place (2) leave $to in its place, copy the new file to $to.$savetime (3) do nothing (4) see a diff between $to and the new file choice 2 is currently the default, someday there will be a menu to choose what the default will be


function is_depends_enabled()

Parameters:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API

Description

Returns whether or not a given dependency is enabled


function installed_version()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Returns the current version of the given spell


function install_config_file()

Parameters:

See

var.lib.sorcery.modules.libresurrect.html for more details.

Type

API

Description

$(date +'%Y%m%d%H%M') Returns the current version of the given spell


function invoke_installwatch()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API

Description

Starts using installwatch


function invoke_stage_root()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API

Description

Starts using stage root


function list_remove()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
MY_LIST="--disable-static --enable-dynamic"
list_remove MY_LIST "--enable-dynamic"


function list_add()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
list_add MY_LIST "--with-x"
list_add MY_LIST "--with-jpeg" $OTHER_OPTS
echo $MY_LIST


function list_find()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

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.

Example:
if list_find "$MY_LIST" "--with-x"; then
... we have to compile X components in
fi


function message()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Stdout

message

Type

API

Description

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


function mk_source_dir()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Creates a tmpfs filesystem. By default, the size is 1GB. The caller may optionally supply a size argument.

Example1: Create a 2GB mount at $SOURCE_DIRECTORY
mk_source_dir $SOURCE_DIRECTORY 2g
Example2: Create a mount at /tmp/newdir, defaults to 1GB size
mk_source_dir /tmp/newdir


function note_config_file()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API


function on_cast()

Parameters:

See

var.lib.sorcery.modules.libtriggers.html for more details.

Type

API

Description

Used by spells to make adding triggerse nice.


function on_dispel()

Parameters:

See

var.lib.sorcery.modules.libtriggers.html for more details.

Type

API

Description

Used by spells to make adding triggers nice.


function on_pre_cast()

Parameters:

See

var.lib.sorcery.modules.libtriggers.html for more details.

Type

API

Description

Used by spells to make adding triggerse nice.


function on_pre_dispel()

Parameters:

See

var.lib.sorcery.modules.libtriggers.html for more details.

Type

API

Description

Used by spells to make adding triggerse nice.


function optional_depends()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

Denotes that a spell can use another spell for additional functionality.


function persistent_add()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

Adds variable names to the list of persistent variables

Example:
persistent_add MY_VARIABLE


function persistent_clear()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

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' )

Example:
persistent_clear


function persistent_load()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

Loads persistent variables stored in file "$SPELL_CONFIG"

Example:
persistent_load


function persistent_remove()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

Removes variable names from the list of persistent variables

Example:
persistent_remove MY_VARIABLE


function persistent_save()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
persistent_save


function persistent_read()

Parameters:

Description

finds the persistent var for a spell and sets the upvar to the value of the variable to read returns: 1 if the var doesn't exist in the file 2 if the tablet dir doesn't exist 3 if the persistent config file doesn't exist 4 if the EXPORTS file doesn't exist


function prepare_install()

Parameters:

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Prepares to install the spell. Writes the boost lock file. If the spell is installed already, the libraries are saved with save_libraries(), the binaries with save_binaries() and the spell is dispelled. Usually called from the BUILD script of a spell.


function provider_ok()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API


function rm_source_dir()

Parameters:

Globals

SOURCE_DIRECTORY

See

var.lib.sorcery.modules.libgrimoire.html for more details.

Type

API

Description

Removes the given directory or SOURCE_DIRECTORY if no argument is given.


function query()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

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. Returns true or false based on the answer given.


function query_string()

Parameters:

Returns:

See

var.lib.sorcery.modules.libmisc.html for more details.

Description

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

Example:
query_string YOUR_HOST "What is your hostname ?" "localhost"


function runtime_depends()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

Denotes that a spell requires another spell to work.


function sedit()

Parameters:

See

var.lib.sorcery.modules.libmisc.html for more details.

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 show_up_depends()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

stdout

recursively prints out the spell that depend on the specified spell


function spell_installed()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API


function spell_held()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API


function spell_ok()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API


function spell_exiled()

Parameters:

Returns:

See

var.lib.sorcery.modules.libstate.html for more details.

Type

API


function sub_depends()

Parameters:

See

<@function var.lib.sorcery.modules.libdepends

Type

API


function suggest_depends()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

Denotes that a spell can use another spell for additional functionality.


function uncompress()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Type

API

Description

Given a file, uncompress runs the decompression program for that file, Note: zip is a special case because it doesn't work with streams.


function unpack()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Type

API

Description

Given a file, unpack runs the decompression program for that file, as well as untar'ing the file if appropriate and if the MD5 matches. Note: zip is a special case because it doesn't work with streams. Note: This function is deprecated and kept for spells that still use the old verification methods (MD5[0]=).


function unpack_file()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Type

API

Description

unpack_file takes the SOURCE suffix and figures out if it is supposed to hash or gpg check it -- then it does its dirty work and runs unpack_hash or unpack_gpg depending upon the circumstances. That's the only argument it takes and needs: '' '2' '3', etc. It is run in default_pre_build for the null argument only. Custom unpacking still requires a custom PRE_BUILD. valid formats: vendor-provided gpg, guru-provided gpg, any hash-algorithm provided by gpg (currently md5, sha1, sha256, sha384, sha512, ripemd160 SOURCE=blah SOURCE2=blah.asc SOURCE_URL=http://blah.com/$SOURCE SOURCE2_URL=http://blah.com/$SOURCE2 SOURCE_GPG=blah.gpg:$SOURCE2:UPSTREAM_KEY SOURCE2_IGNORE=signature # for auditing purposes SOURCE=blah SOURCE_URL=http://blah.com/$SOURCE SOURCE_GPG=swoolley.gpg:$SOURCE.asc:WORKS_FOR_ME SOURCE=blah SOURCE_URL=http://blah.com/$SOURCE MD5[0]=d41d8cd98f00b204e9800998ecf8427e SOURCE=blah SOURCE_URL=http://blah.com/$SOURCE SOURCE_HASH=md5:d41d8cd98f00b204e9800998ecf8427e:WORKS_FOR_ME In GPG mode: Validates the verification level (the third parameter) and the hash algorithm against user defined lists. It finds the public key and signature using locate_spell_file, Then it validates it at the beginning. see unpack_gpg() In HASH mode: Validates the verification level (the third parameter) and the hash algorithm against user defined lists. It uses gpg to calculate the hash value except for md5 and sha1, which coreutils provides. see unpack_hash() In IGNORE mode: It checks for the following text: volatile (for cvs/svn/any-other-scm) unversioned (the source file changes frequently, but not a direct scm) signature (for gnupg signatures) as reasons for ignoring the source code validation. Signatures are silently ignored. Everything else respects MD5SUM_DL. see unpack_ignore Otherwise, it falls back to MISSING mode, see unpack_missing (or for now) Otherwise, it falls back to old uncompressed md5sum check with MD5[n]. see real_unpack() The default verification level is "WORKS_FOR_ME" Verification levels are, these indicate how much effort was put into validating the integrity of the source from the upstream vendor. WORKS_FOR_ME No verification was done. UPSTREAM_HASH Checked the upstream hash file UPSTREAM_KEY Checked upstream (gpg) key, signature matched, but the key was not validated ESTABLISHED_UPSTREAM_KEY Upstream key was not validated against multiple independent sources, but has been in use for several years VERIFIED_UPSTREAM_KEY Upstream key id was verified against multiple independent sources. ID_CHECK_UPSTREAM_KEY Key was verified in person with a photo id check. Also if you want to include more than one signature, hash, etc, just put a 2, 3, 4, etc on the end of the variable like so: SOURCE2_HASH2=... For cascading, currently it will still ask abort questions: a no abort will make it fail over all cascades; a yes abort will have it skip to the next cascades. Missing binaries or other failures like that (error 200 below) will silently fail over to the next check. The cascade order is: GPG, HASH, IGNORE, MISSING The cascade setup allows you to place a higher bit checksum earlier in the cascade and even if the binary doesn't work it will just print out an abort query which can be said no to and it will continue to fail over to the lower bit checksum that should be available in coreutils (like sha1/md5). That's if you're not using gpg, which is preferred. If multiple hashes are included of different ciphers, the user can abort on either that go bad, so it can be considered a security increase to have more than one, but only if the harder cipher is first in the cascade order, as the first successful hash match will go ahead and prompt an untarball. It may change later, but for now we think the first successful match skipping the rest is least intrusive, and I'd need to add an interface element to let the user choose to run all checks on a single source.


function unpack_file_simple()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Type

API

params

Name of a file to unpack

Description

Interface to unpack a file without any verification.


function verify_file()

Parameters:

See

var.lib.sorcery.modules.libunpack.html for more details.

Type

API

Description

verify_file takes the SOURCE suffix and verifies the file without unpacking it. It does not work with the old 'MD5[0]=...' style. Only with the "new" SOURCEn_(GPG|HASH|IGNORE) style.


function using_gcc()

Parameters:

Returns:

See

var.lib.sorcery.modules.libgcc.html for more details.

Description

to the passed version installed gcc is at least "version" Checks if the system gcc version is equal to the passed version or when the version ends with a + marker, if it the system version is greater or equal to it. The gcc version is of the major.minor.patchlevel form, but trailing digits can be omitted and will default to 0 in the comparison.

Example:
if using_gcc 4.3+; then # same as 4.3.0+
patch -p1 < $SPELL_DIRECTORY/gcc43-compilation-fixes.patch
elif using_gcc 4.0.0; then
# gcc 4.0.0 triggers a memleak when -O3 is used
CFLAGS=${CFLAGS/-O3/-O2}
fi


function up_trigger()

Parameters:

See

var.lib.sorcery.modules.libdepends.html for more details.

Type

API

Description

Only allowed from UP_TRIGGERS file. Specify that the current spell should trigger the specifed action on the target spell. This is a shortcut for the TRIGGERS file in the target spell, this lets you specify lots of triggers easily.


function track_manual()

Parameters:

See

var.lib.sorcery.modules.libtrack.html for more details.

Type

API

params

list of files to track manually

Description

Given a list of files it will notify installwatch of them. Useful for spells whose components are not dynamicly linked to glibc. Installwatch must be running for this to work.