Support installation to different directoy

Introduce configuration file to set a custom seqs collection
This commit is contained in:
2022-03-07 00:15:27 +01:00
parent 56765a0884
commit b894a756ea
5 changed files with 87 additions and 18 deletions

View File

@@ -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
```

View File

@@ -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:"

View File

@@ -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

5
sequencer.cfg.dist Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
## Bash completion ##
# Where uses store own seqs or selected distribution selected seqs
SEQUENCER_USER_SEQS="/opt/seqs"

View File

@@ -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