Ein für Shopware 6 vorbereitet Systemmanagment.
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.

164 lines
3.6 KiB

1 year ago
  1. #!/bin/bash
  2. ### DO NOT EDIT THIS FILE
  3. if [ true != ${includes_main_functions:-false} ]
  4. then
  5. includes_main_functions=true
  6. function echoMainTitle {
  7. echo -e "\033[38;5;214m$1\033[0m"
  8. }
  9. function echoSubTitle {
  10. echo -e "\033[38;5;142m$1\033[0m"
  11. }
  12. function echoSmall {
  13. echo -e "\033[38;5;240m$1\033[0m"
  14. }
  15. function echoSelect {
  16. local select="$1"
  17. local message="$2"
  18. echo -e "\033[0;33m$select\033[0m $message"
  19. }
  20. function echoError {
  21. echo -e "\033[0;91m$1\033[0m"
  22. }
  23. function echoWarning {
  24. echo -e "\033[0;33m$1\033[0m"
  25. }
  26. function echoSuccess {
  27. echo -e "\033[0;32m$1\033[0m"
  28. }
  29. function getParameter {
  30. local name=$1
  31. local has=$2
  32. local parameters=($3)
  33. for i in "${!parameters[@]}"
  34. do
  35. if [ "${parameters[$i]}" == "$name" ] && [ "$has" == true ]
  36. then
  37. ((j=i+1))
  38. echo "${parameters[$j]}"
  39. elif [ "${parameters[$i]}" == "$name" ]
  40. then
  41. echo true
  42. fi
  43. done
  44. }
  45. function getArgument {
  46. local var=$1
  47. local errmsg=${2:-"Invalid Argument"}
  48. local allow=${3:-true}
  49. if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
  50. then
  51. echo "$errmsg" >&2
  52. exit 1
  53. fi
  54. echo "$var"
  55. }
  56. function isAllowed {
  57. local var="$1"
  58. local allow="$2"
  59. local valid=true
  60. if [ "$allow" == true ] && [ "$var" == "" ]
  61. then
  62. valid=false
  63. elif [ "$allow" != false ] && [ "$allow" != true ]
  64. then
  65. allow=($allow)
  66. local found=false
  67. for i in "${!allow[@]}"
  68. do
  69. if [ "${allow[$i]}" == "$var" ]
  70. then
  71. found=true
  72. fi
  73. done
  74. if [ "$found" != true ]
  75. then
  76. valid=false
  77. fi
  78. fi
  79. echo $valid
  80. }
  81. function readConsole {
  82. local message="$1"
  83. local errmsg="$2"
  84. local allow=${3:-false}
  85. local default="$4"
  86. if [ "$default" != "" ]
  87. then
  88. read -p "$message [default:$default]: " var
  89. else
  90. read -p "$message: " var
  91. fi
  92. if [ "$var" == "" ] && [ "$default" != "" ]
  93. then
  94. var="$default"
  95. fi
  96. if [ "$(isAllowed "$var" "$allow")" == false ]
  97. then
  98. echo "$errmsg" >&2
  99. var=$(readConsole "$message" "$errmsg" "$allow" "$default")
  100. fi
  101. echo "$var"
  102. }
  103. function postScript {
  104. local script=$(getArgument "$1" "Usage: postScript \"post_script.sh\"" true)
  105. if [ -f "$script" ]
  106. then
  107. source "$script"
  108. fi
  109. }
  110. function getConfig {
  111. local env=$(getArgument "$1" "Usage getEnvVar [live|stage|local_live|local_stage] var" "live stage local_live local_stage")
  112. local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|local_live|local_stage] var" true)
  113. echo "$(eval "echo \"\$${env}_$suffix\"")"
  114. }
  115. function sedEscape {
  116. echo "$1" | sed -r 's/([\$\.\*\/\[\\^])/\\\1/g' | sed 's/[]]/\[]]/g'
  117. }
  118. function confirm {
  119. confirm="$(readConsole "Should i execute? [y,n]" "Invalid selection" "y n")"
  120. if [ "$confirm" == "n" ]
  121. then
  122. echo
  123. echoError "Aborting"
  124. echo
  125. exit
  126. fi
  127. }
  128. function getSudoPassword {
  129. if [ "${project_manager_sudo_password}" == "" ]
  130. then
  131. echo -n "Sudo Password:"
  132. read -s project_manager_sudo_password
  133. fi
  134. echo project_manager_sudo_password
  135. }
  136. fi