wok diff libtaz/stuff/libtaz @ rev 8822

Put libtaz stuff into wok
author Antoine Bodin <gokhlayeh@slitaz.org>
date Thu Feb 24 00:23:25 2011 +0100 (2011-02-24)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libtaz/stuff/libtaz	Thu Feb 24 00:23:25 2011 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +########################################################################
     1.5 +# This is the SliTaz main library (/usr/lib/slitaz/libtaz).
     1.6 +# libtaz is modular : see explanation of the function source_lib bellow.
     1.7 +#
     1.8 +# Author :	Antoine Bodin <gokhlayeh@mailoo.org>
     1.9 +#
    1.10 +# Version : 0.0.1 (alpha1)
    1.11 +#
    1.12 +# Documentation : none (will be avaible with beta version)
    1.13 +# The documentation will include an explanation of all fonction, how to 
    1.14 +# use them and how to improve this library.
    1.15 +#
    1.16 +# Devnotes (suppress while beta is released) :
    1.17 +# Add a generic download script ? -> download from tazlito & tazwok
    1.18 +# Add a generic create/cleanup script for tmp files ?
    1.19 +# check_for (pkg on cmd line, pkg, receipt, etc.) -> tazwok,tazpkg,list
    1.20 +#
    1.21 +# Note : as the work is progress some part are dirty code or some other
    1.22 +# are note finish. I update this because we need the libdep
    1.23 +#
    1.24 +########################################################################
    1.25 +# INITIALIZATION
    1.26 +########################
    1.27 +# Load the Slitaz main configuration file : /etc/slitaz/slitaz.conf.
    1.28 +# Don't load it if application is called by one having already loaded it, 
    1.29 +# to avoid options overwrite.
    1.30 +
    1.31 +. /etc/slitaz/slitaz.conf
    1.32 +
    1.33 +# Load the command as some module use it.
    1.34 +log_command="$0 $@"
    1.35 +
    1.36 +# Define & create temporary directory as it's used by report.
    1.37 +tmp=/tmp/$(basename $0)-$$
    1.38 +mkdir -p $tmp
    1.39 +
    1.40 +########################################################################
    1.41 +# EXIT FUNCTIONS
    1.42 +########################
    1.43 +# run_on_exit commands are executed when apps exit (whatever the reason)
    1.44 +# run_on_kill commands are executed only when apps is killed (or Ctrl+C)
    1.45 +# Note : one command per line in the variable.
    1.46 +run_on_exit="rm -rf $tmp"
    1.47 +run_on_kill=""
    1.48 +trap run_on_exit EXIT
    1.49 +trap run_on_kill INT KILL
    1.50 +
    1.51 +run_on_exit()
    1.52 +{
    1.53 +	echo "$run_on_exit" | while read c; do
    1.54 +		run_on_exit=$(echo "$run_on_exit" | sed 1d)
    1.55 +		$c
    1.56 +	done
    1.57 +	trap - EXIT
    1.58 +}
    1.59 +
    1.60 +run_on_kill()
    1.61 +{
    1.62 +	echo "$run_on_kill" | while read c; do
    1.63 +		run_on_kill=$(echo "$run_on_kill" | sed 1d)
    1.64 +		$c
    1.65 +	done
    1.66 +	trap - INT KILL
    1.67 +	run_on_exit
    1.68 +}
    1.69 +
    1.70 +########################################################################
    1.71 +# This function should be used after sourcing libtaz to source modular
    1.72 +# libraries. Libtaz only source main configuration file and contain only
    1.73 +# this function. The modular libraries should be put in slitaz lib
    1.74 +# directory (/usr/lib/slitaz/libtaz-modules).
    1.75 +#
    1.76 +# Usage : source_lib lib [lib2] [lib3] ...
    1.77 +#
    1.78 +# Description of libraries including with libtaz :
    1.79 +#	commons		: functions used by most SliTaz scripts
    1.80 +#	get_option*	: function to check & parse arguments of a command line
    1.81 +#	report		: display and log script in a configurable way
    1.82 +#
    1.83 +# * need a code rewiew, please don't use them for production : code can
    1.84 +# be hardly modified.
    1.85 +#
    1.86 +# All theses libraries contains additionnal functions. Check them to
    1.87 +# if you want to know wich ones and how to use them.
    1.88 +# More information will be avaible at beta release.
    1.89 +
    1.90 +sourced_lib=""
    1.91 +source_lib()
    1.92 +{
    1.93 +	for i in $@; do
    1.94 +		[ "$(echo $sourced_lib | grep $i)" ] && continue
    1.95 +		[ ! -f "/usr/lib/slitaz/libtaz-modules/$i" ] && \
    1.96 +			echo "WARNING: libtaz source_lib: can't find /usr/lib/slitaz/libtaz-modules/$i" >&2 && \
    1.97 +			continue
    1.98 +		. /usr/lib/slitaz/libtaz-modules/$i && sourced_lib="$sourced_lib $i"
    1.99 +	done
   1.100 +}