#!/bin/bash

# Featured feed for the MOTD tips (35-armbian-tips). Keep the cached copy
# unless the download is complete, valid JSON.
FEATURED=/var/lib/armbian/featured.json
mkdir -p "${FEATURED%/*}"
tmp=$(mktemp "${FEATURED}.XXXXXX") || exit 0
if curl --max-time 20 -L -s -f -o "${tmp}" "https://github.armbian.com/featured.json" \
	&& jq -e '.entries | length > 0' "${tmp}" > /dev/null 2>&1; then
	chmod 644 "${tmp}"
	mv -f "${tmp}" "${FEATURED}"
else
	rm -f "${tmp}"
fi
exit 0
