From f3508cf9d90e37eb5f449a0825b4076518432efc Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 6 Nov 2023 13:11:44 +0100 Subject: [PATCH] shellcheck braces and updated check-project file --- dev-tools/check_project.sh | 188 +++++++++++++++--------------- dev-tools/clean-setup.sh | 56 ++++----- dev-tools/debug-server-start.sh | 48 ++++---- dev-tools/prepare.sh | 32 ++--- dev-tools/test.sh | 26 ++--- embark/entrypoint.sh | 22 ++-- export-DB.sh | 16 +-- helper/helper_embark_general.sh | 76 ++++++------ helper/wickStrictModeFail.sh | 16 +-- import-DB.sh | 18 +-- installer.sh | 200 ++++++++++++++++---------------- run-server.sh | 104 ++++++++--------- supervisor.sh | 4 +- 13 files changed, 403 insertions(+), 403 deletions(-) diff --git a/dev-tools/check_project.sh b/dev-tools/check_project.sh index 8a20a2937..8314fe3b5 100755 --- a/dev-tools/check_project.sh +++ b/dev-tools/check_project.sh @@ -16,10 +16,10 @@ # And check Django if its deployable export DJANGO_SETTINGS_MODULE=embark.settings.dev -export PYTHONPATH="$PYTHONPATH:${PWD}/embark/embark/:${PWD}/embark/" +export PYTHONPATH="${PYTHONPATH}:${PWD}/embark/embark/:${PWD}/embark/" export PIPENV_VENV_IN_PROJECT="True" -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 cd .. || exit 1 RED='\033[0;31m' @@ -28,35 +28,35 @@ ORANGE='\033[0;33m' BOLD='\033[1m' NC='\033[0m' # no color -if [[ $EUID -eq 0 ]]; then - echo -e "\\n$RED""Running this script as root is not supported""$NC\\n" +if [[ ${EUID} -eq 0 ]]; then + echo -e "\\n${RED}""Running this script as root is not supported""${NC}\\n" fi # check that all tools are installed check_tools(){ TOOLS=("jshint" "shellcheck" "pylint" "yamllint") for TOOL in "${TOOLS[@]}";do - if ! command -v "$TOOL" > /dev/null ; then - echo -e "\\n""$RED""$TOOL is not installed correctly""$NC""\\n" + if ! command -v "${TOOL}" > /dev/null ; then + echo -e "\\n""${RED}""${TOOL} is not installed correctly""${NC}""\\n" exit 1 fi done pipenv run djlint --version | grep "version"; RES=$? - if [[ -z "$RES" ]];then - echo -e "\\n""$RED""djlint(pip) is not installed correctly""$NC""\\n" + if [[ -z "${RES}" ]];then + echo -e "\\n""${RED}""djlint(pip) is not installed correctly""${NC}""\\n" fi } # checks django configuration check_django(){ cd ./embark || exit 1 - echo -e "\\n""$ORANGE""$BOLD""EMBArk django-settings check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk django-settings check""${NC}""\\n""${BOLD}""=================================================================""${NC}" if ! pipenv run python ./manage.py check | grep -q "System check identified no issues"; then #TODO add --deploy flag - echo -e "\\n""$RED$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${RED}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) MODULES_TO_CHECK_ARR+=( "./embark/settings.py" ) else - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" fi cd .. || exit 1 } @@ -64,25 +64,25 @@ check_django(){ # checks js-scripts with jshint for errors # config @ .jshintrc jscheck(){ - echo -e "\\n""$ORANGE""$BOLD""EMBArk javascript-files check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk javascript-files check""${NC}""\\n""${BOLD}""=================================================================""${NC}" mapfile -t JS_SCRIPTS < <(find ./embark -iname "*.js") for JS_SCRIPT in "${JS_SCRIPTS[@]}"; do - echo -e "\\n""$GREEN""Run jshint on $JS_SCRIPT:""$NC""\\n" - # mapfile -t JS_RESULT < <(jshint "$JS_SCRIPT") - jshint -c ./.jshintrc "$JS_SCRIPT" + echo -e "\\n""${GREEN}""Run jshint on ${JS_SCRIPT}:""${NC}""\\n" + # mapfile -t JS_RESULT < <(jshint "${JS_SCRIPT}") + jshint -c ./.jshintrc "${JS_SCRIPT}" RES=$? - if [[ $RES -eq 2 ]] ; then - echo -e "\\n""$RED$BOLD==> FIX ERRORS""$NC""\\n" + if [[ ${RES} -eq 2 ]] ; then + echo -e "\\n""${RED}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$JS_SCRIPT" ) - elif [[ $RES -eq 1 ]]; then - echo -e "\\n""$ORANGE$BOLD==> FIX WARNINGS""$NC""\\n" + MODULES_TO_CHECK_ARR+=( "${JS_SCRIPT}" ) + elif [[ ${RES} -eq 1 ]]; then + echo -e "\\n""${ORANGE}${BOLD}==> FIX WARNINGS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$JS_SCRIPT" ) - elif [[ $RES -eq 0 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + MODULES_TO_CHECK_ARR+=( "${JS_SCRIPT}" ) + elif [[ ${RES} -eq 0 ]]; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$RED$BOLD""[jshint]ERRORS in SCRIPT""$NC""\\n" + echo -e "\\n""${RED}${BOLD}""[jshint]ERRORS in SCRIPT""${NC}""\\n" fi done } @@ -90,109 +90,109 @@ jscheck(){ # uses djlint to check for errors in all html-template files inside /embark (Django-root-dir) # no config templatechecker(){ - echo -e "\\n""$ORANGE""$BOLD""EMBArk html-templates check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk html-templates check""${NC}""\\n""${BOLD}""=================================================================""${NC}" mapfile -t HTML_FILE < <(find ./embark -iname "*.html") for HTML_FILE in "${HTML_FILE[@]}"; do - echo -e "\\n""$GREEN""Run djlint on $HTML_FILE:""$NC""\\n" - pipenv run djlint "$HTML_FILE" + echo -e "\\n""${GREEN}""Run djlint on ${HTML_FILE}:""${NC}""\\n" + pipenv run djlint "${HTML_FILE}" RES=$? - if [[ $RES -eq 1 ]]; then - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + if [[ ${RES} -eq 1 ]]; then + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$HTML_FILE" ) - elif [[ $RES -eq 0 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + MODULES_TO_CHECK_ARR+=( "${HTML_FILE}" ) + elif [[ ${RES} -eq 0 ]]; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$RED$BOLD""[html-check(tidy)]ERRORS in SCRIPT""$NC""\\n" + echo -e "\\n""${RED}${BOLD}""[html-check(tidy)]ERRORS in SCRIPT""${NC}""\\n" fi done } shellchecker() { - echo -e "\\n""$ORANGE""$BOLD""EMBArk Shellcheck""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk Shellcheck""${NC}""\\n""${BOLD}""=================================================================""${NC}" if ! command -v shellcheck >/dev/null 2>&1; then - echo -e "\\n""$ORANGE""Shellcheck not found!""$NC""\\n""$ORANGE""Install shellcheck via 'apt-get install shellcheck'!""$NC\\n" + echo -e "\\n""${ORANGE}""Shellcheck not found!""${NC}""\\n""${ORANGE}""Install shellcheck via 'apt-get install shellcheck'!""${NC}\\n" exit 1 fi - echo -e "\\n""$GREEN""Run shellcheck on installer:""$NC""\\n" + echo -e "\\n""${GREEN}""Run shellcheck on installer:""${NC}""\\n" if shellcheck ./installer.sh || [[ $? -ne 1 && $? -ne 2 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) MODULES_TO_CHECK_ARR+=( "installer.sh" ) fi - echo -e "\\n""$GREEN""Run shellcheck on this script:""$NC""\\n" + echo -e "\\n""${GREEN}""Run shellcheck on this script:""${NC}""\\n" if shellcheck ./dev-tools/check_project.sh || [[ $? -ne 1 && $? -ne 2 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) MODULES_TO_CHECK_ARR+=( "dev-tools/check_project.sh" ) fi - echo -e "\\n""$GREEN""Find shell scripts and run shellcheck on them:""$NC""\\n" + echo -e "\\n""${GREEN}""Find shell scripts and run shellcheck on them:""${NC}""\\n" mapfile -t SH_SCRIPTS < <(find embark -iname "*.sh") for SH_SCRIPT in "${SH_SCRIPTS[@]}"; do - echo -e "\\n""$GREEN""Run shellcheck on $SH_SCRIPT:""$NC""\\n" - if shellcheck -x "$SH_SCRIPT" || [[ $? -ne 1 && $? -ne 2 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "\\n""${GREEN}""Run shellcheck on ${SH_SCRIPT}:""${NC}""\\n" + if shellcheck -x -o require-variable-braces "${SH_SCRIPT}" || [[ $? -ne 1 && $? -ne 2 ]]; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$SH_SCRIPT" ) + MODULES_TO_CHECK_ARR+=( "${SH_SCRIPT}" ) fi done } pycodestyle_check(){ - echo -e "\\n""$ORANGE""$BOLD""EMBArk pycodestyle check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk pycodestyle check""${NC}""\\n""${BOLD}""=================================================================""${NC}" echo -e "[*] Searching python files and test with pycodestyle.py" if command -v pipenv run pycodstyle >/dev/null 2>&1; then - echo -e "\\n""$ORANGE""pycodestyle found in PATH!""$NC""\\n" + echo -e "\\n""${ORANGE}""pycodestyle found in PATH!""${NC}""\\n" PYCODESTYLE="pycodestyle" elif [[ -f "/usr/lib/python3/dist-packages/pycodestyle.py" ]]; then - echo -e "\\n""$ORANGE""pycodestyle found!""$NC""\\n" + echo -e "\\n""${ORANGE}""pycodestyle found!""${NC}""\\n" PYCODESTYLE="/usr/lib/python3/dist-packages/pycodestyle.py" else - echo -e "\\n""$ORANGE""pycodestyle not found!""$NC""\\n""$ORANGE""Install pycodestyle via 'apt-get install pycodestyle'!""$NC\\n" + echo -e "\\n""${ORANGE}""pycodestyle not found!""${NC}""\\n""${ORANGE}""Install pycodestyle via 'apt-get install pycodestyle'!""${NC}\\n" exit 1 fi - echo -e "\\n""$GREEN""Find python scripts and run pycodestyle on them:""$NC""\\n" + echo -e "\\n""${GREEN}""Find python scripts and run pycodestyle on them:""${NC}""\\n" mapfile -t PY_SCRIPTS < <(find embark -iname "*.py") for PY_SCRIPT in "${PY_SCRIPTS[@]}"; do - echo -e "\\n""$GREEN""Run pycodestyle on $PY_SCRIPT:""$NC""\\n" - if pipenv run "$PYCODESTYLE" --config=./.pycodestylerc --first "$PY_SCRIPT" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) || [[ $? -ne 1 && $? -ne 2 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "\\n""${GREEN}""Run pycodestyle on ${PY_SCRIPT}:""${NC}""\\n" + if pipenv run "${PYCODESTYLE}" --config=./.pycodestylerc --first "${PY_SCRIPT}" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) || [[ $? -ne 1 && $? -ne 2 ]]; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$PY_SCRIPT" ) + MODULES_TO_CHECK_ARR+=( "${PY_SCRIPT}" ) fi done } banditer() { - echo -e "\\n""$ORANGE""$BOLD""EMBArk bandit check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk bandit check""${NC}""\\n""${BOLD}""=================================================================""${NC}" if command -v bandit >/dev/null 2>&1; then - echo -e "\\n""$ORANGE""bandit found in PATH!""$NC""\\n" + echo -e "\\n""${ORANGE}""bandit found in PATH!""${NC}""\\n" else - echo -e "\\n""$ORANGE""bandit not found!""$NC""\\n""$ORANGE""Install bandit via 'apt-get install bandit'!""$NC\\n" + echo -e "\\n""${ORANGE}""bandit not found!""${NC}""\\n""${ORANGE}""Install bandit via 'apt-get install bandit'!""${NC}\\n" exit 1 fi for PY_SCRIPT in "${PY_SCRIPTS[@]}"; do - echo -e "\\n""$GREEN""Run bandit on $PY_SCRIPT:""$NC""\\n" - if bandit -c .banditrc "$PY_SCRIPT" 2> /dev/null | grep -q "No issues identified."; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "\\n""${GREEN}""Run bandit on ${PY_SCRIPT}:""${NC}""\\n" + if bandit -c .banditrc "${PY_SCRIPT}" 2> /dev/null | grep -q "No issues identified."; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - bandit -c .banditrc "$PY_SCRIPT" - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + bandit -c .banditrc "${PY_SCRIPT}" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$PY_SCRIPT" ) + MODULES_TO_CHECK_ARR+=( "${PY_SCRIPT}" ) fi done @@ -200,33 +200,33 @@ banditer() { pylinter(){ cd ./embark || exit 1 - echo -e "\\n""$ORANGE""$BOLD""EMBArk pylint check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk pylint check""${NC}""\\n""${BOLD}""=================================================================""${NC}" mapfile -t PY_SCRIPTS < <(find . -type d -name migrations -prune -false -o -iname "*.py") for PY_SCRIPT in "${PY_SCRIPTS[@]}"; do - echo -e "\\n""$GREEN""Run pylint on $PY_SCRIPT:""$NC""\\n" - mapfile -t PY_RESULT < <(pipenv run pylint --rcfile=../.pylintrc "$PY_SCRIPT" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) ) + echo -e "\\n""${GREEN}""Run pylint on ${PY_SCRIPT}:""${NC}""\\n" + mapfile -t PY_RESULT < <(pipenv run pylint --rcfile=../.pylintrc "${PY_SCRIPT}" 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) ) local RATING_10=0 if [[ "${#PY_RESULT[@]}" -gt 0 ]]; then if ! printf '%s\n' "${PY_RESULT[@]}" | grep -q -P '^Your code has been rated at 10'; then for LINE in "${PY_RESULT[@]}"; do - echo "$LINE" + echo "${LINE}" done else RATING_10=1 fi - if [[ "$RATING_10" -ne 1 ]]; then - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + if [[ "${RATING_10}" -ne 1 ]]; then + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$PY_SCRIPT" ) + MODULES_TO_CHECK_ARR+=( "${PY_SCRIPT}" ) else - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" fi else - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" fi done - echo -e "\\n""$GREEN""Run pylint on all scripts:""$NC""\\n" + echo -e "\\n""${GREEN}""Run pylint on all scripts:""${NC}""\\n" pipenv run pylint --rcfile=../.pylintrc ./* 2> >(grep -v "Courtesy Notice\|Loading .env" >&2) | grep "Your code has been rated" cd .. || exit 1 } @@ -238,35 +238,35 @@ dockerchecker(){ else ENV=0 fi - echo -e "\\n""$ORANGE""$BOLD""EMBArk docker-files check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk docker-files check""${NC}""\\n""${BOLD}""=================================================================""${NC}" mapfile -t DOCKER_COMPS < <(find . -maxdepth 1 -type d -name migrations -prune -false -o -iname "docker-compose*.yml") for DOCKER_COMP in "${DOCKER_COMPS[@]}"; do - echo -e "\\n""$GREEN""Run docker check on $DOCKER_COMP:""$NC""\\n" - if docker-compose -f "$DOCKER_COMP" config 1>/dev/null || [[ $? -ne 1 ]]; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "\\n""${GREEN}""Run docker check on ${DOCKER_COMP}:""${NC}""\\n" + if docker-compose -f "${DOCKER_COMP}" config 1>/dev/null || [[ $? -ne 1 ]]; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$DOCKER_COMP" ) + MODULES_TO_CHECK_ARR+=( "${DOCKER_COMP}" ) fi done #TODO dockerlinter -f ./Dockerfile - if [[ $ENV -gt 0 ]]; then + if [[ ${ENV} -gt 0 ]]; then rm .env #remove dummy fi } yamlchecker(){ - echo -e "\\n""$ORANGE""$BOLD""EMBArk yaml-files check""$NC""\\n""$BOLD""=================================================================""$NC" + echo -e "\\n""${ORANGE}""${BOLD}""EMBArk yaml-files check""${NC}""\\n""${BOLD}""=================================================================""${NC}" mapfile -t YAML_COMPS < <(find . -maxdepth 1 -type d -name migrations -prune -false -o -iname "*.yml") for YAML_COMP_ in "${YAML_COMPS[@]}"; do - echo -e "\\n""$GREEN""Run docker check on $YAML_COMP_:""$NC""\\n" - if yamllint "$YAML_COMP_" ; then - echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n" + echo -e "\\n""${GREEN}""Run docker check on ${YAML_COMP_}:""${NC}""\\n" + if yamllint "${YAML_COMP_}" ; then + echo -e "${GREEN}""${BOLD}""==> SUCCESS""${NC}""\\n" else - echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n" + echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n" ((MODULES_TO_CHECK=MODULES_TO_CHECK+1)) - MODULES_TO_CHECK_ARR+=( "$YAML_COMP_" ) + MODULES_TO_CHECK_ARR+=( "${YAML_COMP_}" ) fi done } @@ -286,12 +286,12 @@ check_django yamlchecker if [[ "${#MODULES_TO_CHECK_ARR[@]}" -gt 0 ]]; then - echo -e "\\n\\n""$GREEN$BOLD""SUMMARY:$NC\\n" - echo -e "Modules to check: $MODULES_TO_CHECK\\n" + echo -e "\\n\\n""${GREEN}${BOLD}""SUMMARY:${NC}\\n" + echo -e "Modules to check: ${MODULES_TO_CHECK}\\n" for MODULE in "${MODULES_TO_CHECK_ARR[@]}"; do - echo -e "$RED$BOLD==> FIX MODULE: ""$MODULE""$NC" + echo -e "${RED}${BOLD}==> FIX MODULE: ""${MODULE}""${NC}" done exit 1 fi -echo -e "$GREEN$BOLD===> ALL CHECKS SUCCESSFUL""$NC" -exit 0 \ No newline at end of file +echo -e "${GREEN}${BOLD}===> ALL CHECKS SUCCESSFUL""${NC}" +exit 0 diff --git a/dev-tools/clean-setup.sh b/dev-tools/clean-setup.sh index e179e58c1..7e1806239 100755 --- a/dev-tools/clean-setup.sh +++ b/dev-tools/clean-setup.sh @@ -11,65 +11,65 @@ # Description: Script for cleaning up all docker- container and images -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 cd .. -echo -e "\n$GREEN""$BOLD""Reset docker container & networks""$NC" +echo -e "\n${GREEN}""${BOLD}""Reset docker container & networks""${NC}" docker images docker container ls -a while docker images | grep -qE "\"; do IMAGE_ID=$(docker images | grep -E "\" | awk '{print $3}') - echo -e "$GREEN""$BOLD""Remove failed docker image""$NC" - docker image rm "$IMAGE_ID" -f + echo -e "${GREEN}""${BOLD}""Remove failed docker image""${NC}" + docker image rm "${IMAGE_ID}" -f done if docker images | grep -qE "^mysql[[:space:]]*latest"; then - echo -e "\n$GREEN""$BOLD""Found mysql docker environment - removing it""$NC" + echo -e "\n${GREEN}""${BOLD}""Found mysql docker environment - removing it""${NC}" CONTAINER_ID=$(docker container ls -a | grep -E "embark_db" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Stop mysql docker container""$NC" - docker container stop "$CONTAINER_ID" - echo -e "$GREEN""$BOLD""Remove mysql docker container""$NC" - docker container rm "$CONTAINER_ID" -f - echo -e "$GREEN""$BOLD""Remove mysql docker image""$NC" + echo -e "${GREEN}""${BOLD}""Stop mysql docker container""${NC}" + docker container stop "${CONTAINER_ID}" + echo -e "${GREEN}""${BOLD}""Remove mysql docker container""${NC}" + docker container rm "${CONTAINER_ID}" -f + echo -e "${GREEN}""${BOLD}""Remove mysql docker image""${NC}" docker image rm mysql:latest -f fi if docker images | grep -qE "^redis[[:space:]]*5"; then - echo -e "\n$GREEN""$BOLD""Found redis docker environment - removing it""$NC" + echo -e "\n${GREEN}""${BOLD}""Found redis docker environment - removing it""${NC}" CONTAINER_ID=$(docker container ls -a | grep -E "embark_redis" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Stop redis docker container""$NC" - docker container stop "$CONTAINER_ID" - echo -e "$GREEN""$BOLD""Remove redis docker container""$NC" - docker container rm "$CONTAINER_ID" -f - echo -e "$GREEN""$BOLD""Remove redis docker image""$NC" + echo -e "${GREEN}""${BOLD}""Stop redis docker container""${NC}" + docker container stop "${CONTAINER_ID}" + echo -e "${GREEN}""${BOLD}""Remove redis docker container""${NC}" + docker container rm "${CONTAINER_ID}" -f + echo -e "${GREEN}""${BOLD}""Remove redis docker image""${NC}" docker image rm redis:5 -f fi #networks if docker network ls | grep -E "embark_dev"; then - echo -e "\n$GREEN""$BOLD""Found EMBArk_dev network - removing it""$NC" + echo -e "\n${GREEN}""${BOLD}""Found EMBArk_dev network - removing it""${NC}" NET_ID=$(docker network ls | grep -E "embark_dev" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Remove EMBArk_dev network""$NC" - docker network rm "$NET_ID" + echo -e "${GREEN}""${BOLD}""Remove EMBArk_dev network""${NC}" + docker network rm "${NET_ID}" fi if docker network ls | grep -E "embark_frontend"; then - echo -e "\n$GREEN""$BOLD""Found EMBArk_frontend network - removing it""$NC" + echo -e "\n${GREEN}""${BOLD}""Found EMBArk_frontend network - removing it""${NC}" NET_ID=$(docker network ls | grep -E "embark_frontend" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Remove EMBArk_frontend network""$NC" - docker network rm "$NET_ID" + echo -e "${GREEN}""${BOLD}""Remove EMBArk_frontend network""${NC}" + docker network rm "${NET_ID}" fi if docker network ls | grep -E "embark_backend"; then - echo -e "\n$GREEN""$BOLD""Found EMBArk_backend network - removing it""$NC" + echo -e "\n${GREEN}""${BOLD}""Found EMBArk_backend network - removing it""${NC}" NET_ID=$(docker network ls | grep -E "embark_backend" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Remove EMBArk_backend network""$NC" - docker network rm "$NET_ID" + echo -e "${GREEN}""${BOLD}""Remove EMBArk_backend network""${NC}" + docker network rm "${NET_ID}" fi -echo -e "\n$GREEN""$BOLD""Clearing Migrations""$NC" +echo -e "\n${GREEN}""${BOLD}""Clearing Migrations""${NC}" find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete @@ -79,8 +79,8 @@ fuser -k 8080/tcp docker container prune -echo -e "$ORANGE""$BOLD""Consider running \$docker system prune""$NC" +echo -e "${ORANGE}""${BOLD}""Consider running \$docker system prune""${NC}" rm -Rf -I ./embark_db find . -path "*/migrations/*.py" -not -name "__init__.py" -delete -pipenv run ./embark/manage.py flush \ No newline at end of file +pipenv run ./embark/manage.py flush diff --git a/dev-tools/debug-server-start.sh b/dev-tools/debug-server-start.sh index 51c468601..b41737309 100755 --- a/dev-tools/debug-server-start.sh +++ b/dev-tools/debug-server-start.sh @@ -28,7 +28,7 @@ export WSL=0 cleaner() { pkill -u root daphne - pkill -u root "$PWD"/emba/emba + pkill -u root "${PWD}"/emba/emba pkill -u root runapscheduler docker container stop embark_db @@ -37,8 +37,8 @@ cleaner() { # docker container prune -f --filter "label=flag" # rm embark_db/* -rf - fuser -k "$PORT"/tcp - chown "${SUDO_USER:-${USER}}" "$PWD" -R + fuser -k "${PORT}"/tcp + chown "${SUDO_USER:-${USER}}" "${PWD}" -R exit 1 } @@ -48,25 +48,25 @@ import_helper() local HELPER_COUNT=0 local HELPER_FILE="" local HELP_DIR='helper' - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } set -a trap cleaner INT -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 -if ! [[ $EUID -eq 0 ]] ; then - echo -e "\\n$RED""Run script with root permissions!""$NC\\n" +if ! [[ ${EUID} -eq 0 ]] ; then + echo -e "\\n${RED}""Run script with root permissions!""${NC}\\n" exit 1 fi @@ -79,31 +79,31 @@ import_helper # WSL/OS version check # WSL support - currently experimental! if grep -q -i wsl /proc/version; then - echo -e "\n${ORANGE}INFO: System running in WSL environment!$NC" - echo -e "\n${ORANGE}INFO: WSL is currently experimental!$NC" + echo -e "\n${ORANGE}INFO: System running in WSL environment!${NC}" + echo -e "\n${ORANGE}INFO: WSL is currently experimental!${NC}" WSL=1 fi -if [[ "$WSL" -eq 1 ]]; then +if [[ "${WSL}" -eq 1 ]]; then check_docker_wsl fi # check emba -echo -e "$BLUE""$BOLD""checking EMBA""$NC" +echo -e "${BLUE}""${BOLD}""checking EMBA""${NC}" if ! (cd ./emba && ./emba -d 1) ; then - echo -e "$RED""EMBA is not configured correctly""$NC" + echo -e "${RED}""EMBA is not configured correctly""${NC}" exit 1 fi check_db -if ! [[ -d "$PWD"/logs ]]; then +if ! [[ -d "${PWD}"/logs ]]; then mkdir logs fi -echo -e "\n[""$BLUE JOB""$NC""] Redis logs are copied to ./logs/redis_dev.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] Redis logs are copied to ./logs/redis_dev.log""${NC}" docker container logs embark_redis -f > ./logs/redis_dev.log & -echo -e "\n[""$BLUE JOB""$NC""] DB logs are copied to ./logs/mysql_dev.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] DB logs are copied to ./logs/mysql_dev.log""${NC}" docker container logs embark_db -f > ./logs/mysql_dev.log & # shellcheck disable=SC1091 @@ -118,22 +118,22 @@ python3 ./embark/manage.py migrate | tee -a ./logs/migration.log python3 ./embark/manage.py createsuperuser --noinput ## -echo -e "\n[""$BLUE JOB""$NC""] Starting runapscheduler" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting runapscheduler" python3 ./embark/manage.py runapscheduler | tee -a ./logs/scheduler.log & -echo -e "\n[""$BLUE JOB""$NC""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" echo "START DAPHNE" >./logs/daphne.log cd ./embark || exit 1 -pipenv run daphne -v 3 -p 8001 -b "$IP" --root-path="$PWD"/embark embark.asgi:application &>../logs/daphne.log & +pipenv run daphne -v 3 -p 8001 -b "${IP}" --root-path="${PWD}"/embark embark.asgi:application &>../logs/daphne.log & cd .. || exit 1 # start embark # systemctl start embark.service -echo -e "$ORANGE""$BOLD""start EMBArk server (WS/WSS not enabled -a also asgi)""$NC" -python3 ./embark/manage.py runserver "$IP":"$PORT" |& tee -a ./logs/debug-server.log +echo -e "${ORANGE}""${BOLD}""start EMBArk server (WS/WSS not enabled -a also asgi)""${NC}" +python3 ./embark/manage.py runserver "${IP}":"${PORT}" |& tee -a ./logs/debug-server.log wait -echo -e "\n$ORANGE""$BOLD""Done. To clean-up use the clean-setup script""$NC" \ No newline at end of file +echo -e "\n${ORANGE}""${BOLD}""Done. To clean-up use the clean-setup script""${NC}" diff --git a/dev-tools/prepare.sh b/dev-tools/prepare.sh index 136471cff..f094e5143 100755 --- a/dev-tools/prepare.sh +++ b/dev-tools/prepare.sh @@ -27,7 +27,7 @@ export "$(grep PYTHONPATH ./.env)" cleaner() { pkill -u root daphne - pkill -u root "$PWD"/emba/emba + pkill -u root "${PWD}"/emba/emba pkill -u root runapscheduler docker container stop embark_db @@ -36,8 +36,8 @@ cleaner() { # docker container prune -f --filter "label=flag" # rm embark_db/* -rf - fuser -k "$PORT"/tcp - chown "${SUDO_USER:-${USER}}" "$PWD" -R + fuser -k "${PORT}"/tcp + chown "${SUDO_USER:-${USER}}" "${PWD}" -R exit 1 } @@ -47,25 +47,25 @@ import_helper() local HELPER_COUNT=0 local HELPER_FILE="" local HELP_DIR='helper' - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } set -a trap cleaner INT -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 -if ! [[ $EUID -eq 0 ]] ; then - echo -e "\\n$RED""Run script with root permissions!""$NC\\n" +if ! [[ ${EUID} -eq 0 ]] ; then + echo -e "\\n${RED}""Run script with root permissions!""${NC}\\n" exit 1 fi @@ -78,20 +78,20 @@ import_helper # WSL/OS version check # WSL support - currently experimental! if grep -q -i wsl /proc/version; then - echo -e "\n${ORANGE}INFO: System running in WSL environment!$NC" - echo -e "\n${ORANGE}INFO: WSL is currently experimental!$NC" + echo -e "\n${ORANGE}INFO: System running in WSL environment!${NC}" + echo -e "\n${ORANGE}INFO: WSL is currently experimental!${NC}" WSL=1 fi check_db -if ! [[ -d "$PWD"/logs ]]; then +if ! [[ -d "${PWD}"/logs ]]; then mkdir logs fi -echo -e "\n[""$BLUE JOB""$NC""] Redis logs are copied to ./logs/redis_dev.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] Redis logs are copied to ./logs/redis_dev.log""${NC}" docker container logs embark_redis -f > ./logs/redis_dev.log & -echo -e "\n[""$BLUE JOB""$NC""] DB logs are copied to ./logs/mysql_dev.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] DB logs are copied to ./logs/mysql_dev.log""${NC}" docker container logs embark_db -f > ./logs/mysql_dev.log & # shellcheck disable=SC1091 @@ -103,4 +103,4 @@ python3 ./embark/manage.py makemigrations users uploader reporter dashboard port python3 ./embark/manage.py migrate | tee -a ./logs/migration.log # superuser -python3 ./embark/manage.py createsuperuser --noinput \ No newline at end of file +python3 ./embark/manage.py createsuperuser --noinput diff --git a/dev-tools/test.sh b/dev-tools/test.sh index 208ee4319..9c37b3f29 100755 --- a/dev-tools/test.sh +++ b/dev-tools/test.sh @@ -35,7 +35,7 @@ cleaner() { docker container prune -f --filter "label=flag" - fuser -k "$PORT"/tcp + fuser -k "${PORT}"/tcp exit 1 } @@ -44,25 +44,25 @@ import_helper() local HELPERS=() local HELPER_COUNT=0 local HELPER_FILE="" - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } set -a trap cleaner INT -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 cd .. || exit 1 import_helper -echo -e "\n$GREEN""$BOLD""Configuring Embark""$NC" +echo -e "\n${GREEN}""${BOLD}""Configuring Embark""${NC}" # shellcheck disable=SC1091 source ./.venv/bin/activate || exit 1 @@ -83,19 +83,19 @@ pipenv run ./embark/manage.py migrate | tee -a ./logs/migration.log pipenv run ./embark/manage.py createsuperuser --noinput # add privs -# echo -e "$BLUE""$BOLD""[+] Adding permissions for testing""$NC\\n" -# mysql --host="$(grep DATABASE_HOST ./.env | sed 's/DATABASE\_HOST\=//')" --user=root --password="$MYSQL_ROOT_PASSWORD" -e"GRANT ALL PRIVILEGES ON test_db.* TO 'embark'@'%';" +# echo -e "${BLUE}""${BOLD}""[+] Adding permissions for testing""$NC\\n" +# mysql --host="$(grep DATABASE_HOST ./.env | sed 's/DATABASE\_HOST\=//')" --user=root --password="${MYSQL_ROOT_PASSWORD}" -e"GRANT ALL PRIVILEGES ON test_db.* TO 'embark'@'%';" -echo -e "\n[""$BLUE JOB""$NC""] Redis logs are copied to ./embark/logs/redis.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] Redis logs are copied to ./embark/logs/redis.log""${NC}" docker container logs embark_redis -f > ./logs/redis.log & -echo -e "\n[""$BLUE JOB""$NC""] DB logs are copied to ./embark/logs/mysql.log""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] DB logs are copied to ./embark/logs/mysql.log""${NC}" docker container logs embark_db -f > ./logs/mysql.log & ## -echo -e "\n[""$BLUE JOB""$NC""] Testing""$NC" +echo -e "\n[""${BLUE} JOB""${NC}""] Testing""${NC}" pipenv run ./embark/manage.py test pipenv run ./embark/manage.py test embark.test_logreader # pipenv run ./embark/manage.py test users.tests.SeleniumTests.test_register # pipenv run ./embark/manage.py test users.tests.SeleniumTests.test_login pipenv run ./embark/manage.py test porter.tests.TestImport -echo -e "\n$ORANGE""$BOLD""Done. To clean-up use the clean-setup script""$NC" \ No newline at end of file +echo -e "\n${ORANGE}""${BOLD}""Done. To clean-up use the clean-setup script""${NC}" diff --git a/embark/entrypoint.sh b/embark/entrypoint.sh index 1ce740da0..ceb19162a 100755 --- a/embark/entrypoint.sh +++ b/embark/entrypoint.sh @@ -7,10 +7,10 @@ export HTTPS_PORT=443 export BIND_IP='0.0.0.0' export FILE_SIZE=2000000000 -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 # check emba -echo -e "$BLUE""$BOLD""checking EMBA""$NC" +echo -e "${BLUE}""${BOLD}""checking EMBA""${NC}" # TODO pipe # start venv (ignore source in script) @@ -30,36 +30,36 @@ if ! [[ -d /var/www/logs ]]; then fi # db_init -echo -e "\n[""$BLUE JOB""$NC""] Starting migrations - log to embark/logs/migration.log" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting migrations - log to embark/logs/migration.log" python3.10 manage.py makemigrations users uploader dashboard reporter | tee -a /var/www/logs/migration.log python3.10 manage.py migrate | tee -a /var/www/logs/migration.log # collect staticfiles and make accesable for server -echo -e "\n[""$BLUE JOB""$NC""] Collecting static files" +echo -e "\n[""${BLUE} JOB""${NC}""] Collecting static files" python3.10 manage.py collectstatic --no-input chown www-embark /var/www/ -R chmod 760 /var/www/media/ -R # TODO other fileperms -echo -e "\n[""$BLUE JOB""$NC""] Starting runapscheduler" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting runapscheduler" python3.10 manage.py runapscheduler | tee -a /var/www/logs/scheduler.log & sleep 5 -echo -e "\n[""$BLUE JOB""$NC""] Starting Apache" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting Apache" python3.10 manage.py runmodwsgi --user www-embark --group sudo \ ---host "$BIND_IP" --port="$HTTP_PORT" --limit-request-body "$FILE_SIZE" \ +--host "${BIND_IP}" --port="${HTTP_PORT}" --limit-request-body "${FILE_SIZE}" \ --url-alias /static/ /var/www/static/ \ --url-alias /media/ /var/www/media/ \ --allow-localhost --working-directory ./embark/ --server-root /var/www/httpd80/ \ --include-file /var/www/conf/embark.conf \ --server-name embark.local & # --ssl-certificate /var/www/conf/cert/embark.local --ssl-certificate-key-file /var/www/conf/cert/embark.local.key \ -# --https-port "$HTTPS_PORT" & +# --https-port "${HTTPS_PORT}" & # --enable-debugger --https-only \ sleep 5 -echo -e "\n[""$BLUE JOB""$NC""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" -daphne --access-log /var/www/logs/daphne.log -e ssl:8000:privateKey=/var/www/conf/cert/embark-ws.local.key:certKey=/var/www/conf/cert/embark-ws.local.crt -b "$BIND_IP" -p 8001 -s embark-ws.local --root-path=/var/www/embark embark.asgi:application & +echo -e "\n[""${BLUE} JOB""${NC}""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" +daphne --access-log /var/www/logs/daphne.log -e ssl:8000:privateKey=/var/www/conf/cert/embark-ws.local.key:certKey=/var/www/conf/cert/embark-ws.local.crt -b "${BIND_IP}" -p 8001 -s embark-ws.local --root-path=/var/www/embark embark.asgi:application & sleep 5 -wait \ No newline at end of file +wait diff --git a/export-DB.sh b/export-DB.sh index c429c9f35..7f33ea9f1 100755 --- a/export-DB.sh +++ b/export-DB.sh @@ -26,23 +26,23 @@ import_helper() local HELPER_COUNT=0 local HELPER_FILE="" local HELP_DIR='helper' - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 -if ! [[ $EUID -eq 0 ]] ; then - echo -e "\\n$RED""Run script with root permissions!""$NC\\n" +if ! [[ ${EUID} -eq 0 ]] ; then + echo -e "\\n${RED}""Run script with root permissions!""${NC}\\n" exit 1 fi @@ -50,4 +50,4 @@ echo "USER is ${SUDO_USER:-${USER}}" import_helper cp -urvi ./embark_db ./.embark_db_backup -tar -cf full-backup-"$(date +%F)".tar ./.embark_db_backup \ No newline at end of file +tar -cf full-backup-"$(date +%F)".tar ./.embark_db_backup diff --git a/helper/helper_embark_general.sh b/helper/helper_embark_general.sh index 2013d7a81..73a9ca2e9 100644 --- a/helper/helper_embark_general.sh +++ b/helper/helper_embark_general.sh @@ -18,19 +18,19 @@ docker_image_rm(){ local IMAGE_NAME_="${1:-}" local IMAGE_VERSION_="${2:-}" - if [[ $(docker image ls -q "$IMAGE_NAME_"":""$IMAGE_VERSION_" | wc -c ) -ne 0 ]] ; then - if [[ $(docker ps -a -q --filter "ancestor=""$IMAGE_NAME_"":""$IMAGE_VERSION_" | wc -c) -ne 0 ]]; then + if [[ $(docker image ls -q "${IMAGE_NAME_}"":""${IMAGE_VERSION_}" | wc -c ) -ne 0 ]] ; then + if [[ $(docker ps -a -q --filter "ancestor=""${IMAGE_NAME_}"":""${IMAGE_VERSION_}" | wc -c) -ne 0 ]]; then local CONTAINERS_ - mapfile -t CONTAINERS_ < <(docker ps -a -q --filter ancestor="$IMAGE_NAME_"":""$IMAGE_VERSION_" --format="{{.ID}}") + mapfile -t CONTAINERS_ < <(docker ps -a -q --filter ancestor="${IMAGE_NAME_}"":""${IMAGE_VERSION_}" --format="{{.ID}}") for CONTAINER_ID_ in "${CONTAINERS_[@]}" ; do - echo -e "$GREEN""$BOLD""Stopping ""$CONTAINER_ID_"" docker container""$NC" - docker stop "$CONTAINER_ID_" - echo -e "$GREEN""$BOLD""Remove ""$CONTAINER_ID_"" docker container""$NC" - docker container rm "$CONTAINER_ID_" -f + echo -e "${GREEN}""${BOLD}""Stopping ""${CONTAINER_ID_}"" docker container""${NC}" + docker stop "${CONTAINER_ID_}" + echo -e "${GREEN}""${BOLD}""Remove ""${CONTAINER_ID_}"" docker container""${NC}" + docker container rm "${CONTAINER_ID_}" -f done fi - echo -e "$GREEN$BOLD""Removing ""$IMAGE_NAME_"":""$IMAGE_VERSION_" "docker image""$NC\\n" - docker image rm "$IMAGE_NAME_"":""$IMAGE_VERSION_" -f + echo -e "${GREEN}${BOLD}""Removing ""${IMAGE_NAME_}"":""${IMAGE_VERSION_}" "docker image""${NC}\\n" + docker image rm "${IMAGE_NAME_}"":""${IMAGE_VERSION_}" -f fi } @@ -38,11 +38,11 @@ docker_network_rm(){ # removes docker networks by name local NET_NAME="${1:-}" local NET_ID="" - if docker network ls | grep -E "$NET_NAME"; then - echo -e "\n$GREEN""$BOLD""Found ""$NET_NAME"" - removing it""$NC" - NET_ID=$(docker network ls | grep -E "$NET_NAME" | awk '{print $1}') - echo -e "$GREEN""$BOLD""Remove ""$NET_NAME"" network""$NC" - docker network rm "$NET_ID" + if docker network ls | grep -E "${NET_NAME}"; then + echo -e "\n${GREEN}""${BOLD}""Found ""${NET_NAME}"" - removing it""${NC}" + NET_ID=$(docker network ls | grep -E "${NET_NAME}" | awk '{print $1}') + echo -e "${GREEN}""${BOLD}""Remove ""${NET_NAME}"" network""${NC}" + docker network rm "${NET_ID}" fi } @@ -50,20 +50,20 @@ copy_file(){ # check and copy file forcing overwrite local SOURCE_="${1:-}" local DESTINATION_="${2:-}" - if ! [[ -f "$SOURCE_" ]] ; then - echo -e "\\n$RED""Could not find ""$SOURCE_""$NC\\n" + if ! [[ -f "${SOURCE_}" ]] ; then + echo -e "\\n${RED}""Could not find ""${SOURCE_}""${NC}\\n" return 1 - elif ! [[ -d $(dirname "$DESTINATION_") ]] ; then - echo -e "\\n$RED""Could not find ""$DESTINATION_""$NC\\n" + elif ! [[ -d $(dirname "${DESTINATION_}") ]] ; then + echo -e "\\n${RED}""Could not find ""${DESTINATION_}""${NC}\\n" return 1 fi - cp -f "$SOURCE_" "$DESTINATION_" + cp -f "${SOURCE_}" "${DESTINATION_}" } enable_strict_mode() { local STRICT_MODE_="${1:-}" - if [[ "$STRICT_MODE_" -eq 1 ]]; then + if [[ "${STRICT_MODE_}" -eq 1 ]]; then # http://redsymbol.net/articles/unofficial-bash-strict-mode/ # https://github.com/tests-always-included/wick/blob/master/doc/bash-strict-mode.md # shellcheck disable=SC1091 @@ -83,7 +83,7 @@ enable_strict_mode() { check_docker_wsl() { # checks if service docker is running - echo -e "$BLUE""$BOLD""checking docker""$NC\\n" + echo -e "${BLUE}""${BOLD}""checking docker""${NC}\\n" service docker status } @@ -100,8 +100,8 @@ run_mysql_cmd() { PW_ENV=$(grep DATABASE_PASSWORD ./.env | sed 's/DATABASE\_PASSWORD\=//') USER_ENV=$(grep DATABASE_USER ./.env | sed 's/DATABASE\_USER\=//') HOST_ENV=$(grep DATABASE_HOST ./.env | sed 's/DATABASE\_HOST\=//') - echo -e "\n[""$BLUE JOB""$NC""] Running the following command: $SQL_COMMAND ""$NC" - mysql --host="$HOST_ENV" --user="$USER_ENV" --password="$PW_ENV" -e"$SQL_COMMAND" + echo -e "\n[""${BLUE} JOB""${NC}""] Running the following command: ${SQL_COMMAND} ""${NC}" + mysql --host="${HOST_ENV}" --user="${USER_ENV}" --password="${PW_ENV}" -e"${SQL_COMMAND}" } check_db() { @@ -111,32 +111,32 @@ check_db() { PW_ENV=$(grep DATABASE_PASSWORD ./.env | sed 's/DATABASE\_PASSWORD\=//') USER_ENV=$(grep DATABASE_USER ./.env | sed 's/DATABASE\_USER\=//') HOST_ENV=$(grep DATABASE_HOST ./.env | sed 's/DATABASE\_HOST\=//') - echo -e "\\n$ORANGE""$BOLD""checking database""$NC\\n""$BOLD=================================================================$NC" - echo -e "$BLUE""$BOLD""1. checking startup""$NC\\n" + echo -e "\\n${ORANGE}""${BOLD}""checking database""${NC}\\n""${BOLD}=================================================================${NC}" + echo -e "${BLUE}""${BOLD}""1. checking startup""${NC}\\n" if docker-compose -f ./docker-compose.yml up -d ; then - echo -e "$GREEN""$BOLD""Finished setup mysql and redis docker images""$NC" - add_to_env_history "$PW_ENV" "$(docker-compose ps -q embark_db)" + echo -e "${GREEN}""${BOLD}""Finished setup mysql and redis docker images""${NC}" + add_to_env_history "${PW_ENV}" "$(docker-compose ps -q embark_db)" else - echo -e "$ORANGE""$BOLD""Failed setup mysql and redis docker images""$NC" + echo -e "${ORANGE}""${BOLD}""Failed setup mysql and redis docker images""${NC}" exit 1 fi - echo -e "$BLUE""$BOLD""2. checking password""$NC\\n" - if ! mysql --host="$HOST_ENV" --user="$USER_ENV" --password="$PW_ENV" -e"quit"; then - echo -e "$ORANGE""$BOLD""[*] Retesting the mysql connection""$NC" + echo -e "${BLUE}""${BOLD}""2. checking password""${NC}\\n" + if ! mysql --host="${HOST_ENV}" --user="${USER_ENV}" --password="${PW_ENV}" -e"quit"; then + echo -e "${ORANGE}""${BOLD}""[*] Retesting the mysql connection""${NC}" sleep 35s if ! mysql --host="${HOST_ENV}" --user="${USER_ENV}" --password="${PW_ENV}" -e"quit"; then - echo -e "$ORANGE""$BOLD""Failed logging into database with password""$NC" + echo -e "${ORANGE}""${BOLD}""Failed logging into database with password""${NC}" echo -e "---------------------------------------------------------------------------" - echo -e "$CYAN""Old passwords are stored in the \"safe\" folder when uninstalling EMBArk""$NC\\n" - echo -e "$CYAN""You could try recoverying manually by overwriting your\".env\" file""$NC\\n" + echo -e "${CYAN}""Old passwords are stored in the \"safe\" folder when uninstalling EMBArk""${NC}\\n" + echo -e "${CYAN}""You could try recoverying manually by overwriting your\".env\" file""${NC}\\n" if [[ -f safe/history.env ]]; then - echo -e "$CYAN""The mysql-db was first started with the password(sha256sum): $(head -n1 ./safe/history.env | cut -d";" -f1) ""$NC\\n" - echo -e "$CYAN""And the password used was (sha256sum): $(echo "${PW_ENV}" | sha256sum)""$NC\\n" + echo -e "${CYAN}""The mysql-db was first started with the password(sha256sum): $(head -n1 ./safe/history.env | cut -d";" -f1) ""${NC}\\n" + echo -e "${CYAN}""And the password used was (sha256sum): $(echo "${PW_ENV}" | sha256sum)""${NC}\\n" fi exit 1 fi fi - echo -e "$GREEN""$BOLD""[+] Everything checks out""$NC\\n" + echo -e "${GREEN}""${BOLD}""[+] Everything checks out""${NC}\\n" } add_to_env_history(){ @@ -146,6 +146,6 @@ add_to_env_history(){ if ! [[ -d safe ]]; then mkdir safe fi - printf '%s;%s;\n' "$(echo "$PASSWORD_" | sha256sum)" "$CONTAINER_HASH_" >> ./safe/history.env + printf '%s;%s;\n' "$(echo "${PASSWORD_}" | sha256sum)" "${CONTAINER_HASH_}" >> ./safe/history.env } diff --git a/helper/wickStrictModeFail.sh b/helper/wickStrictModeFail.sh index 61d8dd055..93711ade1 100644 --- a/helper/wickStrictModeFail.sh +++ b/helper/wickStrictModeFail.sh @@ -16,9 +16,9 @@ wickStrictModeFail() ( set +x local argsList argsLeft i nextArg - echo -e "Error detected - status code $ORANGE$1$NC" - echo -e "Command: $ORANGE$BASH_COMMAND$NC" - echo -e "Location: $ORANGE${BASH_SOURCE[1]:-unknown}$NC, line $ORANGE${BASH_LINENO[0]:-unknown}$NC" + echo -e "Error detected - status code ${ORANGE}${1}${NC}" + echo -e "Command: ${ORANGE}${BASH_COMMAND}${NC}" + echo -e "Location: ${ORANGE}${BASH_SOURCE[1]:-unknown}${NC}, line ${ORANGE}${BASH_LINENO[0]:-unknown}${NC}" if [[ ${#PIPESTATUS[@]} -gt 1 ]]; then echo "Pipe status: " "${PIPESTATUS[@]}" @@ -27,19 +27,19 @@ wickStrictModeFail() ( i=$# nextArg=$# - if [[ $i -lt ${#BASH_LINENO[@]} ]]; then + if [[ ${i} -lt ${#BASH_LINENO[@]} ]]; then echo "Stack Trace:" else echo "Stack trace is unavailable" fi - while [[ $i -lt ${#BASH_LINENO[@]} ]]; do + while [[ ${i} -lt ${#BASH_LINENO[@]} ]]; do argsList=() - if [[ ${#BASH_ARGC[@]} -gt $i ]] && [[ ${#BASH_ARGV[@]} -ge $(( nextArg + BASH_ARGC[i] )) ]]; then + if [[ ${#BASH_ARGC[@]} -gt ${i} ]] && [[ ${#BASH_ARGV[@]} -ge $(( nextArg + BASH_ARGC[i] )) ]]; then for (( argsLeft = BASH_ARGC[i]; argsLeft; --argsLeft )); do # Note: this reverses the order on purpose - argsList[$argsLeft]=${BASH_ARGV[nextArg]} + argsList[${argsLeft}]=${BASH_ARGV[nextArg]} (( nextArg ++ )) done @@ -56,7 +56,7 @@ wickStrictModeFail() ( argsList="" fi - echo " [$i] ${FUNCNAME[i]:+${FUNCNAME[i]}(): }${BASH_SOURCE[i]}, line ${BASH_LINENO[i - 1]} -> ${FUNCNAME[i]:-${BASH_SOURCE[i]##*/}}$argsList" + echo " [${i}] ${FUNCNAME[i]:+${FUNCNAME[i]}(): }${BASH_SOURCE[i]}, line ${BASH_LINENO[i - 1]} -> ${FUNCNAME[i]:-${BASH_SOURCE[i]##*/}}${argsList}" (( i ++ )) done echo -e "\n${BLUE}${BOLD}Important: Consider filling out a bug report at https://github.com/e-m-b-a/embark/issues${NC}\n" diff --git a/import-DB.sh b/import-DB.sh index 89aea6fae..83a66c2a4 100755 --- a/import-DB.sh +++ b/import-DB.sh @@ -26,23 +26,23 @@ import_helper() local HELPER_COUNT=0 local HELPER_FILE="" local HELP_DIR='helper' - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } ALT_BACKUP_FILE="${1:-}" export BACKUP_FILE="" if [[ -n "${ALT_BACKUP_FILE}" ]]; then if ! [[ -f "${ALT_BACKUP_FILE}" ]]; then - echo -e "\\n$RED""Error with input for BACKUP FILE!""$NC\\n" + echo -e "\\n${RED}""Error with input for BACKUP FILE!""${NC}\\n" exit 1 fi BACKUP_FILE="${ALT_BACKUP_FILE}" @@ -50,10 +50,10 @@ else BACKUP_FILE="$(find . -type f -iname "full-backup-*.tar" | sort -n | tail -n 1)" fi -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 -if ! [[ $EUID -eq 0 ]] ; then - echo -e "\\n$RED""Run script with root permissions!""$NC\\n" +if ! [[ ${EUID} -eq 0 ]] ; then + echo -e "\\n${RED}""Run script with root permissions!""${NC}\\n" exit 1 fi @@ -67,4 +67,4 @@ rsync -a --progress ./.embark_db_backup/ ./embark_db/ rm -rf ./.embark_db_backup/ -echo -e "\\n""==> ""$GREEN""Import successful""$NC" \ No newline at end of file +echo -e "\\n""==> ""${GREEN}""Import successful""${NC}" diff --git a/installer.sh b/installer.sh index 61b6648c7..e86709e33 100755 --- a/installer.sh +++ b/installer.sh @@ -38,33 +38,33 @@ export BOLD='\033[1m' export NC='\033[0m' # no print_help(){ - echo -e "\\n""$CYAN""USAGE""$NC" - echo -e "$CYAN-h$NC Print this help message" - echo -e "$CYAN-d$NC EMBArk default installation" - echo -e "$CYAN-F$NC Installation of EMBArk for developers" - echo -e "$CYAN-e$NC Install EMBA only" - echo -e "$CYAN-s$NC Installation without EMBA (use in combination with d/F)" + echo -e "\\n""${CYAN}""USAGE""${NC}" + echo -e "${CYAN}-h${NC} Print this help message" + echo -e "${CYAN}-d${NC} EMBArk default installation" + echo -e "${CYAN}-F${NC} Installation of EMBArk for developers" + echo -e "${CYAN}-e${NC} Install EMBA only" + echo -e "${CYAN}-s${NC} Installation without EMBA (use in combination with d/F)" echo -e "---------------------------------------------------------------------------" - echo -e "$CYAN-U$NC Uninstall EMBArk" - echo -e "$CYAN-rd$NC Reinstallation of EMBArk with all dependencies" - echo -e "$CYAN-rF$NC Reinstallation of EMBArk with all dependencies in Developer-mode" - echo -e "$RED ! Both options delete all Database-files as well !""$NC" + echo -e "${CYAN}-U${NC} Uninstall EMBArk" + echo -e "${CYAN}-rd${NC} Reinstallation of EMBArk with all dependencies" + echo -e "${CYAN}-rF${NC} Reinstallation of EMBArk with all dependencies in Developer-mode" + echo -e "${RED} ! Both options delete all Database-files as well !""${NC}" } import_helper(){ local HELPERS=() local HELPER_COUNT=0 local HELPER_FILE="" - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } # Source: https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash @@ -92,8 +92,8 @@ write_env(){ if [[ -d safe ]]; then mapfile -d '' ENV_FILES < <(find ./safe -iname "*.env" -print0 2> /dev/null) if [[ ${#ENV_FILES[@]} -gt 0 ]] && [[ -f safe/history.env ]]; then - echo -e "$ORANGE""$BOLD""Using old env file""$NC" - # check which env file was the last one where $(echo "$PASSWORD_" | sha256sum) matches the first line and entry + echo -e "${ORANGE}""${BOLD}""Using old env file""${NC}" + # check which env file was the last one where $(echo "${PASSWORD_}" | sha256sum) matches the first line and entry LAST_PW_HASH="$(grep -v "$(echo "" | sha256sum)" safe/history.env | tail -n 1 | cut -d";" -f1)" for FILE_ in "${ENV_FILES[@]}"; do CHECK_PW="$(grep "DATABASE_PASSWORD=" "${FILE_}" | sed -e "s/^DATABASE_PASSWORD=//" )" @@ -107,59 +107,59 @@ write_env(){ fi if [[ -z ${DJANGO_SECRET_KEY} ]] || [[ -z ${DJANGO_SECRET_KEY} ]]; then - echo -e "$ORANGE""$BOLD""Did not find safed passwords""$NC" + echo -e "${ORANGE}""${BOLD}""Did not find safed passwords""${NC}" DJANGO_SECRET_KEY=$(python3.10 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())') RANDOM_PW=$(openssl rand -base64 12) fi - echo -e "$ORANGE""$BOLD""Creating a EMBArk configuration file .env""$NC" + echo -e "${ORANGE}""${BOLD}""Creating a EMBArk configuration file .env""${NC}" { echo "DATABASE_NAME=embark" echo "DATABASE_USER=embark" - echo "DATABASE_PASSWORD=$RANDOM_PW" + echo "DATABASE_PASSWORD=${RANDOM_PW}" echo "DATABASE_HOST=172.22.0.5" echo "DATABASE_PORT=3306" - echo "MYSQL_PASSWORD=$RANDOM_PW" + echo "MYSQL_PASSWORD=${RANDOM_PW}" echo "MYSQL_USER=embark" echo "MYSQL_DATABASE=embark" echo "REDIS_HOST=172.22.0.8" echo "REDIS_PORT=7777" - echo "SECRET_KEY=$DJANGO_SECRET_KEY" - echo "DJANGO_SUPERUSER_USERNAME=$SUPER_USER" - echo "DJANGO_SUPERUSER_EMAIL=$SUPER_EMAIL" - echo "DJANGO_SUPERUSER_PASSWORD=$SUPER_PW" + echo "SECRET_KEY=${DJANGO_SECRET_KEY}" + echo "DJANGO_SUPERUSER_USERNAME=${SUPER_USER}" + echo "DJANGO_SUPERUSER_EMAIL=${SUPER_EMAIL}" + echo "DJANGO_SUPERUSER_PASSWORD=${SUPER_PW}" echo "PYTHONPATH=${PWD}:${PWD}/embark:/var/www/:/var/www/embark" } > .env chmod 600 .env } install_emba(){ - echo -e "\n$GREEN""$BOLD""Installation of the firmware scanner EMBA on host""$NC" + echo -e "\n${GREEN}""${BOLD}""Installation of the firmware scanner EMBA on host""${NC}" if git submodule status emba | grep --quiet '^-'; then sudo -u "${SUDO_USER:-${USER}}" git submodule init emba fi sudo -u "${SUDO_USER:-${USER}}" git submodule update --remote - sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "$PWD"/emba + sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "${PWD}"/emba cd emba ./installer.sh -d || ( echo "Could not install EMBA" && exit 1 ) cd .. if ! (cd emba && ./emba -d 1); then - echo -e "\n$RED""$BOLD""EMBA installation failed""$NC" + echo -e "\n${RED}""${BOLD}""EMBA installation failed""${NC}" exit 1 fi chown -R "${SUDO_USER:-${USER}}" emba - echo -e "\n""--------------------------------------------------------------------""$NC" + echo -e "\n""--------------------------------------------------------------------""${NC}" } create_ca (){ # FIXME could use some work - echo -e "\n$GREEN""$BOLD""Creating SSL Cert""$NC" + echo -e "\n${GREEN}""${BOLD}""Creating SSL Cert""${NC}" if ! [[ -d cert ]]; then sudo -u "${SUDO_USER:-${USER}}" git checkout -- cert fi cd cert || exit 1 if [[ -f embark.local.csr ]] || [[ -f embark-ws.local.csr ]] || [[ -f embark.local.crt ]] || [[ -f embark-ws.local.crt ]]; then - echo -e "\n$GREEN""$BOLD""Certs already generated, skipping""$NC" + echo -e "\n${GREEN}""${BOLD}""Certs already generated, skipping""${NC}" else # create CA openssl genrsa -out rootCA.key 4096 @@ -177,16 +177,16 @@ create_ca (){ } dns_resolve(){ - echo -e "\n$GREEN""$BOLD""Install hostnames for local dns-resolve""$NC" + echo -e "\n${GREEN}""${BOLD}""Install hostnames for local dns-resolve""${NC}" if ! grep -q "embark.local" /etc/hosts ; then printf "0.0.0.0 embark.local\n" >>/etc/hosts else - echo -e "\n$ORANGE""$BOLD""hostname already in use!""$NC" + echo -e "\n${ORANGE}""${BOLD}""hostname already in use!""${NC}" fi } reset_docker(){ - echo -e "\\n$GREEN""$BOLD""Reset EMBArk docker images""$NC\\n" + echo -e "\\n${GREEN}""${BOLD}""Reset EMBArk docker images""${NC}\\n" # EMBArk docker_image_rm "mysql" "latest" @@ -205,7 +205,7 @@ reset_docker(){ install_debs(){ local DOCKER_COMP_VER="" - echo -e "\n$GREEN""$BOLD""Install debian packages for EMBArk installation""$NC" + echo -e "\n${GREEN}""${BOLD}""Install debian packages for EMBArk installation""${NC}" apt-get update -y # Git if ! command -v git > /dev/null ; then @@ -228,8 +228,8 @@ install_debs(){ apt-get install build-essential fi # Docker - if [[ "$WSL" -eq 1 ]]; then - echo -e "\n${ORANGE}WARNING: If you are using WSL2, disable docker integration from the docker-desktop daemon!$NC" + if [[ "${WSL}" -eq 1 ]]; then + echo -e "\n${ORANGE}WARNING: If you are using WSL2, disable docker integration from the docker-desktop daemon!${NC}" read -p "Fix docker stuff, then continue. Press any key to continue ..." -n1 -s -r fi if ! command -v docker > /dev/null ; then @@ -243,9 +243,9 @@ install_debs(){ fi else DOCKER_COMP_VER=$(docker-compose -v | grep version | awk '{print $3}' | tr -d ',') - if [[ $(version "$DOCKER_COMP_VER") -lt $(version "1.28.5") ]]; then - echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!$NC" - echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.$NC" + if [[ $(version "${DOCKER_COMP_VER}") -lt $(version "1.28.5") ]]; then + echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!${NC}" + echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.${NC}" read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r fi fi @@ -261,15 +261,15 @@ install_debs(){ } install_daemon(){ - echo -e "\n$GREEN""$BOLD""Install embark daemon""$NC" - sed -i "s|{\$EMBARK_ROOT_DIR}|$PWD|g" embark.service + echo -e "\n${GREEN}""${BOLD}""Install embark daemon""${NC}" + sed -i "s|{\$EMBARK_ROOT_DIR}|${PWD}|g" embark.service if ! [[ -e /etc/systemd/system/embark.service ]] ; then - ln -s "$PWD"/embark.service /etc/systemd/system/embark.service + ln -s "${PWD}"/embark.service /etc/systemd/system/embark.service fi } uninstall_daemon(){ - echo -e "\n$ORANGE""$BOLD""Uninstalling embark daemon""$NC" + echo -e "\n${ORANGE}""${BOLD}""Uninstalling embark daemon""${NC}" if [[ -e /etc/systemd/system/embark.service ]] ; then systemctl stop embark.service systemctl disable embark.service @@ -279,10 +279,10 @@ uninstall_daemon(){ } install_embark_default(){ - echo -e "\n$GREEN""$BOLD""Installation of the firmware scanning environment EMBArk""$NC" + echo -e "\n${GREEN}""${BOLD}""Installation of the firmware scanning environment EMBArk""${NC}" - if [[ "$WSL" -eq 1 ]]; then - echo -e "$RED""$BOLD""EMBArk currently does not support WSL in default mode. (only in Dev-mode)""$NC" + if [[ "${WSL}" -eq 1 ]]; then + echo -e "${RED}""${BOLD}""EMBArk currently does not support WSL in default mode. (only in Dev-mode)""${NC}" fi #debs @@ -337,7 +337,7 @@ install_embark_default(){ # download externals if ! [[ -d ./embark/static/external ]]; then - echo -e "\n$GREEN""$BOLD""Downloading of external files, e.g. jQuery, for the offline usability of EMBArk""$NC" + echo -e "\n${GREEN}""${BOLD}""Downloading of external files, e.g. jQuery, for the offline usability of EMBArk""${NC}" mkdir -p ./embark/static/external/{scripts,css} wget -O ./embark/static/external/scripts/jquery.js https://code.jquery.com/jquery-3.6.0.min.js wget -O ./embark/static/external/scripts/confirm.js https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js @@ -355,7 +355,7 @@ install_embark_default(){ # write env-vars into ./.env write_env - if [[ "$WSL" -eq 1 ]]; then + if [[ "${WSL}" -eq 1 ]]; then check_docker_wsl fi @@ -367,12 +367,12 @@ install_embark_default(){ systemctl start embark.service check_db docker-compose stop - echo -e "$GREEN""$BOLD""Ready to use \$sudo ./run-server.sh ""$NC" - echo -e "$GREEN""$BOLD""Which starts the server on (0.0.0.0) port 80 ""$NC" + echo -e "${GREEN}""${BOLD}""Ready to use \$sudo ./run-server.sh ""${NC}" + echo -e "${GREEN}""${BOLD}""Which starts the server on (0.0.0.0) port 80 ""${NC}" } install_embark_dev(){ - echo -e "\n$GREEN""$BOLD""Building Developent-Enviroment for EMBArk""$NC" + echo -e "\n${GREEN}""${BOLD}""Building Developent-Enviroment for EMBArk""${NC}" # apt packages apt-get install -y npm pycodestyle python3-pylint-django default-libmysqlclient-dev build-essential bandit yamllint mysql-client-core-8.0 # get geckodriver @@ -388,9 +388,9 @@ install_embark_dev(){ pip3 install pipenv #Add user nosudo - echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: ""$PWD""/emba/emba" | EDITOR='tee -a' visudo + echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: ""${PWD}""/emba/emba" | EDITOR='tee -a' visudo echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo - echo "root ALL=(ALL) NOPASSWD: ""$PWD""/emba/emba" | EDITOR='tee -a' visudo + echo "root ALL=(ALL) NOPASSWD: ""${PWD}""/emba/emba" | EDITOR='tee -a' visudo echo "root ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo @@ -416,7 +416,7 @@ install_embark_dev(){ # download externals if ! [[ -d ./embark/static/external ]]; then - echo -e "\n$GREEN""$BOLD""Downloading of external files, e.g. jQuery, for the offline usability of EMBArk""$NC" + echo -e "\n${GREEN}""${BOLD}""Downloading of external files, e.g. jQuery, for the offline usability of EMBArk""${NC}" mkdir -p ./embark/static/external/{scripts,css} wget -O ./embark/static/external/scripts/jquery.js https://code.jquery.com/jquery-3.6.0.min.js wget -O ./embark/static/external/scripts/confirm.js https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js @@ -441,22 +441,22 @@ install_embark_dev(){ check_db docker-compose stop - echo -e "$GREEN""$BOLD""Ready to use \$sudo ./dev-tools/debug-server-start.sh""$NC" - echo -e "$GREEN""$BOLD""Or use otherwise""$NC" + echo -e "${GREEN}""${BOLD}""Ready to use \$sudo ./dev-tools/debug-server-start.sh""${NC}" + echo -e "${GREEN}""${BOLD}""Or use otherwise""${NC}" } uninstall (){ - echo -e "[+]$CYAN""$BOLD""Uninstalling EMBArk""$NC" + echo -e "[+]${CYAN}""${BOLD}""Uninstalling EMBArk""${NC}" # check for changes if [[ $(git status --porcelain --untracked-files=no --ignore-submodules=all) ]]; then # Changes - echo -e "[!!]$RED""$BOLD""Changes detected - please stash or commit them $ORANGE( \$git stash )""$NC" + echo -e "[!!]${RED}""${BOLD}""Changes detected - please stash or commit them ${ORANGE}( \$git stash )""${NC}" git status exit 1 fi # delete directories - echo -e "$ORANGE""$BOLD""Delete Directories""$NC" + echo -e "${ORANGE}""${BOLD}""Delete Directories""${NC}" if [[ -d /var/www ]]; then rm -Rv /var/www fi @@ -481,17 +481,17 @@ uninstall (){ if [[ -d ./logs ]]; then rm -Rvf ./logs fi - if [[ "$REFORCE" -eq 0 ]]; then + if [[ "${REFORCE}" -eq 0 ]]; then # user-files if [[ -d ./emba_logs ]]; then - echo -e "$RED""$BOLD""Do you wish to remove the EMBA-Logs (and backups)""$NC" + echo -e "${RED}""${BOLD}""Do you wish to remove the EMBA-Logs (and backups)""${NC}" rm -RIv ./emba_logs fi if [[ -d ./embark_db ]]; then - echo -e "$RED""$BOLD""Do you wish to remove the database(and backups)""$NC" + echo -e "${RED}""${BOLD}""Do you wish to remove the database(and backups)""${NC}" rm -RIv ./embark_db if [[ -f ./safe/history.env ]]; then - echo -e "$RED""$BOLD""Moved old history file""$NC" + echo -e "${RED}""${BOLD}""Moved old history file""${NC}" mv --force ./safe/history.env ./safe/old_env_history fi fi @@ -499,7 +499,7 @@ uninstall (){ # delete user www-embark and reset visudo - echo -e "$ORANGE""$BOLD""Delete user""$NC" + echo -e "${ORANGE}""${BOLD}""Delete user""${NC}" if id -u www-embark &>/dev/null ; then userdel www-embark @@ -507,28 +507,28 @@ uninstall (){ # remove all emba/embark NOPASSWD entries into sudoer file if grep -qE "NOPASSWD\:.*\/emba\/emba" /etc/sudoers ; then - echo -e "$ORANGE""$BOLD""Deleting EMBA NOPASSWD entries""$NC" + echo -e "${ORANGE}""${BOLD}""Deleting EMBA NOPASSWD entries""${NC}" sed -i '/NOPASSWD\:.*\/emba\/emba/d' /etc/sudoers fi if grep -qE "NOPASSWD\:.*\/bin\/pkill" /etc/sudoers ; then - echo -e "$ORANGE""$BOLD""Deleting pkill NOPASSWD entries""$NC" + echo -e "${ORANGE}""${BOLD}""Deleting pkill NOPASSWD entries""${NC}" sed -i '/NOPASSWD\:.*\/bin\/pkill/d' /etc/sudoers fi # delete .env - echo -e "$ORANGE""$BOLD""Delete env""$NC" + echo -e "${ORANGE}""${BOLD}""Delete env""${NC}" if [[ -f ./.env ]]; then rm -Rvf ./.env fi # delete shared volumes and migrations - echo -e "$ORANGE""$BOLD""Delete migration-files""$NC" + echo -e "${ORANGE}""${BOLD}""Delete migration-files""${NC}" find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete # delete all docker interfaces and containers + images reset_docker - echo -e "$ORANGE""$BOLD""Consider running " "$CYAN""\$docker system prune""$NC" + echo -e "${ORANGE}""${BOLD}""Consider running " "${CYAN}""\$docker system prune""${NC}" # delete/uninstall submodules # emba @@ -536,11 +536,11 @@ uninstall (){ rm -r ./emba/external/ fi # all submodules - if [[ $REFORCE -eq 1 ]]; then + if [[ ${REFORCE} -eq 1 ]]; then sudo -u "${SUDO_USER:-${USER}}" git submodule status else if [[ $(sudo -u "${SUDO_USER:-${USER}}" git submodule foreach git status --porcelain --untracked-files=no) ]]; then - echo -e "[!!]$RED""$BOLD""Submodule changes detected - please commit them...otherwise they will be lost""$NC" + echo -e "[!!]${RED}""${BOLD}""Submodule changes detected - please commit them...otherwise they will be lost""${NC}" read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r fi sudo -u "${SUDO_USER:-${USER}}" git submodule foreach git reset --hard @@ -549,7 +549,7 @@ uninstall (){ fi # stop&reset daemon - if [[ "$WSL" -ne 1 ]]; then + if [[ "${WSL}" -ne 1 ]]; then uninstall_daemon systemctl daemon-reload fi @@ -561,19 +561,19 @@ uninstall (){ sudo -u "${SUDO_USER:-${USER}}" git checkout HEAD -- cert # final - if [[ "$REFORCE" -eq 0 ]]; then + if [[ "${REFORCE}" -eq 0 ]]; then sudo -u "${SUDO_USER:-${USER}}" git reset rm -r ./safe fi - echo -e "$ORANGE""$BOLD""Consider ""$CYAN""\$git pull""$ORANGE""$BOLD"" and ""$CYAN""\$git clean""$NC" + echo -e "${ORANGE}""${BOLD}""Consider ""${CYAN}""\$git pull""${ORANGE}""${BOLD}"" and ""${CYAN}""\$git clean""${NC}" } -echo -e "\\n$ORANGE""$BOLD""EMBArk Installer""$NC\\n""$BOLD=================================================================$NC" -echo -e "$ORANGE""$BOLD""WARNING: This script can harm your environment!""$NC\n" +echo -e "\\n${ORANGE}""${BOLD}""EMBArk Installer""${NC}\\n""${BOLD}=================================================================${NC}" +echo -e "${ORANGE}""${BOLD}""WARNING: This script can harm your environment!""${NC}\n" import_helper -if [[ "$STRICT_MODE" -eq 1 ]]; then +if [[ "${STRICT_MODE}" -eq 1 ]]; then # http://redsymbol.net/articles/unofficial-bash-strict-mode/ # https://github.com/tests-always-included/wick/blob/master/doc/bash-strict-mode.md set -e # Exit immediately if a command exits with a non-zero status @@ -586,76 +586,76 @@ if [[ "$STRICT_MODE" -eq 1 ]]; then fi if [ "$#" -ne 1 ]; then - echo -e "$RED""$BOLD""Invalid number of arguments""$NC" + echo -e "${RED}""${BOLD}""Invalid number of arguments""${NC}" print_help exit 1 fi while getopts esFUrdDSh OPT ; do - case $OPT in + case ${OPT} in e) export EMBA_ONLY=1 - echo -e "$GREEN""$BOLD""Install only emba""$NC" + echo -e "${GREEN}""${BOLD}""Install only emba""${NC}" ;; s) export NO_EMBA=1 - echo -e "$GREEN""$BOLD""Install without emba""$NC" + echo -e "${GREEN}""${BOLD}""Install without emba""${NC}" ;; F) export DEV=1 - echo -e "$GREEN""$BOLD""Building Development-Enviroment""$NC" + echo -e "${GREEN}""${BOLD}""Building Development-Enviroment""${NC}" ;; U) export UNINSTALL=1 - echo -e "$GREEN""$BOLD""Uninstall EMBArk""$NC" + echo -e "${GREEN}""${BOLD}""Uninstall EMBArk""${NC}" ;; r) export UNINSTALL=1 export REFORCE=1 - echo -e "$GREEN""$BOLD""Re-Install all dependecies while keeping user-files""$NC" + echo -e "${GREEN}""${BOLD}""Re-Install all dependecies while keeping user-files""${NC}" ;; d) export DEFAULT=1 - echo -e "$GREEN""$BOLD""Default installation of EMBArk""$NC" + echo -e "${GREEN}""${BOLD}""Default installation of EMBArk""${NC}" ;; S) export STRICT_MODE=1 - echo -e "$GREEN""$BOLD""Strict-mode enabled""$NC" + echo -e "${GREEN}""${BOLD}""Strict-mode enabled""${NC}" ;; h) print_help exit 0 ;; *) - echo -e "$RED""$BOLD""Invalid option""$NC" + echo -e "${RED}""${BOLD}""Invalid option""${NC}" print_help exit 1 ;; esac done -enable_strict_mode $STRICT_MODE +enable_strict_mode ${STRICT_MODE} # WSL/OS version check # WSL support - currently experimental! if grep -q -i wsl /proc/version; then - echo -e "\n${ORANGE}INFO: System running in WSL environment!$NC" - echo -e "\n${ORANGE}INFO: WSL is currently experimental!$NC" - echo -e "\n${ORANGE}INFO: Ubuntu 22.04 is required for WSL!$NC" + echo -e "\n${ORANGE}INFO: System running in WSL environment!${NC}" + echo -e "\n${ORANGE}INFO: WSL is currently experimental!${NC}" + echo -e "\n${ORANGE}INFO: Ubuntu 22.04 is required for WSL!${NC}" read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r WSL=1 fi -if [[ $EUID -ne 0 ]]; then - echo -e "\\n$RED""Run EMBArk installation script with root permissions!""$NC\\n" +if [[ ${EUID} -ne 0 ]]; then + echo -e "\\n${RED}""Run EMBArk installation script with root permissions!""${NC}\\n" print_help exit 1 fi -if [[ $REFORCE -eq 1 ]] && [[ $UNINSTALL -eq 1 ]]; then +if [[ ${REFORCE} -eq 1 ]] && [[ ${UNINSTALL} -eq 1 ]]; then save_old_env uninstall -elif [[ $UNINSTALL -eq 1 ]]; then +elif [[ ${UNINSTALL} -eq 1 ]]; then save_old_env uninstall exit 0 @@ -664,17 +664,17 @@ fi install_debs # mark dir as safe for git -sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "$PWD" +sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "${PWD}" -if [[ "$NO_EMBA" -eq 0 ]]; then +if [[ "${NO_EMBA}" -eq 0 ]]; then install_emba fi -if [[ "$EMBA_ONLY" -eq 1 ]]; then +if [[ "${EMBA_ONLY}" -eq 1 ]]; then exit 0 fi -if [[ $DEFAULT -eq 1 ]]; then +if [[ ${DEFAULT} -eq 1 ]]; then install_embark_default -elif [[ $DEV -eq 1 ]]; then +elif [[ ${DEV} -eq 1 ]]; then install_embark_dev fi exit 0 diff --git a/run-server.sh b/run-server.sh index f84526092..3ee7e1748 100755 --- a/run-server.sh +++ b/run-server.sh @@ -36,25 +36,25 @@ import_helper() local HELPERS=() local HELPER_COUNT=0 local HELPER_FILE="" - mapfile -d '' HELPERS < <(find "$HELP_DIR" -iname "helper_embark_*.sh" -print0 2> /dev/null) + mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null) for HELPER_FILE in "${HELPERS[@]}" ; do - if ( file "$HELPER_FILE" | grep -q "shell script" ) && ! [[ "$HELPER_FILE" =~ \ |\' ]] ; then + if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then # https://github.com/koalaman/shellcheck/wiki/SC1090 # shellcheck source=/dev/null - source "$HELPER_FILE" + source "${HELPER_FILE}" (( HELPER_COUNT+=1 )) fi done - echo -e "\\n""==> ""$GREEN""Imported ""$HELPER_COUNT"" necessary files""$NC\\n" + echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n" } cleaner() { pkill -u root daphne - pkill -u root "$PWD"/emba/emba + pkill -u root "${PWD}"/emba/emba pkill -u root runapscheduler - fuser -k "$HTTP_PORT"/tcp - fuser -k "$HTTPS_PORT"/tcp + fuser -k "${HTTP_PORT}"/tcp + fuser -k "${HTTPS_PORT}"/tcp fuser -k 8000/tcp fuser -k 8001/tcp @@ -68,73 +68,73 @@ cleaner() { } # main -echo -e "\\n$ORANGE""$BOLD""EMBArk Startup""$NC\\n""$BOLD=================================================================$NC" +echo -e "\\n${ORANGE}""${BOLD}""EMBArk Startup""${NC}\\n""${BOLD}=================================================================${NC}" while getopts "ha:" OPT ; do - case $OPT in + case ${OPT} in h) - echo -e "\\n""$CYAN""USAGE""$NC" - echo -e "$CYAN-h$NC Print this help message" - echo -e "$CYAN-a $NC Add a server Domain-name alias" + echo -e "\\n""${CYAN}""USAGE""${NC}" + echo -e "${CYAN}-h${NC} Print this help message" + echo -e "${CYAN}-a ${NC} Add a server Domain-name alias" echo -e "---------------------------------------------------------------------------" if ip addr show eth0 &>/dev/null ; then IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) - echo -e "$GREEN Suggestion:$NC sudo ./run-server.sh -a $IP" - echo -e "$GREEN nslookup helper:$NC" - nslookup "$IP" + echo -e "${GREEN} Suggestion:${NC} sudo ./run-server.sh -a ${IP}" + echo -e "${GREEN} nslookup helper:${NC}" + nslookup "${IP}" fi exit 0 ;; a) - SERVER_ALIAS+=("$OPTARG") + SERVER_ALIAS+=("${OPTARG}") WSGI_FLAGS+=(--server-alias "${OPTARG}") ;; :) - echo -e "$CYAN Usage: [-a ] $NC" + echo -e "${CYAN} Usage: [-a ] ${NC}" exit 1 ;; *) - echo -e "\\n$ORANGE""$BOLD""No Alias set""$NC\\n" + echo -e "\\n${ORANGE}""${BOLD}""No Alias set""${NC}\\n" ;; esac done # Alias if [[ ${#SERVER_ALIAS[@]} -ne 0 ]]; then - echo -e "$GREEN Server-alias:$NC" + echo -e "${GREEN} Server-alias:${NC}" for VAR in "${SERVER_ALIAS[@]}"; do - echo "[*] $VAR" + echo "[*] ${VAR}" done fi -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "${0}")" || exit 1 import_helper -enable_strict_mode "$STRICT_MODE" +enable_strict_mode "${STRICT_MODE}" set -a trap cleaner INT -if ! [[ $EUID -eq 0 ]] ; then - echo -e "\\n$RED""Run Server script with root permissions!""$NC\\n" +if ! [[ ${EUID} -eq 0 ]] ; then + echo -e "\\n${RED}""Run Server script with root permissions!""${NC}\\n" exit 1 fi # check emba -echo -e "$BLUE""$BOLD""checking EMBA""$NC" +echo -e "${BLUE}""${BOLD}""checking EMBA""${NC}" if ! [[ -d ./emba ]]; then - echo -e "$RED""$BOLD""You are using the wrong installation and missing the EMBA subdirectory""$NC" + echo -e "${RED}""${BOLD}""You are using the wrong installation and missing the EMBA subdirectory""${NC}" fi -if ! (cd "$PWD"/emba && ./emba -d 1); then - echo -e "$BLUE""Trying auto-maintain""$NC" +if ! (cd "${PWD}"/emba && ./emba -d 1); then + echo -e "${BLUE}""Trying auto-maintain""${NC}" # automaintain if ! [[ -d ./emba ]]; then - echo -e "$RED""EMBA not installed""$NC" + echo -e "${RED}""EMBA not installed""${NC}" exit 1 fi cd ./emba || exit 1 systemctl restart NetworkManager docker ./emba -d 1 1>/dev/null if [[ $? -eq 1 ]]; then - echo -e "$RED""EMBA is not configured correctly""$NC" + echo -e "${RED}""EMBA is not configured correctly""${NC}" exit 1 fi cd .. || exit 1 @@ -142,7 +142,7 @@ fi # check venv if ! [[ -d /var/www/.venv ]]; then - echo -e "$RED""$BOLD""Pip-enviroment not found!""$NC" + echo -e "${RED}""${BOLD}""Pip-enviroment not found!""${NC}" exit 1 fi if ! nc -zw1 google.com 443 &>/dev/null ; then @@ -164,9 +164,9 @@ if ! [[ -d ./docker_logs ]]; then fi # container-logs (2 jobs) -echo -e "\n[""$BLUE JOB""$NC""] Redis logs are copied to ./docker_logs/redis.log" +echo -e "\n[""${BLUE} JOB""${NC}""] Redis logs are copied to ./docker_logs/redis.log" docker container logs embark_redis -f &> ./docker_logs/redis.log & -echo -e "\n[""$BLUE JOB""$NC""] DB logs are copied to ./embark/logs/mysql.log" +echo -e "\n[""${BLUE} JOB""${NC}""] DB logs are copied to ./embark/logs/mysql.log" docker container logs embark_db -f &> ./docker_logs/mysql.log & # start the supervisor @@ -193,10 +193,10 @@ fi if ! [[ -d /var/www/conf/cert ]]; then mkdir /var/www/conf/cert fi -copy_file "$PWD"/cert/embark.local.crt /var/www/conf/cert -copy_file "$PWD"/cert/embark.local.key /var/www/conf/cert -copy_file "$PWD"/cert/embark-ws.local.key /var/www/conf/cert -copy_file "$PWD"/cert/embark-ws.local.crt /var/www/conf/cert +copy_file "${PWD}"/cert/embark.local.crt /var/www/conf/cert +copy_file "${PWD}"/cert/embark.local.key /var/www/conf/cert +copy_file "${PWD}"/cert/embark-ws.local.key /var/www/conf/cert +copy_file "${PWD}"/cert/embark-ws.local.crt /var/www/conf/cert # cp .env copy_file ./.env /var/www/embark/embark/settings/ @@ -214,23 +214,23 @@ if ! [[ -d /var/www/logs ]]; then fi # db_init -echo -e "\n[""$BLUE JOB""$NC""] Starting migrations - log to embark/logs/migration.log" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting migrations - log to embark/logs/migration.log" pipenv run ./manage.py makemigrations | tee -a /var/www/logs/migration.log pipenv run ./manage.py migrate | tee -a /var/www/logs/migration.log # collect staticfiles and make accesable for server -echo -e "\n[""$BLUE JOB""$NC""] Collecting static files" +echo -e "\n[""${BLUE} JOB""${NC}""] Collecting static files" pipenv run ./manage.py collectstatic --no-input chown www-embark /var/www/ -R chmod 760 /var/www/media/ -R -echo -e "\n[""$BLUE JOB""$NC""] Starting runapscheduler" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting runapscheduler" pipenv run ./manage.py runapscheduler | tee -a /var/www/logs/scheduler.log & sleep 5 -echo -e "\n[""$BLUE JOB""$NC""] Starting Apache" +echo -e "\n[""${BLUE} JOB""${NC}""] Starting Apache" pipenv run ./manage.py runmodwsgi --user www-embark --group sudo \ ---host "$BIND_IP" --port="$HTTP_PORT" --limit-request-body "$FILE_SIZE" \ +--host "${BIND_IP}" --port="${HTTP_PORT}" --limit-request-body "${FILE_SIZE}" \ --url-alias /static/ /var/www/static/ \ --url-alias /media/ /var/www/media/ \ --allow-localhost --working-directory /var/www/embark/ --server-root /var/www/httpd80/ \ @@ -240,22 +240,22 @@ pipenv run ./manage.py runmodwsgi --user www-embark --group sudo \ --log-level debug \ --server-name embark.local "${WSGI_FLAGS[@]}" & # --ssl-certificate /var/www/conf/cert/embark.local --ssl-certificate-key-file /var/www/conf/cert/embark.local.key \ -# --https-port "$HTTPS_PORT" & +# --https-port "${HTTPS_PORT}" & # --https-only --enable-debugger \ sleep 5 -echo -e "\n[""$BLUE JOB""$NC""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" -pipenv run daphne --access-log /var/www/logs/daphne.log -e ssl:8000:privateKey=/var/www/conf/cert/embark-ws.local.key:certKey=/var/www/conf/cert/embark-ws.local.crt -b "$BIND_IP" -p 8001 -s embark-ws.local --root-path=/var/www/embark embark.asgi:application & +echo -e "\n[""${BLUE} JOB""${NC}""] Starting daphne(ASGI) - log to /embark/logs/daphne.log" +pipenv run daphne --access-log /var/www/logs/daphne.log -e ssl:8000:privateKey=/var/www/conf/cert/embark-ws.local.key:certKey=/var/www/conf/cert/embark-ws.local.crt -b "${BIND_IP}" -p 8001 -s embark-ws.local --root-path=/var/www/embark embark.asgi:application & sleep 5 -echo -e "\n""$ORANGE$BOLD""=============================================================""$NC" -echo -e "\n""$ORANGE$BOLD""EMBA logs are under /var/www/emba_logs/ ""$NC" -# echo -e "\n\n""$GREEN$BOLD""the trusted rootCA.key for the ssl encryption is in ./cert""$NC" +echo -e "\n""${ORANGE}${BOLD}""=============================================================""${NC}" +echo -e "\n""${ORANGE}${BOLD}""EMBA logs are under /var/www/emba_logs/ ""${NC}" +# echo -e "\n\n""${GREEN}${BOLD}""the trusted rootCA.key for the ssl encryption is in ./cert""${NC}" if [[ ${#SERVER_ALIAS[@]} -ne 0 ]]; then - echo -e "\n""$ORANGE$BOLD""Server started on http://embark.local with alias:""${SERVER_ALIAS[*]}""$NC" + echo -e "\n""${ORANGE}${BOLD}""Server started on http://embark.local with alias:""${SERVER_ALIAS[*]}""${NC}" else - echo -e "\n""$ORANGE$BOLD""Server started on http://embark.local""$NC" + echo -e "\n""${ORANGE}${BOLD}""Server started on http://embark.local""${NC}" fi -# echo -e "\n""$ORANGE$BOLD""For SSL you may use https://embark.local (Not recommended for local use)""$NC" -wait \ No newline at end of file +# echo -e "\n""${ORANGE}${BOLD}""For SSL you may use https://embark.local (Not recommended for local use)""${NC}" +wait diff --git a/supervisor.sh b/supervisor.sh index 7e1a9f67e..33a5c5db0 100755 --- a/supervisor.sh +++ b/supervisor.sh @@ -16,7 +16,7 @@ LOG_FILE='/var/log/embark-supervisor.log' # Close standard output file descriptors and reroute to log exec 1<&- exec 2<&- -exec 1<>$LOG_FILE +exec 1<>${LOG_FILE} exec 2>&1 while :; do @@ -25,4 +25,4 @@ while :; do echo "$(date +"%D %T")""retstarted docker-networks" fi sleep 1m -done \ No newline at end of file +done