<commit_before>#!/bin/bash

if [[ $(id -u) -ne 0 ]] ; then echo "Please run the installation script as root" ; exit 1 ; fi

SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
INSTALL_PADIR="$(dirname "$SCRIPT_DIR")"
PA_FOLDER_NAME="$(basename "$INSTALL_PADIR")"
OLD_PADIR=
OS=
PKG_TOOL=

if which dnf > /dev/null 2>&1; then
   OS="RedHat"
   PKG_TOOL="dnf"
elif which yum > /dev/null 2>&1; then
   OS="RedHat"
   PKG_TOOL="yum"
elif which apt-get > /dev/null 2>&1; then
   OS="Debian"
   PKG_TOOL="apt-get"
else
    echo "This operating system is not supported by the ProActive installer."; exit 1 ;
fi

RSYNC_VER=$( rsync --version|grep "protocol version"|awk '{print $6}' )

if [[ $RSYNC_VER -ge 31 ]]; then
	RSYNC_PROGRESS="--info=progress2"
else
	RSYNC_PROGRESS="--progress"
fi

confirm() {
    # call with a prompt string or use a default
    read -r -e -p "${1:-Are you sure? [Y/n]} " -i "${2:-y}" yn
    yn=${yn,,}    # tolower
    yn=$(echo $yn | xargs)   # trim
    if [[ $yn =~ ^(yes|y|)$ ]]; then
            true
    else
            false
    fi
}

echo "This will install the ProActive scheduler as a service."
echo "Once the installer is started, it must process until the end otherwise the installation may be corrupted."


if confirm "Do you want to continue? [Y/n] " ; then
    :
else
    exit 1
fi

# checking java installation

JAVA_CMD=

if [ ! -f "$INSTALL_PADIR/jre/bin/java" ]; then
    if [[ "$JAVA_HOME" == "" ]]; then
	    if ! which java > /dev/null 2>&1; then
            echo "JAVA_HOME is not set, no 'java' command could be found in your PATH, and this ProActive distribution does not contain an embedded JRE, please install a JRE or JDK." ; exit 1 ;
        else
            JAVA_CMD=java
        fi
    else
        JAVA_CMD="$JAVA_HOME/bin/java"
    fi
fi

if ! which git > /dev/null 2>&1; then
     echo "Git is not installed on this computer and is required by the ProActive installation."
     if confirm "Do you want to install it? [Y/n] " ; then
         if [[ "$OS" == "RedHat" ]]; then
            $PKG_TOOL -y install git
         elif [[ "$OS" == "Debian" ]]; then
            $PKG_TOOL -y install git
         fi
     fi
fi

# stopping service

if [ -f /etc/init.d/proactive-scheduler ]; then
    service proactive-scheduler stop
fi

# installation of the ProActive distribution
 
read -e -p "Directory where to install the scheduler: " -i "/opt/proactive" PA_ROOT

PA_ROOT=$(echo $PA_ROOT | xargs)

mkdir -p $PA_ROOT

# handle overwriting an existing installation and finding the previous installation
if [ -d "$PA_ROOT/$PA_FOLDER_NAME" ]; then
    if confirm "A folder $PA_ROOT/$PA_FOLDER_NAME already exists. This installer must delete its content and replace it by a fresh install, do you want to continue? [Y/n] " ; then
        if [ -h "$PA_ROOT/previous" ]; then
            OLD_PADIR=$(readlink "$PA_ROOT/previous")
        fi

        rm -rf $PA_ROOT/$PA_FOLDER_NAME
        rm -f $PA_ROOT/default
    else
        exit 1
    fi
else
    # checking the previous installation
    if [ -h "$PA_ROOT/default" ]; then
        OLD_PADIR=$(readlink "$PA_ROOT/default")
        rm -f $PA_ROOT/default
    fi
fi

rsync $RSYNC_PROGRESS -a $INSTALL_PADIR $PA_ROOT

ln -s -f $PA_ROOT/$PA_FOLDER_NAME "$PA_ROOT/default"


# creation of the proactive user

read -e -p "Name of the user starting the ProActive service: " -i "proactive" USER

USER=$(echo $USER | xargs)

read -e -p "Group of the user starting the ProActive service: " -i "proactive" GROUP

GROUP=$(echo $GROUP | xargs)

id -u "$USER" > /dev/null

