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