#---------------------------------------------------------------------------- # /var/install/include/jedlib - library for eisfair scripts # # Copyright (c) 2001-2020 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2006-03-29 jed # Last Update: $Id: jedlib 63283 2019-02-18 16:19:27Z jed $ # # Usage: jed-lib --version - print jedlib version number # # 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. #---------------------------------------------------------------------------- _jedlib_passwdfile=/etc/passwd _jedlib_date=`/bin/date +%Y-%m-%d` _jedlib_time=`/bin/date +%H:%M:%S` #---------------------------------------------------------------------------- # interface description #---------------------------------------------------------------------------- # Variables: # configlog_file This variable needs to contain a valid path # to the configlog file. # force_quiet_run This variable need to be set to 'true' or '1' # to suppress screen output # # Routines: # update_jedlib() update jedlib function_library # # myecho() special echo command which allows to suppress # screen output based on the global variable # ${force_quiet_run} and the '--force-output' # switch. # myanykey() special anykey command which allows to suppress # a hard key input and replace it by a delay based # on the global variable $force_quiet_run and the # '--force-input' switch. # # install_config() install/update package configuration file # # write_to_config_log() writes a message to config log # compress_config_log() compress config log to given number of configuration logs # display_config_log() display config log file if it exists # # print_short_header() print a short file header which references to # the config file # # insert_date() insert date_stamp into text string # insert_hostname() insert hostname into text string # # trim_spaces() return string with no spaces # # get_accessrights() get file/directory ownership and access rights # set_accessrights() set file/directory ownership and access rights # # rand_char() return random character # rand_string() return random string # # shorten_string() return shortened string # # get_last_day_of_month() return date of last day of the month # get_yesterday() return date of previous day # get_tomorrow() return date of next day # get_diff_days() return number of days between two dates # get_diff_dates() return number of years, month, days, hours, # minutes and seconds between two dates # sec_to_formated_time() return formated time "[HH:]MM:SS" from pure seconds # formated_time_to_sec() return seconds from formated time "[HH:]MM:SS" # # unit_to_numeric() return pure integer value from value incl. unit (k/M/G/T) # numeric_to_unit() return value incl. unit (k/M/G/T/P) from pure integer # # abs_path() return the absolute path to a given file # # delay_script_exec() delay script execution, except the current script # is the first one on the list # # format_version() format version number, e.g. 1.002.3. -> 1.2.3.0 # compare_version() compare two version numbers, e.g. 1.0.2 and 1.1.0 # # Functions: # is_root() check if root equivalent user # is_numeric() check if numeric value # is_date() check if date value [YYYY-MM-DD] # is_time() check if time value [HH:MM:SS] # # called_from_install() check if script was called from the install # process # # host_exists() check if host exists #---------------------------------------------------------------------------- #============================================================================ # only include this file once #============================================================================ if [ "$_JEDLIB" != 'true' ] then _JEDLIB='true' if [ "$1" = "version" -o "$1" = '-version' -o "$1" = '--version' ] then _jedlib_version=`grep -E "Last Update *:" $0 | sed "s/.*jedlib[-_.a-z0-9]* //g" | cut -d' ' -f1` echo ${_jedlib_version} exit 0 fi # # update_jedlib # ------------- # # update shared jedlib library file # # Parameters: $1 name of package # update_jedlib () { local _uj_destfile local _uj_destver local _uj_packfile local _uj_srcfile local _uj_srcver _uj_srcfile=/var/install/include/jedlib.${1} _uj_destfile=/var/install/include/jedlib # extract jedlib from archive _uj_packfile=`find /tmp -maxdepth 1 -type l -name "${1}.*" ! -name "*.info" | head -n1` if [ -n "${_uj_packfile}" ] then if [ -s "${_uj_packfile}" ] then tar xjf ${_uj_packfile} var/install/include/jedlib.${1} -C / fi fi if [ -f ${_uj_srcfile} ] then # src file exists, go on ... if [ -f ${_uj_destfile} ] then # file exists - check versions _uj_srcver=`/bin/sh ${_uj_srcfile} version` _uj_destver=`/bin/sh ${_uj_destfile} version` if [ -n "${_uj_destver}" ] then # version number exists - compare version numbers if [ `echo "${_uj_srcver} > ${_uj_destver}" | bc` -eq 1 ] then # update file echo "updating shared library file (${_uj_destver}->${_uj_srcver}) ..." mv -v ${_uj_srcfile} ${_uj_destfile} fi else # no version number exists - update file echo "updating shared library file ..." mv -v ${_uj_srcfile} ${_uj_destfile} fi else # file doesn't exist - update file echo "updating shared library file ..." mv -v ${_uj_srcfile} ${_uj_destfile} fi # make sure that the file is world readable chmod 644 ${_uj_destfile} # remove copy of shared library file rm -f ${_uj_srcfile} fi } # # myecho # ------ # # special echo command which allows to suppress screen output # based on the global variable '$force_quiet_run'. # # Parameters: $1/$2 '--package ' and optionally # '--force-output' and/or # $3-$n normal mecho switches and text # # Output: output text # myecho () { local _me_exit local _me_force_output local _me_outstr local _me_switch local _me_quiet if [ "${_EISLIB}" != 'true' ] then # load eislib if not already loaded . /var/install/include/eislib fi # check if quiet run has been requested _me_quiet=false if is_numeric "${force_quiet_run}" then if [ ${force_quiet_run} -eq 1 ] then _me_quiet=true fi else if [ -n "${force_quiet_run}" ] then _me_quiet=${force_quiet_run} fi fi _me_exit=0 _me_force_output=0 while [ ${_me_exit} -eq 0 ] do case $1 in *-force-output ) _me_force_output=1 shift ;; *-pack|*-package ) _me_package="$2" shift; shift ;; * ) _me_exit=1 ;; esac done if [ ${_me_force_output} -eq 1 ] then _me_quiet=false else if called_from_install --pack "${_me_package}" then _me_quiet=true fi fi if ! ${_me_quiet:-false} then _me_exit=0 _me_switch='' _me_outstr='' while [ ${_me_exit} -eq 0 ] do case $1 in -n|*-std|*stdbr|*-info|*-warn|*-error|*-link|*-ok|*-fail|*-tty|*-html|*-file ) _me_switch="${_me_switch}$1 " shift ;; * ) _me_outstr="$*" _me_exit=1 ;; esac done # be verbose mecho ${_me_switch} "${_me_outstr}" fi } # # myanykey # -------- # # special anykey command which allows to suppress a hard # key input and replace it by a delay based on the global # variable 'force_quiet_run'. # # Parameters: $1 '--package ' and optionally # '--force-input' and/or optionally # '--timeout