if (( $? != 0 )); then
    echo "The user $USER does not exist. The installation script must create this user."
    if confirm "Proceed? [Y/n] "; then
        if [ "$GROUP" == "$USER" ]; then
            useradd $USER -d $PA_ROOT
        else
            useradd $USER -d $PA_ROOT -g $GROUP
        fi
        passwd $USER;
    else
        exit 1
    fi

fi

chown $USER:$GROUP $PA_ROOT
chown $USER:$GROUP $PA_ROOT/default
chown -R $USER:$GROUP $PA_ROOT/$PA_FOLDER_NAME


# Configuration of the service script

if [ -f /etc/init.d/proactive-scheduler ] && [[ "$OLD_PADIR" != "" ]]; then
    # backup previous service file
    cp /etc/init.d/proactive-scheduler $OLD_PADIR/config/
fi

cp $SCRIPT_DIR/proactive-scheduler /etc/init.d/

read -e -p "Protocol to use for accessing Web apps deployed by the proactive server: [http/https] " -i "http" PROTOCOL

PROTOCOL=$(echo $PROTOCOL | xargs)

SELF_SIGNED=false
if [[ "$PROTOCOL" == "https" ]]; then
    if confirm "Do you want to use the provided self-signed certificate? [Y/n] " ; then
        SELF_SIGNED=true
    else
        echo "In order to install a signed certificate, you need to follow the manual configuration steps described in the ProActive documentation :"
        echo "http://doc.activeeon.com/dev/admin/ProActiveAdminGuide.html#_enable_https"
    fi

fi

if [[ "$PROTOCOL" == "https" ]]; then
    DEFAULT_PORT=8443
else
    DEFAULT_PORT=8080
fi

read -e -p "Port to use for accessing Web apps deployed by the proactive server: " -i "$DEFAULT_PORT" PORT

PORT=$(echo $PORT | xargs)

HTTP_REDIRECT_PORT=8080
if [[ "$PROTOCOL" == "https" ]]; then
    HTTP_REDIRECT=false
    if confirm "Do you want to redirect an http port to https? [Y/n] " ; then
        HTTP_REDIRECT=true
        read -e -p "Which port do you want to redirect? [8080] " -i "8080" HTTP_REDIRECT_PORT
    fi
fi

if [[ "$JAVA_CMD" == "" ]]; then
   JAVA_CMD=$PA_ROOT/default/jre/bin/java
   JAVA_HOME=$PA_ROOT/default/jre
fi

if [[ "$PORT" -lt "1024" ]] || [[ "$HTTP_REDIRECT_PORT" -lt "1024" ]] ; then

    if ! which setcap > /dev/null 2>&1; then
        echo "libcap2 is not installed on this computer and is required to start the server on a port below 1024."
        if confirm "Do you want to install it? [Y/n] " ; then
            if [[ "$OS" == "RedHat" ]]; then
                $PKG_TOOL -y install libcap2
            elif [[ "$OS" == "Debian" ]]; then
                $PKG_TOOL -y install libcap2-bin
            fi
        fi
    fi
    echo "Enabling priviledge to run server on port lower than 1024"

    if [[ "$JAVA_HOME" == "" ]]; then
        echo "Unable to locate JAVA_HOME, installation will exit."
        exit 1
    fi
    echo "$JAVA_HOME/lib/amd64/jli" > /etc/ld.so.conf.d/proactive-java.conf
    ldconfig | grep libjli
fi


read -e -p "Number of ProActive nodes to start on the server machine: " -i "4" NB_NODES
NB_NODES=$(echo $NB_NODES | xargs)

if confirm "Setup cron task for cleaning old logs? [Y/n] " ; then
     read -e -p "Cleaning logs older than (in days) [50]: " -i "50" LOGS_CLEANUP_DAYS

     LOGS_CLEANUP_DAYS=$(echo $LOGS_CLEANUP_DAYS | xargs)
     if [[ $(grep -c "$PA_ROOT/default/logs" /etc/crontab) == 0 ]]; then
        echo "1 0   * * *   root   find $PA_ROOT/default/logs -mtime +$LOGS_CLEANUP_DAYS -name '*.log' -exec rm {} \;" >> /etc/crontab
     fi
fi



