<commit_before>#!/bin/bash

# TODO: Figure out they want for a real shell
REAL_SHELL=/bin/ash

# Must use a conistent naming scheme, docker will only let one of these run
# at a time.
DOCKER_NAME="${USER}_shell"

# TODO: Figure out what they want from config
DOCKER_CONTAINER=busybox

PID=$(docker inspect --format {{.State.Pid}} "$DOCKER_NAME")
# If we got here, then the docker is not running.
if [ -z "$PID" ] || [ "$PID" == 0 ]; then
    # If the docker is stopped, we must remove it and start a new one
    docker rm --name="$DOCKER_NAME"
    # TODO: Configur the bind mounts
    docker run -t -i --name="$DOCKER_NAME" -v "$HOME":/root/:rw -d "$DOCKER_CONTAINER"
    PID=$(docker inspect --format {{.State.Pid}} "$DOCKER_NAME")
fi

sudo nsenter --target "$PID" --mount --uts --ipc --net --pid -- "$REAL_SHELL"
<commit_msg>Make setting the UID and gid to not root work<commit_after>#!/bin/bash

# TODO: Figure out they want for a real shell
REAL_SHELL=/bin/ash

# Must use a conistent naming scheme, docker will only let one of these run
# at a time.
DOCKER_NAME="${USER}_shell"

# TODO: Figure out what they want from config
DOCKER_CONTAINER=busybox

DESIRED_USER="nobody"
DESIRED_GROUP="nobody"
# FIXME - We should instead work out the target UID inside the destination container?
MYUID=$(id -u $DESIRED_USER)
MYGID=$(id -g $DESIRED_GROUP)

PID=$(docker inspect --format {{.State.Pid}} "$DOCKER_NAME")
# If we got here, then the docker is not running.
if [ -z "$PID" ] || [ "$PID" == 0 ]; then
    # If the docker is stopped, we must remove it and start a new one
    docker rm --name="$DOCKER_NAME"
    # TODO: Configur the bind mounts
    # FIXME - If you docker attach to this container, then Ctrl-D, it dies. (This is expected?)
    docker run -t -i -u $DESIRED_USER --name="$DOCKER_NAME" -v "$HOME":/root/:rw -d "$DOCKER_CONTAINER"
    PID=$(docker inspect --format {{.State.Pid}} "$DOCKER_NAME")
fi

sudo nsenter --target "$PID" --mount --uts --ipc --net --pid --setuid $MYUID --setgid $MYGID -- "$REAL_SHELL"

{'fraction_non_alphanumeric': 0.1414441147378833, 'fraction_numerical': 0.0009891196834817012, 'mean_word_length': 3.5977272727272727, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3894188', 'n_tokens_mistral': 740, 'n_tokens_neox': 693, 'n_words': 263}