Files
shell_sequencer/install.sh
Martin Winkler ff48af2fa6 install.sh - repair existing symlink
Possibility to clone from a custom git branch (--branch)
2022-05-30 17:08:00 +02:00

84 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# shellcheck disable=SC1090 # dynamically sourced file
readonly sequencerGitUrl="https://winklerfamilie.eu/git/efelon/shell_sequencer.git"
defaultBranch="master"
readonly defaultDir="/opt/sequencer"
readonly defaultUserSeqs="/opt/seqs"
readonly sequencerBin="/usr/local/bin/sequencer.sh"
sequencerDir=
# Get script working directory
workDir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
for _ in "$@"; do
case "${1:-}" in
--)
shift && break ;;
-b|--branch) # Clone a different branch than master
shift
defaultBranch="${1:-}"
shift ;;
esac
done
sequencerDir="${1:-}"
# Installation directory was not set by argument $1
if [ -z "${sequencerDir}" ]; then
[ -w "$(dirname -- "${defaultDir}")" ] && sequencerDir="${defaultDir}"
# Fallback to working directory
[ -z "${sequencerDir}" ] && sequencerDir="${workDir}/sequencer"
fi
# Check if already installed
if [ -d "${sequencerDir}" ]; then
if [[ $(readlink -- "${sequencerBin}") != ${sequencerDir}/sequencer.sh ]] && [[ -e "${sequencerDir}/sequencer.sh" ]] ; then
echo " [i] Repairing legacy symlink"
ln -fsT "${sequencerDir}/sequencer.sh" "${sequencerBin}"
fi
echo " [e] Sequencer seems to be already installed at:"
echo " ${sequencerDir}"
exit 1
fi
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"
if ! apt update; then
echo " [w] Cannot update apt repositories"
fi
if ! apt install git -y; then
echo " [e] Cannot install git via apt"
exit 3
fi
fi
# Clone sequncer to target directory
if ! git clone --branch "${defaultBranch}" "${sequencerGitUrl}" "$sequencerDir"; then
echo " [e] Error cloning git repository:"
echo " ${sequencerGitUrl}"
exit 4
fi
# If available use configuration
. "${sequencerDir}/sequencer.cfg" >/dev/null 2>&1
# Set to default if not configured
[ -z "${SEQUENCER_USER_SEQS}" ] && SEQUENCER_USER_SEQS="${defaultUserSeqs}"
# Install sequncer script
ln -s "${sequencerDir}/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: ${sequencerDir}"