Skip to content
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
5 changes: 2 additions & 3 deletions config.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Services
rest_port=8080
frontend_port=80

# DB Settings
db_user=root
db_port=27017
db_name=filefighter
use_stable_versions=true
db_password=
46 changes: 33 additions & 13 deletions init_setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
source lib/config.shlib; # load the config library functions
source lib/dockertags.shlib # load docker functions.

# Check if docker is running
if ! docker info >/dev/null 2>&1; then
Expand All @@ -14,10 +15,14 @@ frontendname="FileFighterFrontend"
dbname="FileFighterDB"
networkname="FileFighterNetwork"

# latest stable versions.
frontendVersion="latest" #"$(getTagsByName filefighter/frontend v | tail -1)"
restVersion="latest" #$(getTagsByName filefighter/rest v | tail -1)"

# Startup Message.
echo ""
echo "-------------------------< FileFighter >--------------------------"
echo "| Version 0.0.1 last updated at 14.10.20 |"
echo "| Version 0.0.1. Last updated at 14.10.20 |"
echo "| Developed by Gimleux, Valentin, Open-Schnick. |"
echo "| Development Blog: https://filefighter.github.io |"
echo "| The code can be found at: https://www.github.com/filefighter |"
Expand All @@ -33,45 +38,60 @@ db_port="$(read ./config.cfg db_port)"
db_name="$(read ./config.cfg db_name)"
db_user="$(read ./config.cfg db_user)"
db_password="$(read ./config.cfg db_password)"
use_stable_versions="$(read ./config.cfg use_stable_versions)"

if ! [[ $frontend_port ]]; then
echo "Config for frontend_port not found, using defaults."
frontend_port="$(read ./config.cfg frontend_port)"
frontend_port="$(read ./config.cfg.defaults frontend_port)"
fi

if ! [[ $rest_port ]]; then
echo "Config for rest_port not found, using defaults."
rest_port="$(read ./config.cfg rest_port)"
rest_port="$(read ./config.cfg.defaults rest_port)"
fi

if ! [[ $db_port ]]; then
echo "Config for db_port not found, using defaults."
db_port="$(read ./config.cfg db_port)"
db_port="$(read ./config.cfg.defaults db_port)"
fi

if ! [[ $db_name ]]; then
echo "Config for db_name not found, using defaults."
db_name="$(read ./config.cfg db_name)"
db_name="$(read ./config.cfg.defaults db_name)"
fi

if ! [[ $db_user ]]; then
echo "Config for db_user not found, using defaults."
db_user="$(read ./config.cfg db_user)"
db_user="$(read ./config.cfg.defaults db_user)"
fi

if ! [[ $db_password ]]; then
echo "Config for db_password not found, using defaults."
db_password="$(read ./config.cfg db_password)"
db_password="$(read ./config.cfg.defaults db_password)"
fi

if ! [[ $use_stable_versions ]]; then
echo "Config for use_stable_versions not found, using defaults."
use_stable_versions="$(read ./config.cfg.defaults use_stable_versions)"
fi

# Check if (default) password was empty.
if ! [[ $db_password ]]; then
# Create new Password
echo "Creating new random password for the database."
db_password="asdasdasd"
db_password=$(wget -qO- "https://www.passwordrandom.com/query?command=password&scheme=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
write $configFilePath db_password $db_password
fi

# Check versions config
if [[ $use_stable_versions == "true" ]]; then
echo "Installing stable versions."
frontendVersion="$(getTagsByName filefighter/frontend v | tail -1)"
restVersion="$(getTagsByName filefighter/rest v | tail -1)"
else
echo "Installing latest versions. Be aware that minor bugs could occur. Please report found bugs: filefigther@t-online.de."
fi

# Finished Config:
echo "Finished reading config. Building containers..."

Expand All @@ -90,7 +110,7 @@ echo "Creating necessary network."
docker network create $networkname >/dev/null 2>&1

# Database
echo "Creating latest DB Container."
echo "Creating DB Container, with tag: latest."
docker create \
-e MONGO_INITDB=$db_name \
-e MONGO_INITDB_ROOT_USERNAME=$db_user \
Expand All @@ -102,7 +122,7 @@ docker start $dbname >/dev/null 2>&1
sleep 3 # waiting 3 seconds for mongo to start.

# REST APP
echo "Creating latest REST Container."
echo "Creating REST Container, with tag: $restVersion."
docker create \
-e DB_USERNAME=$db_user \
-e DB_PASSWORD=$db_password \
Expand All @@ -111,15 +131,15 @@ docker create \
-e SPRING_PROFILES_ACTIVE="prod" \
-p $rest_port:8080 \
--network $networkname \
--name $restname filefighter/rest:latest >/dev/null 2>&1
--name $restname filefighter/rest:$restVersion >/dev/null 2>&1
docker start $restname >/dev/null 2>&1

# Frontend
echo "Creating latest Frontend Container."
echo "Creating Frontend Container, with tag: $frontendVersion."
docker create \
-e REST_PORT=$rest_port \
-p $frontend_port:5000 \
--name $frontendname filefighter/frontend:latest >/dev/null 2>&1
--name $frontendname filefighter/frontend:$frontendVersion >/dev/null 2>&1
docker start $frontendname >/dev/null 2>&1

# DataHandler
Expand Down
3 changes: 3 additions & 0 deletions lib/config.cfg.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ db_user=root
db_password=
db_port=27017
db_name=filefighter

# Versions
use_stable_versions=true
6 changes: 3 additions & 3 deletions lib/config.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ read() { # path, key -> value
}

delete() { # path, key
test -f "$1" && sed -i "" -e "/^$(echo $2 | sed_escape).*$/d" "$1"
# UNIX VERSION:
# test -f "$1" && sed -i "/^$(echo $2 | sed_escape).*$/d" "$1"
test -f "$1" && sed -i "/^$(echo $2 | sed_escape).*$/d" "$1"
# MacOs
# test -f "$1" && sed -i "" -e "/^$(echo $2 | sed_escape).*$/d" "$1"
}

has_key() { # path, key
Expand Down
12 changes: 12 additions & 0 deletions lib/dockertags.shlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
getTagsByName() {
image="$1"
# REMEMBER wget is not native on mac os.
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`

if [ -n "$2" ]
then
tags=` echo "${tags}" | grep "$2" `
fi

echo "${tags}"
}