slitaz-dev-tools view libtaz/libtaz @ rev 31

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Mar 06 16:43:54 2011 +0000 (2011-03-06)
parents 3ad78186f531
children cb635b5b55a4
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 below.
4 #
5 # Author : Antoine Bodin <gokhlayeh@mailoo.org>
6 #
7 # Version : 0.0.1 (alpha1)
8 #
9 # Documentation : none (will be available with beta version)
10 # The documentation will include an explanation of all functions, 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 in progress some parts are dirty code or others
19 # are not finished. I will 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 an application is called by one already,
26 # to avoid options overwrite.
28 . /etc/slitaz/slitaz.conf
30 # Load the command as some modules use it.
31 log_command="$0 $@"
33 # Define & create a 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 are 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 sources main configuration files and contains only
70 # this function. The modular libraries should be put in the slitaz lib
71 # directory (/usr/lib/slitaz/libtaz-modules).
72 #
73 # Usage : source_lib lib [lib2] [lib3] ...
74 #
75 # Description of libraries included 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 scripts in a configurable way
79 #
80 # * needs a code review, please don't use them for production : code can
81 # be hardly modified.
82 #
83 # All these libraries contains additional functions. Check them to
84 # know which ones and how to use them.
85 # More information will be available 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 }