Refactor variables names
This commit is contained in:
48
install.sh
48
install.sh
@@ -1,66 +1,66 @@
|
||||
#!/bin/bash
|
||||
# shellcheck disable=SC1090 # dynamically sourced file
|
||||
|
||||
SEQGITURL="https://winklerfamilie.eu/git/efelon/shell_sequencer.git"
|
||||
DEFAULT_DIR="/opt/sequencer"
|
||||
DEFAULT_USER_SEQS="/opt/seqs"
|
||||
SEQUENCER_DIR=
|
||||
sequencer_gitUrl="https://winklerfamilie.eu/git/efelon/shell_sequencer.git"
|
||||
defaultDir="/opt/sequencer"
|
||||
defaultUserSeqs="/opt/seqs"
|
||||
sequencerDir=
|
||||
|
||||
# Get script working directory
|
||||
WDIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
|
||||
|
||||
SEQUENCER_DIR="$1"
|
||||
sequencerDir="${1:-}"
|
||||
|
||||
# Installation directory was not set by argument -d
|
||||
if [ -z "$SEQUENCER_DIR" ]; then
|
||||
[ -w "$(dirname "$DEFAULT_DIR")" ] && SEQUENCER_DIR="$DEFAULT_DIR"
|
||||
if [ -z "${sequencerDir}" ]; then
|
||||
[ -w "$(dirname -- "${defaultDir}")" ] && sequencerDir="${defaultDir}"
|
||||
# Fallback to working directory
|
||||
[ -z "$SEQUENCER_DIR" ] && SEQUENCER_DIR="${WDIR}/sequencer"
|
||||
[ -z "${sequencerDir}" ] && sequencerDir="${WDIR}/sequencer"
|
||||
fi
|
||||
|
||||
# Check if already installed
|
||||
if [ -d "$SEQUENCER_DIR" ]; then
|
||||
echo " [E] Sequencer seems to be already installed at:"
|
||||
echo " $SEQUENCER_DIR"
|
||||
if [ -d "${sequencerDir}" ]; then
|
||||
echo " [e] Sequencer seems to be already installed at:"
|
||||
echo " ${sequencerDir}"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -w "$(dirname "$SEQUENCER_DIR")" ]; then
|
||||
echo " [E] Your user has no permission to write to $(dirname "$SEQUENCER_DIR")"
|
||||
if [ ! -w "$(dirname -- "${sequencerDir}")" ]; then
|
||||
echo " [e] Your user has no permission to write to $(dirname -- "${sequencerDir}")"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Install git if neccessary
|
||||
if ! which git >>/dev/null 2>&1; then
|
||||
echo " [W] Git not found and will be installed"
|
||||
echo " [w] Git not found and will be installed"
|
||||
|
||||
if ! apt update; then
|
||||
echo " [W] Cannot update apt repositories"
|
||||
echo " [w] Cannot update apt repositories"
|
||||
fi
|
||||
|
||||
if ! apt install git -y; then
|
||||
echo " [E] Cannot install git via apt"
|
||||
echo " [e] Cannot install git via apt"
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clone sequncer to target directory
|
||||
if ! git clone $SEQGITURL "$SEQUENCER_DIR"; then
|
||||
if ! git clone "${sequencer_gitUrl}" "$sequencerDir"; then
|
||||
echo " [E] Error cloning git repository:"
|
||||
echo " $SEQGITURL"
|
||||
echo " ${sequencer_gitUrl}"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# If available use configuration
|
||||
. "${SEQUENCER_DIR}/sequencer.cfg" >/dev/null 2>&1
|
||||
. "${sequencerDir}/sequencer.cfg" >/dev/null 2>&1
|
||||
|
||||
# Set to default if not configured
|
||||
[ -z "$SEQUENCER_USER_SEQS" ] && SEQUENCER_USER_SEQS="$DEFAULT_USER_SEQS"
|
||||
[ -z "${SEQUENCER_USER_SEQS}" ] && SEQUENCER_USER_SEQS="${defaultUserSeqs}"
|
||||
|
||||
# Install sequncer script
|
||||
ln -s "${SEQUENCER_DIR}/sequencer/sequencer.sh" "/usr/local/bin"
|
||||
if [ "$SEQUENCER_USER_SEQS" != "$SEQUENCER_DIR/seqs" ]; then
|
||||
ln -sT "${SEQUENCER_DIR}/seqs" "${SEQUENCER_USER_SEQS}"
|
||||
ln -s "${sequencerDir}/sequencer/sequencer.sh" "/usr/local/bin"
|
||||
if [ "${SEQUENCER_USER_SEQS}" != "${sequencerDir}/seqs" ]; then
|
||||
ln -sT "${sequencerDir}/seqs" "${SEQUENCER_USER_SEQS}"
|
||||
fi
|
||||
|
||||
echo " [I] Successfully installed shell sequencer"
|
||||
echo " to: $SEQUENCER_DIR"
|
||||
echo " to: ${sequencerDir}"
|
||||
|
@@ -1,21 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Get script working directory
|
||||
sq_dir="$(cd "$(dirname -- "$(realpath "${BASH_SOURCE[0]}")")" >>/dev/null 2>&1 && pwd)"
|
||||
sq_dir="$(cd "$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")")" >>/dev/null 2>&1 && pwd)"
|
||||
|
||||
_sequencerCompletion() {
|
||||
local SEQCOMP_LOC="${sq_dir}/sqn-completion.bash"
|
||||
local SEQCOMP_LOADER="$HOME/.bashrc"
|
||||
local SEQCOMP_SOURCE=". \"$SEQCOMP_LOC\""
|
||||
local seqcomp_loc="${sq_dir}/sqn-completion.bash"
|
||||
local seqcomp_loader="$HOME/.bashrc"
|
||||
local seqcomp_source=". \"${seqcomp_loc}\""
|
||||
|
||||
if grep "$SEQCOMP_SOURCE" "$SEQCOMP_LOADER" >>/dev/null 2>&1; then
|
||||
echo " [I] Completion already installed ($SEQCOMP_LOADER)"
|
||||
if grep "${seqcomp_source}" "${seqcomp_loader}" >>/dev/null 2>&1; then
|
||||
echo " [i] Completion already installed (${seqcomp_loader})"
|
||||
else
|
||||
echo "$SEQCOMP_SOURCE" >>"$SEQCOMP_LOADER"
|
||||
echo " [I] Sequence bash-completion installed"
|
||||
echo "${seqcomp_source}" >>"${seqcomp_loader}"
|
||||
echo " [i] Sequence bash-completion installed"
|
||||
fi
|
||||
# shellcheck source=sqn-completion.bash
|
||||
. "$SEQCOMP_LOC"
|
||||
. "${seqcomp_loc}"
|
||||
}
|
||||
|
||||
_sequencerCompletion
|
||||
|
@@ -8,7 +8,7 @@ _sqn_completions()
|
||||
# Extract alias command with buildins same as:
|
||||
# local curCmd="$(alias $1 | sed "s/^alias.*\" \"\(.*\)\"'$/\1/")"
|
||||
local curCmd=
|
||||
curCmd="$(alias "$1")"
|
||||
curCmd="$(alias "${1:-}")"
|
||||
curCmd="${curCmd##*\" \"}"
|
||||
curCmd="${curCmd%\"\'*}"
|
||||
COMPREPLY=()
|
||||
@@ -66,24 +66,25 @@ installCompletion() {
|
||||
|
||||
. "${script_dir}/sequencer.cfg" >/dev/null 2>&1
|
||||
|
||||
local SEQBASE="${script_dir}/seqs"
|
||||
local SEQPREFIX="sqn_"
|
||||
local SEQSHORT=()
|
||||
local seq_base="${script_dir}/seqs"
|
||||
local seq_prefix="sqn_"
|
||||
local seq_short=()
|
||||
local seq_list=()
|
||||
|
||||
# Check for user selected sequences
|
||||
[ -e "$SEQUENCER_USER_SEQS" ] && SEQBASE="$SEQUENCER_USER_SEQS"
|
||||
[ -e "$SEQUENCER_USER_SEQS" ] && seq_base="$SEQUENCER_USER_SEQS"
|
||||
|
||||
# Create aliases and command (alias) list for "complete" command"
|
||||
IFS=$'\n' read -r -d '' -a SEQLIST < <(ls -1 "$SEQBASE/${cur}"*.sh)
|
||||
for i in "${!SEQLIST[@]}"; do
|
||||
SEQLIST[$i]="${SEQLIST[$i]##*/}"
|
||||
SEQLIST[$i]="${SEQLIST[$i]%.*}"
|
||||
SEQSHORT[$i]="${SEQPREFIX}${SEQLIST[$i]/[[:blank:]]/_}"
|
||||
IFS=$'\n' read -r -d '' -a seq_list < <(ls -1 "${seq_base}/${cur}"*.sh)
|
||||
for i in "${!seq_list[@]}"; do
|
||||
seq_list[$i]="${seq_list[$i]##*/}"
|
||||
seq_list[$i]="${seq_list[$i]%.*}"
|
||||
seq_short[$i]="${seq_prefix}${seq_list[$i]/[[:blank:]]/_}"
|
||||
# shellcheck disable=SC2139,SC2086
|
||||
# alias should be expanded when defined
|
||||
alias ${SEQSHORT[$i]}="_SQN_ALIAS=\"${SEQSHORT[$i]}\" \"$SEQBASE/${SEQLIST[$i]}.sh\""
|
||||
alias ${seq_short[$i]}="_SQN_ALIAS=\"${seq_short[$i]}\" \"${seq_base}/${seq_list[$i]}.sh\""
|
||||
done
|
||||
complete -o nosort -o bashdefault -o default -F _sqn_completions "${SEQSHORT[@]}"
|
||||
complete -o nosort -o bashdefault -o default -F _sqn_completions "${seq_short[@]}"
|
||||
}
|
||||
|
||||
installCompletion
|
||||
|
Reference in New Issue
Block a user