<commit_before>#!/usr/bin/env bash

# Function to prefix stdout with current formulae name
function prefix {
    if [[ ! -z "${1}" ]]; then
        sed -e "s/^/[vhost][${1}] /"
    else
        sed -e "s/^/[vhost] /"
    fi
}

# Store arguments and variables
args_root_password="${1}"

###
# Initial bootstrap
###

if [[ ! -f /opt/servant/formulae/vhosts.lockfile ]]; then
    # none

    # Create lockfile to indicate successful inital provisions
    touch /opt/servant/formulae/vhosts.lockfile
fi

###
# Recurring bootstrap
###

# If there are any projects in public/
if [[ ! -z $(find /var/www/html/ -maxdepth 1 -type d ! -path /var/www/html/) ]]; then
    # For each custom virtual host
    for directory in /var/www/html/*; do
        # Store hostname in variable and substitute dots with dashes for MySQL
        virtual_hostname=$(basename "${directory}")
        virtual_db_hostname=${virtual_hostname/./_}

        # write configuration file
        sudo bash -c "cat > /etc/apache2/sites-available/${virtual_hostname}.conf" <<EOAPACHE
<VirtualHost *:80>
    ServerName ${virtual_hostname}

    DocumentRoot /var/www/html/${virtual_hostname}

    <Directory /var/www/html/${virtual_hostname}>
        Options +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    CustomLog \${APACHE_LOG_DIR}/${virtual_hostname}_access.log combined
    ErrorLog \${APACHE_LOG_DIR}/${virtual_hostname}_error.log
</VirtualHost>
EOAPACHE

        # Enable config
        sudo a2ensite ${virtual_hostname}.conf | prefix "+][${virtual_hostname}][Apache"

        # Create MySQL database and user
        MYSQL_PWD=${args_root_password} mysql -u root -e """
        CREATE DATABASE IF NOT EXISTS ${virtual_db_hostname} DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
        GRANT ALL ON ${virtual_db_hostname}.* TO '${virtual_db_hostname}'@'localhost' IDENTIFIED BY '${virtual_db_hostname}';
        """

        # Make sure to restart Apache at the end of the script
        touch /opt/servant/apache.restart

        # Create lockfile
        touch /opt/servant/projects/${virtual_hostname}

        echo "Created user and database \"${virtual_db_hostname}\"" | prefix "+][${virtual_hostname}][MySQL"
    done
else
    echo "No projects found in \"public/\" folder." | prefix
fi

# Check if lockfile folder is not empty
if [[ ! -z $(find /opt/servant/projects/ -maxdepth 1 -type f) ]]; then
    # Check if there are stale projects
    for lockfile in /opt/servant/projects/*; do
         # Store hostname in variable and substitute dots with dashes for MySQL
        virtual_hostname=$(basename "${lockfile}")
        virtual_db_hostname=${virtual_hostname/./_}

        if [[ ! -d "/var/www/html/${virtual_hostname}" ]]; then
            # Disable and remove virtual host
            sudo a2dissite ${virtual_hostname}.conf | prefix "-][${virtual_hostname}][Apache"
            rm /etc/apache2/sites-available/${virtual_hostname}.conf

            # Drop database and SQL user
            MYSQL_PWD=${args_<PASSWORD>_password} mysql -u root -e """
            DROP DATABASE ${virtual_db_hostname};
            DROP USER '${virtual_db_hostname}'@'localhost';
            """

            # Make sure to restart Apache at the end of the script
            touch /opt/servant/apache.restart

            # Remove lockfile
            rm ${lockfile}

            echo "Removed user and database \"${virtual_db_hostname}\"" | prefix "-][${virtual_hostname}][MySQL"
        fi
    done
fi

# Restart Apache if necessary
if [[ -f /opt/servant/apache.restart ]]; then
    sudo service apache2 restart | prefix "service"
    rm /opt/servant/apache.restart
fi

# Exit without errors
exit 0
<commit_msg>Remove notice when there is no action<commit_after>#!/usr/bin/env bash

# Function to prefix stdout with current formulae name
function prefix {
    if [[ ! -z "${1}" ]]; then
        sed -e "s/^/[vhost][${1}] /"
    else
        sed -e "s/^/[vhost] /"
    fi
}

# Store arguments and variables
args_root_password="${1}"

###
# Initial bootstrap
###

if [[ ! -f /opt/servant/formulae/vhosts.lockfile ]]; then
    # none

    # Create lockfile to indicate successful inital provisions
    touch /opt/servant/formulae/vhosts.lockfile
fi

###
# Recurring bootstrap
###

# If there are any projects in public/
if [[ ! -z $(find /var/www/html/ -maxdepth 1 -type d ! -path /var/www/html/) ]]; then
    # For each custom virtual host
    for directory in /var/www/html/*; do
        # Store hostname in variable and substitute dots with dashes for MySQL
        virtual_hostname=$(basename "${directory}")
        virtual_db_hostname=${virtual_hostname/./_}

        # write configuration file
        sudo bash -c "cat > /etc/apache2/sites-available/${virtual_hostname}.conf" <<EOAPACHE
<VirtualHost *:80>
    ServerName ${virtual_hostname}

    DocumentRoot /var/www/html/${virtual_hostname}

    <Directory /var/www/html/${virtual_hostname}>
        Options +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    CustomLog \${APACHE_LOG_DIR}/${virtual_hostname}_access.log combined
    ErrorLog \${APACHE_LOG_DIR}/${virtual_hostname}_error.log
</VirtualHost>
EOAPACHE

        # Enable config
        sudo a2ensite ${virtual_hostname}.conf | prefix "+][${virtual_hostname}][Apache"

        # Create MySQL database and user
        MYSQL_PWD=${args_root_password} mysql -u root -e """
        CREATE DATABASE IF NOT EXISTS ${virtual_db_hostname} DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
        GRANT ALL ON ${virtual_db_hostname}.* TO '${virtual_db_hostname}'@'localhost' IDENTIFIED BY '${virtual_db_hostname}';
        """

        # Make sure to restart Apache at the end of the script
        touch /opt/servant/apache.restart

        # Create lockfile
        touch /opt/servant/projects/${virtual_hostname}

        echo "Created user and database \"${virtual_db_hostname}\"" | prefix "+][${virtual_hostname}][MySQL"
    done
fi

# Check if lockfile folder is not empty
if [[ ! -z $(find /opt/servant/projects/ -maxdepth 1 -type f) ]]; then
    # Check if there are stale projects
    for lockfile in /opt/servant/projects/*; do
         # Store hostname in variable and substitute dots with dashes for MySQL
        virtual_hostname=$(basename "${lockfile}")
        virtual_db_hostname=${virtual_hostname/./_}

        if [[ ! -d "/var/www/html/${virtual_hostname}" ]]; then
            # Disable and remove virtual host
            sudo a2dissite ${virtual_hostname}.conf | prefix "-][${virtual_hostname}][Apache"
            rm /etc/apache2/sites-available/${virtual_hostname}.conf

            # Drop database and SQL user
            MYSQL_PWD=${<PASSWORD>} mysql -u root -e """
            DROP DATABASE ${virtual_db_hostname};
            DROP USER '${virtual_db_hostname}'@'localhost';
            """

            # Make sure to restart Apache at the end of the script
            touch /opt/servant/apache.restart

            # Remove lockfile
            rm ${lockfile}

            echo "Removed user and database \"${virtual_db_hostname}\"" | prefix "-][${virtual_hostname}][MySQL"
        fi
    done
fi

# Restart Apache if necessary
if [[ -f /opt/servant/apache.restart ]]; then
    sudo service apache2 restart | prefix "service"
    rm /opt/servant/apache.restart
fi

# Exit without errors
exit 0

{'fraction_non_alphanumeric': 0.12064306944069171, 'fraction_numerical': 0.00405295865982167, 'mean_word_length': 2.7597765363128492, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, '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': '2446610', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2230, 'n_words': 637}