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