From 0f13154d6feba831cb67619ba1bb7daf595587b3 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Fri, 13 Mar 2026 17:52:26 +0100 Subject: [PATCH] comment lib/setup/* (#LLM assisted - Claude Code) --- lib/setup/destination | 13 +++++++++++++ lib/setup/destinations | 13 +++++++++++++ lib/setup/general | 21 +++++++++++++++++++++ lib/setup/regen | 13 +++++++++++++ lib/setup/setup | 24 ++++++++++++++++++++++++ lib/setup/source | 24 +++++++++++++++++++++++- 6 files changed, 107 insertions(+), 1 deletion(-) diff --git a/lib/setup/destination b/lib/setup/destination index 1885bfc..33ec03f 100644 --- a/lib/setup/destination +++ b/lib/setup/destination @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setupDestination() { cat <<-EODesc diff --git a/lib/setup/destinations b/lib/setup/destinations index 4e1c2b3..d225246 100644 --- a/lib/setup/destinations +++ b/lib/setup/destinations @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setupDestinations() { cat <<-EODesc diff --git a/lib/setup/general b/lib/setup/general index 3d6d0c3..c22c716 100644 --- a/lib/setup/general +++ b/lib/setup/general @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setupGeneral() { cat <<-EODesc @@ -14,11 +27,14 @@ setupGeneral() { 1 minute load average between and +1 by adjusting concurrency. Initial concurrency will be set to half of that value. EODesc + # Check input is an integer + # Reused across multiple prompts in this function expr='^[0-9]*$' comeagain() { read \ -e \ -p'Target load: (integer) ' \ + # Pre-fill with the existing value when re-running setup ${maxload+-i"$maxload"} \ value if [ -n "$value" ] && [[ $value =~ $expr ]] @@ -26,6 +42,7 @@ setupGeneral() { maxload="$value" else echo "Invalid max-load value: $value" >&2 + # Recurse until we get a valid value comeagain fi } @@ -64,6 +81,7 @@ setupGeneral() { read \ -e \ -p'Ionice: <1-3> [0-7] ' \ + # Default to class 3 (idle) when no prior value exists -i"${class:-3} ${niceness}" \ class niceness case $class in @@ -87,6 +105,7 @@ setupGeneral() { fi ;; 2) + # Best-effort class; niceness 0-7 is mandatory if [ -n "$niceness" ] \ && (( niceness >= 0 && niceness <= 7 )) then @@ -98,6 +117,7 @@ setupGeneral() { fi ;; 3) + # Idle class; no niceness level is accepted ionice="ionice -c3 " ;; *) @@ -115,6 +135,7 @@ setupGeneral() { sqlite) and temporary WAVE files will be created. Note that debug logs (if enabled) will go there too. EODesc + # Tab-completion (-e) works here because readline is active read \ -e \ -i"${tempdir:-$HOME/.atom/tmp}" \ diff --git a/lib/setup/regen b/lib/setup/regen index c6c9fe8..06106fb 100644 --- a/lib/setup/regen +++ b/lib/setup/regen @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setupRegen() { (( regen )) && return 0 echo "Parameter $1 for destination $destination changed." diff --git a/lib/setup/setup b/lib/setup/setup index f6f9f8c..391aebc 100644 --- a/lib/setup/setup +++ b/lib/setup/setup @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setup() { cat <<-EOStartConf You will now be asked (hopefully) simple questions to help you configure AtOM's @@ -7,11 +20,17 @@ behavior. Completion is available for prompts asking for a paths or filenames. EOStartConf + # Collect all configuration sections in order setupGeneral setupSource setupDestinations + # Clear the regex used by validation loops inside setup sub-functions unset expr + # Write the newly gathered config to a temp file so the original is + # preserved until the user confirms writeConfig >"$cffile".tmp + # Unset all config variables so getConfig can repopulate them cleanly + # from the temp file; avoids stale values leaking into the review unset \ sourcepath \ skippeddirectories \ @@ -37,6 +56,8 @@ Completion is available for prompts asking for a paths or filenames. destinationnoresample \ destinationrenamepath \ destinationskipmime + # Re-declare per-destination variables as associative arrays so + # getConfig can populate them with [destinationname]=value entries declare -A \ destinationchannels \ destinationfat32compat \ @@ -54,6 +75,8 @@ Completion is available for prompts asking for a paths or filenames. destinationnoresample \ destinationrenamepath \ destinationskipmime + # Point getConfig at the temp file so the review reflects exactly what + # would be written, not the old on-disk config oldcffile="$cffile" cffile="$cffile".tmp getConfig @@ -61,6 +84,7 @@ Completion is available for prompts asking for a paths or filenames. echo $'Please review your new configuration:\n' printConfig }| less -F -e + # Restore the original config path before deciding whether to commit cffile="$oldcffile" read -p'Write config file? [y/N] ' do_write case $do_write in diff --git a/lib/setup/source b/lib/setup/source index 03c2c5a..fd7bb95 100644 --- a/lib/setup/source +++ b/lib/setup/source @@ -1,5 +1,18 @@ #!/bin/bash +# Copyright © 2012-2026 ScriptFanix +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# A copy of the GNU General Public License v3 is includded in the LICENSE file +# at the root of the project. + setupSource() { cat <<-EODesc @@ -18,6 +31,7 @@ setupSource() { -i"${sourcepath:-/var/lib/mpd/music}" \ -p'Music collection ( for completion): ' \ sourcepath + # Reject paths that don't exist; AtOM doesn't create the source if ! [ -d "$sourcepath" ] then echo "$sourcepath does not exist or is not a" \ @@ -31,15 +45,20 @@ setupSource() { Skip (path): Files in these directories will be ignored. Path is relative to $sourcepath. - + This prompt will loop until an empty string is encountered. EODesc + # Change into the source directory so readline tab-completion resolves + # relative paths correctly while the user types skip entries cd "$sourcepath" + # Remember how many skip entries already exist so we know when to stop + # re-presenting existing entries vs. treating blanks as "done" count=${#skippeddirectories[@]} for (( i=0 ; 1 ; i++ )) do read \ -e \ + # Pre-fill with the existing entry at this index, if any ${skippeddirectories[i]+-i"${skippeddirectories[i]}"}\ -p'Skip: ' \ value @@ -48,11 +67,14 @@ setupSource() { skippeddirectories[i]="$value" elif (( i < count )) then + # Blank input on a previously set entry removes it unset skippeddirectories[i] else + # Blank input beyond the old list signals end of input break fi done unset count + # Return to the prior directory; output suppressed to keep the UI clean cd - >/dev/null }