Harden fix-genre, sync-bandcamp, upgrade-mp3-to-flac under strict mode (R1)

- fix-genre.sh: set -euo pipefail; guard the tag-remove metaflac calls and the
  'beet ls | head -5' verify (SIGPIPE) that would otherwise abort.
- sync-bandcamp.sh: set -euo pipefail; the destructive chain already used
  'if cmd; then..else WARN' (set -e exempt); guard the staging mv.
- upgrade-mp3-to-flac.sh: set -euo pipefail; capture sldl/replace-with-better
  exit codes without aborting (was 'cmd; RC=$?', which set -e breaks); read
  Soulseek creds from the first available .conf instead of a hardcoded y2k.conf,
  guarded; guard the xargs purge and a grep -c.
- pipeline-status.sh: deliberately kept at set -u (documented). It is read-only
  and assembles ~30 independent probes; set -e would abort the whole digest on
  one missing optional file, which is exactly how the 9am notification broke.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
andrew
2026-07-10 10:52:44 -06:00
parent 41ef26a40b
commit db13890fe1
4 changed files with 41 additions and 20 deletions
+9 -5
View File
@@ -18,7 +18,7 @@
# sudo fix-genre.sh "Aphex Twin" "IDM; Electronic; Ambient"
# sudo fix-genre.sh --dry "Mac DeMarco" "Indie; Indie Rock"
set -u
set -euo pipefail
DRY=0
if [[ "${1:-}" == "--dry" ]]; then
@@ -55,10 +55,12 @@ for cp in "${paths[@]}"; do
fi
case "${hp,,}" in
*.flac)
metaflac --remove-tag=GENRE "$hp" 2>/dev/null
# remove-tag returns non-zero when the tag isn't present; `|| true` so
# that expected case doesn't abort under set -e.
metaflac --remove-tag=GENRE "$hp" 2>/dev/null || true
metaflac --set-tag="GENRE=$GENRE" "$hp" 2>/dev/null && ok=$((ok + 1)) || fail=$((fail + 1))
metaflac --remove-tag=GENRE_LOCK "$hp" 2>/dev/null
metaflac --set-tag="GENRE_LOCK=1" "$hp" 2>/dev/null
metaflac --remove-tag=GENRE_LOCK "$hp" 2>/dev/null || true
metaflac --set-tag="GENRE_LOCK=1" "$hp" 2>/dev/null || true
;;
*.mp3)
# mid3v2 / id3v2 don't have a clean way to set TCON via plain id3v2 here,
@@ -115,7 +117,9 @@ beet update "artist:$ARTIST" 2>&1 | grep -E '^\s+[+-]' || true
# Verify
echo "[fix-genre] new state:"
beet ls -f ' $title — $genres' "artist:$ARTIST" | head -5
# `|| true`: head closes the pipe after 5 lines, so beet exits with SIGPIPE for
# any artist with more than 5 tracks; that's expected, not a failure.
beet ls -f ' $title — $genres' "artist:$ARTIST" | head -5 || true
remaining=$(beet ls "artist:$ARTIST" | wc -l)
shown=5
[[ "$remaining" -gt "$shown" ]] && echo " ...and $((remaining - shown)) more"