#! /bin/bash # function library for versions retrieval # v. 1.0.2 # Function list: # k_centos_version() - function returns CentOS version in variable 'centos_version' # k_script_version() - function returns C script version # k_mysql_version() - function returns mysql version, MYSQL_VERSION - full x.y.z, MYSQL_VERSION1 - x, MYSQL_VERSION2 - y, MYSQL_VERSION3 - z # k_ruby_version() - function returns RUBY_VERSION, 0 - not installed # k_gem_version() - function returns GEM_VERSION, 0 - not installed # k_passenger_version() - function returns PASSENGER_VERSION, 0 - not installed # Function naming rules # k__ where either object or action are not mandatory (only object or only action is necessary, could be both also) # function returns CentOS version k_centos_version() { k_detect_os if [[ "$OS" == "centos" ]]; then centos_version=$DIST else report "OS $OS $DIST, not Centos!" 1 EXIT_CODE=1 fi } # function returns mysql version # MYSQL_VERSION - full x.y.z MYSQL_VERSION1 - x MYSQL_VERSION2 - y MYSQL_VERSION3 - z k_mysql_version() { if [ ! -f /usr/bin/mysql ]; then report "MySQL not installed" 2 return fi local mv=$(mysql -V) if echo $mv | grep -q "Ver 14.14"; then MYSQL_VERSION=`echo $mv | awk '{print $5}' | sed 's/,$//' | xargs` elif echo $mv | grep -q "Ver 8."; then MYSQL_VERSION=`echo $mv | awk '{print $3}' | xargs` else MYSQL_VERSION="unknown" report "MYSQL_VERSION unknown: $mv" 1 report " fix the script /kf/date_get.sh k_mysql_version()" fix EXIT_CODE=1 return fi MYSQL_VERSION1=`echo $MYSQL_VERSION | awk -F "." '{print $1}'` MYSQL_VERSION2=`echo $MYSQL_VERSION | awk -F "." '{print $2}'` MYSQL_VERSION3=`echo $MYSQL_VERSION | awk -F "." '{print $3}'` } # function returns C script version k_script_version() { script=$1 date_check="2021-11-22 00:00:00" # (constant) date when all C scripts started to produce version output (until this date, all scripts are considered as outdated) if [ ! -e $script ]; then echo "" return fi # get script modify date (time when it was installed) script_installed_at=$(stat $script | grep Modify | cut -c9-27) # convert dates to seconds (for easy comparison) date_check_seconds=$(date -d "$date_check" +%s) script_installed_at_seconds=$(date -d "$script_installed_at" +%s) if [ $date_check_seconds -ge $script_installed_at_seconds ]; then echo "" return fi $script -v } # function returns RUBY_VERSION, 0 - not installed k_ruby_version() { RUBY_VERSION="0" if `gem --version | grep -q -v 'command not found'`; then RUBY_VERSION=`ruby --version | awk '{print $2}' | awk -F "p" '{print $1}' | xargs` fi } # function returns GEM_VERSION, 0 - not installed k_gem_version() { GEM_VERSION="0" if `gem --version | grep -q -v 'command not found'`; then GEM_VERSION=`gem --version | xargs` fi } # function returns PASSENGER_VERSION, 0 - not installed k_passenger_version() { # local pv=`passenger --version` # # v6+ # PASSENGER_VERSION=`echo $pv | awk '{print $3}' | xargs` # # v4+ # if [[ $PASSENGER_VERSION == "" ]]; then # if echo $pv | grep -q Hongli; then # PASSENGER_VERSION=`echo $pv | grep 'Phusion Passenger version' | awk '{print $4}' | xargs` # fi # fi # if [[ $PASSENGER_VERSION == "" ]]; then # PASSENGER_VERSION="0" # fi local pv=`passenger-config --version` PASSENGER_VERSION=`echo $pv | xargs` if echo $PASSENGER_VERSION | grep -q 'Phusion Passenger(R)'; then PASSENGER_VERSION=`echo $PASSENGER_VERSION | awk '{print $3}' | xargs` fi if [[ $PASSENGER_VERSION == "" ]]; then PASSENGER_VERSION="0" fi }