<commit_before>#! /bin/sh

get_existing() {
    CONTAINER_ID=`docker ps -a --filter name=my-running-dudle --format "{{.ID}}"`

    if [ $? -ne 0 ] || [ "$CONTAINER_ID" == "" ]; then
        echo Dudle container not found $CONTAINER_ID
        exit 1
    fi
}

run() {
    docker run -d -v /srv/dudle/backup:/backup:Z -p 8888:80 --name my-running-dudle my-dudle || exit 1
}

backup() {
    echo Running backup for container $CONTAINER_ID

    docker exec -it $CONTAINER_ID /usr/local/bin/backup.sh || exit 1
}

connect() {
    echo Connecting to container $CONTAINER_ID

    docker exec -it $CONTAINER_ID /bin/bash
}

upgrade() {
    DOCKER_FILE=$SRC_DIR/Dockerfile
    if [ ! -d "$SRC_DIR" ] || [ ! -f $DOCKER_FILE ]; then
        echo $DOCKER_FILE does not exist
        exit 1
    fi
    cd $SRC_DIR
    FROM_IMAGE=`cat Dockerfile | sed 's/^[ \t]*//g' | grep "FROM " | cut -d" " -f2`
    docker pull $FROM_IMAGE || exit 1

    ( cd cgi; bzr merge ) || exit 1

    echo Creating new image...
    docker build -t my-dudle . || exit 1

    backup

    echo Stopping and removing old container...
    docker stop $CONTAINER_ID || exit 1
    docker rm $CONTAINER_ID || exit 1

    echo Creating a new container...
    run
}

case "$1" in
    run)
        run
        ;;
    backup)
        get_existing
        backup
        ;;
    connect)
        get_existing
        connect
        ;;
    start)
	get_existing
        docker start $CONTAINER_ID
        ;;
    stop)
	get_existing
        docker stop $CONTAINER_ID
        ;;
    restart)
        get_existing
        docker stop $CONTAINER_ID || exit 1
        docker start $CONTAINER_ID<commit_msg>Fix upgrade via cron, indent cleanup<commit_after>#! /bin/sh

get_existing() {
    CONTAINER_ID=`docker ps -a --filter name=my-running-dudle --format "{{.ID}}"`

    if [ $? -ne 0 ] || [ "$CONTAINER_ID" == "" ]; then
        echo Dudle container not found $CONTAINER_ID
        exit 1
    fi
}

run() {
    docker run -d -v /srv/dudle/backup:/backup:Z -p 8888:80 --name my-running-dudle my-dudle || exit 1
}

backup() {
    echo Running backup for container $CONTAINER_ID

    docker exec $CONTAINER_ID /usr/local/bin/backup.sh || exit 1
}

connect() {
    echo Connecting to container $CONTAINER_ID

    docker exec -it $CONTAINER_ID /bin/bash
}

upgrade() {
    DOCKER_FILE=$SRC_DIR/Dockerfile
    if [ ! -d "$SRC_DIR" ] || [ ! -f $DOCKER_FILE ]; then
        echo $DOCKER_FILE does not exist
        exit 1
    fi
    cd $SRC_DIR
    FROM_IMAGE=`cat Dockerfile | sed 's/^[ \t]*//g' | grep "FROM " | cut -d" " -f2`
    docker pull $FROM_IMAGE || exit 1

    ( cd cgi; bzr merge ) || exit 1

    echo Creating new image...
    docker build -t my-dudle . || exit 1

    backup

    echo Stopping and removing old container...
    docker stop $CONTAINER_ID || exit 1
    docker rm $CONTAINER_ID || exit 1

    echo Creating a new container...
    run
}

case "$1" in
    run)
        run
        ;;
    backup)
        get_existing
        backup
        ;;
    connect)
        get_existing
        connect
        ;;
    start)
        get_existing
        docker start $CONTAINER_ID
        ;;
    stop)
        get_existing
        docker stop $CONTAINER_ID
        ;;
    restart)
        get_existing
        docker stop $CONTAINER_ID || exit 1
        docker start $CONTAINER_ID
{'fraction_non_alphanumeric': 0.11394302848575712, 'fraction_numerical': 0.011394302848575712, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 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': '5544884', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1126, 'n_words': 333}