Skip to content
Snippets Groups Projects
setup-eccs-dev.sh 1.81 KiB
#!/bin/bash

function modify_hosts_file() {
    local action="$1"
    local domain_name="$2"
    local ip_address="$3"
    local hosts_path="/etc/hosts"

    if [[ "$action" == "add" ]]; then
        if sudo grep -q "$ip_address $domain_name" "$hosts_path"; then
            return 0
        fi
        echo -ne "\n$ip_address\t$domain_name" | sudo tee -a "$hosts_path" >/dev/null
        #echo "\nAdded $ip_address $domain_name to /etc/hosts file"
    elif [[ "$action" == "remove" ]]; then
        if ! sudo grep -q "$domain_name" "$hosts_path"; then
            return 0
        fi
        sudo sed -i "/$domain_name/d" "$hosts_path"
        #echo "\nRemoved line containing $domain_name from /etc/hosts file"
    else
        echo "Usage: modify_hosts_file [add|remove] <domain> [<IP address>]"
        return 1
    fi
}

echo "Stop and remove all"
docker compose down

echo "Stop any local Apache2 Web Server started"
sudo systemctl stop apache2.service

echo "Remove old container image to be able to create it from scratch"
docker rmi gitlab.software.geant.org:5050/edugain/eccs:dev

echo "Start docker container creation"
docker compose up -d

ECCS_IP=$(docker inspect eccs | grep "IPAddress" | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | tail -n 1)

DOMAIN_NAME="eccs.edugain.org"

modify_hosts_file "remove" "$DOMAIN_NAME"
modify_hosts_file "add" "$DOMAIN_NAME" "$ECCS_IP"

echo ""
echo "Useful command to access the 'eccs' terminal:"
echo ""
echo "docker exec -it -u root eccs bash"
echo ""
echo "Run ECCS manually for today:"
echo ""
echo "docker exec -it -u eccs -w /home/eccs eccs ./cleanAndRunEccs.sh > logs/eccs-cron.log 2>&1"
echo ""
echo "Delete all results of today"
echo ""
echo "docker exec -it -u eccs -w /home/eccs/ eccs rm -rf html/$(date +%Y-%m-%d) output/eccs_$(date +%Y-%m-%d).log logs/*_$(date +%Y-%m-%d).log"