wok view 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 source
1 ########################################################################
2 # This is the SliTaz main library (/usr/lib/slitaz/libtaz).
3 # libtaz is modular : see explanation of the function source_lib bellow.
4 #
5 # Author : Antoine Bodin <gokhlayeh@mailoo.org>
6 #
7 # Version : 0.0.1 (alpha1)
8 #
9 # Documentation : none (will be avaible with beta version)
10 # The documentation will include an explanation of all fonction, how to
11 # use them and how to improve this library.
12 #
13 # Devnotes (suppress while beta is released) :
14 # Add a generic download script ? -> download from tazlito & tazwok
15 # Add a generic create/cleanup script for tmp files ?
16 # check_for (pkg on cmd line, pkg, receipt, etc.) -> tazwok,tazpkg,list
17 #
18 # Note : as the work is progress some part are dirty code or some other
19 # are note finish. I update this because we need the libdep
20 #
21 ########################################################################
22 # INITIALIZATION
23 ########################
24 # Load the Slitaz main configuration file : /etc/slitaz/slitaz.conf.
25 # Don't load it if application is called by one having already loaded it,
26 # to avoid options overwrite.
28 . /etc/slitaz/slitaz.conf
30 # Load the command as some module use it.
31 log_command="$0 $@"
33 # Define & create temporary directory as it's used by report.
34 tmp=/tmp/$(basename $0)-$$
35 mkdir -p $tmp
37 ########################################################################
38 # EXIT FUNCTIONS
39 ########################
40 # run_on_exit commands are executed when apps exit (whatever the reason)
41 # run_on_kill commands are executed only when apps is killed (or Ctrl+C)
42 # Note : one command per line in the variable.
43 run_on_exit="rm -rf $tmp"
44 run_on_kill=""
45 trap run_on_exit EXIT
46 trap run_on_kill INT KILL
48 run_on_exit()
49 {
50 echo "$run_on_exit" | while read c; do
51 run_on_exit=$(echo "$run_on_exit" | sed 1d)
52 $c
53 done
54 trap - EXIT
55 }
57 run_on_kill()
58 {
59 echo "$run_on_kill" | while read c; do
60 run_on_kill=$(echo "$run_on_kill" | sed 1d)
61 $c
62 done
63 trap - INT KILL
64 run_on_exit
65 }
67 ########################################################################
68 # This function should be used after sourcing libtaz to source modular
69 # libraries. Libtaz only source main configuration file and contain only
70 # this function. The modular libraries should be put in slitaz lib
71 # directory (/usr/lib/slitaz/libtaz-modules).
72 #
73 # Usage : source_lib lib [lib2] [lib3] ...
74 #
75 # Description of libraries including with libtaz :
76 # commons : functions used by most SliTaz scripts
77 # get_option* : function to check & parse arguments of a command line
78 # report : display and log script in a configurable way
79 #
80 # * need a code rewiew, please don't use them for production : code can
81 # be hardly modified.
82 #
83 # All theses libraries contains additionnal functions. Check them to
84 # if you want to know wich ones and how to use them.
85 # More information will be avaible at beta release.
87 sourced_lib=""
88 source_lib()
89 {
90 for i in $@; do
91 [ "$(echo $sourced_lib | grep $i)" ] && continue
92 [ ! -f "/usr/lib/slitaz/libtaz-modules/$i" ] && \
93 echo "WARNING: libtaz source_lib: can't find /usr/lib/slitaz/libtaz-modules/$i" >&2 && \
94 continue
95 . /usr/lib/slitaz/libtaz-modules/$i && sourced_lib="$sourced_lib $i"
96 done
97 }