Skip to content

Instantly share code, notes, and snippets.

@ArtBIT
Created April 29, 2023 07:04
Show Gist options
  • Save ArtBIT/364fd43a75d2ec38a09fb070d597bd71 to your computer and use it in GitHub Desktop.
Save ArtBIT/364fd43a75d2ec38a09fb070d597bd71 to your computer and use it in GitHub Desktop.

Revisions

  1. ArtBIT created this gist Apr 29, 2023.
    77 changes: 77 additions & 0 deletions kimai
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    #!/usr/bin/env bash

    # Bash Helper Script For Kimai Docker
    # https://www.kimai.org/documentation/docker.html

    kimai_install() {
    docker run --name kimai-mysql \
    -e MYSQL_DATABASE=kimai \
    -e MYSQL_USER=kimai \
    -e MYSQL_PASSWORD=kimai \
    -e MYSQL_ROOT_PASSWORD=kimai \
    -p 3399:3306 -d mysql

    docker run --name kimai \
    -tid \
    -p 8001:8001 \
    -e DATABASE_URL=mysql://kimai:kimai@${HOSTNAME}:3399/kimai \
    kimai/kimai2:apache

    docker exec -ti kimai \
    /opt/kimai/bin/console kimai:create-user artbit [email protected] ROLE_SUPER_ADMIN

    }

    kimai_uninstall() {
    docker rm kimai
    docker rm kimai-mysql
    }

    kimai_backup() {
    mysqldump -u kimai –p kimai -h 127.0.0.1 -P 3399 kimai > kimai.$(date +"%Y-%m-%dT%H:%M:%S").sql
    }

    kimai_check() {
    if docker container ls -a -f name=kimai | grep -q kimai; then
    # kimai docker exists
    return 0
    else
    # kimai docker does not exist
    return 1
    fi
    }
    kimai_start() {
    if ! kimai_check; then
    kimai_install
    fi
    docker start kimai-mysql kimai
    kimai_web
    }

    kimai_web() {
    xdg-open http://localhost:8001
    }
    kimai_stop() {
    docker stop kimai-mysql kimai
    }


    case "$1" in
    install)
    kimai_install
    ;;
    uninstall)
    kimai_uninstall
    ;;
    stop)
    kimai_stop
    ;;
    web)
    kimai_web
    ;;
    backup)
    kimai_backup
    ;;
    *)
    kimai_start
    esac