From 78913b6da37e0967fe9f165d5cf2c37ca54ffe38 Mon Sep 17 00:00:00 2001 From: Dimitri Enns Date: Mon, 16 Aug 2021 15:50:44 +0200 Subject: [PATCH 1/2] Init Commit --- officetime.sh | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/officetime.sh b/officetime.sh index 8b13789..eb3804e 100644 --- a/officetime.sh +++ b/officetime.sh @@ -1 +1,138 @@ +#! /bin/bash +PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin +APP="OfficeTime" +JOURNALDIR="$HOME/.work_journal" +HO_FILE="${JOURNALDIR}/home_office_days.csv" +OF_FILE="${JOURNALDIR}/office_days.csv" +PD_FILE="${JOURNALDIR}/phone_duty_days.csv" +SUM_FILE="${JOURNALDIR}/summary.csv" +LOCKFILE="${JOURNALDIR}/.lock.file" +T_HEADER="Datum,Uhrzeit,Arbeitsmodell" +DATE=$(date +"%d.%m.%Y") +TIME=$(date +"%H:%M") +function echox() { + echo "${APP} - $(date) - ${1}" +} + +if [[ ! $(which which) ]]; then + echox "Which is missing. Exiting here!" + exit 1; +fi + +if [[ ! $(which whiptail) ]]; then + echox "whiptail is missing. Exiting here!" + exit 1; +fi + + +function lockfile() { + PID="$$" + if [[ ! -f ${LOCKFILE} ]]; then + touch ${LOCKFILE} + echo "${PID}" > ${LOCKFILE} + else + LKFILEPID="$(cat ${LOCKFILE})" + if [[ -f ${LOCKFILE} && ! -d "/proc/${LKFILEPID}" ]]; then + rm -f ${LOCKFILE} + /bin/bash $(basename $0) && exit 0 + elif [[ ${LKFILEPID} != ${PID} && -d "/proc/${LKFILEPID}" ]]; then + echox "A process is already running. PID: ${LKFILEPID}" + exit 0 + fi + fi + if [[ $1 == "clear" ]]; then + if [[ -f ${LOCKFILE} ]]; then + rm -f ${LOCKFILE} + fi + fi +} + + +function init() { + if [[ ! -d ${JOURNALDIR} ]]; then + mkdir ${JOURNALDIR} + sleep 0.2 + if [[ ! -d ${JOURNALDIR} ]]; then + echox "Failed creating directory: ${JOURNALDIR}. Exiting here!" + exit 1 + fi + fi + if [[ ! -f ${SUM_FILE} ]]; then + touch ${SUM_FILE} + if [[ ! -f ${SUM_FILE} ]]; then + echox "Failed creating: ${SUM_FILE}. Exiting here!" + exit 1 + fi + echo "${T_HEADER}" > ${SUM_FILE} + fi + if [[ $1 == "file" ]]; then + TYPE=$2 + if [[ ! -f ${TYPE} ]]; then + touch ${TYPE} + if [[ ! -f ${TYPE} ]]; then + echox "Failed creating: ${TYPE}. Exiting here!" + exit 1 + fi + echo "${T_HEADER}" > ${TYPE} + fi + fi +} + +init +lockfile + +function write () { + declare -A T_ARR + T_ARR[HO]="HomeOffice" + T_ARR[OF]="Office" + T_ARR[PD]="Bereitschaft" + T_ARR[PV]="Privat" + + init file ${2} + if [[ -f ${2} && -f ${SUM_FILE} ]]; then + echo "${DATE},${TIME},${T_ARR[$1]}" >> ${2} + echo "${DATE},${TIME},${T_ARR[$1]}" >> ${SUM_FILE} + else + echox "Cant write to ${2}. File does not exist!" + fi + lockfile clear +} + +CHOICES=$(whiptail --menu "Wähle dein Arbeitsmodell!" 18 100 10 \ + "1" "HomeOffice" \ + "2" "Büro" \ + "3" "Bereitschaft" \ + "4" "Privat" 3>&1 1>&2 2>&3) + + +if [ -z "$CHOICES" ]; then + lockfile clear + exit 0 +else + for CHOICE in $CHOICES; do + case "$CHOICE" in + "1") + FILE=${HO_FILE} + write HO ${FILE} + ;; + "2") + FILE=${OF_FILE} + write OF ${FILE} + ;; + "3") + FILE=${PD_FILE} + write PD ${FILE} + ;; + "4") + echox "Alles klar !" + lockfile clear + exit 0 + ;; + *) + echo "$CHOICE Kann hier nicht verwendet werden!" >&2 + exit 1 + ;; + esac + done +fi -- GitLab From 438d42ecc4862c50b5744ffb632d9b89e892263f Mon Sep 17 00:00:00 2001 From: Dimitri Enns Date: Mon, 16 Aug 2021 18:25:41 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 721bead..4411d8f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # OfficeTime +Just a pretty trivial script to help you track whether you are one phone duty, in home office, in the office or just doing private things on your work computer / laptop. + +Setup this cronjob to remind you one everyday at 10:30. In case things are changing more often in your shift, just let the Cron run more often. +Please make sure you adjust the paths to your terminal application and the path the script. +```bash +30 10 * * * env DISPLAY=:0.0 /usr/bin/terminator --title="OfficeTime" -e "/bin/bash ~/officetime.sh" +``` + +The script just takes your input and writes it into a .csv file so that you have some sort of a journal / report at the end of the year. +See the `~/.work_journal/` Directory for the files. -- GitLab