#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.

# DO NOT EDIT THIS FILE but add config options to /etc/default/armbian-motd
# any changes will be lost on board support package update

THIS_SCRIPT="tips"
MOTD_DISABLE=""

[[ -f /etc/default/armbian-motd ]] && . /etc/default/armbian-motd

for f in $MOTD_DISABLE; do
	[[ $f == $THIS_SCRIPT ]] && exit 0
done

quotes="/etc/update-motd.d/quotes.txt"
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)
	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
		printf "\e[0;90m Tips:\x1B[0m\n " #; printf '%.s─' $(seq 1 5); echo -e " \x1B[0m"
		echo -e "\n$SELECTED_QUOTE" | fold -w 79 -s | sed 's/^/ /'
		echo ""
	fi
fi
