<commit_before>#!/bin/ash
set -e
if [ $DEBUG ]; then
    set -x
fi

WORKSPACE=${WORKSPACE:$HOME/workspace}
HOME=${HOME:-/Users/$USER}

start() {
    _set_timezone
    _ensure_workspace_git_folder
    _prepare_zsh
    _create_home_directory
    _create_user
    set-docker-client-version
    /usr/sbin/sshd -D
}

build_time() {
    echo -n "Build time: "
    date -d @$(cat /.build-time)
}

help() {
    echo "Workspace container commands"
    echo "  start             Starts the SSH daemon"
    echo "  version [args]    Show version info for given program or all"
    echo "  help              Show this help"
}

_set_timezone() {
    if [ -f /usr/share/zoneinfo/$TIMEZONE ];then
        cp -f /usr/share/zoneinfo/$TIMEZONE /etc/localtime
    else
        echo "Invalid timezone: $TIMEZONE"
    fi
}

_ensure_workspace_git_folder() {
    if [ ! -e $WORKSPACE/.git ] && [ -f $WORKSPACE/upstream-workspace-repo.txt ];then
        branch='master'
        if [ -f $WORKSPACE/upstream-workspace-branch.txt];then
            branch=$(cat $WORKSPACE/upstream-workspace-branch.txt)
        fi
        git clone \
            --no-checkout \
            --branch $branch \
            $(cat $WORKSPACE/upstream-workspace-repo.txt) \
            $WORKSPACE/upstream-workspace \
        && mv $WORKSPACE/upstream-workspace/.git $WORKSPACE/.git \
        && rmdir $WORKSPACE/upstream-workspace
    fi
}

_prepare_zsh() {
    echo "[ -f $WORKSPACE/home/.zshrc ] && source $WORKSPACE/home/.zshrc" > /etc/zsh/zshrc
    echo '' > /etc/zsh/zshenv
    env | while read env_var;do
        echo "export $env_var" >> /etc/zsh/zshenv
    done
    touch $HOME/.zshrc
}

_create_home_directory() {
    if [ ! -d $WORKSPACE/home/ ];then
        cp -r /tmp/home-workspace-template $WORKSPACE/home
    fi

    for file in `find /tmp/home-template/`;do
        home_file="$HOME/${file:19}"
        if [ -f $file ];then
            if [ ! -e $home_file ];then
                cp $file $home_file
            fi
        fi
        if [ -d $file ];then
            if [ ! -d $home_file ];then
                mkdir -p $home_file<commit_msg>Skip exporting env PWD.<commit_after>#!/bin/ash
set -e
if [ $DEBUG ]; then
    set -x
fi

WORKSPACE=${WORKSPACE:$HOME/workspace}
HOME=${HOME:-/Users/$USER}

start() {
    _set_timezone
    _ensure_workspace_git_folder
    _prepare_zsh
    _create_home_directory
    _create_user
    set-docker-client-version
    /usr/sbin/sshd -D
}

build_time() {
    echo -n "Build time: "
    date -d @$(cat /.build-time)
}

help() {
    echo "Workspace container commands"
    echo "  start             Starts the SSH daemon"
    echo "  version [args]    Show version info for given program or all"
    echo "  help              Show this help"
}

_set_timezone() {
    if [ -f /usr/share/zoneinfo/$TIMEZONE ];then
        cp -f /usr/share/zoneinfo/$TIMEZONE /etc/localtime
    else
        echo "Invalid timezone: $TIMEZONE"
    fi
}

_ensure_workspace_git_folder() {
    if [ ! -e $WORKSPACE/.git ] && [ -f $WORKSPACE/upstream-workspace-repo.txt ];then
        branch='master'
        if [ -f $WORKSPACE/upstream-workspace-branch.txt];then
            branch=$(cat $WORKSPACE/upstream-workspace-branch.txt)
        fi
        git clone \
            --no-checkout \
            --branch $branch \
            $(cat $WORKSPACE/upstream-workspace-repo.txt) \
            $WORKSPACE/upstream-workspace \
        && mv $WORKSPACE/upstream-workspace/.git $WORKSPACE/.git \
        && rmdir $WORKSPACE/upstream-workspace
    fi
}

_prepare_zsh() {
    echo "[ -f $WORKSPACE/home/.zshrc ] && source $WORKSPACE/home/.zshrc" > /etc/zsh/zshrc
    echo '' > /etc/zsh/zshenv
    env | while read env_var;do
        if [ "${env_var:0:4}" == "PWD=" ];then
            continue
        fi
        echo "export $env_var" >> /etc/zsh/zshenv
    done
    touch $HOME/.zshrc
}

_create_home_directory() {
    if [ ! -d $WORKSPACE/home/ ];then
        cp -r /tmp/home-workspace-template $WORKSPACE/home
    fi

    for file in `find /tmp/home-template/`;do
        home_file="$HOME/${file:19}"
        if [ -f $file ];then
            if [ ! -e $home_file ];then
                cp $file $home_file
            fi
        fi
        if [ -d $file ];then
            if [ ! -d $home_file ];then
                mkdir -p $home_file
{'fraction_non_alphanumeric': 0.13268383205752726, 'fraction_numerical': 0.0013917884481558804, 'mean_word_length': 1.963573883161512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '945215', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1513, 'n_words': 326}