Created
November 26, 2013 04:10
-
-
Save olegchir/7653336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Arguments | |
export NOVO_LOCALE="EN" | |
#Constants | |
export DEPENDS_CMD=( ) | |
export EXIT_CODE_OK=0 | |
export EXIT_CODE_DEPENDENCIES_FAILED=-1 | |
export UI_HORIZONTAL_RULER="================================================================================" | |
#Localization | |
export CHECKING_DEPENDENCIES_IN_PROGRESS_RU="Проверка зависимостей..." | |
export CHECKING_DEPENDENCIES_IN_PROGRESS_EN="Checking dependencies..." | |
export DEPENDENCIES_OK_RU="Зависимости в порядке." | |
export DEPENDENCIES_OK_EN="Dependencies OK." | |
#Methods | |
#append to file (file name in $1) | |
append_from_end_of_file () { | |
# Skip first argument, all next transformed into one line | |
TEMP_PRINT="" | |
FIRST_IN_ARRAY="yes" | |
for i in "$@" | |
do | |
if [ ${FIRST_IN_ARRAY} == "yes" ]; then | |
FIRST_IN_ARRAY="no"; | |
else | |
TEMP_PRINT="${TEMP_PRINT}${i} "; | |
fi | |
done | |
TEMP_PRINT="${TEMP_PRINT%?}" #remove trailing space character | |
export TO_PRINT=${TEMP_PRINT} | |
#Use Perl to append to the end of file | |
perl -i -pe 'eof && do{chomp; print "$_ \n$ENV{TO_PRINT}\n"; exit}' ${1} | |
} | |
hr () { | |
echo ${UI_HORIZONTAL_RULER} | |
} | |
p () { | |
echo $1 | |
} | |
#http://www.linuxjournal.com/content/return-values-bash-functions | |
p_ret () { | |
RESULT=$2 | |
local __resultvar=$1 | |
local myresult=$RESULT | |
if [[ "$__resultvar" ]]; then | |
eval $__resultvar="'$myresult'" | |
else | |
echo "$myresult" | |
fi | |
} | |
lp () { | |
MAIN_RESULT="" | |
for var in "$@" | |
do | |
LOCALIZED_VAR_NAME="${var}_${NOVO_LOCALE}" | |
UNIVERSAL_VAR_NAME="${var}" | |
RESULT="err" | |
if [ -n "${!LOCALIZED_VAR_NAME}" ]; then | |
p_ret RESULT "${!LOCALIZED_VAR_NAME}" | |
elif [ -n "${!UNIVERSAL_VAR_NAME}" ]; then | |
p_ret RESULT "${!UNIVERSAL_VAR_NAME}" | |
else | |
p_ret RESULT "${var}" | |
fi | |
MAIN_RESULT="${MAIN_RESULT} ${RESULT} " | |
done | |
p "${MAIN_RESULT}" | |
} | |
#http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script | |
check_dependency () { | |
if hash $1 2>/dev/null; then | |
lp $1 "DEPENDENCY_FOUND" | |
else | |
p ${EXIT_CODE_DEPENDENCIES_FAILED} | |
fi | |
} | |
check_dependencies () { | |
lp "CHECKING_DEPENDENCIES_IN_PROGRESS" | |
for dep in "${DEPENDS_CMD[@]}" | |
do | |
check_dependency "${dep}" | |
done | |
lp "DEPENDENCIES_OK" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment