* -S option
	* call setup when no conf file present
	* [general] setup
This commit is contained in:
Vincent Riquer 2013-06-17 13:39:28 +02:00
parent 9bb66ba76c
commit 9cde5ba272
5 changed files with 178 additions and 13 deletions

41
atom
View File

@ -72,7 +72,7 @@ help() {
#parse arguments #parse arguments
OPTERR=0 OPTERR=0
while getopts ':c:Cl:T:F:hD' opt while getopts ':c:Cl:T:F:ShD' opt
do do
case $opt in case $opt in
c) c)
@ -90,6 +90,9 @@ do
F) F)
forceall+=("$OPTARG") forceall+=("$OPTARG")
;; ;;
S)
forcesetup=1
;;
h) h)
help help
exit 0 exit 0
@ -110,24 +113,38 @@ do
esac esac
done done
askconf() {
read -p"Create one now? [Y/n/q] " createconf
case $createconf in
''|[yY])
setup
;;
[nNqQ])
echo "You need a configuration file. If you" \
"want to create it yourself, please" \
"read doc/config and doc/example.cfg." >&2
exit $ENOCFG
;;
*)
echo "Come again?" >&2
askconf
;;
esac
}
if [ ! -f "$cffile" ] if [ ! -f "$cffile" ]
then then
if [ ! -d ~/.atom ] if [ ! -d "${cffile%/*}" ]
then then
mkdir -p ~/.atom mkdir -p "${cffile%/*}"
fi fi
sed "s:%HOME%:$HOME:" "$exampleconf" > "$cffile" echo "No configuration file found!" >&2
cat >&2 <<-EOCfgNotice askconf
No configuration file found!
An example file has been created as "${cffile/$HOME/~}".
You should change it to your likings using you favorite editor.
Bailing out.
EOCfgNotice
exit $ENOCFG
fi fi
getConfig getConfig
(( forcesetup )) && setup
set +H set +H
# Apply CLI overrides # Apply CLI overrides

View File

@ -19,6 +19,7 @@ getConfig() {
context=Destination context=Destination
destination="${key#[}" destination="${key#[}"
destination="${destination%]}" destination="${destination%]}"
destinations+=("${destination%]}")
;; ;;
*) *)
getConfig$context getConfig$context

View File

@ -19,7 +19,7 @@ getConfigDestination() {
oggencneeded=1 oggencneeded=1
;; ;;
*) *)
echo "Unsupported destination format: $value" >2& echo "Unsupported destination format: $value" >&2
exit $EFORMAT exit $EFORMAT
;; ;;
esac esac

15
lib/setup/setup Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
setup() {
cat <<-EOStartConf
You will now be asked (hopefully) simple questions to help you configure AtOM's
behavior.
Completion is available for prompts asking for a paths or filenames.
EOStartConf
setupGeneral
setupSource
setupDestinations
unset expr
exit
}

132
lib/setup/setupGeneral Normal file
View File

@ -0,0 +1,132 @@
#!/bin/bash
setupGeneral() {
cat <<-EODesc
[General]
We will start by setting the general parameters defining the program's
behavior.
EODesc
cat <<-EODesc
Target load (integer):
Defines how parallel processing will behave. AtOM will try to keep the
1 minute load average between <load> and <load>+1 by adjusting
concurrency. Initial concurrency will be set to half of that value.
EODesc
expr='^[0-9]*$'
comeagain() {
read \
-e \
-p'Target load: (integer) ' \
${maxload+-i"$maxload"} \
value
if [ -n "$value" ] && [[ $value =~ $expr ]]
then
maxload="$value"
else
echo "Invalid max-load value: $value" >&2
comeagain
fi
}
comeagain
cat <<-EODesc
Load interval (seconds, integer):
How often should we check the load average and adjust concurrency. Set
this too low, and concurrency may be increased too quickly. Set this
too high, and AtOM will not adapt quickly enough to load increase. In
both cases, your hard drive will suffer. In my experience, 30 seconds
is a good value.
EODesc
comeagain() {
read \
-e \
-p'Load interval: (integer) ' \
-i${loadinterval:-30} \
value
if [[ $value =~ $expr ]]
then
loadinterval="$value"
else
echo "Invalid load-interval value: $value" >&2
comeagain
fi
}
comeagain
cat <<-EODesc
Ionice <class> [niceness]:
IO-hungry processes will be run with ionice class <class> and niceness
[niceness] (if applicable). See man ionice for details.
EODesc
comeagain() {
read \
-e \
-p'Ionice: <1-3> [0-7] ' \
-i"${class:-3} ${niceness}" \
class niceness
case $class in
1)
# real-time class, only root can do that
if (( UID ))
then
echo "IO class 'realtime' is"\
"not available to unprivileged"\
"users" >&2
comeagain
fi
if [ -n "$niceness" ] \
&& (( niceness >= 0 && niceness <= 7 ))
then
ionice="ionice -c1 -n$niceness "
else
echo "Invalid IO priority"\
"'$niceness'" >&2
comeagain
fi
;;
2)
if [ -n "$niceness" ] \
&& (( niceness >= 0 && niceness <= 7 ))
then
ionice="ionice -c2 -n$niceness "
else
echo "Invalid IO priority"\
"'$niceness'" >&2
comeagain
fi
;;
3)
ionice="ionice -c3 "
;;
*)
echo "Invalid ionice parameters $value"\
>&2
comeagain
;;
esac
}
comeagain
cat <<-EODesc
Temporary Directory (path):
Name speaks for itself: this is where FIFOs (for communicating with
sqlite) and temporary WAVE files will be created. Note that debug logs
(if enabled) will go there too.
EODesc
read \
-e \
-i"${tempdir:-$HOME/.atom/tmp}" \
-p'Temporary directory (<TAB> for completion): '\
tempdir
cat <<-EODesc
Database (filename):
EODesc
read \
-e \
-i"${database:-$HOME/.atom/atom.db}" \
-p'Database file (<TAB> for completion): ' \
database
}