X-Git-Url: https://git.grml.org/?p=grml-autoconfig.git;a=blobdiff_plain;f=autoconfig.functions;h=e659549e194b77c08ec70afcde932fbccfa959ad;hp=b7d694c0fe4b0c35238c62c0245059eec5fd8756;hb=HEAD;hpb=60157801aae38ff3348715f7a68d0e5ba6bfc2ba diff --git a/autoconfig.functions b/autoconfig.functions index b7d694c..3bab753 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -1412,7 +1412,7 @@ else else eindent einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0 - DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')" + DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2; exit }}')" if [ -n "$DCSDIR" ]; then ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0 else @@ -1633,75 +1633,6 @@ config_swraid(){ } # }}} -# {{{ dmraid -config_dmraid(){ - [ -n "$INSTALLED" ] && return 0 - - if checkbootparam 'nodmraid' ; then - ewarn "Skipping dmraid code as requested on boot commandline." ; eend 0 - return 0 - fi - - if ! [ -x /sbin/dmraid ] ; then - ewarn "dmraid not available, can not execute it." ; eend 1 - return - fi - - dmraid_wrapper() { - # usage: dmraid_wrapper - [ -n "$1" ] || return 1 - - IFSOLD=${IFS:-} - IFS=$'\n' - eindent - - for line in $(dmraid $1 ; echo errcode:$?); do - case $line in - *'no block devices found'*) - einfo "No block devices found" ; eend 0 - break - ;; - *'no raid disks'*) - einfo "No active dmraid devices found" ; eend 0 - break - ;; - errcode:0) - eend 0; - ;; - errcode:1) - eend 1 - ;; - *) - einfo "$line" - ;; - esac - done - - eoutdent - IFS=$IFSOLD - } - - if checkbootparam 'dmraid' ; then - local ACTION="$(getbootparam 'dmraid' 2>>$DEBUG)" - if [ "$ACTION" = "off" ] ; then - # Deactivates all active software RAID sets: - einfo "Deactivating present dmraid sets (as requested via dmraid=off):" - dmraid_wrapper -an - else - # Activate all software RAID sets discovered: - einfo "Activating present dmraid sets (as requested via dmraid):" - dmraid_wrapper -ay - fi - - return - fi - - # by default (no special bootoptions) discover all software RAID devices: - einfo "Searching for any present dmraid sets:" - dmraid_wrapper -r -} -# }}} - # {{{ LVM (Logical Volumes) config_lvm(){ [ -n "$INSTALLED" ] && return 0 @@ -1993,18 +1924,9 @@ fi # }}} # {{{ Easteregg (for 20 years grml.org) -config_easteregg() { - current_date=$(date +%Y-%m-%d) - birthday="2023-09-16" - one_month_later=$(date -d "${current_date} + 1 month" +%Y-%m-%d) - +display_easteregg() { einfo "You found the birthday easter egg!" ; eend 0 - # nothing to be done if it's more than one month since $birthday - if ! [[ "${current_date}" == "${birthday}" || "${current_date}" == "${one_month_later}" ]]; then - return 0 - fi - if [[ -x /bin/toilet && -x /usr/games/lolcat ]] ; then visualize() { printf "%s\n" "$*" | toilet | /usr/games/lolcat ; } elif [[ -x /bin/toilet ]] ; then @@ -2017,6 +1939,26 @@ config_easteregg() { visualize "20 years" visualize "grml.org" } + +config_easteregg() { + checkbootparam 'noeasteregg' && return 0 + + zmodload zsh/datetime 2>/dev/null || return 0 + zmodload zsh/mathfunc 2>/dev/null || return 0 + + local birthday=1694822400 # := 2023-09-16 -> TZ=UTC date -d "2023-09-16" +%s + local one_month=$[24*30*3600] + local pi=3.14159265358979323846 + local magic=$(( one_month/(pi/2) )) # normalization factor, used to map the [birthday;birthday+-one_month] range onto [0;+-pi/2] + + if [[ $(( abs(birthday-EPOCHSECONDS) )) -le $one_month ]] ; then + if [[ $(( rand48() )) -le $(( cos((birthday-EPOCHSECONDS)/magic) )) ]] ; then + display_easteregg + fi + fi + + return 0 +} # }}} ## END OF FILE #################################################################