From 2acc9755e06751b6a87e715e35561b093dbcb61c Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 16:15:36 +0300 Subject: [PATCH 1/7] Install the AWS CLI tool --- .config/setup/01-install-packages.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/setup/01-install-packages.sh b/.config/setup/01-install-packages.sh index 7159b5a..8a7568c 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 From 4645874c82b2a5c61c6dda9f6a4b23bfb61e1c61 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 22:30:24 +0300 Subject: [PATCH 2/7] Create a script to download the NASA Astronomy Picture of the Day --- .local/bin/get-nasa-apod | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 .local/bin/get-nasa-apod diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod new file mode 100755 index 0000000..08454e8 --- /dev/null +++ b/.local/bin/get-nasa-apod @@ -0,0 +1,34 @@ +#! /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}" + +curl \ + --location \ + --output "${outfile}" \ + --silent \ + "${picture_url}" +ln \ + --force \ + --symbolic \ + "${outfile}" \ + "${WALLPAPERS}/today.${extension}" +swaymsg reload From e68569bc81e57e7ac3faeba0a9dde262b323fb84 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 22:25:01 +0300 Subject: [PATCH 3/7] Ensure atomic write to the output file --- .local/bin/get-nasa-apod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index 08454e8..2f68b97 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -21,11 +21,13 @@ extension="${picture_url##*.}" filename="${picture_date}.${extension}" outfile="${WALLPAPERS}/${filename}" +tempfile="$(mktemp)" curl \ --location \ - --output "${outfile}" \ + --output "${tempfile}" \ --silent \ "${picture_url}" +mv "${tempfile}" "${outfile}" ln \ --force \ --symbolic \ From 1b03164a319ce5d183955532cfd63c396d51d73d Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 22:28:04 +0300 Subject: [PATCH 4/7] Skip downloading existing pictures --- .local/bin/get-nasa-apod | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index 2f68b97..e6560b9 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -21,6 +21,11 @@ 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 \ From f5eb2ff1ac168e71711e218d1900131a4d597af3 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 22:30:37 +0300 Subject: [PATCH 5/7] Create a daily job to download the NASA Astronomy Picture of the Day --- .config/systemd/user/get-nasa-apod.service | 10 ++++++++++ .config/systemd/user/get-nasa-apod.timer | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .config/systemd/user/get-nasa-apod.service create mode 100644 .config/systemd/user/get-nasa-apod.timer 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 From ae0fecf014e42d88885ae107153a8983ef1d9f63 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 25 Jun 2025 23:29:53 +0300 Subject: [PATCH 6/7] Elide the extension in the wallpapaer filename --- .local/bin/get-nasa-apod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index e6560b9..5e128b2 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -37,5 +37,5 @@ ln \ --force \ --symbolic \ "${outfile}" \ - "${WALLPAPERS}/today.${extension}" + "${WALLPAPERS}/today" swaymsg reload From a1aef0ef795f205b0a15fb73ec3fb2979a5e7613 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Thu, 26 Jun 2025 07:37:26 +0300 Subject: [PATCH 7/7] Install a linter for Go --- .config/setup/01-install-packages.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/setup/01-install-packages.sh b/.config/setup/01-install-packages.sh index 8a7568c..f8c15ee 100755 --- a/.config/setup/01-install-packages.sh +++ b/.config/setup/01-install-packages.sh @@ -28,6 +28,7 @@ DEB_PKGS=( fuzzel gdb gnumeric + go-staticcheck gopls graphviz grim