scriptify-all.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # /////////////////////////////////////////////////////////////////////////////
  2. # REFCODES.ORG
  3. # =============================================================================
  4. # This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
  5. # under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
  6. # licenses:
  7. # =============================================================================
  8. # GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
  9. # =============================================================================
  10. # Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
  11. # =============================================================================
  12. # Please contact the copyright holding author(s) of the software artifacts in
  13. # question for licensing issues not being covered by the above listed licenses,
  14. # also regarding commercial licensing models or regarding the compatibility
  15. # with other open source licenses.
  16. # /////////////////////////////////////////////////////////////////////////////
  17. #!/bin/bash
  18. # ------------------------------------------------------------------------------
  19. # INIT:
  20. # ------------------------------------------------------------------------------
  21. CURRENT_PATH="$(pwd)"
  22. SCRIPT_PATH="$(dirname $0)"
  23. cd "${SCRIPT_PATH}"
  24. SCRIPT_PATH="$(pwd)"
  25. cd "${CURRENT_PATH}"
  26. SCRIPT_DIR="${SCRIPT_PATH##*/}"
  27. SCRIPT_NAME="$(basename $0 .sh)"
  28. PARENT_PATH="$(realpath $(dirname $0)/..)"
  29. PARENT_DIR="${PARENT_PATH##*/}"
  30. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f3- )"
  31. if [ -z "${MODULE_NAME}" ]; then
  32. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f2- )"
  33. if [ -z "${MODULE_NAME}" ]; then
  34. MODULE_NAME="${SCRIPT_DIR}"
  35. fi
  36. fi
  37. # ------------------------------------------------------------------------------
  38. # ANSI ESCAPE CODES:
  39. # ------------------------------------------------------------------------------
  40. ESC_BOLD="\E[1m"
  41. ESC_FAINT="\E[2m"
  42. ESC_FG_RED="\E[31m"
  43. ESC_FG_GREEN="\E[32m"
  44. ESC_FG_YELLOW="\E[33m"
  45. ESC_FG_BLUE="\E[34m"
  46. ESC_FG_MAGENTA="\E[35m"
  47. ESC_FG_CYAN="\E[36m"
  48. ESC_FG_WHITE="\E[37m"
  49. ESC_RESET="\E[0m"
  50. # ------------------------------------------------------------------------------
  51. # PRINTLN:
  52. # ------------------------------------------------------------------------------
  53. function printLn {
  54. char="-"
  55. if [[ $# == 1 ]] ; then
  56. char="$1"
  57. fi
  58. echo -en "${ESC_FAINT}"
  59. printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ${char}
  60. echo -en "${ESC_RESET}"
  61. }
  62. # ------------------------------------------------------------------------------
  63. # QUIT:
  64. # ------------------------------------------------------------------------------
  65. function quit {
  66. input=""
  67. while ([ "$input" != "q" ] && [ "$input" != "y" ]); do
  68. echo -ne "> Continue? Enter [${ESC_BOLD}q${ESC_RESET}] to quit, [${ESC_BOLD}y${ESC_RESET}] to continue: ";
  69. read input;
  70. done
  71. # printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
  72. if [ "$input" == "q" ] ; then
  73. printLn
  74. echo -e "> ${ESC_BOLD}Aborting due to user input.${ESC_RESET}"
  75. exit
  76. fi
  77. }
  78. # ------------------------------------------------------------------------------
  79. # BANNER:
  80. # ------------------------------------------------------------------------------
  81. function printBanner {
  82. figlet -w 180 "/${MODULE_NAME}:>>>${SCRIPT_NAME}..." 2> /dev/null
  83. if [ $? -ne 0 ]; then
  84. banner "${SCRIPT_NAME}..." 2> /dev/null
  85. if [ $? -ne 0 ]; then
  86. echo -e "> ${SCRIPT_NAME}:" | tr a-z A-Z
  87. fi
  88. fi
  89. }
  90. printBanner
  91. # ------------------------------------------------------------------------------
  92. # HELP:
  93. # ------------------------------------------------------------------------------
  94. function printHelp {
  95. printLn
  96. echo -e "Usage: ${ESC_BOLD}${SCRIPT_NAME}${ESC_RESET}.sh [-h]"
  97. printLn
  98. echo -e "Scriptifies all projects possible found in the parent folder of this script, e.g. fat self-executable shell scripts are created where applicable."
  99. printLn
  100. echo -e "${ESC_BOLD}-h${ESC_RESET}: Print this help"
  101. printLn
  102. }
  103. if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
  104. printHelp
  105. exit 0
  106. fi
  107. # ------------------------------------------------------------------------------
  108. # MAIN:
  109. # ------------------------------------------------------------------------------
  110. cd "${SCRIPT_PATH}/.."
  111. dirs=$(find . -maxdepth 2 -type d | grep -v -e "target" -e "src" -F -e "/.")
  112. for dir in $dirs ; do
  113. if [ -d "${dir}" ] && [ "$dir" != 'RemoteSystemsTempFiles/' ] && [ "$dir" != '.' ] ; then
  114. cd "$dir"
  115. if [ -f "./scriptify.sh" ] && [ -d "./target" ] ; then
  116. ./scriptify.sh
  117. fi
  118. cd "${SCRIPT_PATH}/.."
  119. fi
  120. done
  121. cd "${CURRENT_PATH}"