diff --git a/.env b/.env new file mode 100644 index 0000000..ff493f6 --- /dev/null +++ b/.env @@ -0,0 +1,79 @@ +# ------------------------------------------------------------------------- +# _____ _ _ _____ _ _ _ +# | ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __ +# | |_ | | | | / _ \ | |_ | | / _ | | '_ \ | __| / _ \ | '__| +# | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | | +# |_| |_| |_| \___| |_| |_| \__, | |_| |_| \__| \___| |_| +# |___/ +# +# This is the FileFighter config file +# +# When running docker-compose up the values of these keys will be inserted +# into the docker-compose.yml file +# +# ------------------------------------------------------------------------- +# General Settings: +# +# can be: no, on-failure[:max-retries], always, unless-stopped +RESTART_POLICY=unless-stopped + +# specifies which kind of release to use +# can be: latest, stable +RELEASE_CHANNEL=stable + +# ------------------------------------------------------------------------- +# Frontend Settings: +# +# the port for the FileFighter Frontend. +# can be any valid port +FRONTEND_PORT=80 + +# the origin of the application. +# TODO: Change this to the url that will be used to access filefighter with +# a browser (add port if using non standard ports) +FRONTEND_ORIGIN=http://localhost + +# ------------------------------------------------------------------------- +# Database Settings: +# +# the name of the local data directory for the database +DB_VOLUME=./database + +# name of the database, can be whatever you want to be +DB_NAME=filefighter + +# database username for the other services +DB_USERNAME=root + +# database password for the user +# TODO: Change this to something secure +DB_PASSWORD=admin + +# ------------------------------------------------------------------------- +# Filehandler Settings: +# +# the name of the local data directory for the filehandler +FILEHANDLER_VOLUME=./filehandler + + +# TODO: Change this to something secure to enable encryption +# leave or set it to null to not use encryption +ENCRYPTION_PASSWORD=null + +# TODO: When using encryption these settings are relevant + +# database user name used for the filehandler application +FH_DB_USERNAME=filehandler + +# database name used for the filehandler application +FH_DB_NAME=filehandler + +# database password used for the filehandler application +FH_DB_PASSWORD=secure + +# ------------------------------------------------------------------------- +# Filesystemservice Settings: +# +# secret used to sign jwts +# TODO: change this to something secure +JWT_SECRET=s3cr3t diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e75dd11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.idea +*.log +tmp/ + + +# volumes +database/ +filehandler/ diff --git a/Download.sh b/Download.sh deleted file mode 100755 index 79ce9f1..0000000 --- a/Download.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -DOWNLOAD_DIR="/tmp" - -cd $DOWNLOAD_DIR -echo "Downloading FileFighter ClientSetup." -curl https://codeload.github.com/FileFighter/ClientSetup/zip/master > FileFighter.zip - -echo "" -echo "finshed downloading." - -if ! unzip>/dev/null 2>&1; then - echo "'unzip' not found. Install it with 'sudo apt install unzip'." - exit 1 -fi - -unzip -o FileFighter.zip >/dev/null 2>&1 - -echo "" -echo "finished unpacking FileFighter. Installing it now..." -echo "" - -chmod -R +x $DOWNLOAD_DIR/ClientSetup-master/ -cd $DOWNLOAD_DIR/ClientSetup-master/ -./Install.sh diff --git a/Install.sh b/Install.sh deleted file mode 100755 index c418fdf..0000000 --- a/Install.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Source logo and usage. -source ./lib/utils.sh - -# Move other files in this dir to /home/$USER/filefighter/ -SCRIPTS_LOCATION="/home/$USER/filefighter" - -# Move ffighter to this dir. -APPLICATION_LOCATION="/usr/bin" - -# Read in base dir for Path. -DOWNLOAD_LOCATION=$(realpath $0) -DOWNLOAD_LOCATION=${DOWNLOAD_LOCATION/%Install.sh} # Very HACKY YES. - -VERSION="v1.6" -DATE="24.01.21" - -echoLogo $VERSION $DATE "Initial Install" - -if [ ! -d "/home/$USER" ]; then - echo "Home directory for the current user not found. If you are root, switch to a user with a directory under /home/" - exit 1 -fi - -if [ ! -d $SCRIPTS_LOCATION ]; then - echo "Creating Install Location under $SCRIPTS_LOCATION" - mkdir $SCRIPTS_LOCATION -fi - -echo "Copying Scripts to new location..." -cd $DOWNLOAD_LOCATION -cp -r . $SCRIPTS_LOCATION - -echo "Copying FileFighter Application to $APPLICATION_LOCATION..." -echo "This may need administrator rights (sudo) if you are not root." -sudo cp $DOWNLOAD_LOCATION/ffighter $APPLICATION_LOCATION - -echo "" -echo "Successfully installed FileFighter!" -echo "You can delete the downloaded files ($DOWNLOAD_LOCATION) if you want." -echo "" -printUsage \ No newline at end of file diff --git a/config.cfg b/config.cfg deleted file mode 100644 index 719bf1d..0000000 --- a/config.cfg +++ /dev/null @@ -1,5 +0,0 @@ -app_port=80 -db_user=root -db_name=filefighter -use_stable_versions=true -db_password= diff --git a/docker-compose.yml b/docker-compose.yml index ae5c41b..d2d97ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,41 +1,101 @@ +# ------------------------------------------------------------------------- +# _____ _ _ _____ _ _ _ +# | ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __ +# | |_ | | | | / _ \ | |_ | | / _ | | '_ \ | __| / _ \ | '__| +# | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | | +# |_| |_| |_| \___| |_| |_| \__, | |_| |_| \__| \___| |_| +# |___/ +# +# This is the FileFighter docker-compose file +# +# DO NOT CHANGE THIS FILE DIRECTY (unless you know what you are doing)! +# If you want to configure your instance of FileFighter edit the .env file. +# +# Starting FileFighter: +# docker-compose up -d +# +# ------------------------------------------------------------------------- version: "3.3" services: - FileFighterFrontend: - image: filefighter/frontend:stable + frontend: + image: filefighter/frontend:feature + ports: + - ${FRONTEND_PORT}:80 + depends_on: + - fss + - filehandler networks: - FileFighterNetwork - depends_on: - - FileFighterREST - - FileFighterFileHandler - ports: - - "80:80" - FileFighterREST: - image: filefighter/rest:stable + restart: ${RESTART_POLICY} + + fss: + image: filefighter/filesystemservice:feature environment: - DB_USERNAME: root - DB_PASSWORD: GUZFDEGFIDGSZGFZGZDGSZ #change this - DB_NAME: filefighter - DB_CONTAINER_NAME: FileFighterDB + DB_USERNAME: ${DB_USERNAME} + DB_PASSWORD: ${DB_PASSWORD} + DB_NAME: ${DB_NAME} + DB_CONTAINER_NAME: db + JWT_SECRET: ${JWT_SECRET} + FRONTEND_ORIGIN: ${FRONTEND_ORIGIN} # FIXME: This option is ignored by spring SPRING_PROFILES_ACTIVE: "prod" - expose: - - "8080" depends_on: - - FileFighterDB + - db networks: - FileFighterNetwork - FileFighterDB: + restart: ${RESTART_POLICY} + + db: image: mongo:latest environment: - MONGO_INITDB: filefighter - MONGO_INITDB_ROOT_USERNAME: root - MONGO_INITDB_ROOT_PASSWORD: GUZFDEGFIDGSZGFZGZDGSZ #change this + MONGO_INITDB: ${DB_NAME} + MONGO_INITDB_ROOT_USERNAME: ${DB_USERNAME} + MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD} + FH_DB_USERNAME: ${FH_DB_USERNAME} + FH_DB_PASSWORD: ${FH_DB_PASSWORD} + FH_DB_NAME: ${FH_DB_NAME} networks: - FileFighterNetwork - FileFighterFileHandler: - image: filefighter/filehandler:stable + volumes: + - ${DB_VOLUME}:/data/db + - ./docker-entrypoint-initdb.d/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro + restart: ${RESTART_POLICY} + + filehandler: + image: filefighter/filehandler:feature + environment: + DB_USERNAME: ${FH_DB_USERNAME} + DB_PASSWORD: ${FH_DB_PASSWORD} + DB_NAME: ${FH_DB_NAME} + DB_CONTAINER_NAME: db + FILESYSTEMSERVICE_URL: fss + FILESYSTEMSERVICE_PORT: 8080 + ENCRYPTION_PASSWORD: ${ENCRYPTION_PASSWORD} + FRONTEND_ORIGIN: ${FRONTEND_ORIGIN} + depends_on: + - fss networks: - FileFighterNetwork + volumes: + - ${FILEHANDLER_VOLUME}:/workdir + restart: ${RESTART_POLICY} + + ftp-service: + image: filefighter/ftp-service:${RELEASE_CHANNEL} + environment: + # TODO: remove after fixing the paths in fss + FTP_SERVICE_BACKEND_URL: http://fss:8080/api + FTP_SERVICE_FILEHANDLER_URL: http://filehandler:5000 + # IDEA: make this customizable + # IDEA: implement tls for ftp? + ports: + - "2121:2121" + - "10000-10010:10000-10010" depends_on: - - FileFighterREST + - fss + - filehandler + networks: + - FileFighterNetwork + restart: ${RESTART_POLICY} + networks: FileFighterNetwork: diff --git a/lib/utils.sh b/docker-entrypoint-initdb.d/init-mongo.sh old mode 100644 new mode 100755 similarity index 59% rename from lib/utils.sh rename to docker-entrypoint-initdb.d/init-mongo.sh index 29d199b..30e38c3 --- a/lib/utils.sh +++ b/docker-entrypoint-initdb.d/init-mongo.sh @@ -1,3 +1,5 @@ +set -e + echoLogo() { echo " _____ _ _ _____ _ _ _ " echo " | ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __ " @@ -5,22 +7,30 @@ echoLogo() { echo " | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | | " echo " |_| |_| |_| \___| |_| |_| \__, | |_| |_| \__| \___| |_| " echo " |___/ " - echo " Version $1 Last updated: $2" echo " Developed by Gimleux, Valentin, Open-Schnick. " echo " Development Blog: https://blog.filefighter.de " echo " The code can be found at: https://www.github.com/filefighter " echo "" - echo "-------------------------< $3 >---------------------------" + echo "-------------------------< DB SETUP >---------------------------" echo "" } -printUsage() { - echo "usage: ffighter " - echo "" - echo " status - show status of the FileFighter application." - echo " install - install the FileFighter application." - echo " start - start the services." - echo " stop - stop the services." - echo " remove - remove all services." - echo " update - update all the services that have a new version available." -} +echoLogo + +echo "Adding users with init script" + +echo "Adding user $FH_DB_USERNAME to db $FH_DB_NAME" + +mongo </dev/null 2>&1; then - echo "Docker is not running, install it first or retry." - exit 1 -fi - -if [ -z "$1" ]; then - echoLogo $VERSION $DATE "Show Usage" - printUsage - exit 1 -fi - -if [[ $1 == "status" ]]; then - echoLogo $VERSION $DATE "Show Status" - ffstatus - exit 0 -fi - -if [[ $1 == "install" ]]; then - echoLogo $VERSION $DATE "Installing FileFighter" - ffinstall - exit 0 -fi - -if [[ $1 == "start" ]]; then - echoLogo $VERSION $DATE "Starting FileFighter" - ffstart - exit 0 -fi - -if [[ $1 == "stop" ]]; then - echoLogo $VERSION $DATE "Stopping FileFighter" - ffstop - exit 0 -fi - -if [[ $1 == "remove" ]]; then - echoLogo $VERSION $DATE "Removing FileFighter" - ffremove - exit 0 -fi - -if [[ $1 == "update" ]]; then - echoLogo $VERSION $DATE "Updating FileFighter" - ffupdate - exit 0 -fi - -echoLogo $VERSION $DATE "Show Usage" -printUsage -exit 1 diff --git a/lib/config.cfg.defaults b/lib/config.cfg.defaults deleted file mode 100644 index 4d9c94c..0000000 --- a/lib/config.cfg.defaults +++ /dev/null @@ -1,13 +0,0 @@ -# DO NOT CHANGE OR REMOVE THIS FILE! - -# Services -app_port=80 - - -# DB Settings -db_user=root -db_password= -db_name=filefighter - -# Versions -use_stable_versions=true \ No newline at end of file diff --git a/lib/config.sh b/lib/config.sh deleted file mode 100644 index e21eebd..0000000 --- a/lib/config.sh +++ /dev/null @@ -1,22 +0,0 @@ -sed_escape() { - sed -e 's/[]\/$*.^[]/\\&/g' -} - -write() { # path, key, value - delete "$1" "$2" - echo "$2=$3" >> "$1" -} - -read() { # path, key -> value - test -f "$1" && grep "^$(echo "$2" | sed_escape)=" "$1" | sed "s/^$(echo "$2" | sed_escape)=//" | tail -1 -} - -delete() { # path, key - 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 - test -f "$1" && grep "^$(echo "$2" | sed_escape)=" "$1" > /dev/null -} diff --git a/lib/dockertags.sh b/lib/dockertags.sh deleted file mode 100644 index a75e80c..0000000 --- a/lib/dockertags.sh +++ /dev/null @@ -1,12 +0,0 @@ -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}" -} diff --git a/lib/install.sh b/lib/install.sh deleted file mode 100755 index 2672813..0000000 --- a/lib/install.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash -ffinstall() { - source lib/config.sh # load the config library functions - source lib/dockertags.sh # load docker functions. - - # setup variables - configFilePath=$(pwd)/config.cfg - restname="FileFighterREST" - frontendname="FileFighterFrontend" - filehandlername="FileFighterFileHandler" - dbname="FileFighterDB" - networkname="FileFighterNetwork" - - # latest stable versions. - frontendVersion="latest" - restVersion="latest" - filehandlerVersion="latest" - - # cors profile - profile="prod" - - volumesLocation="/home/$USER/filefighter/volumes" - - echo "Docker prerequisites matched. Docker instance running." - echo "Reading in config file from: $configFilePath." - - # Read in default keys. - app_port="$(read $configFilePath app_port)" - db_name="$(read $configFilePath db_name)" - db_user="$(read $configFilePath db_user)" - db_password="$(read $configFilePath db_password)" - use_stable_versions="$(read $configFilePath use_stable_versions)" - - if ! [[ $app_port ]]; then - echo "Config for app_port not found, using defaults." - app_port="$(read ./lib/config.cfg.defaults app_port)" - fi - - if ! [[ $db_name ]]; then - echo "Config for db_name not found, using defaults." - 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.defaults db_user)" - fi - - if ! [[ $db_password ]]; then - echo "Config for db_password not found, using defaults." - 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=$(curl -s "https://www.passwordrandom.com/query?command=password&scheme=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr") - 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)" - filehandlerVersion="$(getTagsByName filefighter/filehandler v | tail -1)" - else - echo "Installing latest versions. Be aware that minor bugs could occur. Please report found bugs: filefigther@t-online.de." - docker rmi filefighter/rest:$restVersion >/dev/null 2>&1 - docker rmi filefighter/frontend:$frontendVersion >/dev/null 2>&1 - docker rmi filefighter/filehandler:$filehandlerVersion >/dev/null 2>&1 - docker rmi mongo >/dev/null 2>&1 - fi - - # Finished Config: - echo "Finished reading config. Building containers..." - - # Check for already existing CONTAINERS. - if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $filehandlername) ]]; then - echo "" - echo "A container with already exists with the name $restname or $frontendname or $dbname or $filehandlername." - echo "Maybe its the second time that you run this script. If not please remove these containers." - echo "If you want to check for updates, run the update.sh script." - echo "" - exit 1 - fi - - echo "" - # Network - echo "Creating necessary network." - docker network create $networkname >/dev/null 2>&1 - - # Database - echo "Creating DB Container, with tag: latest." - echo "Downloading mongodb image." - docker create \ - -e MONGO_INITDB=$db_name \ - -e MONGO_INITDB_ROOT_USERNAME=$db_user \ - -e MONGO_INITDB_ROOT_PASSWORD=$db_password \ - --network $networkname \ - --name $dbname mongo:latest >/dev/null 2>&1 - - echo "" - - # REST APP - echo "Creating REST Container, with tag: $restVersion." - echo "Downloading filefighter/rest image." - docker create \ - -e DB_USERNAME=$db_user \ - -e DB_PASSWORD=$db_password \ - -e DB_NAME=$db_name \ - -e DB_CONTAINER_NAME=$dbname \ - -e SPRING_PROFILES_ACTIVE=$profile \ - --expose 8080 \ - --network $networkname \ - --name $restname filefighter/rest:$restVersion >/dev/null 2>&1 - - echo "" - - #FileHandler - echo "Creating FileHandler Container, with tag: $filehandlerVersion." - echo "Downloading filefighter/filehandler image." - docker create \ - -e PROFILE=$profile \ - -v $volumesLocation:/workdir \ - --network $networkname \ - --name $filehandlername filefighter/filehandler:$filehandlerVersion >/dev/null 2>&1 - - echo "" - - # Frontend - echo "Creating Frontend Container, with tag: $frontendVersion." - echo "Downloading filefighter/frontend image." - docker create \ - --network $networkname \ - -p $app_port:80 \ - --name $frontendname filefighter/frontend:$frontendVersion >/dev/null 2>&1 - - echo "Finished downloading." - echo "" - - echo "" - echo "Finished Building FileFighter." - echo "Start FileFighter with 'ffighter start'." - echo "" -} diff --git a/lib/remove.sh b/lib/remove.sh deleted file mode 100755 index 992c638..0000000 --- a/lib/remove.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -ffremove() { - restname="FileFighterREST" - frontendname="FileFighterFrontend" - filehandlername="FileFighterFileHandler" - dbname="FileFighterDB" - - if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $filehandlername) ]]; then - docker container stop $restname && docker container rm $restname >/dev/null 2>&1 - docker container stop $frontendname && docker container rm $frontendname >/dev/null 2>&1 - docker container stop $dbname && docker container rm $dbname >/dev/null 2>&1 - docker container stop $filehandlername && docker container rm $filehandlername >/dev/null 2>&1 - - echo "" - echo "Removed FileFighter Application. Install it again with 'ffighter install'." - exit 0 - fi - - echo "FileFighter Application not found. Install it with 'ffighter install'." - echo "" - exit 1; -} diff --git a/lib/start.sh b/lib/start.sh deleted file mode 100755 index 9420d46..0000000 --- a/lib/start.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -ffstart() { - source ./lib/config.sh # load the config library functions - appport=$(read config.cfg app_port) - - # setup variables - restname="FileFighterREST" - frontendname="FileFighterFrontend" - filehandlername="FileFighterFileHandler" - dbname="FileFighterDB" - - - if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $filehandlername) ]]; then - echo "Docker prerequisites matched. Docker instance running." - echo "Starting services..." - - docker start $dbname - docker start $restname - docker start $filehandlername - docker start $frontendname - - - echo "" - echo "Finished starting FileFighter services." - echo "Frontend is running here: http://localhost:$appport." - echo "You can stop them again with 'ffighter stop'." - echo "The default login is admin admin." - echo "" - exit 0 - fi - - echo "FileFighter Application not found. Install it with 'ffighter install'." - echo "" - exit 1; -} diff --git a/lib/status.sh b/lib/status.sh deleted file mode 100644 index 3095538..0000000 --- a/lib/status.sh +++ /dev/null @@ -1,28 +0,0 @@ -function ffstatus() { - restname="FileFighterREST" - frontendname="FileFighterFrontend" - filehandlername="FileFighterFileHandler" - dbname="FileFighterDB" - - # installed - if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $filehandlername) ]]; then - echo "FileFigher Application is currently installed." - echo "Remove it with 'ffighter remove'." - - else - echo "FileFigher Application is currently not installed." - echo "Install it with 'ffighter install'." - fi - - echo "" - # running - if [[ $(docker ps --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps --format "{{.Names}}" | grep $filehandlername) ]]; then - echo "FileFigher Application is currently running." - echo "Stop it with 'ffighter stop'." - echo "" - docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" - else - echo "FileFigher Application is currently not running." - echo "Run it with 'ffighter start'." - fi -} diff --git a/lib/stop.sh b/lib/stop.sh deleted file mode 100755 index e147856..0000000 --- a/lib/stop.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -ffstop() { # setup variables - restname="FileFighterREST" - frontendname="FileFighterFrontend" - filehandlername="FileFighterFileHandler" - dbname="FileFighterDB" - - echo "Docker prerequisites matched. Docker instance running." - echo "Stopping services..." - - docker stop $frontendname - docker stop $restname - docker stop $filehandlername - docker stop $dbname - - echo "Finished stopping FileFighter services." - echo "You can start them again with 'ffighter start'." - echo "" -} diff --git a/lib/update.sh b/lib/update.sh deleted file mode 100644 index 1ec8f5b..0000000 --- a/lib/update.sh +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env bash - -restname="FileFighterREST" -frontendname="FileFighterFrontend" -filehandlername="FileFighterFileHandler" -networkname="FileFighterNetwork" -dbname="FileFighterDB" - -# cors profile -profile="prod" - -volumesLocation="/home/$USER/filefighter/volumes" - -ffupdate(){ - -echo "Starting Update." -date - -if [[ $(docker ps -a --format "{{.Names}}" | grep $restname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $frontendname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $dbname) ]] || [[ $(docker ps -a --format "{{.Names}}" | grep $filehandlername) ]]; then - echo "Installation is fine, starting to read config..." -else - echo "FileFighter is not installed, run 'ffighter install' first" -fi - - source lib/config.sh # load the config library functions - source lib/dockertags.sh # load docker functions. - -configFilePath=$(pwd)/config.cfg - - # Read in default keys. - app_port="$(read $configFilePath app_port)" - db_name="$(read $configFilePath db_name)" - db_user="$(read $configFilePath db_user)" - db_password="$(read $configFilePath db_password)" - use_stable_versions="$(read $configFilePath use_stable_versions)" - - - if ! [[ $app_port ]]; then - echo "Config for app_port not found, using defaults." - app_port="$(read ./lib/config.cfg.defaults app_port)" - fi - - if ! [[ $db_name ]]; then - echo "Config for db_name not found, using defaults." - 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.defaults db_user)" - fi - - if ! [[ $db_password ]]; then - echo "Config for db_password not found, using defaults." - db_password="$(read config.cfg.defaults db_password)" - fi - - # Finished Config: - echo "Finished reading config. starting update..." - - # Check if (default) password was empty. - if ! [[ $db_password ]]; then - echo "Password was not set, please set the password in your config ($configFilePath) or run 'ffighter install' again" - exit 1 - fi - - # Check versions config - if [[ $use_stable_versions == "true" ]]; then - echo "Updating stable versions." - ffupdateStable - else - echo "Warning! Updating latest versions." - echo "Updating latest version is not recommended and might break the application. Please report found problems here: dev@filefighter.de." - ffupdateLatest - fi -} - -ffupdateStable(){ - -frontendVersionRepo="$(getTagsByName filefighter/frontend v | tail -1)" -restVersionRepo="$(getTagsByName filefighter/rest v | tail -1)" -filehandlerVersionRepo="$(getTagsByName filefighter/filehabdler v | tail -1)" - -if [[ "$(docker images -q filefighter/frontend:$frontendVersionRepo 2> /dev/null)" == "" ]]; then - echo "New version for FileFighter Frontend available, downloading it" - docker container stop $frontendname && docker container rm $frontendname - - echo "Creating Frontend Container, with tag: $frontendVersionRepo." - echo "Downloading filefighter/frontend image." - docker create \ - --network $networkname \ - -p $app_port:80 \ - --name $frontendname filefighter/frontend:$frontendVersionRepo >/dev/null 2>&1 - - echo "Finished downloading. Starting the updated container..." - docker start $frontendname - -else - echo "FileFighter Frontend is up to date" -fi - -if [[ "$(docker images -q filefighter/rest:$restVersionRepo 2> /dev/null)" == "" ]]; then - echo "New version for FileFighter Rest available, downloading it" - docker container stop $restname && docker container rm $restname - - # REST APP - echo "Creating REST Container, with tag: $restVersionRepo." - echo "Downloading filefighter/rest image." - docker create \ - -e DB_USERNAME=$db_user \ - -e DB_PASSWORD=$db_password \ - -e DB_NAME=$db_name \ - -e DB_CONTAINER_NAME=$dbname \ - -e SPRING_PROFILES_ACTIVE=$profile \ - --expose 8080 \ - --network $networkname \ - --name $restname filefighter/rest:$restVersionRepo >/dev/null 2>&1 - - echo "Finished downloading. Restarting the updated container..." - docker start $restname - - echo "" -else - echo "FileFighter FileFighter Rest is up to date" -fi - -if [[ "$(docker images -q filefighter/filehandler:$filehandlerVersionRepo 2> /dev/null)" == "" ]]; then - echo "New version for FileFighter FileHandler available, downloading it" - docker container stop $filehandlername && docker container rm $filehandlername - - # FileHandler - echo "Creating FileHandler Container, with tag: $filehandlerVersionRepo." - echo "Downloading filefighter/filehandler image." - docker create \ - -e PROFILE=$profile \ - -v $volumesLocation:/workdir \ - --network $networkname \ - --name $filehandlername filefighter/filehandler:$filehandlerVersionRepo >/dev/null 2>&1 - - echo "Finished downloading. Restarting the updated container..." - docker start $filehandlername - - echo "" -else - echo "FileFighter FileFighter FileHandler is up to date" -fi -} - -ffupdateLatest(){ - - -echo "" - -echo "Warning! Updating latest version, this is not recommended" - -if ! command -v regctl &> /dev/null; then - echo "regctl not found! Install it from here https://github.com/regclient/regclient/releases" - echo "" - exit 1 -fi - -frontendDigest="$(regctl image digest --list filefighter/frontend:latest)" -restDigest="$(regctl image digest --list filefighter/rest:latest)" -filehandlerDigest="$(regctl image digest --list filefighter/filehandler:latest)" - -if [[ "$( docker inspect --format='{{.RepoDigests}}' filefighter/frontend:latest 2> /dev/null)" == "[filefighter/frontend@$frontendDigest]" ]]; then - echo "FileFighter Frontend is up to date" -else - - echo "New version for FileFighter Frontend available, downloading it" - - docker container stop $frontendname >/dev/null 2>&1 && docker container rm $frontendname >/dev/null 2>&1 - docker rmi filefighter/frontend:latest >/dev/null 2>&1 - - echo "Creating Frontend Container, with tag: latest." - echo "Downloading filefighter/frontend image." - docker create \ - --network $networkname \ - -p $app_port:80 \ - --name $frontendname filefighter/frontend:latest >/dev/null 2>&1 - - echo "Finished downloading. Restarting the updated container..." - docker start $frontendname >/dev/null 2>&1 -fi - -if [[ "$( docker inspect --format='{{.RepoDigests}}' filefighter/rest:latest 2> /dev/null)" == "[filefighter/rest@$restDigest]" ]]; then - echo "FileFighter Rest is up to date" -else - echo "New version for FileFighter Rest available, downloading it" - -docker container stop $restname >/dev/null 2>&1 && docker container rm $restname >/dev/null 2>&1 -docker rmi filefighter/rest:latest >/dev/null 2>&1 - - # REST APP - echo "Creating REST Container, with tag: latest." - echo "Downloading filefighter/rest image." - docker create \ - -e DB_USERNAME=$db_user \ - -e DB_PASSWORD=$db_password \ - -e DB_NAME=$db_name \ - -e DB_CONTAINER_NAME=$dbname \ - -e SPRING_PROFILES_ACTIVE=$profile \ - --expose 8080 \ - --network $networkname \ - --name $restname filefighter/rest:latest >/dev/null 2>&1 - - echo "Finished downloading. Restarting the updated container..." - docker start $restname >/dev/null 2>&1 - echo "" -fi - -if [[ "$( docker inspect --format='{{.RepoDigests}}' filefighter/filehandler:latest 2> /dev/null)" == "[filefighter/filehandler@$filehandlerDigest]" ]]; then - echo "FileFighter FileHandler is up to date" -else - echo "New version for FileFighter FileHandler available, downloading it" - -docker container stop $filehandlername >/dev/null 2>&1 && docker container rm $filehandlername >/dev/null 2>&1 -docker rmi filefighter/filehandler:latest >/dev/null 2>&1 - - # FileHandler - echo "Creating FileHandler Container, with tag: latest." - echo "Downloading filefighter/filehandler image." - docker create \ - -e PROFILE=$profile \ - -v $volumesLocation:/workdir \ - --network $networkname \ - --name $filehandlername filefighter/filehandler:latest >/dev/null 2>&1 - - - echo "Finished downloading. Restarting the updated container..." - docker start $filehandlername >/dev/null 2>&1 - echo "" -fi -}