From 9cde5ba27228a10df64402effd550f132d5108ae Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 17 Jun 2013 13:39:28 +0200 Subject: [PATCH] Setup * -S option * call setup when no conf file present * [general] setup --- atom | 41 +++++++--- lib/config/getConfig | 1 + lib/config/getConfigDestination | 2 +- lib/setup/setup | 15 ++++ lib/setup/setupGeneral | 132 ++++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 13 deletions(-) create mode 100644 lib/setup/setup create mode 100644 lib/setup/setupGeneral diff --git a/atom b/atom index a89f4ba..4844961 100755 --- a/atom +++ b/atom @@ -72,7 +72,7 @@ help() { #parse arguments OPTERR=0 -while getopts ':c:Cl:T:F:hD' opt +while getopts ':c:Cl:T:F:ShD' opt do case $opt in c) @@ -90,6 +90,9 @@ do F) forceall+=("$OPTARG") ;; + S) + forcesetup=1 + ;; h) help exit 0 @@ -110,24 +113,38 @@ do esac 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" ] then - if [ ! -d ~/.atom ] + if [ ! -d "${cffile%/*}" ] then - mkdir -p ~/.atom + mkdir -p "${cffile%/*}" fi - sed "s:%HOME%:$HOME:" "$exampleconf" > "$cffile" - cat >&2 <<-EOCfgNotice - 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 + echo "No configuration file found!" >&2 + askconf fi getConfig +(( forcesetup )) && setup + set +H # Apply CLI overrides diff --git a/lib/config/getConfig b/lib/config/getConfig index cbc9b5f..63e0e50 100644 --- a/lib/config/getConfig +++ b/lib/config/getConfig @@ -19,6 +19,7 @@ getConfig() { context=Destination destination="${key#[}" destination="${destination%]}" + destinations+=("${destination%]}") ;; *) getConfig$context diff --git a/lib/config/getConfigDestination b/lib/config/getConfigDestination index 8fa63c6..6620dff 100644 --- a/lib/config/getConfigDestination +++ b/lib/config/getConfigDestination @@ -19,7 +19,7 @@ getConfigDestination() { oggencneeded=1 ;; *) - echo "Unsupported destination format: $value" >2& + echo "Unsupported destination format: $value" >&2 exit $EFORMAT ;; esac diff --git a/lib/setup/setup b/lib/setup/setup new file mode 100644 index 0000000..c814d31 --- /dev/null +++ b/lib/setup/setup @@ -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 +} diff --git a/lib/setup/setupGeneral b/lib/setup/setupGeneral new file mode 100644 index 0000000..3d6d0c3 --- /dev/null +++ b/lib/setup/setupGeneral @@ -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 and +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 [niceness]: + IO-hungry processes will be run with ionice 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 ( for completion): '\ + tempdir + cat <<-EODesc + + Database (filename): + EODesc + read \ + -e \ + -i"${database:-$HOME/.atom/atom.db}" \ + -p'Database file ( for completion): ' \ + database +}