Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #155

Merged
merged 5 commits into from
Sep 17, 2023
Merged

Dev #155

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions helper/helper_embark_general.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,14 @@ check_db() {
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"
fi
exit 1
fi
fi
echo -e "$GREEN""$BOLD""[+] Everything checks out""$NC\\n"
}

check_safe() {
local ENV_FILES=()
if [[ -d safe ]] ; then
mapfile -d '' ENV_FILES < <(find ./safe -iname "*.env" -print0 2> /dev/null)
if [ ${#ENV_FILES[@]} -gt 0 ]; then
return 0
fi
fi
return 1
}

add_to_env_history(){
local PASSWORD_="${1:-}"
local CONTAINER_HASH_="${2:-}"
Expand Down
47 changes: 36 additions & 11 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ write_env(){
local SUPER_USER="superuser"
local RANDOM_PW=""
local DJANGO_SECRET_KEY=""
local ENV_FILES=()
local LAST_PW_HASH=""
local CHECK_PW=""

if check_safe; then
echo -e "$ORANGE""$BOLD""Using old env file""$NC"
DJANGO_SECRET_KEY="$(grep "SECRET_KEY=" "$(find ./safe -name "*.env" | head -1)" | sed -e "s/^SECRET_KEY=//" )"
RANDOM_PW="$(grep "DATABASE_PASSWORD=" "$(find ./safe -name "*.env" | head -1)" | sed -e "s/^DATABASE_PASSWORD=//" )"
else
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
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=//" )"
if [[ "${LAST_PW_HASH}" == "$(echo "${CHECK_PW}" | sha256sum)" ]]; then
RANDOM_PW="${CHECK_PW}"
DJANGO_SECRET_KEY="$(grep "SECRET_KEY=" "${FILE_}" | sed -e "s/^SECRET_KEY=//" )"
break
fi
done
fi
fi

if [[ -z ${DJANGO_SECRET_KEY} ]] || [[ -z ${DJANGO_SECRET_KEY} ]]; then
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)
Expand Down Expand Up @@ -125,11 +141,10 @@ install_emba(){
sudo -u "${SUDO_USER:-${USER}}" git submodule update --remote
sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "$PWD"/emba
cd emba
./installer.sh -d | tee install.log || ( echo "Could not install EMBA" && exit 1 )
./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"
tail emba/install.log
exit 1
fi
chown -R "${SUDO_USER:-${USER}}" emba
Expand Down Expand Up @@ -456,6 +471,9 @@ uninstall (){
if [[ -d ./.venv ]]; then
rm -Rvf ./.venv
fi
if [[ -d ./logs ]]; then
rm -Rvf ./logs
fi
if [[ "$REFORCE" -eq 0 ]]; then
# user-files
if [[ -d ./emba_logs ]]; then
Expand All @@ -475,11 +493,21 @@ uninstall (){

# delete user www-embark and reset visudo
echo -e "$ORANGE""$BOLD""Delete user""$NC"
# sed -i 's/www\-embark\ ALL\=\(ALL\)\ NOPASSWD\:\ \/app\/emba\/emba//g' /etc/sudoers #TODO doesnt work yet

if id -u www-embark &>/dev/null ; then
userdel www-embark
fi

# 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"
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"
sed -i '/NOPASSWD\:.*\/bin\/pkill/d' /etc/sudoers
fi

# delete .env
echo -e "$ORANGE""$BOLD""Delete env""$NC"
if [[ -f ./.env ]]; then
Expand All @@ -497,9 +525,6 @@ uninstall (){

# delete/uninstall submodules
# emba
if [ -f ./emba/install.log ]; then
rm ./emba/install.log
fi
if [[ -d ./emba/external ]]; then
rm -r ./emba/external/
fi
Expand Down
Loading