diff --git a/.config/setup/01-install-packages.sh b/.config/setup/01-install-packages.sh index 7159b5a..f8c15ee 100755 --- a/.config/setup/01-install-packages.sh +++ b/.config/setup/01-install-packages.sh @@ -9,6 +9,7 @@ DEB_PKGS=( alsa-utils audacity avahi-daemon + awscli bluez borgbackup build-essential @@ -27,6 +28,7 @@ DEB_PKGS=( fuzzel gdb gnumeric + go-staticcheck gopls graphviz grim diff --git a/.config/systemd/user/get-nasa-apod.service b/.config/systemd/user/get-nasa-apod.service new file mode 100644 index 0000000..1da3c26 --- /dev/null +++ b/.config/systemd/user/get-nasa-apod.service @@ -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 diff --git a/.config/systemd/user/get-nasa-apod.timer b/.config/systemd/user/get-nasa-apod.timer new file mode 100644 index 0000000..4cac963 --- /dev/null +++ b/.config/systemd/user/get-nasa-apod.timer @@ -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 diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod new file mode 100755 index 0000000..5e128b2 --- /dev/null +++ b/.local/bin/get-nasa-apod @@ -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