Compare commits

...

7 commits

4 changed files with 63 additions and 0 deletions

View file

@ -9,6 +9,7 @@ DEB_PKGS=(
alsa-utils alsa-utils
audacity audacity
avahi-daemon avahi-daemon
awscli
bluez bluez
borgbackup borgbackup
build-essential build-essential
@ -27,6 +28,7 @@ DEB_PKGS=(
fuzzel fuzzel
gdb gdb
gnumeric gnumeric
go-staticcheck
gopls gopls
graphviz graphviz
grim grim

View file

@ -0,0 +1,10 @@
[Unit]
Description=Refresh the wallpaper using the NASA Astronomy Picture of the Day
Wants=get-nasa-apod.timer
[Service]
WorkingDirectory=%h
ExecStart=%h/.local/bin/get-nasa-apod
[Install]
WantedBy=default.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Daily NASA wallpaper fetch
Requires=get-nasa-apod.service
[Timer]
Unit=nasa-apod.service
OnCalendar=daily
[Install]
WantedBy=timers.target

41
.local/bin/get-nasa-apod Executable file
View file

@ -0,0 +1,41 @@
#! /usr/bin/bash
set -euo pipefail
IFS=$'\n\t'
API_KEY="${NASA_API_KEY:-DEMO_KEY}"
if [ "${API_KEY}" = "DEMO_KEY" ]; then
echo "No API key set! using demo key."
fi
WALLPAPERS="$(systemd-path user)"/Wallpapers
mkdir --parents "${WALLPAPERS}"
APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}"
response="$(curl --silent "${APOD_URL}")"
picture_date="$(printf '%s' "${response}" | jq --raw-output .date)"
picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)"
extension="${picture_url##*.}"
filename="${picture_date}.${extension}"
outfile="${WALLPAPERS}/${filename}"
if [ -f "${outfile}" ]; then
echo "Target file already exists"
exit 0
fi
tempfile="$(mktemp)"
curl \
--location \
--output "${tempfile}" \
--silent \
"${picture_url}"
mv "${tempfile}" "${outfile}"
ln \
--force \
--symbolic \
"${outfile}" \
"${WALLPAPERS}/today"
swaymsg reload