Skip to content

Commit

Permalink
Fix: Quote variables for well defined behavior
Browse files Browse the repository at this point in the history
By quoting variables we can improve stability of this script. $HOME and
$password are both user supplied variables, that may contain spaces.

We need to quote them, or they may be expanded into extra arguments.
This means this script will no longer break, if a space is supplied
inside the password.

`read` treats backslashes differently, which can be annoying when
entering a random password. with the `-r` flag we can disable this
behavior.

`$@` will return an array of all arguments, which will then be
translated into a string. When using `$*` we will get a sting which is
safe to use, as its behavior is defined.
  • Loading branch information
ailox authored and greenbonebot committed Feb 13, 2025
1 parent 028f752 commit 50823c8
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/_static/setup-and-start-greenbone-community-edition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ installed() {
# $1 should be the command to look for. If $2 is set, we have arguments
local failed=0
if [ -z "$2" ]; then
if ! [ -x "$(command -v $1)" ]; then
if ! [ -x "$(command -v "$1")" ]; then
failed=1
fi
else
local ret=0
$@ &> /dev/null || ret=$?
"$@" &> /dev/null || ret=$?
if [ "$ret" -ne 0 ]; then
failed=1
fi
fi

if [ $failed -ne 0 ]; then
echo "$@ is not available. See https://greenbone.github.io/docs/latest/$RELEASE/container/#prerequisites."
echo "$* is not available. See https://greenbone.github.io/docs/latest/$RELEASE/container/#prerequisites."
exit 1
fi

Expand All @@ -48,24 +48,22 @@ installed curl
installed docker
installed docker compose

echo "Using Greenbone Community Containers $RELEASE"

mkdir -p $DOWNLOAD_DIR && cd $DOWNLOAD_DIR
mkdir -p "$DOWNLOAD_DIR" && cd "$DOWNLOAD_DIR"

echo "Downloading docker-compose file..."
curl -f -O https://greenbone.github.io/docs/latest/_static/docker-compose.yml

echo "Pulling Greenbone Community Containers"
docker compose -f $DOWNLOAD_DIR/docker-compose.yml pull
docker compose -f "$DOWNLOAD_DIR"/docker-compose.yml pull
echo

echo "Starting Greenbone Community Containers"
docker compose -f $DOWNLOAD_DIR/docker-compose.yml up -d
docker compose -f "$DOWNLOAD_DIR"/docker-compose.yml up -d
echo

read -s -p "Password for admin user: " password
docker compose -f $DOWNLOAD_DIR/docker-compose.yml \
exec -u gvmd gvmd gvmd --user=admin --new-password=$password
read -r -s -p "Password for admin user: " password
docker compose -f "$DOWNLOAD_DIR"/docker-compose.yml \
exec -u gvmd gvmd gvmd --user=admin --new-password="$password"

echo
echo "The feed data will be loaded now. This process may take several minutes up to hours."
Expand Down

0 comments on commit 50823c8

Please sign in to comment.