#!/usr/bin/env bash # ARG_OPTIONAL_SINGLE([start],[s],[start time HH:mm]) # ARG_OPTIONAL_SINGLE([end],[e],[end time HH:mm])\ # ARG_OPTIONAL_SINGLE([rrule],[r],[rrule can be done via https://jakubroztocil.github.io/rrule/]) # ARG_OPTIONAL_SINGLE([loop],[l],[how many dates should be generated]) # ARG_HELP([Generate events based on rrule strings]) # ARGBASH_GO() # needed because of Argbash --> m4_ignore([ ### START OF CODE GENERATED BY Argbash v2.9.0 one line above ### # Argbash is a bash code generator used to get arguments parsing right. # Argbash is FREE SOFTWARE, see https://argbash.io for more info # Generated online by https://argbash.io/generate die() { local _ret="${2:-1}" test "${_PRINT_HELP:-no}" = yes && print_help >&2 echo "$1" >&2 exit "${_ret}" } begins_with_short_option() { local first_option all_short_options='serlh' first_option="${1:0:1}" test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 } # THE DEFAULTS INITIALIZATION - OPTIONALS _arg_start= _arg_end= _arg_rrule= _arg_loop= print_help() { printf '%s\n' "Generate events based on rrule strings" printf 'Usage: %s [-s|--start ] [-e|--end ] [-r|--rrule ] [-l|--loop ] [-h|--help]\n' "$0" printf '\t%s\n' "-s, --start: start time HH:mm (no default)" printf '\t%s\n' "-e, --end: end time HH:mm (no default)" printf '\t%s\n' "-r, --rrule: rrule can be done via https://jakubroztocil.github.io/rrule/ (no default)" printf '\t%s\n' "-l, --loop: how many dates should be generated (no default)" printf '\t%s\n' "-h, --help: Prints help" } parse_commandline() { while test $# -gt 0 do _key="$1" case "$_key" in -s|--start) test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 _arg_start="$2" shift ;; --start=*) _arg_start="${_key##--start=}" ;; -s*) _arg_start="${_key##-s}" ;; -e|--end) test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 _arg_end="$2" shift ;; --end=*) _arg_end="${_key##--end=}" ;; -e*) _arg_end="${_key##-e}" ;; -r|--rrule) test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 _arg_rrule="$2" shift ;; --rrule=*) _arg_rrule="${_key##--rrule=}" ;; -r*) _arg_rrule="${_key##-r}" ;; -l|--loop) test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 _arg_loop="$2" shift ;; --loop=*) _arg_loop="${_key##--loop=}" ;; -l*) _arg_loop="${_key##-l}" ;; -h|--help) print_help exit 0 ;; -h*) print_help exit 0 ;; *) _PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1 ;; esac shift done } parse_commandline "$@" # OTHER STUFF GENERATED BY Argbash ### END OF CODE GENERATED BY Argbash (sortof) ### ]) # [ <-- needed because of Argbash IFS=" " REPEAT=${_arg_loop:-10} START=${_arg_start:-00:00} END=${_arg_end:-12:00} STARTDATE="$(date -I)T${START}" DTSTART=$(date -u --date="${STARTDATE}" +"%Y%m%dT%H%M%SZ") RRULE=${_arg_rrule:-FREQ=MONTHLY;BYSETPOS=1;BYDAY=TH;INTERVAL=1} RRULE_CMD=rrule if ! command -v ${RRULE_CMD} &> /dev/null then cat < ${DATE} HQ, /proc, Zentralwerk, Riesaer Straße 32, 01127 Dresden https://codimd.c3d2.de/plenum-${DATEONLY} EOF done