2024-01-27 17:24:14 -08:00
|
|
|
#!/usr/bin/bash
|
2024-01-28 21:20:02 -08:00
|
|
|
escape() {
|
|
|
|
sed 's/[&/\]/\\&/g' <<< "$1"
|
|
|
|
}
|
|
|
|
|
2024-01-28 19:42:03 -08:00
|
|
|
TIP_FILE=$(ls "/usr/share/ublue-os/motd/tips/"*".md" | shuf -n 1)
|
2024-01-27 17:24:14 -08:00
|
|
|
if [[ -f "$TIP_FILE" ]]; then
|
|
|
|
IMAGE_INFO="/usr/share/ublue-os/image-info.json"
|
|
|
|
IMAGE_NAME=$(jq -r '."image-name"' < $IMAGE_INFO)
|
2024-01-28 21:20:02 -08:00
|
|
|
IMAGE_NAME_ESCAPED=$(escape "$IMAGE_NAME")
|
2024-04-21 10:49:04 -07:00
|
|
|
IMAGE_BRANCH=$(jq -r '."image-branch"' < $IMAGE_INFO)
|
|
|
|
IMAGE_BRANCH_ESCAPED=$(escape "$IMAGE_BRANCH")
|
2024-01-30 15:52:03 -08:00
|
|
|
TIP=" $(shuf -n 1 "$TIP_FILE")"
|
|
|
|
|
|
|
|
IMAGE_DATE=$(rpm-ostree status --booted | sed -n 's/.*Timestamp: \(.*\)/\1/p')
|
|
|
|
IMAGE_DATE_SECONDS=$(date -d "$IMAGE_DATE" +%s)
|
|
|
|
CURRENT_SECONDS=$(date +%s)
|
|
|
|
DIFFERENCE=$((CURRENT_SECONDS - IMAGE_DATE_SECONDS))
|
|
|
|
MONTH=$((30 * 24 * 60 * 60))
|
|
|
|
if [ "$DIFFERENCE" -ge "$MONTH" ]; then
|
|
|
|
TIP='# Your current image is over 1 month old, run `ujust update`'
|
|
|
|
fi
|
|
|
|
|
2024-01-28 21:20:02 -08:00
|
|
|
TIP_ESCAPED=$(escape "$TIP")
|
2024-01-30 15:52:03 -08:00
|
|
|
|
2024-04-21 10:49:04 -07:00
|
|
|
sed -e "s/%IMAGE_NAME%/$IMAGE_NAME_ESCAPED/g" -e "s/%IMAGE_BRANCH%/$IMAGE_BRANCH_ESCAPED/g" -e "s/%TIP%/$TIP_ESCAPED/g" /usr/share/ublue-os/motd/bazzite.md | tr '~' '\n' | /usr/bin/glow -s auto -
|
2024-01-28 20:13:58 -08:00
|
|
|
fi
|