comment lib/setup/* (#LLM assisted - Claude Code)

This commit is contained in:
Vincent Riquer 2026-03-13 17:52:26 +01:00
parent 3995e92323
commit 0f13154d6f
6 changed files with 107 additions and 1 deletions

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setupDestination() {
cat <<-EODesc cat <<-EODesc

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setupDestinations() {
cat <<-EODesc cat <<-EODesc

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setupGeneral() {
cat <<-EODesc cat <<-EODesc
@ -14,11 +27,14 @@ setupGeneral() {
1 minute load average between <load> and <load>+1 by adjusting 1 minute load average between <load> and <load>+1 by adjusting
concurrency. Initial concurrency will be set to half of that value. concurrency. Initial concurrency will be set to half of that value.
EODesc EODesc
# Check input is an integer
# Reused across multiple prompts in this function
expr='^[0-9]*$' expr='^[0-9]*$'
comeagain() { comeagain() {
read \ read \
-e \ -e \
-p'Target load: (integer) ' \ -p'Target load: (integer) ' \
# Pre-fill with the existing value when re-running setup
${maxload+-i"$maxload"} \ ${maxload+-i"$maxload"} \
value value
if [ -n "$value" ] && [[ $value =~ $expr ]] if [ -n "$value" ] && [[ $value =~ $expr ]]
@ -26,6 +42,7 @@ setupGeneral() {
maxload="$value" maxload="$value"
else else
echo "Invalid max-load value: $value" >&2 echo "Invalid max-load value: $value" >&2
# Recurse until we get a valid value
comeagain comeagain
fi fi
} }
@ -64,6 +81,7 @@ setupGeneral() {
read \ read \
-e \ -e \
-p'Ionice: <1-3> [0-7] ' \ -p'Ionice: <1-3> [0-7] ' \
# Default to class 3 (idle) when no prior value exists
-i"${class:-3} ${niceness}" \ -i"${class:-3} ${niceness}" \
class niceness class niceness
case $class in case $class in
@ -87,6 +105,7 @@ setupGeneral() {
fi fi
;; ;;
2) 2)
# Best-effort class; niceness 0-7 is mandatory
if [ -n "$niceness" ] \ if [ -n "$niceness" ] \
&& (( niceness >= 0 && niceness <= 7 )) && (( niceness >= 0 && niceness <= 7 ))
then then
@ -98,6 +117,7 @@ setupGeneral() {
fi fi
;; ;;
3) 3)
# Idle class; no niceness level is accepted
ionice="ionice -c3 " ionice="ionice -c3 "
;; ;;
*) *)
@ -115,6 +135,7 @@ setupGeneral() {
sqlite) and temporary WAVE files will be created. Note that debug logs sqlite) and temporary WAVE files will be created. Note that debug logs
(if enabled) will go there too. (if enabled) will go there too.
EODesc EODesc
# Tab-completion (-e) works here because readline is active
read \ read \
-e \ -e \
-i"${tempdir:-$HOME/.atom/tmp}" \ -i"${tempdir:-$HOME/.atom/tmp}" \

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setupRegen() {
(( regen )) && return 0 (( regen )) && return 0
echo "Parameter $1 for destination $destination changed." echo "Parameter $1 for destination $destination changed."

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setup() {
cat <<-EOStartConf cat <<-EOStartConf
You will now be asked (hopefully) simple questions to help you configure AtOM's 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. Completion is available for prompts asking for a paths or filenames.
EOStartConf EOStartConf
# Collect all configuration sections in order
setupGeneral setupGeneral
setupSource setupSource
setupDestinations setupDestinations
# Clear the regex used by validation loops inside setup sub-functions
unset expr unset expr
# Write the newly gathered config to a temp file so the original is
# preserved until the user confirms
writeConfig >"$cffile".tmp 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 \ unset \
sourcepath \ sourcepath \
skippeddirectories \ skippeddirectories \
@ -37,6 +56,8 @@ Completion is available for prompts asking for a paths or filenames.
destinationnoresample \ destinationnoresample \
destinationrenamepath \ destinationrenamepath \
destinationskipmime destinationskipmime
# Re-declare per-destination variables as associative arrays so
# getConfig can populate them with [destinationname]=value entries
declare -A \ declare -A \
destinationchannels \ destinationchannels \
destinationfat32compat \ destinationfat32compat \
@ -54,6 +75,8 @@ Completion is available for prompts asking for a paths or filenames.
destinationnoresample \ destinationnoresample \
destinationrenamepath \ destinationrenamepath \
destinationskipmime destinationskipmime
# Point getConfig at the temp file so the review reflects exactly what
# would be written, not the old on-disk config
oldcffile="$cffile" oldcffile="$cffile"
cffile="$cffile".tmp cffile="$cffile".tmp
getConfig getConfig
@ -61,6 +84,7 @@ Completion is available for prompts asking for a paths or filenames.
echo $'Please review your new configuration:\n' echo $'Please review your new configuration:\n'
printConfig printConfig
}| less -F -e }| less -F -e
# Restore the original config path before deciding whether to commit
cffile="$oldcffile" cffile="$oldcffile"
read -p'Write config file? [y/N] ' do_write read -p'Write config file? [y/N] ' do_write
case $do_write in case $do_write in

View File

@ -1,5 +1,18 @@
#!/bin/bash #!/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() { setupSource() {
cat <<-EODesc cat <<-EODesc
@ -18,6 +31,7 @@ setupSource() {
-i"${sourcepath:-/var/lib/mpd/music}" \ -i"${sourcepath:-/var/lib/mpd/music}" \
-p'Music collection (<TAB> for completion): ' \ -p'Music collection (<TAB> for completion): ' \
sourcepath sourcepath
# Reject paths that don't exist; AtOM doesn't create the source
if ! [ -d "$sourcepath" ] if ! [ -d "$sourcepath" ]
then then
echo "$sourcepath does not exist or is not a" \ echo "$sourcepath does not exist or is not a" \
@ -31,15 +45,20 @@ setupSource() {
Skip (path): Skip (path):
Files in these directories will be ignored. Files in these directories will be ignored.
Path is relative to $sourcepath. Path is relative to $sourcepath.
This prompt will loop until an empty string is encountered. This prompt will loop until an empty string is encountered.
EODesc EODesc
# Change into the source directory so readline tab-completion resolves
# relative paths correctly while the user types skip entries
cd "$sourcepath" 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[@]} count=${#skippeddirectories[@]}
for (( i=0 ; 1 ; i++ )) for (( i=0 ; 1 ; i++ ))
do do
read \ read \
-e \ -e \
# Pre-fill with the existing entry at this index, if any
${skippeddirectories[i]+-i"${skippeddirectories[i]}"}\ ${skippeddirectories[i]+-i"${skippeddirectories[i]}"}\
-p'Skip: ' \ -p'Skip: ' \
value value
@ -48,11 +67,14 @@ setupSource() {
skippeddirectories[i]="$value" skippeddirectories[i]="$value"
elif (( i < count )) elif (( i < count ))
then then
# Blank input on a previously set entry removes it
unset skippeddirectories[i] unset skippeddirectories[i]
else else
# Blank input beyond the old list signals end of input
break break
fi fi
done done
unset count unset count
# Return to the prior directory; output suppressed to keep the UI clean
cd - >/dev/null cd - >/dev/null
} }