wok view libtaz/stuff/libtaz-modules/commons @ 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 status()
2 {
3 local CHECK=$?
4 echo -en "\\033[70G[ "
5 if [ $CHECK = 0 ]; then
6 echo -en "\\033[1;32mOK"
7 else
8 echo -en "\\033[1;31mFailed"
9 fi
10 echo -e "\\033[0;39m ]"
11 }
13 get_config()
14 {
15 if [ -f "./`basename $0`.conf" ]; then
16 . ./`basename $0`.conf
17 elif [ -f "/etc/slitaz/`basename $0`.conf" ]; then
18 . /etc/slitaz/`basename $0`.conf
19 else
20 echo -e "\nUnable to find the configuration file : /etc/slitaz/`basename $0`.conf" >&2
21 echo -e "Please read the `basename $0` documentation.\n" >&2
22 exit 1
23 fi
24 }
26 # The classic SliTaz check_root function used in near all SliTaz tools.
27 check_root()
28 {
29 [ $(id -u) = 0 ] && return
30 echo -e "\nYou must be root to run `basename $0` with this option." >&2
31 echo -e "Please type 'su' and root password to become super-user.\n" >&2
32 exit 1
33 }
35 # A classic check_dir function :
36 # - create directory if needed and echo about it.
37 # Return error if directory is created (to chain other commands with ||)
38 check_dir()
39 {
40 if ! [ -d "$1" ]; then
41 echo -n "Creating $1..."
42 mkdir -p "$1"
43 status
44 return 1
45 fi
46 }
48 # Install package if missing.
49 check_pkg()
50 {
51 if ! [ -d $INSTALLED/$1 ]; then
52 # report step "Installing package : $1"
53 tazpkg get-install $1
54 # report end-step
55 fi
56 }
58 # Display an horizontal line, can be used to have clearest script.
59 horizontal_line()
60 {
61 echo "================================================================================"
62 }
64 # Store -- options in a variable.
65 # Test phase.
66 # Need to add something to filter options and report error in case option is not
67 # listed a used by the command.
68 get_options()
69 {
70 if echo "$log_command" | fgrep -q ' '--help; then
71 echo "Avaible options for $(echo `basename "$log_command"` | cut -d ' ' -f 1,2) : $get_options_list"
72 exit 0
73 fi
74 for get_option in $(echo "$log_command" | tr ' ' '\n' | grep ^-- | sed 's/^--//'); do
75 if [ "${get_options_list/${get_option%%=*}}" = "$get_options_list" ]; then
76 echo "Option ${get_option%%=*} is incorrect, valid options are : $get_options_list". >&2
77 exit 1
78 fi
79 if [ "$get_option" = "${get_option/=}" ]; then
80 export $get_option=yes
81 else
82 export $get_option
83 fi
84 done
85 }