install.sh - repair existing symlink

Possibility to clone from a custom git branch (--branch)
This commit is contained in:
2022-05-30 17:08:00 +02:00
parent 27ed63996a
commit ff48af2fa6

View File

@@ -1,25 +1,42 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC1090 # dynamically sourced file # shellcheck disable=SC1090 # dynamically sourced file
sequencer_gitUrl="https://winklerfamilie.eu/git/efelon/shell_sequencer.git" readonly sequencerGitUrl="https://winklerfamilie.eu/git/efelon/shell_sequencer.git"
defaultDir="/opt/sequencer" defaultBranch="master"
defaultUserSeqs="/opt/seqs" readonly defaultDir="/opt/sequencer"
readonly defaultUserSeqs="/opt/seqs"
readonly sequencerBin="/usr/local/bin/sequencer.sh"
sequencerDir= sequencerDir=
# Get script working directory # Get script working directory
WDIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" 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:-}" sequencerDir="${1:-}"
# Installation directory was not set by argument -d # Installation directory was not set by argument $1
if [ -z "${sequencerDir}" ]; then if [ -z "${sequencerDir}" ]; then
[ -w "$(dirname -- "${defaultDir}")" ] && sequencerDir="${defaultDir}" [ -w "$(dirname -- "${defaultDir}")" ] && sequencerDir="${defaultDir}"
# Fallback to working directory # Fallback to working directory
[ -z "${sequencerDir}" ] && sequencerDir="${WDIR}/sequencer" [ -z "${sequencerDir}" ] && sequencerDir="${workDir}/sequencer"
fi fi
# Check if already installed # Check if already installed
if [ -d "${sequencerDir}" ]; then 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 " [e] Sequencer seems to be already installed at:"
echo " ${sequencerDir}" echo " ${sequencerDir}"
exit 1 exit 1
@@ -32,11 +49,11 @@ fi
# Install git if neccessary # Install git if neccessary
if ! which git >>/dev/null 2>&1; then 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 if ! apt update; then
echo " [w] Cannot update apt repositories" echo " [w] Cannot update apt repositories"
fi fi
if ! apt install git -y; then if ! apt install git -y; then
echo " [e] Cannot install git via apt" echo " [e] Cannot install git via apt"
exit 3 exit 3
@@ -44,9 +61,9 @@ if ! which git >>/dev/null 2>&1; then
fi fi
# Clone sequncer to target directory # Clone sequncer to target directory
if ! git clone "${sequencer_gitUrl}" "$sequencerDir"; then if ! git clone --branch "${defaultBranch}" "${sequencerGitUrl}" "$sequencerDir"; then
echo " [E] Error cloning git repository:" echo " [e] Error cloning git repository:"
echo " ${sequencer_gitUrl}" echo " ${sequencerGitUrl}"
exit 4 exit 4
fi fi
@@ -62,5 +79,5 @@ if [ "${SEQUENCER_USER_SEQS}" != "${sequencerDir}/seqs" ]; then
ln -sT "${sequencerDir}/seqs" "${SEQUENCER_USER_SEQS}" ln -sT "${sequencerDir}/seqs" "${SEQUENCER_USER_SEQS}"
fi fi
echo " [I] Successfully installed shell sequencer" echo " [i] Successfully installed shell sequencer"
echo " to: ${sequencerDir}" echo " to: ${sequencerDir}"