From b894a756ea0d4d96eba585a63c5f2eca4d0f7dbf Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Mon, 7 Mar 2022 00:15:27 +0100 Subject: [PATCH] Support installation to different directoy Introduce configuration file to set a custom seqs collection --- README.md | 27 ++++++++++++++++++++- install.sh | 53 +++++++++++++++++++++++++++++++----------- installCompletion.sh | 8 ++++--- sequencer.cfg.dist | 5 ++++ sqnall-completion.bash | 12 +++++++++- 5 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 sequencer.cfg.dist diff --git a/README.md b/README.md index 7c53f07..4950505 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,16 @@ ln -s /opt/sequencer/seqs /opt ``` or -use the simple bash installation script in the repository: +use the simple bash installation script in the repository which installs git and performs the steps above: ``` curl -L https://winklerfamilie.eu/git/efelon/shell_sequencer/raw/branch/master/install.sh | bash ``` +You may override the default installation path `/opt/sequencer` by appending `-s /custom/path` to the command above: + +e.g. `curl -L https://winklerfamilie.eu/git/efelon/shell_sequencer/raw/branch/master/install.sh | bash -s /usr/lib/sequencer` + ## Bash-completion The included optional bash-completion script `sqnall-completion.bash` provides aliases to all available sequences as well as completion for sequencer.sh options and steps (including aliases) individually for each sequence. The aliases have the prefix `sqn_` which stands for _sequence name_. @@ -50,6 +54,19 @@ source /opt/sequencer/sqnall-completion.bash e.g. `/opt/sequencer/seqs/kodi.sh` can be started anyhere with `sqn_kodi` +### Custom sequence directory + +To control which seqs are available for bash-completion, copy `sequencer.cfg.dist` to `sequencer.cfg` and adjust the value of the variable `SEQUENCER_USER_SEQS`. + +To make these changes active run the following commands. You don't need the last step if you already used `installCompletion.sh`. + +``` +unalias -a +source ~/.bashrc +source /opt/sequencer/sqnall-completion.bash +``` + +or simply logout from the current session and login again. ### Automatic setup after login @@ -60,3 +77,11 @@ source /opt/sequencer/installCompletion.sh ``` This sources the bash-completion script in the users .bashrc file. + +## Default text editor + +Sequencer uses the Debian alternatives system to the select which editor to use. To change the default editor, which by default is most likely _nano_: + +``` +update-alternatives --config editor +``` diff --git a/install.sh b/install.sh index bdbe078..c5ad5bc 100755 --- a/install.sh +++ b/install.sh @@ -1,19 +1,42 @@ #!/bin/bash -SEQLOC="/opt" -SEQHOME="${SEQLOC}/sequencer" SEQGITURL="https://winklerfamilie.eu/git/efelon/shell_sequencer.git" +SEQUENCER_DIR= -if [ -d "$SEQHOME" ]; then - echo " [E] Sequencer seems to be installed already at:" - echo " $SEQHOME" +# Get script working directory +WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" + +SEQUENCER_DIR="$1" + +# Installation directory was not set by argument -d +if [ -z "$SEQUENCER_DIR" ]; then + # Fallback to working directory + if [ $? -ne 0 ]; then + SEQUENCER_DIR="${WDIR}" + fi +fi + +echo $SEQUENCER_DIR +exit 0 + +# If available use configuration +. ${WDIR}/sequencer.cfg &>/dev/null + +# Set to default if not configured +[ -z "$SEQUENCER_USER_SEQS" ] && SEQUENCER_USER_SEQS="/opt/seqs" + +# Check if already installed +if [ -d "$SEQUENCER_DIR" ]; then + echo " [E] Sequencer seems to be already installed at:" + echo " $SEQUENCER_DIR" exit 1 fi -if [ ! -w "$SEQLOC" ]; then - echo " [E] Your user has no permission to write to $SEQLOC" +if [ ! -w "$(dirname $SEQUENCER_DIR)" ]; then + echo " [E] Your user has no permission to write to $(dirname $SEQUENCER_DIR)" exit 2 fi +# Install git if neccessary which git >>/dev/null 2>&1 if [ $? != 0 ]; then echo " [W] Git not found and will be installed" @@ -24,19 +47,23 @@ if [ $? != 0 ]; then apt install git -y if [ $? != 0 ]; then echo " [E] Cannot install git via apt" - exit 4 + exit 3 fi fi -git clone $SEQGITURL "$SEQHOME" -if [ $? != 0 ]; then +# Clone sequncer to target directory +git clone $SEQGITURL "$SEQUENCER_DIR" +if [ $? -ne 0 ]; then echo " [E] Error cloning git repository:" echo " $SEQGITURL" - exit 6 + exit 4 fi -ln -s "${SEQHOME}/sequencer/sequencer.sh" "/usr/local/bin" -ln -s "${SEQHOME}/seqs" "/opt" +# Install sequncer script +ln -s "${SEQUENCER_DIR}/sequencer/sequencer.sh" "/usr/local/bin" +if [ "$SEQUENCER_USER_SEQS" != "$SEQUENCER_DIR/seqs" ]; then + ln -s "${SEQUENCER_DIR}/seqs" "${SEQUENCER_USER_SEQS}" +fi echo " [I] Successfully installed shell sequencer" echo " Don't forget to set git user variables:" diff --git a/installCompletion.sh b/installCompletion.sh index e5b5ed5..2572c5f 100755 --- a/installCompletion.sh +++ b/installCompletion.sh @@ -1,9 +1,11 @@ #!/bin/bash +# Get script working directory +WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" + _sequencerCompletion() { - local SEQBASE="/opt/sequencer" - local SEQCOMP_LOC="$SEQBASE/sqnall-completion.bash" - local SEQCOMP_LOADER="$(realpath ~/.bashrc)" + local SEQCOMP_LOC="${WDIR}/sqnall-completion.bash" + local SEQCOMP_LOADER="$HOME/.bashrc)" local SEQCOMP_SOURCE="source \"$SEQCOMP_LOC\"" grep "$SEQCOMP_SOURCE" "$SEQCOMP_LOADER" >>/dev/null 2>&1 diff --git a/sequencer.cfg.dist b/sequencer.cfg.dist new file mode 100644 index 0000000..ffbe7b7 --- /dev/null +++ b/sequencer.cfg.dist @@ -0,0 +1,5 @@ +#!/bin/bash + +## Bash completion ## +# Where uses store own seqs or selected distribution selected seqs +SEQUENCER_USER_SEQS="/opt/seqs" diff --git a/sqnall-completion.bash b/sqnall-completion.bash index 9f8f5d3..f78d9c4 100755 --- a/sqnall-completion.bash +++ b/sqnall-completion.bash @@ -36,9 +36,19 @@ _sqnall_completions() } installCompletion() { - local SEQBASE="/opt/sequencer/seqs" + # Get script working directory + # (when called from a different directory) + local WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" + + . ${WDIR}/sequencer.cfg &>/dev/null + + local SEQBASE="${WDIR}/seqs" local SEQPREFIX="sqn_" local SEQSHORT=() + + # Check for user selected sequences + [ -e "$SEQUENCER_USER_SEQS" ] && SEQBASE="$SEQUENCER_USER_SEQS" + # Create aliases and command (alias) list for "complete" command" SEQLIST=($(ls "$SEQBASE/$cur"*.sh)) for i in "${!SEQLIST[@]}"; do