# Escape functions for sed 
escape_rhs_sed ()
{
        echo $(printf '%s\n' "$1" | sed 's:[\/&]:\\&:g;$!s/$/\\/')

}

sed -e "s/^USER=.*/USER=$USER/g" -i "/etc/init.d/proactive-scheduler"
sed -e "s/^PROTOCOL=.*/PROTOCOL=$PROTOCOL/g" -i "/etc/init.d/proactive-scheduler"

if [[ "$PROTOCOL" == "https" ]]; then
    sed -e "s/^web\.https=.*/web.https=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
    sed -e "s/http:/https:/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
    sed -e "s/http:/https:/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
    if $SELF_SIGNED; then
        sed -e "s/^#web\.https\.keystore=\(.*\)/web.https.keystore=\1/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.keystore\.password=\(.*\)/web.https.keystore.password=\1/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
    fi
fi

sed -e "s/^PORT=.*/PORT=$PORT/g" -i "/etc/init.d/proactive-scheduler"
if [[ "$PROTOCOL" == "https" ]]; then
    sed -e "s/^web\.https\.port=.*/web.https.port=$PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
    if $HTTP_REDIRECT; then
        sed -e "s/^web\.redirect_http_to_https=.*/web.redirect_http_to_https=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^web\.http\.port=.*/web.http.port=$HTTP_REDIRECT_PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
    fi
else
    sed -e "s/^web\.http\.port=.*/web.http.port=$PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
fi
sed -e "s/:8080/:${PORT}/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
sed -e "s/:8080/:${PORT}/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
sed -e "s/^NB_NODES=.*/NB_NODES=$NB_NODES/g"  -i "/etc/init.d/proactive-scheduler"
sed -e "s/^PA_ROOT=.*/PA_ROOT=$(escape_rhs_sed "$PA_ROOT")/g" -i "/etc/init.d/proactive-scheduler"

if confirm "Start ProActive Nodes in a single JVM process (y) or multiple JVM Processes (n)? [Y/n] " ; then
    sed -e "s/^SINGLE_JVM=.*/SINGLE_JVM=true/g" -i "/etc/init.d/proactive-scheduler"
fi

echo "Here are the network interfaces available on your machine and the interface which will be automatically selected by ProActive: "



# Select network interface

NETWORK_OUTPUT=$( $JAVA_CMD -cp "$PA_ROOT/default/dist/lib:$PA_ROOT/default/dist/lib/*" org.objectweb.proactive.core.util.ProActiveInet )
echo "$NETWORK_OUTPUT"


if confirm "Do you want to change the network interface used? [y/N] " "n" ; then
     ITF_ARRAY=( $( echo "$NETWORK_OUTPUT" | grep -e 'MAC:' | awk '{ print $1 }' ) )
     echo "Available interfaces : " "${ITF_ARRAY[@]}"
     ITF_SELECTED=false
     while  ! $ITF_SELECTED ; do
        read -e -p "Enter the interface name you want to use: " ITF_NAME
        ITF_NAME=$(echo $ITF_NAME | xargs)

        if [[ " ${ITF_ARRAY[@]} " =~ " ${ITF_NAME} " ]]; then
            ITF_SELECTED=true
        else
            echo "Interface $ITF_NAME not in the list"
        fi
     done

     echo "proactive.net.interface=$ITF_NAME" >> "$PA_ROOT/default/config/network/server.ini"
     echo "proactive.net.interface=$ITF_NAME" >> "$PA_ROOT/default/config/network/node.ini"
fi


# installation of the proactive-scheduler service

chmod 700 /etc/init.d/proactive-scheduler

mkdir -p /var/log/proactive
touch /var/log/proactive/scheduler

chown -R $USER:$GROUP /var/log/proactive

if confirm "Start the proactive-scheduler service at startup? [Y/n] " ; then
    if [[ "$OS" == "RedHat" ]]; then
       chkconfig proactive-scheduler on<commit_msg>install.sh script : trimming using xargs can eat special characters<commit_after>#!/bin/bash

if [[ $(id -u) -ne 0 ]] ; then echo "Please run the installation script as root" ; exit 1 ; fi

SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
INSTALL_PADIR="$(dirname "$SCRIPT_DIR")"
PA_FOLDER_NAME="$(basename "$INSTALL_PADIR")"
OLD_PADIR=
OS=
PKG_TOOL=

