From 5888bc97042da95c155ab437f8ef86a07f9ab41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Pe=C4=8Dovnik?= Date: Mon, 14 Nov 2022 14:59:58 +0100 Subject: [PATCH] Enable additional motd tips showing some internal ads (#4396) * Enable additional motd tips showing some internal ads 33% probability of showing, just like for the armbian-config * Update quotes and add expiration date support * Change variable names * Add support to download quotes from our server * Fix curl parameters * Keep only weekly update --- packages/bsp/common/etc/cron.weekly/armbian-quotes | 3 +++ packages/bsp/common/etc/update-motd.d/35-armbian-tips | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100755 packages/bsp/common/etc/cron.weekly/armbian-quotes diff --git a/packages/bsp/common/etc/cron.weekly/armbian-quotes b/packages/bsp/common/etc/cron.weekly/armbian-quotes new file mode 100755 index 000000000..f02f01a85 --- /dev/null +++ b/packages/bsp/common/etc/cron.weekly/armbian-quotes @@ -0,0 +1,3 @@ +#!/bin/bash + +curl -s -o "/etc/update-motd.d/quotes.txt" "https://dl.armbian.com/quotes.txt" diff --git a/packages/bsp/common/etc/update-motd.d/35-armbian-tips b/packages/bsp/common/etc/update-motd.d/35-armbian-tips index 3643f97ad..0b54c9c3f 100755 --- a/packages/bsp/common/etc/update-motd.d/35-armbian-tips +++ b/packages/bsp/common/etc/update-motd.d/35-armbian-tips @@ -19,8 +19,12 @@ for f in $MOTD_DISABLE; do done quotes="/etc/update-motd.d/quotes.txt" -if [[ -f $quotes ]]; then +if [[ -f $quotes && $(( $RANDOM % 1 )) == 0 ]]; then random_line=$(shuf -i 1-$(wc -l < $quotes) -n 1) quote=$(sed -n -e "$random_line"p $quotes) - [[ -n $quote ]] && echo -e "\e[93mTip of the day:\e[39m $quote\n" + DUE_DATE=$(echo $quote | cut -d"|" -f1) + SELECTED_QUOTE=$(echo $quote | cut -d"|" -f2) + if [[ -n $SELECTED_QUOTE && $(date +'%Y-%m-%d') < $(date -d $DUE_DATE +"%Y-%m-%d") ]]; then + echo -e "\e[93mTip of the day:\e[39m $SELECTED_QUOTE\n" + fi fi