<commit_before>#!/bin/bash


function escape_path()
{
    echo $1 | sed -e 's/\//\\\//g'
}

function network_add()
{
    if [ -z "$1" ]; then
	echo "network_add(): Need machine name!"
	exit 1
    fi
    num=`cat $IPFILE`
    echo "dhcp-host=$1,$IPBASE.$num" >> $DNSMASQFILE
    echo "lxc.network.hwaddr = $MACBASE:$num" >> $CONFIG
    num=`expr $num + 1`
    echo "$num" > $IPFILE
    echo "Restart lxc-net service to apply changes!"
}

if [ -z "$1" ]; then
    echo "Need machine name!"
    exit 1
fi

mname="$1"

SLURM_LXC_HOME=`pwd`

. ./slxc.conf

# Check nessesary dirs and file
FSTAB_IN=$TEMPLATES/fstab.in
SLURM_LXC_CONF_IN=$TEMPLATES/slurm_lxc.conf.in
MACHINE_INIT_SCRIPT_IN=$TEMPLATES/machine_init.sh.in

CHECK_DIRS="$BUILD $TEMPLATES"
CHECK_FILES="$FSTAB_IN $SLURM_LXC_CONF_IN $MACHINE_INIT_SCRIPT_IN"

for i in $CHECK_DIRS; do
    if [ ! -d "$i" ]; then
        echo "No mandatory directory $i found. Check consistency!"
        exit 1
    fi
done

for i in $CHECK_FILES; do
    if [ ! -f "$i" ]; then
        echo "No mandatory file $i found. Check consistency!"
        exit 1
    fi
done

if [ -z "$IPBASE" ] || [ -z "$MACBASE" ]; then
    echo "Either IPBASE or MACBASE wasn't specifyed!"
    exit 1
fi

# Full path to BUILD
bkp=`pwd`
cd $BUILD
BUILD=`pwd`
cd $bkp

# Create nessesary files and directorys if not exist
CONTAINERS_DIR="$BUILD/containers"
FSTAB="$BUILD/fstab"
MACHINE_INIT_SCRIPT="$BUILD/machine_init.sh"
CONFIG="$CONTAINERS_DIR/$mname.conf"
MACHINEFILE="$BUILD/machines"
DNSMASQFILE="$BUILD/dnsmasq.conf"
IPFILE="$BUILD/ipnumbering"


if [ ! -d "$CONTAINERS_DIR" ]; then
    mkdir -p "$CONTAINERS_DIR"
fi

if [ ! -f "$FSTAB" ]; then
    # Form & Escape it
    MUNGE_VAR=`escape_path $MUNGE_PATH/var/`
    SLURM_VAR=`escape_path $SLURM_PATH/var/`
    cat $FSTAB_IN \
	| sed -e "s/@MUNGEVAR@/$MUNGE_VAR/g" \
	| sed -e "s/@SLURMVAR@/$SLURM_VAR/g" \
	> $FSTAB<commit_msg>Check SLURM installation when creating the virtual host.<commit_after>#!/bin/bash


function escape_path()
{
    echo $1 | sed -e 's/\//\\\//g'
}

function network_add()
{
    if [ -z "$1" ]; then
	echo "network_add(): Need machine name!"
	exit 1
    fi
    num=`cat $IPFILE`
    echo "dhcp-host=$1,$IPBASE.$num" >> $DNSMASQFILE
    echo "lxc.network.hwaddr = $MACBASE:$num" >> $CONFIG
    num=`expr $num + 1`
    echo "$num" > $IPFILE
    echo "Restart lxc-net service to apply changes!"
}

if [ -z "$1" ]; then
    echo "Need machine name!"
    exit 1
fi

mname="$1"

SLURM_LXC_HOME=`pwd`

. ./slxc.conf

# Check nessesary dirs and file
FSTAB_IN=$TEMPLATES/fstab.in
SLURM_LXC_CONF_IN=$TEMPLATES/slurm_lxc.conf.in
MACHINE_INIT_SCRIPT_IN=$TEMPLATES/machine_init.sh.in

CHECK_DIRS="$BUILD $TEMPLATES"
CHECK_FILES="$FSTAB_IN $SLURM_LXC_CONF_IN $MACHINE_INIT_SCRIPT_IN"

for i in $CHECK_DIRS; do
    if [ ! -d "$i" ]; then
        echo "No mandatory directory $i found. Check consistency!"
        exit 1
    fi
done

for i in $CHECK_FILES; do
    if [ ! -f "$i" ]; then
        echo "No mandatory file $i found. Check consistency!"
        exit 1
    fi
done

if [ -z "$IPBASE" ] || [ -z "$MACBASE" ]; then
    echo "Either IPBASE or MACBASE wasn't specifyed!"
    exit 1
fi

# Full path to BUILD
bkp=`pwd`
cd $BUILD
BUILD=`pwd`
cd $bkp

# Create nessesary files and directorys if not exist
CONTAINERS_DIR="$BUILD/containers"
FSTAB="$BUILD/fstab"
MACHINE_INIT_SCRIPT="$BUILD/machine_init.sh"
CONFIG="$CONTAINERS_DIR/$mname.conf"
MACHINEFILE="$BUILD/machines"
DNSMASQFILE="$BUILD/dnsmasq.conf"
IPFILE="$BUILD/ipnumbering"


if [ ! -d "$CONTAINERS_DIR" ]; then
    mkdir -p "$CONTAINERS_DIR"
fi

if [ ! -d $SLURM_PATH/var ]; then
    mkdir $SLURM_PATH/var 
fi

if [ ! -f $SLURM_PATH/etc/slurm.conf ]; then
    echo "No $SLURM_PATH/etc/slurm.conf file found. Configure SLURM first"
    exit 1
fi

if [ ! -f "$FSTAB" ]; then
    # Form & Escape it
    MUNGE_VAR=`escape_path $MUNGE_PATH/var/`
    SLURM_VAR=`escape_path $SLURM_PATH/var/`
    cat $FSTAB_IN \
	| sed -e "s/@MUNGEVAR@/$MUNGE_VAR/g" \
	| sed -e "s/@SLURMVAR@/$SLURM_VAR/g" \
	> $FSTAB
{'fraction_non_alphanumeric': 0.14904679376083188, 'fraction_numerical': 0.00569447883139391, 'mean_word_length': 3.3675675675675674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4641329', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1656, 'n_words': 392}