if which dnf > /dev/null 2>&1; then
   OS="RedHat"
   PKG_TOOL="dnf"
elif which yum > /dev/null 2>&1; then
   OS="RedHat"
   PKG_TOOL="yum"
elif which apt-get > /dev/null 2>&1; then
   OS="Debian"
   PKG_TOOL="apt-get"
else
    echo "This operating system is not supported by the ProActive installer."; exit 1 ;
fi

RSYNC_VER=$( rsync --version|grep "protocol version"|awk '{print $6}' )

if [[ $RSYNC_VER -ge 31 ]]; then
	RSYNC_PROGRESS="--info=progress2"
else
	RSYNC_PROGRESS="--progress"
fi

trim() {
    echo "$1" | sed -e 's/^[[:space:]]*//'|sed -e 's/[[:space:]]*$//'
}

confirm() {
    # call with a prompt string or use a default
    read -r -e -p "${1:-Are you sure? [Y/n]} " -i "${2:-y}" yn
    yn=${yn,,}    # tolower
    yn=$(trim "$yn")
    if [[ $yn =~ ^(yes|y|)$ ]]; then
            true
    else
            false
    fi
}



echo "This will install the ProActive scheduler as a service."
echo "Once the installer is started, it must process until the end otherwise the installation may be corrupted."


if confirm "Do you want to continue? [Y/n] " ; then
    :
else
    exit 1
fi

# checking java installation

JAVA_CMD=

if [ ! -f "$INSTALL_PADIR/jre/bin/java" ]; then
    if [[ "$JAVA_HOME" == "" ]]; then
	    if ! which java > /dev/null 2>&1; then
            echo "JAVA_HOME is not set, no 'java' command could be found in your PATH, and this ProActive distribution does not contain an embedded JRE, please install a JRE or JDK." ; exit 1 ;
        else
            JAVA_CMD=java
        fi
    else
        JAVA_CMD="$JAVA_HOME/bin/java"
    fi
fi

if ! which git > /dev/null 2>&1; then
     echo "Git is not installed on this computer and is required by the ProActive installation."
     if confirm "Do you want to install it? [Y/n] " ; then
         if [[ "$OS" == "RedHat" ]]; then
            $PKG_TOOL -y install git
         elif [[ "$OS" == "Debian" ]]; then
            $PKG_TOOL -y install git
         fi
     fi
fi

# stopping service

if [ -f /etc/init.d/proactive-scheduler ]; then
    service proactive-scheduler stop
fi

# installation of the ProActive distribution
 
read -e -p "Directory where to install the scheduler: " -i "/opt/proactive" PA_ROOT

PA_ROOT=$(trim "$PA_ROOT")

mkdir -p $PA_ROOT

# handle overwriting an existing installation and finding the previous installation
if [ -d "$PA_ROOT/$PA_FOLDER_NAME" ]; then
    if confirm "A folder $PA_ROOT/$PA_FOLDER_NAME already exists. This installer must delete its content and replace it by a fresh install, do you want to continue? [Y/n] " ; then
        if [ -h "$PA_ROOT/previous" ]; then
            OLD_PADIR=$(readlink "$PA_ROOT/previous")
        fi

        rm -rf $PA_ROOT/$PA_FOLDER_NAME
        rm -f $PA_ROOT/default
    else
        exit 1
    fi
else
    # checking the previous installation
    if [ -h "$PA_ROOT/default" ]; then
        OLD_PADIR=$(readlink "$PA_ROOT/default")
        rm -f $PA_ROOT/default
    fi
fi

rsync $RSYNC_PROGRESS -a $INSTALL_PADIR $PA_ROOT

ln -s -f $PA_ROOT/$PA_FOLDER_NAME "$PA_ROOT/default"


# creation of the proactive user

read -e -p "Name of the user starting the ProActive service: " -i "proactive" USER

USER=$(trim "$USER")

read -e -p "Group of the user starting the ProActive service: " -i "proactive" GROUP

GROUP=$(trim "$GROUP")

id -u "$USER" > /dev/null

if (( $? != 0 )); then
    echo "The user $USER does not exist. The installation script must create this user."
    if confirm "Proceed? [Y/n] "; then
        if [ "$GROUP" == "$USER" ]; then
            useradd $USER -d $PA_ROOT
        else
            useradd $USER -d $PA_ROOT -g $GROUP
        fi
        passwd $USER;
    else
        exit 1
    fi

