tazwok view libtazwok/libtazwok @ rev 555

Add libtazwok (old libtaz) - Lib taz is unmaintained and report only used by tazwok. Also for the future we need a better libtaz (now in slitaz-base-files)
author Christophe Lincoln <pankso@slitaz.org>
date Wed Apr 11 02:02:59 2012 +0200 (2012-04-11)
parents
children 857659a86f24
line source
1 ########################################################################
2 # This is the SliTaz main library (/usr/lib/slitaz/libtaz).
3 # libtazwok 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/libtazwok.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 exit
56 }
58 run_on_kill()
59 {
60 echo "$run_on_kill" | while read c; do
61 run_on_kill=$(echo "$run_on_kill" | sed 1d)
62 $c
63 done
64 trap - INT KILL
65 run_on_exit
66 }
68 ########################################################################
69 # This function should be used after sourcing libtaz to source modular
70 # libraries. Libtaz only sources main configuration files and contains only
71 # this function. The modular libraries should be put in the slitaz lib
72 # directory (/usr/lib/slitaz/libtazwok-modules).
73 #
74 # Usage : source_lib lib [lib2] [lib3] ...
75 #
76 # Description of libraries included with libtaz :
77 # commons : functions used by most SliTaz scripts
78 # get_option* : function to check & parse arguments of a command line
79 # report : display and log scripts in a configurable way
80 #
81 # * needs a code review, please don't use them for production : code can
82 # be hardly modified.
83 #
84 # All these libraries contains additional functions. Check them to
85 # know which ones and how to use them.
86 # More information will be available at beta release.
88 sourced_lib=""
89 source_lib()
90 {
91 for i in $@; do
92 [ "$(echo $sourced_lib | grep $i)" ] && continue
93 [ ! -f "/usr/lib/slitaz/libtazwok-modules/$i" ] && \
94 echo "WARNING: libtazwok source_lib: can't find /usr/lib/slitaz/libtazwok-modules/$i" >&2 && \
95 continue
96 . /usr/lib/slitaz/libtazwok-modules/$i && sourced_lib="$sourced_lib $i"
97 done
98 }