reGen2 Linux Release Metatool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.5 KiB

  1. #!/bin/bash
  2. # Copyright 2010-2011, Asio Software Technologies
  3. # Distributed under the terms of the GNU General Public License v3
  4. #-------------------------------------------------------------------------------
  5. # Checks whether a supplied variable is defined or not
  6. # Parameters: %variable%
  7. #-------------------------------------------------------------------------------
  8. function isDefined() {
  9. [[ ${!1-X} == ${!1-Y} ]]
  10. }
  11. #-------------------------------------------------------------------------------
  12. # Checks whether a supplied variable is enabled or not
  13. # Parameters: %variable%
  14. #-------------------------------------------------------------------------------
  15. function isEnabled() {
  16. case "${1}" in
  17. [Ee][Nn][Aa][Bb][Ll][Ee][Dd])
  18. return 0
  19. ;;
  20. [Tt][Rr][Uu][Ee])
  21. return 0
  22. ;;
  23. [Yy][Ee][Ss])
  24. return 0
  25. ;;
  26. 1)
  27. return 0
  28. ;;
  29. esac
  30. return 1
  31. }
  32. #-------------------------------------------------------------------------------
  33. # Checks whether a variable is defined and if value's length > 0
  34. # Parameters: %variable%
  35. #-------------------------------------------------------------------------------
  36. function isSet() {
  37. if isDefined ${1}; then
  38. if [[ -n ${!1} ]]; then
  39. return 0
  40. fi
  41. fi
  42. return 1
  43. }
  44. #-------------------------------------------------------------------------------
  45. # Loads EzBuild configuration
  46. #-------------------------------------------------------------------------------
  47. function loadConfiguration() {
  48. source ${EZROOT}/config/${EZNAME}.conf &> /dev/null || panic
  49. source ${EZROOT}/config/layout.conf &> /dev/null || panic
  50. source /etc/ezbuild/${EZNAME}.conf &> /dev/null || panic
  51. source /etc/ezbuild/layout.conf &> /dev/null || panic
  52. }
  53. #-------------------------------------------------------------------------------
  54. # Loads all EzBuild Libraries
  55. #-------------------------------------------------------------------------------
  56. function loadLibraries() {
  57. source ${EZROOT}/libraries/colors &> /dev/null || panic
  58. }
  59. #-------------------------------------------------------------------------------
  60. # Saves specified message into a log file
  61. # Parameters: %message% %level%
  62. #-------------------------------------------------------------------------------
  63. function logMessage() {
  64. if isEnabled ${LOGGING}; then
  65. MESSAGE="${1}"
  66. TYPE="${2}"
  67. DATE=$(date +"${LOGDATEFORMAT}")
  68. if [ -z ${TYPE} ]; then
  69. TYPE=" - "
  70. fi
  71. echo -e "[${DATE}][${TYPE}] ${MESSAGE}" >> ${LOGFILE}
  72. fi
  73. }
  74. #-------------------------------------------------------------------------------
  75. # Saves executed command multiline output into a log file
  76. # Parameters: %command_output%
  77. #-------------------------------------------------------------------------------
  78. function logOutput() {
  79. if isEnabled ${LOGGING}; then
  80. echo -e "${@}" | awk '{ print " )> ", $0; }' >> ${LOGFILE}
  81. fi
  82. }
  83. #-------------------------------------------------------------------------------
  84. # Outputs error message and aborts program execution
  85. #-------------------------------------------------------------------------------
  86. function panic() {
  87. echo -e "FATAL ERROR: Unable to load necessary files!"
  88. echo -e "Your EzBuild installation seems to be broken..."
  89. exit 1
  90. }
  91. #-------------------------------------------------------------------------------
  92. # Outputs formatted error message to both display and log file
  93. # Parameters: %message%
  94. #-------------------------------------------------------------------------------
  95. function printError() {
  96. logMessage "${1}" "ERROR"
  97. echo -e " ${MESSAGE_ERROR} ${@}"
  98. }
  99. #-------------------------------------------------------------------------------
  100. # Outputs formatted information to both display and log file
  101. # Parameters: %message%
  102. #-------------------------------------------------------------------------------
  103. function printInfo() {
  104. logMessage "${1}" "INFO"
  105. echo -e " ${MESSAGE_INFO} ${@}"
  106. }
  107. #-------------------------------------------------------------------------------
  108. # Outputs formatted warning to both display and log file
  109. # Parameters: %message%
  110. #-------------------------------------------------------------------------------
  111. function printWarn() {
  112. logMessage "${1}" "WARN"
  113. echo -e " ${MESSAGE_WARN} ${@}"
  114. }
  115. #-------------------------------------------------------------------------------
  116. # Silently executes given command and saves its output to log file if enabled
  117. # Parameters: %command%
  118. #-------------------------------------------------------------------------------
  119. function run() {
  120. COMMAND="${1}"
  121. logMessage "Executing: \"${COMMAND}\"" "DEBUG"
  122. OUTPUT=$(${COMMAND} 2>&1)
  123. RESULT=${?}
  124. logOutput "${OUTPUT}"
  125. return ${RESULT}
  126. }
  127. #-------------------------------------------------------------------------------
  128. # Returns a UNIX timestamp
  129. #-------------------------------------------------------------------------------
  130. function timestamp() {
  131. echo $(date +%s)
  132. }
  133. #-------------------------------------------------------------------------------
  134. # Returns lowercase string
  135. # Parameters: %string%
  136. #-------------------------------------------------------------------------------
  137. function toLower() {
  138. echo "${@}" | tr '[:upper:]' '[:lower:]'
  139. }
  140. #-------------------------------------------------------------------------------
  141. # Returns uppercase string
  142. # Parameters: %string%
  143. #-------------------------------------------------------------------------------
  144. function toUpper() {
  145. echo "${@}" | tr '[:lower:]' '[:upper:]'
  146. }
  147. #-------------------------------------------------------------------------------
  148. # Returns only the first part of a string, delimited by tabs or spaces
  149. # Parameters: %string%
  150. #-------------------------------------------------------------------------------
  151. function trim() {
  152. echo ${1}
  153. }