fi

chown $USER:$GROUP $PA_ROOT
chown $USER:$GROUP $PA_ROOT/default
chown -R $USER:$GROUP $PA_ROOT/$PA_FOLDER_NAME


# Configuration of the service script

if [ -f /etc/init.d/proactive-scheduler ] && [[ "$OLD_PADIR" != "" ]]; then
    # backup previous service file
    cp /etc/init.d/proactive-scheduler $OLD_PADIR/config/
fi

cp $SCRIPT_DIR/proactive-scheduler /etc/init.d/

read -e -p "Protocol to use for accessing Web apps deployed by the proactive server: [http/https] " -i "http" PROTOCOL

PROTOCOL=$(trim "$PROTOCOL")

SELF_SIGNED=false
if [[ "$PROTOCOL" == "https" ]]; then
    if confirm "Do you want to use the provided self-signed certificate? [Y/n] " ; then
        SELF_SIGNED=true
    else
        echo "In order to install a signed certificate, you need to follow the manual configuration steps described in the ProActive documentation :"
        echo "http://doc.activeeon.com/dev/admin/ProActiveAdminGuide.html#_enable_https"
    fi

fi

if [[ "$PROTOCOL" == "https" ]]; then
    DEFAULT_PORT=8443
else
    DEFAULT_PORT=8080
fi

read -e -p "Port to use for accessing Web apps deployed by the proactive server: " -i "$DEFAULT_PORT" PORT

PORT=$(trim "$PORT")

HTTP_REDIRECT_PORT=8080
if [[ "$PROTOCOL" == "https" ]]; then
    HTTP_REDIRECT=false
    if confirm "Do you want to redirect an http port to https? [Y/n] " ; then
        HTTP_REDIRECT=true
        read -e -p "Which port do you want to redirect? [8080] " -i "8080" HTTP_REDIRECT_PORT
    fi
fi

if [[ "$JAVA_CMD" == "" ]]; then
   JAVA_CMD=$PA_ROOT/default/jre/bin/java
   JAVA_HOME=$PA_ROOT/default/jre
fi

if [[ "$PORT" -lt "1024" ]] || [[ "$HTTP_REDIRECT_PORT" -lt "1024" ]] ; then

    if ! which setcap > /dev/null 2>&1; then
        echo "libcap2 is not installed on this computer and is required to start the server on a port below 1024."
        if confirm "Do you want to install it? [Y/n] " ; then
            if [[ "$OS" == "RedHat" ]]; then
                $PKG_TOOL -y install libcap2
            elif [[ "$OS" == "Debian" ]]; then
                $PKG_TOOL -y install libcap2-bin
            fi
        fi
    fi
    echo "Enabling priviledge to run server on port lower than 1024"

    if [[ "$JAVA_HOME" == "" ]]; then
        echo "Unable to locate JAVA_HOME, installation will exit."
        exit 1
    fi
    echo "$JAVA_HOME/lib/amd64/jli" > /etc/ld.so.conf.d/proactive-java.conf
    ldconfig | grep libjli
fi


read -e -p "Number of ProActive nodes to start on the server machine: " -i "4" NB_NODES
NB_NODES=$(trim "$NB_NODES")

if confirm "Setup cron task for cleaning old logs? [Y/n] " ; then
     read -e -p "Cleaning logs older than (in days) [50]: " -i "50" LOGS_CLEANUP_DAYS

     LOGS_CLEANUP_DAYS=$(trim "$LOGS_CLEANUP_DAYS")
     if [[ $(grep -c "$PA_ROOT/default/logs" /etc/crontab) == 0 ]]; then
        echo "1 0   * * *   root   find $PA_ROOT/default/logs -mtime +$LOGS_CLEANUP_DAYS -name '*.log' -exec rm {} \;" >> /etc/crontab
     fi
fi



# Escape functions for sed 
escape_rhs_sed ()
{
        echo $(printf '%s\n' "$1" | sed 's:[\/&]:\\&:g;$!s/$/\\/')

}

sed -e "s/^USER=.*/USER=$USER/g" -i "/etc/init.d/proactive-scheduler"
sed -e "s/^PROTOCOL=.*/PROTOCOL=$PROTOCOL/g" -i "/etc/init.d/proactive-scheduler"

