From 8e63bbe7dff00d06004ae2cc2aca303908e3b872 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Fri, 19 Mar 2021 01:32:59 +0100 Subject: [PATCH] Sequencer new option to open sequence config file when initialised using initSeqConfig Sequences with exit in step_config, changed to return to support opening config file on first run --- seqs/aria2.sh | 2 +- seqs/debianrpi.sh | 6 +++--- seqs/ebackup.sh | 20 +++++++------------- seqs/kodi.sh | 2 +- seqs/librenms.sh | 2 +- seqs/mailserver.sh | 2 +- seqs/matrix.sh | 4 ++-- seqs/piwigo.sh | 2 +- seqs/torrentwatch.sh | 2 +- sequencer/sequencer.sh | 29 +++++++++++++++++++++++------ 10 files changed, 41 insertions(+), 30 deletions(-) diff --git a/seqs/aria2.sh b/seqs/aria2.sh index 5a3c6ba..8008005 100755 --- a/seqs/aria2.sh +++ b/seqs/aria2.sh @@ -27,7 +27,7 @@ step_config() { CONFIG=1 else # End if no configuration file exists - [ $DRY -eq 0 ] && exit 1 + [ $DRY -eq 0 ] && return 1 fi [ $QUIET -ne 0 ] && aptOpt="-y" } diff --git a/seqs/debianrpi.sh b/seqs/debianrpi.sh index d693d17..832b1e6 100755 --- a/seqs/debianrpi.sh +++ b/seqs/debianrpi.sh @@ -50,7 +50,7 @@ step_1() { toolDownUrl="$1" else echoerr " [E] No image file provided for download" - exit -1 + exit 1 fi toolDownFile="/tmp/${toolDownUrl//*\//}" @@ -129,7 +129,7 @@ step_10_alias() { ALIAS="setup"; } step_10() { if [ -z "$(ls /etc/default | grep raspi)" ] ; then echoerr " [E] Not on a Raspberry pi" - return -1 + return 1 fi exe apt update @@ -143,7 +143,7 @@ step_11() { local localUsDefault="$localUs UTF-8" if [ ! -f "$localesConfigLoc" ] ; then echoerr " [E] Install packages locales first" - exit -1 + exit 1 fi exe sed -i "s/#[[:space:]]*\($localUsDefault\)/\1/" "$localesConfigLoc" diff --git a/seqs/ebackup.sh b/seqs/ebackup.sh index 4b37728..daf5937 100755 --- a/seqs/ebackup.sh +++ b/seqs/ebackup.sh @@ -20,7 +20,7 @@ step_config() { if [ $? -eq 0 ] ; then CONFIG=1 else - exit 1 + [ $DRY -eq 0 ] && return 1 fi toolSyslogTag="${SCRIPT_NAME}-$SEQ_PROFILE_NAME" } @@ -56,14 +56,14 @@ step_1() { if [ -z $EBU_TARGET ] || [ -z $EBU_SOURCE ] ; then echo " [I] Nothing to do. Check $SEQ_CONFIG_FILE" - return -1 + return 1 fi if [ ! -z "$1" ] && ( [ "$1" == "full" ] || [ "$1" == "incremental" ] ) ; then dupArgs+=("$1") elif [ ! -z "$1" ] ; then echo " [W] $toolName command \"$1\" not recognized" - return -1 + return 1 fi echo " [I] Running backup profile [$SEQ_PROFILE_NAME]" @@ -95,7 +95,7 @@ step_3() { if [ -z $EBU_TARGET ] || [ -z $EBU_SOURCE ] ; then echo " [I] Nothing to do. Check $SEQ_CONFIG_FILE" - return -1 + return 1 fi checkInstalled @@ -135,7 +135,7 @@ step_5() { if [ -z "$1" ] ; then echoerr " [E] No target provided" - return -1 + return 1 fi local ebuLocalTarget="$1" local ebuTarget="$EBU_TARGET" @@ -167,7 +167,7 @@ step_7() { dupCommand+="remove-all-inc-of-but-n-full $EBU_MAX_FULLS_WITH_INCRS " else if [ $QUIET -eq 0 ] ; then echoerr " [W] No purge option configured" ; fi - return -1 + return 1 fi checkInstalled @@ -264,12 +264,6 @@ step_72() { done } -step_74_info() { echo "Open configuration file"; } -step_74_alias() { ALIAS='config'; } -step_74() { - exe vi "$SEQ_CONFIG_FILE" -} - step_100_info() { echo "Install $toolName $toolPpa"; } step_100_alias() { ALIAS="install"; } step_100() { @@ -296,7 +290,7 @@ checkFileHead() { local readChar if [ ! -e "$1" ] ; then echoerr " [E] File $1 not found" - return -1 + return 1 fi read -r -n ${#2} readChar < "$1" if [ "$readChar" == "$2" ] ; then diff --git a/seqs/kodi.sh b/seqs/kodi.sh index 6d91f85..286c33f 100755 --- a/seqs/kodi.sh +++ b/seqs/kodi.sh @@ -142,7 +142,7 @@ done" step_11_info() { echo "Create systemd service for logging to syslog"; } step_11() { - [ ! -f "$kodiSyslogLoc" ] && return -1 + [ ! -f "$kodiSyslogLoc" ] && return 1 addConf -s "$kodiSyslogService" "$kodiSyslogServiceLoc" diff --git a/seqs/librenms.sh b/seqs/librenms.sh index ea66feb..88fa8ed 100755 --- a/seqs/librenms.sh +++ b/seqs/librenms.sh @@ -30,7 +30,7 @@ step_config() { echoseq " Install: $LNMS_DIR" echoseq " Backup: $LNMS_BU_DIR" else - [ $DRY -eq 0 ] && exit 1 + [ $DRY -eq 0 ] && return 1 fi } diff --git a/seqs/mailserver.sh b/seqs/mailserver.sh index 384a96c..8ca8a2c 100755 --- a/seqs/mailserver.sh +++ b/seqs/mailserver.sh @@ -34,7 +34,7 @@ step_config() { echo " Domain: $MAS_DOMAIN" elif [ $? -eq 1 ] ; then # Config $CONFIG_FILE_NAME created. Needs modification first - exit 1 + [ $DRY -eq 0 ] && return 1 fi } diff --git a/seqs/matrix.sh b/seqs/matrix.sh index ebf9ded..f0a9571 100755 --- a/seqs/matrix.sh +++ b/seqs/matrix.sh @@ -542,8 +542,8 @@ toolScript() { adminTokenCheck() { if [ -z "$MATRIX_ACCESS" ] ; then [ $QUIET -eq 0 ] && read -s -p "Please enter admin access tocken: " MATRIX_ACCESS - # return -1 if it is still empty - [ -z "$MATRIX_ACCESS" ] && return -1 + # return 1 if it is still empty + [ -z "$MATRIX_ACCESS" ] && return 1 fi return 0 } diff --git a/seqs/piwigo.sh b/seqs/piwigo.sh index 9691770..c43b894 100755 --- a/seqs/piwigo.sh +++ b/seqs/piwigo.sh @@ -20,7 +20,7 @@ step_config() { if [ $? -eq 0 ] ; then CONFIG=1 else - exit 1 + [ $DRY -eq 0 ] && return 1 fi } diff --git a/seqs/torrentwatch.sh b/seqs/torrentwatch.sh index ab5c247..1b4a362 100755 --- a/seqs/torrentwatch.sh +++ b/seqs/torrentwatch.sh @@ -23,7 +23,7 @@ step_config() { if [ $? -eq 0 ] ; then CONFIG=1 else - exit 1 + [ $DRY -eq 0 ] && return 1 fi toolConfigLoc=`eval echo "$TWXA_CONFIG_LOC"` toolConfig="$toolConfigLoc/config_cache/$toolConfigName" diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 4d516a7..e75e3db 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -8,7 +8,7 @@ ## Version information VERSION_REV=12 -VERSION_MAJOR=1 +VERSION_MAJOR=2 VERSION_MINOR=0 ## Start of generic script part @@ -24,6 +24,7 @@ STEP_RETURN=255 MAX_STEP=512 ALIAS= CONTEXT_HELP=0 +SEQ_CONFIG_EDIT=0 SEQ_CONFIG_NAME=".seqs" SEQ_CONFIG_HOME="$HOME/$SEQ_CONFIG_NAME" SEQ_CONFIG_FILE= @@ -56,6 +57,7 @@ helpSequencer() { Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS] [OPTIONS] + --config, -c : Open sequence configuration file (also sets -qq) --dry-run, -d : Only print to console what would be done ! Attention - Sequence must support this --help, -h : Display help @@ -449,8 +451,8 @@ initSeqConfig() { # Create config subdir in users home if [ ! -e "$configDir/" ] ; then - echo -n " [I] Creating $(realpath $configDir)..." - exe mkdir -p "$configDir" && echo "Ok" || echo "Nok" + echoseq -n " [I] Creating $(realpath $configDir)..." + exe mkdir -p "$configDir" && echoseq "Ok" || echoseq "Nok" exe chmod 700 "$configDir" fi @@ -483,8 +485,11 @@ initSeqConfig() { exe chmod 600 "$configLoc" if [ $sourceAlways -eq 0 ] ; then - echoerr " [W] Seq configuration created from template but not used" - echoerr " Please modify "$configLoc" first and restart sequence" + if [ $SEQ_CONFIG_EDIT -eq 0 ] ; then + echoerr " [W] Seq configuration created from template but not used" + echoerr " Please modify "$configLoc" first and restart sequence" + fi + SEQ_CONFIG_FILE="$configLoc" return 1 else echo " [W] Using seq configuration from template $configTemplate" @@ -821,7 +826,7 @@ step_config() { # CONFIG=1 #else # # End if no configuration file exists - # [ \$DRY -eq 0 ] && exit 1 + # [ \$DRY -eq 0 ] && return -1 #fi } @@ -1003,6 +1008,11 @@ main() { # options check for arg in "$@" ; do case "$1" in + --config|-c) # open sequence configuration file + QUIET=2 + SEQ_CONFIG_EDIT=1 + shift + ;; --dry-run|-d) # shows what would be done DRY=1 SEQUENCER_ARGS+=" $1" @@ -1091,10 +1101,17 @@ main() { # run configuration for seq only if available and if first step is valid existsFunction step_config if [ $? -eq 0 ] ; then + if [ $SEQ_CONFIG_EDIT -ne 0 ] ; then + step_config "${STEP_ARGS[@]}" + [ -w "$SEQ_CONFIG_FILE" ] && vi "$SEQ_CONFIG_FILE" \ + || echoerr " [E] No configuration file available" + exit 0 + fi checkStep "${START[0]}" if [ $? -ne 0 ] ; then if [ $QUIET -ne 2 ] ; then echo " [I] Configuring sequence (step_config) ..." ; fi step_config "${STEP_ARGS[@]}" + [ $? -ne 0 ] && exit 1 else return 1 fi