#---------------------------------------------------------------------------- # /var/install/include/baselib - basic library for eisfair scripts # # Creation: 2004-09-29 max # Last Update: $Id$ # # Copyright (c) 2001-2007 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # interface description #---------------------------------------------------------------------------- # # _EISLIB_BASELIB is set to 'true' if this file is already included # # _EISLIB_PRINTMODE is set to 'tty' if output goes to a tty # is set to 'html' if output goes to a webbrowser # is set to 'file' if output is redirected to a file # # get_printmode() echo the actual _EISLIB_PRINTMODE # # _EISLIB_SCREENSIZE_X actual number of screen columns # _EISLIB_SCREENSIZE_Y actual number of screen lines # # refresh_screensize() refresh the values of # _EISLIB_SCREENSIZE_X and # _EISLIB_SCREENSIZE_Y # by calling resize (if possible) # Function refresh_screensize is called when baselib is loaded. # The function can be called any time. # # check_screensize() check actual screensize for # _EISLIB_SCREENSIZE_X_MIN and # _EISLIB_SCREENSIZE_Y_MIN # return 1 if screen size to small # #---------------------------------------------------------------------------- #============================================================================ # only include this file once #============================================================================ if [ "$_EISLIB_BASELIB" != "true" ] then _EISLIB_BASELIB='true' #============================================================================ # defaults for screensize #============================================================================ _EISLIB_SCREENSIZE_X_MIN=80 _EISLIB_SCREENSIZE_Y_MIN=24 _EISLIB_SCREENSIZE_Y_FILE=999999 #============================================================================ # define basic functions #============================================================================ get_printmode() { echo $_EISLIB_PRINTMODE } refresh_screensize() { case "$1" in -tty) _refresh_printmode="tty";; -file) _refresh_printmode="file";; -html) _refresh_printmode="html";; *) _refresh_printmode="${_EISLIB_PRINTMODE}";; esac case "${_refresh_printmode}" in tty) eval `/usr/bin/resize 2>/dev/null` _EISLIB_SCREENSIZE_X="${COLUMNS:=$_EISLIB_SCREENSIZE_X_MIN}" _EISLIB_SCREENSIZE_Y="${LINES:=$_EISLIB_SCREENSIZE_Y_MIN}" ;; file) _EISLIB_SCREENSIZE_X="$_EISLIB_SCREENSIZE_X_MIN" _EISLIB_SCREENSIZE_Y="$_EISLIB_SCREENSIZE_Y_FILE" ;; *) _EISLIB_SCREENSIZE_X="$_EISLIB_SCREENSIZE_X_MIN" _EISLIB_SCREENSIZE_Y="$_EISLIB_SCREENSIZE_Y_MIN" ;; esac } check_screensize() { [ "${_EISLIB_PRINTMODE}" != 'tty' ] && return 0 if [ "$_EISLIB_SCREENSIZE_X" -lt $_EISLIB_SCREENSIZE_X_MIN -o \ "$_EISLIB_SCREENSIZE_Y" -lt $_EISLIB_SCREENSIZE_Y_MIN ] then mecho -error "The screen size is ${_EISLIB_SCREENSIZE_X}x${_EISLIB_SCREENSIZE_Y}" mecho -info "The screen size has to be at least ${_EISLIB_SCREENSIZE_X_MIN}x${_EISLIB_SCREENSIZE_Y_MIN}" mecho -info "Please resize the screen first." anykey return 1 else return 0 fi } #============================================================================ # autodetect output: tty / html / file #============================================================================ if /usr/bin/tty -s <&1 then _EISLIB_PRINTMODE='tty' else if [ "$GATEWAY_INTERFACE" != "" ] then _EISLIB_PRINTMODE='html' else _EISLIB_PRINTMODE='file' fi fi #============================================================================ # determine screen size #============================================================================ refresh_screensize #============================================================================ # define colors #============================================================================ # textcolor _EISLIB_COLOR_TTY_TEXT_BLACK="\033[30m" _EISLIB_COLOR_FILE_TEXT_BLACK="" _EISLIB_COLOR_HTML_TEXT_BLACK="color:black;" _EISLIB_COLOR_TTY_TEXT_RED="\033[31m" _EISLIB_COLOR_FILE_TEXT_RED="" _EISLIB_COLOR_HTML_TEXT_RED="color:red;" _EISLIB_COLOR_TTY_TEXT_GREEN="\033[32m" _EISLIB_COLOR_FILE_TEXT_GREEN="" _EISLIB_COLOR_HTML_TEXT_GREEN="color:green;" _EISLIB_COLOR_TTY_TEXT_YELLOW="\033[33m" _EISLIB_COLOR_FILE_TEXT_YELLOW="" _EISLIB_COLOR_HTML_TEXT_YELLOW="color:brown;" _EISLIB_COLOR_TTY_TEXT_BLUE="\033[34m" _EISLIB_COLOR_FILE_TEXT_BLUE="" _EISLIB_COLOR_HTML_TEXT_BLUE="color:blue;" _EISLIB_COLOR_TTY_TEXT_MAGENTA="\033[35m" _EISLIB_COLOR_FILE_TEXT_MAGENTA="" _EISLIB_COLOR_HTML_TEXT_MAGENTA="color:fuchsia;" _EISLIB_COLOR_TTY_TEXT_CYAN="\033[36m" _EISLIB_COLOR_FILE_TEXT_CYAN="" _EISLIB_COLOR_HTML_TEXT_CYAN="color:cyan;" _EISLIB_COLOR_TTY_TEXT_WHITE="\033[37m" _EISLIB_COLOR_FILE_TEXT_WHITE="" _EISLIB_COLOR_HTML_TEXT_WHITE="color:white;" _EISLIB_COLOR_TTY_TEXT_DEFAULT="\033[0m" _EISLIB_COLOR_FILE_TEXT_DEFAULT="" _EISLIB_COLOR_HTML_TEXT_DEFAULT="color:white;" # backgroundcolor _EISLIB_COLOR_TTY_BACK_BLACK="\033[40m" _EISLIB_COLOR_FILE_BACK_BLACK="" _EISLIB_COLOR_HTML_BACK_BLACK="background-color:black;" _EISLIB_COLOR_TTY_BACK_RED="\033[41m" _EISLIB_COLOR_FILE_BACK_RED="" _EISLIB_COLOR_HTML_BACK_RED="background-color:red;" _EISLIB_COLOR_TTY_BACK_GREEN="\033[42m" _EISLIB_COLOR_FILE_BACK_GREEN="" _EISLIB_COLOR_HTML_BACK_GREEN="background-color:green;" _EISLIB_COLOR_TTY_BACK_YELLOW="\033[43m" _EISLIB_COLOR_FILE_BACK_YELLOW="" _EISLIB_COLOR_HTML_BACK_YELLOW="background-color:brown;" _EISLIB_COLOR_TTY_BACK_BLUE="\033[44m" _EISLIB_COLOR_FILE_BACK_BLUE="" _EISLIB_COLOR_HTML_BACK_BLUE="background-color:blue;" _EISLIB_COLOR_TTY_BACK_MAGENTA="\033[45m" _EISLIB_COLOR_FILE_BACK_MAGENTA="" _EISLIB_COLOR_HTML_BACK_MAGENTA="background-color:fuchsia;" _EISLIB_COLOR_TTY_BACK_CYAN="\033[46m" _EISLIB_COLOR_FILE_BACK_CYAN="" _EISLIB_COLOR_HTML_BACK_CYAN="background-color:cyan;" _EISLIB_COLOR_TTY_BACK_WHITE="\033[47m" _EISLIB_COLOR_FILE_BACK_WHITE="" _EISLIB_COLOR_HTML_BACK_WHITE="background-color:white;" _EISLIB_COLOR_TTY_BACK_DEFAULT="\033[49m" _EISLIB_COLOR_FILE_BACK_DEFAULT="" _EISLIB_COLOR_HTML_BACK_DEFAULT="background-color:white;" # textmode _EISLIB_COLOR_TTY_MODE_BRIGHT="\033[1m" _EISLIB_COLOR_FILE_MODE_BRIGHT="" _EISLIB_COLOR_HTML_MODE_BRIGHT="font-weight:bold;" _EISLIB_COLOR_TTY_MODE_DARK="\033[2m" _EISLIB_COLOR_FILE_MODE_DARK="" _EISLIB_COLOR_HTML_MODE_DARK="font-weight:lighter;" _EISLIB_COLOR_TTY_MODE_UNDERLINE="\033[4m" _EISLIB_COLOR_FILE_MODE_UNDERLINE="" _EISLIB_COLOR_HTML_MODE_UNDERLINE="text-decoration:underline;" _EISLIB_COLOR_TTY_MODE_BRIGHTBACK="\033[5m" _EISLIB_COLOR_FILE_MODE_BRIGHTBACK="" _EISLIB_COLOR_HTML_MODE_BRIGHTBACK="text-decoration:blink;" _EISLIB_COLOR_TTY_MODE_INVERS="\033[7m" _EISLIB_COLOR_FILE_MODE_INVERS="" _EISLIB_COLOR_HTML_MODE_INVERS="font-style:italic;" _EISLIB_COLOR_TTY_MODE_BRIGHTBRIGHTBACK="\033[1m\033[5m" _EISLIB_COLOR_FILE_MODE_BRIGHTBRIGHTBACK="" _EISLIB_COLOR_HTML_MODE_BRIGHTBRIGHTBACK="font-weight:bold;text-decoration:blink;" _EISLIB_COLOR_TTY_MODE_BRIGHTINVERS="\033[1m\033[7m" _EISLIB_COLOR_FILE_MODE_BRIGHTINVERS="" _EISLIB_COLOR_HTML_MODE_BRIGHTINVERS="font-weight:bold;font-weight:lighter;" _EISLIB_COLOR_TTY_MODE_DARKBRIGHTBACK="\033[2m\033[5m" _EISLIB_COLOR_FILE_MODE_DARKBRIGHTBACK="" _EISLIB_COLOR_HTML_MODE_DARKBRIGHTBACK="font-weight:lighter;font-weight:bold;" _EISLIB_COLOR_TTY_MODE_DARKINVERS="\033[2m\033[7m" _EISLIB_COLOR_FILE_MODE_DARKINVERS="" _EISLIB_COLOR_HTML_MODE_DARKINVERS="font-weight:lighter;font-style:italic;" # formatting _EISLIB_COLOR_TTY_PRE="" _EISLIB_COLOR_FILE_PRE="" _EISLIB_COLOR_HTML_PRE="" _EISLIB_COLOR_TTY_RESET="\033[0m" _EISLIB_COLOR_FILE_RESET="" _EISLIB_COLOR_HTML_RESET="" # predefined message styles _EISLIB_COLOR_TTY_STD="${_EISLIB_COLOR_TTY_TEXT_DEFAULT}${_EISLIB_COLOR_TTY_BACK_DEFAULT}" _EISLIB_COLOR_FILE_STD="" _EISLIB_COLOR_HTML_STD="${_EISLIB_COLOR_HTML_TEXT_BLACK}" _EISLIB_COLOR_TTY_INFO="${_EISLIB_COLOR_TTY_TEXT_GREEN}${_EISLIB_COLOR_TTY_BACK_DEFAULT}" _EISLIB_COLOR_FILE_INFO="" _EISLIB_COLOR_HTML_INFO="${_EISLIB_COLOR_HTML_TEXT_GREEN}" _EISLIB_COLOR_TTY_WARN="${_EISLIB_COLOR_TTY_TEXT_YELLOW}${_EISLIB_COLOR_TTY_BACK_BLACK}${_EISLIB_COLOR_TTY_MODE_BRIGHT}" _EISLIB_COLOR_FILE_WARN="" _EISLIB_COLOR_HTML_WARN="${_EISLIB_COLOR_HTML_TEXT_YELLOW}" _EISLIB_COLOR_TTY_ERROR="${_EISLIB_COLOR_TTY_TEXT_RED}${_EISLIB_COLOR_TTY_BACK_WHITE}${_EISLIB_COLOR_TTY_MODE_BRIGHTINVERS}" _EISLIB_COLOR_FILE_ERROR="" _EISLIB_COLOR_HTML_ERROR="${_EISLIB_COLOR_HTML_TEXT_RED}${_EISLIB_COLOR_HTML_MODE_BRIGHT}" #============================================================================ # end only include once #============================================================================ fi #============================================================================ # end #============================================================================