<commit_before>import exec from './exec.js';
import Host from './host.js';

// private functions

const createHomeFolder = async (name) => {
    await exec('mkdir -p /var/www/{{name}}', { name });
    await exec('chown -R {{name}}:{{name}} /var/www/{{name}}', { name });
};

const createBackupFolder = async (name) => {
    await exec('mkdir -p /var/backup-www/{{name}}', { name });
};

const removeHomeFolder = async (name) => {
    await exec('rm -fr /var/www/{{name}}', { name });
};

// customer class

class Customer {
    constructor(name) {
        if (name.length > 16 || name.match(/[^a-z0-9]/i)) {
            throw `invalid customer name "${name}"`;
        }
        this.name = name;
        this.hostnames = {};
    }

    async create() {
        await exec('useradd --home-dir /var/www/{{name}} --shell /bin/false {{name}}', {
            name: this.name
        });
        await createHomeFolder(this.name);
    }

    async remove() {
        await createBackupFolder(this.name);

        // generate a compressed backup of the customer's home folder and then remove the home folder
        await exec('deluser --backup --backup-to /var/backup-www/{{name}} --remove-home {{name}}', {
            name: this.name
        });

        // for some reason, the '--remove-home' command is not working properly, so we have to delete the home folder "manually"
        await removeHomeFolder(this.name);
    }
<commit_msg>update regexp an set user length to 32<commit_after>import exec from './exec.js';
import Host from './host.js';

// private functions

const createHomeFolder = async (name) => {
    await exec('mkdir -p /var/www/{{name}}', { name });
    await exec('chown -R {{name}}:{{name}} /var/www/{{name}}', { name });
};

const createBackupFolder = async (name) => {
    await exec('mkdir -p /var/backup-www/{{name}}', { name });
};

const removeHomeFolder = async (name) => {
    await exec('rm -fr /var/www/{{name}}', { name });
};

// customer class

class Customer {
    constructor(name) {
        if (name.length > 32 || !name.match(/^[a-z][-a-z0-9_]*$/)) {
            throw `invalid customer name "${name}"`;
        }
        this.name = name;
        this.hostnames = {};
    }

    async create() {
        await exec('useradd --home-dir /var/www/{{name}} --shell /bin/false {{name}}', {
            name: this.name
        });
        await createHomeFolder(this.name);
    }

    async remove() {
        await createBackupFolder(this.name);

        // generate a compressed backup of the customer's home folder and then remove the home folder
        await exec('deluser --backup --backup-to /var/backup-www/{{name}} --remove-home {{name}}', {
            name: this.name
        });

        // for some reason, the '--remove-home' command is not working properly, so we have to delete the home folder "manually"
        await removeHomeFolder(this.name);
    }

{'fraction_non_alphanumeric': 0.17332873880082703, 'fraction_numerical': 0.0034458993797381117, 'mean_word_length': 2.3913551401869158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3167546', 'n_tokens_mistral': 893, 'n_tokens_neox': 889, 'n_words': 251}