#!/usr/bin/env bash readonly toolName=composer # Already defined by sequencer.sh, but may be overwritten #readonly seq_configName="${sq_scriptName:?}.cfg" #readonly seq_configTemplate="${seq_origin:?}/${sq_configName:?}.example" sq_aptOpt= sq_config=0 sq_composerBin= seq_config() { # Apt cmdline option to suppress user interaction interactive || sq_aptOpt="-y" # Disable error checks if external scripts are used # e.g. error on unbound variables #disableErrorCheck # Return of non zero value will abort the sequence return 0 } getComposer() { local lLocalOnly=0 local lGlobalOnly=0 case "${1:-}" in -l) lLocalOnly=1 ;; -g) lGlobalOnly=1 ;; esac if [[ -n "${sq_composerBin:-}" ]] && [[ -z "${1:-}" ]] ; then return 0 fi local lComp= if (( ! lGlobalOnly )) ; then lComp="$(ls composer 2>>/dev/null)" lComp="${lComp:-"$(ls composer.phar 2>>/dev/null)"}" fi if (( ! lLocalOnly )) ; then lComp="${lComp:-"$(ls /usr/local/bin/composer 2>>/dev/null)"}" fi [[ -z "${lComp:-}" ]] && return 1 sq_composerBin="$(readlink -f -- "${lComp}")" return 0 } step_1_info() { echo "Determine status of ${toolName} in current directory or globally"; } step_1_alias() { echo "status"; } step_1() { local lDir="$(pwd)" local lComp getComposer || die "No composer installed" info "Composer found: ${sq_composerBin}" info -a "$(COMPOSER_ALLOW_SUPERUSER=1 "${sq_composerBin}" --version)" info "Available php versions:" info -a "$(update-alternatives --list php)" } step_10_info() { echoinfoArgs "[OPTIONS] [VERSION]" echo "Install ${toolName}" echoinfo " [OPTIONS]" echoinfo " -l: (default) install composer.phar to the current directory" echoinfo " -g: install composer globally to /usr/local/bin" echoinfo " [VERSION]" echoinfo " Install this specific ${toolName} version" } step_10_alias() { echo "install"; } step_10() { shift local lLocal=1 local lArgs=() for _ in "${@}" ; do case "${1:-}" in -l) shift ;; -g) lLocal=0 lArgs+=(--install-dir="/usr/local/bin") lArgs+=(--filename="composer") shift ;; --) shift && break ;; -*) die "Unkown option ${1}" ;; esac done local getArg="-l" (( ! lLocal )) && getArg="-g" getComposer ${getArg} && die "Composer already installed: ${sq_composerBin}" [[ -n "${1:-}" ]] && lArgs+=(--version="${1}") interactive || lArgs+=(--quiet) info "Installing ${toolName}" local checksum_expected="$(wget -q -O - https://composer.github.io/installer.sig)" exe wget -O 'composer-setup.php' 'https://getcomposer.org/installer' local checksum=($(sha384sum 'composer-setup.php')) if [ "${checksum_expected}" != "${checksum}" ] then error -e 'Invalid installer checksum' error -a "Sum: ${checksum}" error -a "Exp: ${checksum_expected}" exe rm composer-setup.php return 1 fi exe php composer-setup.php "${lArgs[@]}" saveReturn $? exe rm composer-setup.php endReturn "Composer setup failed" } # shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 # shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh