Skip to content

Commit

Permalink
Merge pull request #163 from HoxhaEndri/main
Browse files Browse the repository at this point in the history
shellcheck braces and updated check-project file
  • Loading branch information
BenediktMKuehne authored Nov 6, 2023
2 parents 952f217 + f3508cf commit f9d6530
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 403 deletions.
188 changes: 94 additions & 94 deletions dev-tools/check_project.sh

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions dev-tools/clean-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\<none\>"; do
IMAGE_ID=$(docker images | grep -E "\<none\>" | 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

Expand All @@ -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
pipenv run ./embark/manage.py flush
48 changes: 24 additions & 24 deletions dev-tools/debug-server-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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"
echo -e "\n${ORANGE}""${BOLD}""Done. To clean-up use the clean-setup script""${NC}"
32 changes: 16 additions & 16 deletions dev-tools/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
python3 ./embark/manage.py createsuperuser --noinput
26 changes: 13 additions & 13 deletions dev-tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cleaner() {

docker container prune -f --filter "label=flag"

fuser -k "$PORT"/tcp
fuser -k "${PORT}"/tcp
exit 1
}

Expand All @@ -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
Expand All @@ -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"
echo -e "\n${ORANGE}""${BOLD}""Done. To clean-up use the clean-setup script""${NC}"
Loading

0 comments on commit f9d6530

Please sign in to comment.