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

extends the install script to have a random password option #504

Merged
merged 3 commits into from
Oct 13, 2023
Merged
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
17 changes: 15 additions & 2 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ function print_message {
echo "$1"
}

function generate_random_password() {
local length=$1
LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c "$length"
echo
}

db_pw=''
api_url=''
metrics_url=''
Expand Down Expand Up @@ -53,9 +59,16 @@ if [[ -z $metrics_url ]] ; then
metrics_url=${metrics_url:-"http://metrics.green-coding.internal:9142"}
fi

if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi

default_password=${password_from_file:-$(generate_random_password 12)}

if [[ -z "$db_pw" ]] ; then
read -sp "Please enter the new password to be set for the PostgreSQL DB: " db_pw
echo "" # force a newline, because print -sp will consume it
read -sp "Please enter the new password to be set for the PostgreSQL DB (default: $default_password): " db_pw
echo "" # force a newline, because read -sp will consume it
db_pw=${db_pw:-"$default_password"}
fi

if ! mount | grep -E '\s/tmp\s' | grep -Eq '\stmpfs\s' && [[ $ask_tmpfs == true ]]; then
Expand Down
16 changes: 15 additions & 1 deletion install_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ function print_message {
echo "$1"
}

function generate_random_password() {
local length=$1
LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c "$length"
echo
}

db_pw=''
api_url=''
metrics_url=''
Expand Down Expand Up @@ -37,8 +43,16 @@ if [[ -z $metrics_url ]] ; then
metrics_url=${metrics_url:-"http://metrics.green-coding.internal:9142"}
fi

if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi

default_password=${password_from_file:-$(generate_random_password 12)}

if [[ -z "$db_pw" ]] ; then
read -sp "Please enter the new password to be set for the PostgreSQL DB: " db_pw
read -sp "Please enter the new password to be set for the PostgreSQL DB (default: $default_password): " db_pw
echo "" # force a newline, because read -sp will consume it
db_pw=${db_pw:-"$default_password"}
fi

print_message "Clearing old api.conf and frontend.conf files"
Expand Down
Loading