if [[ "$PROTOCOL" == "https" ]]; then
    sed -e "s/^web\.https=.*/web.https=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
    sed -e "s/http:/https:/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
    sed -e "s/http:/https:/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
    if $SELF_SIGNED; then
        sed -e "s/^#web\.https\.keystore=\(.*\)/web.https.keystore=\1/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.keystore\.password=\(.*\)/web.https.keystore.password=\1/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
        sed -e "s/^#web\.https\.allow_any_hostname=.*/web.https.allow_any_hostname=true/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
        sed -e "s/^#web\.https\.allow_any_certificate=.*/web.https.allow_any_certificate=true/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
    fi
fi

sed -e "s/^PORT=.*/PORT=$PORT/g" -i "/etc/init.d/proactive-scheduler"
if [[ "$PROTOCOL" == "https" ]]; then
    sed -e "s/^web\.https\.port=.*/web.https.port=$PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
    if $HTTP_REDIRECT; then
        sed -e "s/^web\.redirect_http_to_https=.*/web.redirect_http_to_https=true/g" -i "$PA_ROOT/default/config/web/settings.ini"
        sed -e "s/^web\.http\.port=.*/web.http.port=$HTTP_REDIRECT_PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
    fi
else
    sed -e "s/^web\.http\.port=.*/web.http.port=$PORT/g" -i "$PA_ROOT/default/config/web/settings.ini"
fi
sed -e "s/:8080/:${PORT}/g" -i "$PA_ROOT/default/dist/war/rm/rm.conf"
sed -e "s/:8080/:${PORT}/g" -i "$PA_ROOT/default/dist/war/scheduler/scheduler.conf"
sed -e "s/^NB_NODES=.*/NB_NODES=$NB_NODES/g"  -i "/etc/init.d/proactive-scheduler"
sed -e "s/^PA_ROOT=.*/PA_ROOT=$(escape_rhs_sed "$PA_ROOT")/g" -i "/etc/init.d/proactive-scheduler"

if confirm "Start ProActive Nodes in a single JVM process (y) or multiple JVM Processes (n)? [Y/n] " ; then
    sed -e "s/^SINGLE_JVM=.*/SINGLE_JVM=true/g" -i "/etc/init.d/proactive-scheduler"
fi

echo "Here are the network interfaces available on your machine and the interface which will be automatically selected by ProActive: "



# Select network interface

NETWORK_OUTPUT=$( $JAVA_CMD -cp "$PA_ROOT/default/dist/lib:$PA_ROOT/default/dist/lib/*" org.objectweb.proactive.core.util.ProActiveInet )
echo "$NETWORK_OUTPUT"


if confirm "Do you want to change the network interface used? [y/N] " "n" ; then
     ITF_ARRAY=( $( echo "$NETWORK_OUTPUT" | grep -e 'MAC:' | awk '{ print $1 }' ) )
     echo "Available interfaces : " "${ITF_ARRAY[@]}"
     ITF_SELECTED=false
     while  ! $ITF_SELECTED ; do
        read -e -p "Enter the interface name you want to use: " ITF_NAME
        ITF_NAME=$(trim "$ITF_NAME")

        if [[ " ${ITF_ARRAY[@]} " =~ " ${ITF_NAME} " ]]; then
            ITF_SELECTED=true
        else
            echo "Interface $ITF_NAME not in the list"
        fi
     done

     echo "proactive.net.interface=$ITF_NAME" >> "$PA_ROOT/default/config/network/server.ini"
     echo "proactive.net.interface=$ITF_NAME" >> "$PA_ROOT/default/config/network/node.ini"
fi


# installation of the proactive-scheduler service

chmod 700 /etc/init.d/proactive-scheduler

mkdir -p /var/log/proactive
touch /var/log/proactive/scheduler

chown -R $USER:$GROUP /var/log/proactive

if confirm "Start the proactive-scheduler service at startup? [Y/n] " ; then
    if [[ "$OS" == "RedHat" ]]; then
       chkconfig proactive-scheduler on
{'fraction_non_alphanumeric': 0.1521381213011169, 'fraction_numerical': 0.008232100743113958, 'mean_word_length': 2.9269613838895685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3169810', 'n_tokens_mistral': 8437, 'n_tokens_neox': 8112, 'n_words': 2211}