From 26d661fa01df5cb2569432413ad91df891d088f2 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Sun, 8 Mar 2020 21:08:42 +0100 Subject: Implement argument parsing. Implement forceupdate argument (Closes #49). --- installer.sh | 160 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 41 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 15ad203..7cf389d 100755 --- a/installer.sh +++ b/installer.sh @@ -12,25 +12,81 @@ latest_version=$(curl --silent "https://api.github.com/repos/cbdevnet/midimonste makeargs=all # Build args +normal=$(tput sgr0) +bold=$(tput bold) +bold2=$(tput smso) +c_red=$(tput setaf 1) +c_green=$(tput setaf 2) + VAR_DESTDIR="" # Unused VAR_PREFIX="/usr" VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" VAR_DEFAULT_CFG="/etc/midimonster/midimonster.cfg" VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" -bold=$(tput bold) -normal=$(tput sgr0) ################################################ SETUP ################################################ ############################################## FUNCTIONS ############################################## -INSTALL-DEPS () { ##Install deps from array "$deps" +ARGS () { + for i in "$@" + do + case $i in + --prefix=*) + VAR_PREFIX="${i#*=}" + VAR_PREFIX_I="1" + ;; + --plugins=*) + VAR_PLUGINS="${i#*=}" + VAR_PLUGINS_I="1" + ;; + --defcfg=*) + VAR_DEFAULT_CFG="${i#*=}" + VAR_DEFAULT_CFG_I="1" + ;; + --examples=*) + VAR_EXAMPLE_CFGS="${i#*=}" + VAR_EXAMPLE_CFGS_I="1" + ;; + --dev) + NIGHTLY=1 + NIGHTLY_I="1" + ;; + -d|--default) + VAR_PREFIX_I="1" + VAR_PLUGINS_I="1" + VAR_DEFAULT_CFG_I="1" + VAR_EXAMPLE_CFGS_I="1" + NIGHTLY_I="1" + NIGHTLY=1 + ;; + -fu|--forceupdate) + UPDATER_FORCE="1" + ;; + -h|--help|*) # [WIP messages] + printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" + printf "\n ${c_green}--prefix${normal} ${c_red}${normal} Sets the prefix" + printf "\n ${c_green}--plugins${normal} ${c_red}${normal} Sets the plugin path" + printf "\n ${c_green}--defcfg${normal} ${c_red}${normal} Sets the config path" + printf "\n ${c_green}--examples${normal} ${c_red}${normal} Sets the example configs path\n" + printf "\n ${c_green}--dev${normal} Install nightly version (combine with --forceupdate to upgrade to nightly version)" + printf "\n ${c_green}-d, --default${normal} Use default values to install" + printf "\n ${c_green}-fu, --forceupdate${normal} Force the updater to update without a version check (Can be used to upgrade to the nightly version)" + printf "\n ${c_green}-h, --help${normal} Show this message\n" + exit 1 + ;; + esac + shift + done +} + +INSTALL-DEPS () { # Install deps from array "$deps" for t in ${deps[@]}; do if [ $(dpkg-query -W -f='${Status}' $t 2>/dev/null | grep -c "ok installed") -eq 0 ]; then printf "Installing %s\n" "$t" apt-get install $t; - printf "Done\n"; + printf "Done.\n"; else printf "%s already installed!\n" "$t" fi @@ -38,26 +94,28 @@ INSTALL-DEPS () { ##Install deps from array "$deps" printf "\n" } -NIGHTLY_CHECK () { - #Asks for nightly version - read -p "Do you want to install the latest development version? (y/n)? " magic - case "$magic" in - y|Y) - printf "OK! You´re a risky person ;D\n" - NIGHTLY=1 - ;; - n|N) - printf "That´s OK - installing the latest stable version for you ;-)\n" - NIGHTLY=0 - ;; - *) - printf "Invalid input\n" - ERROR - ;; - esac +NIGHTLY_CHECK () { # Asks for nightly version + if [ -z "$NIGHTLY_I" ]; then + read -p "Do you want to install the latest development version? (y/n)? " magic + case "$magic" in + y|Y) + printf "OK! You´re a risky person ;D\n" + NIGHTLY=1 + ;; + n|N) + printf "That´s OK - installing the latest stable version for you ;-)\n" + NIGHTLY=0 + ;; + *) + printf "${bold}Invalid input -- INSTALLING LATEST STABLE VERSION!${normal}\n" + NIGHTLY=0 + ;; + esac + fi # Roll back to last tag if we're not on a nightly build if [ "$NIGHTLY" != 1 ]; then + cd "$tmp_path" printf "Finding latest stable version...\n" Iversion=$(git describe --abbrev=0) printf "Starting Git checkout to %s...\n" "$Iversion" @@ -75,20 +133,27 @@ INSTALL-PREP () { printf "\n" ) NIGHTLY_CHECK - printf "Preparation successful\n\n" - printf "${bold}If you don't know what you're doing, just hit enter 4 times.${normal}\n" - - read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX - VAR_PREFIX="${input:-$VAR_PREFIX}" + printf "Preparation done.\n\n" + printf "${bold}If you don't know what you're doing, just hit enter.${normal}\n\n" + if [ -z "$VAR_PREFIX_I" ]; then + read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX + VAR_PREFIX="${input:-$VAR_PREFIX}" + fi - read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS - VAR_PLUGINS="${input:-$VAR_PLUGINS}" + if [ -z "$VAR_PLUGINS_I" ]; then + read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS + VAR_PLUGINS="${input:-$VAR_PLUGINS}" + fi - read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG - VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}" + if [ -z "$VAR_DEFAULT_CFG_I" ]; then + read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG + VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}" + fi - read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS - VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}" + if [ -z "$VAR_EXAMPLE_CFGS_I" ]; then + read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS + VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}" + fi UPDATER_SAVE @@ -106,12 +171,9 @@ UPDATER-PREP () { printf "\nInitializing repository...\n" cd $tmp_path git init $tmp_path - printf "Successfully imported settings from %s\n" "$updater_file" ) NIGHTLY_CHECK - printf "Preparation successful\n\n" - - rm -f "$VAR_PREFIX/bin/midimonster" + printf "Preparation done.\n\n" rm -rf "$VAR_PLUGINS/" UPDATER_SAVE @@ -125,12 +187,12 @@ UPDATER-PREP () { UPDATER () { installed_version="$(midimonster --version)" - #installed_version="MIDIMonster v0.3-40-gafed325" # FOR TESTING ONLY! (or bypassing updater version check) + #installed_version="MIDIMonster v0.3-40-gafed325" # FOR TESTING ONLY! if [[ "$installed_version" =~ "$latest_version" ]]; then printf "Newest Version is already installed! ${bold}($installed_version)${normal}\n\n" ERROR else - printf "The installed Version ${bold}´$installed_version´${normal} equals not the newest stable version ${bold}´$latest_version´${normal} (Maybe you are running a development version?)\n\n" + printf "The installed Version ${bold}´$installed_version´${normal} equals not the newest stable version ${bold}´$latest_version´${normal} (Maybe you are running a development(NIGHTLY) version?)\n\n" fi UPDATER-PREP @@ -180,6 +242,7 @@ CLEAN () { ################################################ Main ################################################# trap ERROR SIGINT SIGTERM SIGKILL +ARGS "$@" # Parse arguments clear # Check if $user = root! @@ -189,16 +252,31 @@ if [ "$user" != "root" ]; then fi if [ $(wget -q --spider http://github.com) $? -eq 1 ]; then - printf "You need connection to the internet\n" + printf "You need a connection to the internet\n" ERROR fi +# Forceupdate # Now only with default config because source imports all and overwrites the args.. [WIP!] +if [ "$UPDATER_FORCE" -eq "1" ]; then + printf "Forcing the updater to start...\n\n" + if [ -f $updater_file ]; then + . $updater_file + ARGS "$@" # Parse arguments again to compensate overwrite from source /\ + fi + + UPDATER-PREP + INSTALL-RUN + DONE +fi + # Check if updater config file exist and import it (overwrites default values!) if [ -f $updater_file ]; then printf "Starting updater...\n\n" . $updater_file + ARGS "$@" # Parse arguments again to compensate overwrite from source /\ + printf "Successfully imported settings from %s\n" "$updater_file" - # Check if binary $updater/bin/midimonster exist. If yes start updater else skip. + # Check if binary $VAR_PREFIX/bin/midimonster exist. If yes start updater else skip. if [ -x "$VAR_PREFIX/bin/midimonster" ]; then UPDATER else @@ -206,8 +284,8 @@ if [ -f $updater_file ]; then fi fi +#Normal install INSTALL-DEPS INSTALL-PREP -printf "\n" INSTALL-RUN DONE -- cgit v1.2.3 From f66a8cf114c113cabd81bc9d8900f22c3e19da3c Mon Sep 17 00:00:00 2001 From: Spacelord Date: Sun, 8 Mar 2020 21:21:59 +0100 Subject: Updater: fix if --- installer.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 7cf389d..30b03e5 100755 --- a/installer.sh +++ b/installer.sh @@ -257,11 +257,12 @@ if [ $(wget -q --spider http://github.com) $? -eq 1 ]; then fi # Forceupdate # Now only with default config because source imports all and overwrites the args.. [WIP!] -if [ "$UPDATER_FORCE" -eq "1" ]; then +if [ "$UPDATER_FORCE" = "1" ]; then printf "Forcing the updater to start...\n\n" if [ -f $updater_file ]; then . $updater_file ARGS "$@" # Parse arguments again to compensate overwrite from source /\ + printf "Successfully imported settings from %s\n" "$updater_file" fi UPDATER-PREP @@ -280,7 +281,7 @@ if [ -f $updater_file ]; then if [ -x "$VAR_PREFIX/bin/midimonster" ]; then UPDATER else - printf "midimonster binary not found, skipping updater.\n" + printf "MIDIMonster binary not found, skipping updater.\nYou can force an update with --forceupdate\n" fi fi -- cgit v1.2.3 From 7085f3511cd41cbb9f05d2ab46f3bcb2b93a6c71 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Sun, 8 Mar 2020 22:00:37 +0100 Subject: Installer: Update prefix-containing variables when the prefix argument is set. --- installer.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 30b03e5..ed6b2aa 100755 --- a/installer.sh +++ b/installer.sh @@ -20,9 +20,9 @@ c_green=$(tput setaf 2) VAR_DESTDIR="" # Unused VAR_PREFIX="/usr" -VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" +VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" # Reassigned in func. ARGS to update "$VAR_PREFIX" when an argument is set. VAR_DEFAULT_CFG="/etc/midimonster/midimonster.cfg" -VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" +VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" # Reassigned in func. ARGS to update "$VAR_PREFIX" when an argument is set. ################################################ SETUP ################################################ @@ -36,6 +36,8 @@ ARGS () { --prefix=*) VAR_PREFIX="${i#*=}" VAR_PREFIX_I="1" + VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" + VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" ;; --plugins=*) VAR_PLUGINS="${i#*=}" @@ -134,7 +136,7 @@ INSTALL-PREP () { ) NIGHTLY_CHECK printf "Preparation done.\n\n" - printf "${bold}If you don't know what you're doing, just hit enter.${normal}\n\n" + printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" if [ -z "$VAR_PREFIX_I" ]; then read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX VAR_PREFIX="${input:-$VAR_PREFIX}" -- cgit v1.2.3 From c656294f14c3b31c408d2e24fa8a062144ceb9ab Mon Sep 17 00:00:00 2001 From: Spacelord Date: Mon, 9 Mar 2020 16:40:43 +0100 Subject: Installer: Update prefix-containing variables. --- installer.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index ed6b2aa..049d7c7 100755 --- a/installer.sh +++ b/installer.sh @@ -38,6 +38,7 @@ ARGS () { VAR_PREFIX_I="1" VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" + VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" ;; --plugins=*) VAR_PLUGINS="${i#*=}" @@ -138,8 +139,10 @@ INSTALL-PREP () { printf "Preparation done.\n\n" printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" if [ -z "$VAR_PREFIX_I" ]; then - read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX + read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX then update containing vars VAR_PREFIX="${input:-$VAR_PREFIX}" + VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" # Update prefix-containing variables. + VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" # Update prefix-containing variables. fi if [ -z "$VAR_PLUGINS_I" ]; then -- cgit v1.2.3 From 62afd5d7fb2c6d764d0756136041d0162cb022db Mon Sep 17 00:00:00 2001 From: Spacelord Date: Mon, 9 Mar 2020 19:07:50 +0100 Subject: Installer: Update help --- installer.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 049d7c7..f8fad18 100755 --- a/installer.sh +++ b/installer.sh @@ -13,10 +13,12 @@ latest_version=$(curl --silent "https://api.github.com/repos/cbdevnet/midimonste makeargs=all # Build args normal=$(tput sgr0) +dim=$(tput dim) bold=$(tput bold) -bold2=$(tput smso) -c_red=$(tput setaf 1) -c_green=$(tput setaf 2) +uline=$(tput smul) +c_red=$(tput setaf 1) +c_green=$(tput setaf 2) +c_mag=$(tput setaf 5) VAR_DESTDIR="" # Unused VAR_PREFIX="/usr" @@ -67,16 +69,17 @@ ARGS () { -fu|--forceupdate) UPDATER_FORCE="1" ;; - -h|--help|*) # [WIP messages] + -h|--help|*) # Help messages printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" - printf "\n ${c_green}--prefix${normal} ${c_red}${normal} Sets the prefix" - printf "\n ${c_green}--plugins${normal} ${c_red}${normal} Sets the plugin path" - printf "\n ${c_green}--defcfg${normal} ${c_red}${normal} Sets the config path" - printf "\n ${c_green}--examples${normal} ${c_red}${normal} Sets the example configs path\n" - printf "\n ${c_green}--dev${normal} Install nightly version (combine with --forceupdate to upgrade to nightly version)" + printf "\n ${c_green}--prefix${normal} ${c_red}${normal} Sets the prefix ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_PREFIX" + printf "\n ${c_green}--plugins${normal} ${c_red}${normal} Sets the plugin path ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_PLUGINS" + printf "\n ${c_green}--defcfg${normal} ${c_red}${normal} Sets the config path ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_DEFAULT_CFG" + printf "\n ${c_green}--examples${normal} ${c_red}${normal} Sets the example configs path ${c_mag}Default:${normal} ${dim}%s ${normal}\n" "$VAR_EXAMPLE_CFGS" + printf "\n ${c_green}--dev${normal} Install nightly version" printf "\n ${c_green}-d, --default${normal} Use default values to install" - printf "\n ${c_green}-fu, --forceupdate${normal} Force the updater to update without a version check (Can be used to upgrade to the nightly version)" - printf "\n ${c_green}-h, --help${normal} Show this message\n" + printf "\n ${c_green}-fu, --forceupdate${normal} Force the updater to update without a version check" + printf "\n ${c_green}-h, --help${normal} Show this message" + printf "\n ${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" exit 1 ;; esac -- cgit v1.2.3 From 9ec65119e11941d81a641f6387cdb542b4e8070e Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 11 Mar 2020 22:23:55 +0100 Subject: Refactor installer --- installer.sh | 356 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 156 insertions(+), 200 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index f8fad18..b2ca958 100755 --- a/installer.sh +++ b/installer.sh @@ -1,16 +1,30 @@ #!/bin/bash ################################################ SETUP ################################################ -deps=(libasound2-dev libevdev-dev liblua5.3-dev libjack-jackd2-dev pkg-config libssl-dev gcc make wget git) -user=$(whoami) # for bypassing user check replace "$(whoami)" with "root". - -tmp_path=$(mktemp -d) # Repo download path -updater_dir=/etc/midimonster-updater # Updater download + config path -updater_file=$updater_dir/updater.conf - -latest_version=$(curl --silent "https://api.github.com/repos/cbdevnet/midimonster/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') - -makeargs=all # Build args +deps=( + libasound2-dev + libevdev-dev + liblua5.3-dev + libjack-jackd2-dev + pkg-config + libssl-dev + python3-dev + gcc + make + wget + git +) +# Replace this with 'root' to bypass the user check +user="$(whoami)" +# Temporary directory used for repository clone +tmp_path="$(mktemp -d)" +# Installer/updater install directory +updater_dir="/etc/midimonster-updater" + +latest_version="$(curl --silent "https://api.github.com/repos/cbdevnet/midimonster/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')" + +# make invocation arguments +makeargs="all" normal=$(tput sgr0) dim=$(tput dim) @@ -20,66 +34,56 @@ c_red=$(tput setaf 1) c_green=$(tput setaf 2) c_mag=$(tput setaf 5) -VAR_DESTDIR="" # Unused -VAR_PREFIX="/usr" -VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" # Reassigned in func. ARGS to update "$VAR_PREFIX" when an argument is set. -VAR_DEFAULT_CFG="/etc/midimonster/midimonster.cfg" -VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" # Reassigned in func. ARGS to update "$VAR_PREFIX" when an argument is set. - - -################################################ SETUP ################################################ +DEFAULT_PREFIX="/usr" +DEFAULT_PLUGINPATH="/lib/midimonster" +DEFAULT_CFGPATH="/etc/midimonster/midimonster.cfg" +DEFAULT_EXAMPLES="/share/midimonster" ############################################## FUNCTIONS ############################################## +assign_defaults(){ + VAR_PREFIX="${VAR_PREFIX:-$DEFAULT_PREFIX}" + VAR_PLUGINS="${VAR_PLUGINS:-$VAR_PREFIX$DEFAULT_PLUGINPATH}" + VAR_DEFAULT_CFG="${VAR_DEFAULT_CFG:-$DEFAULT_CFGPATH}" + VAR_EXAMPLE_CFGS="${VAR_EXAMPLE_CFGS:-$VAR_PREFIX$DEFAULT_EXAMPLES}" +} -ARGS () { - for i in "$@" - do +ARGS(){ + for i in "$@"; do case $i in --prefix=*) VAR_PREFIX="${i#*=}" - VAR_PREFIX_I="1" - VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" - VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" - VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" ;; --plugins=*) VAR_PLUGINS="${i#*=}" - VAR_PLUGINS_I="1" ;; --defcfg=*) VAR_DEFAULT_CFG="${i#*=}" - VAR_DEFAULT_CFG_I="1" ;; --examples=*) VAR_EXAMPLE_CFGS="${i#*=}" - VAR_EXAMPLE_CFGS_I="1" ;; --dev) NIGHTLY=1 - NIGHTLY_I="1" ;; -d|--default) - VAR_PREFIX_I="1" - VAR_PLUGINS_I="1" - VAR_DEFAULT_CFG_I="1" - VAR_EXAMPLE_CFGS_I="1" - NIGHTLY_I="1" - NIGHTLY=1 + assign_defaults ;; -fu|--forceupdate) UPDATER_FORCE="1" - ;; - -h|--help|*) # Help messages + ;; + -h|--help|*) + assign_defaults printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" - printf "\n ${c_green}--prefix${normal} ${c_red}${normal} Sets the prefix ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_PREFIX" - printf "\n ${c_green}--plugins${normal} ${c_red}${normal} Sets the plugin path ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_PLUGINS" - printf "\n ${c_green}--defcfg${normal} ${c_red}${normal} Sets the config path ${c_mag}Default:${normal} ${dim}%s ${normal}" "$VAR_DEFAULT_CFG" - printf "\n ${c_green}--examples${normal} ${c_red}${normal} Sets the example configs path ${c_mag}Default:${normal} ${dim}%s ${normal}\n" "$VAR_EXAMPLE_CFGS" - printf "\n ${c_green}--dev${normal} Install nightly version" - printf "\n ${c_green}-d, --default${normal} Use default values to install" - printf "\n ${c_green}-fu, --forceupdate${normal} Force the updater to update without a version check" - printf "\n ${c_green}-h, --help${normal} Show this message" - printf "\n ${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" + printf "\n\t${c_green}--prefix${normal} ${c_red}${normal}\t\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" + printf "\n\t${c_green}--plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" + printf "\n\t${c_green}--defcfg${normal} ${c_red}${normal}\t\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" + printf "\n\t${c_green}--examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" + printf "\n\t${c_green}--dev${normal}\t\t\tInstall nightly version" + printf "\n\t${c_green}-d, --default${normal}\t\tUse default values to install" + printf "\n\t${c_green}-h, --help${normal}\t\tShow this message" + printf "\n\t${c_green}-fu, --forceupdate${normal}\tForce the updater to update without a version check" + printf "\n\t${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" + rmdir "$tmp_path" exit 1 ;; esac @@ -87,21 +91,49 @@ ARGS () { done } -INSTALL-DEPS () { # Install deps from array "$deps" - for t in ${deps[@]}; do - if [ $(dpkg-query -W -f='${Status}' $t 2>/dev/null | grep -c "ok installed") -eq 0 ]; then - printf "Installing %s\n" "$t" - apt-get install $t; - printf "Done.\n"; - else - printf "%s already installed!\n" "$t" - fi +# Install unmatched dependencies +install_dependencies(){ + for dependency in ${deps[@]}; do + if [ "$(dpkg-query -W -f='${Status}' "$dependency" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then + printf "Installing %s\n" "$dependency" + apt-get install $dependency + else + printf "%s already installed!\n" "$dependency" + fi done printf "\n" } -NIGHTLY_CHECK () { # Asks for nightly version - if [ -z "$NIGHTLY_I" ]; then +ask_questions(){ + printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" + if [ -z "$VAR_PREFIX" ]; then + read -e -i "$DEFAULT_PREFIX" -p "PREFIX (Install root directory): " input + VAR_PREFIX="${input:-$VAR_PREFIX}" + fi + + if [ -z "$VAR_PLUGINS" ]; then + read -e -i "$VAR_PREFIX$DEFAULT_PLUGINPATH" -p "PLUGINS (Plugin directory): " input + VAR_PLUGINS="${input:-$VAR_PLUGINS}" + fi + + if [ -z "$VAR_DEFAULT_CFG" ]; then + read -e -i "$DEFAULT_CFGPATH" -p "Default config path: " input + VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}" + fi + + if [ -z "$VAR_EXAMPLE_CFGS" ]; then + read -e -i "$VAR_PREFIX$DEFAULT_EXAMPLES" -p "Example config directory: " input + VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}" + fi +} + +# Clone the repository and select the correct version +prepare_repo(){ + printf "Cloning the repository\n" + git clone "https://github.com/cbdevnet/midimonster.git" "$tmp_path" + + # If not set via argument, ask whether to install development build + if [ -z "$NIGHTLY" ]; then read -p "Do you want to install the latest development version? (y/n)? " magic case "$magic" in y|Y) @@ -119,182 +151,106 @@ NIGHTLY_CHECK () { # Asks for nightly version esac fi - # Roll back to last tag if we're not on a nightly build + # Roll back to last tag if a stable version was requested if [ "$NIGHTLY" != 1 ]; then cd "$tmp_path" printf "Finding latest stable version...\n" - Iversion=$(git describe --abbrev=0) - printf "Starting Git checkout to %s...\n" "$Iversion" - git checkout -f -q $Iversion + last_tag=$(git describe --abbrev=0) + printf "Checking out %s...\n" "$last_tag" + git checkout -f -q $last_tag fi } -INSTALL-PREP () { - ( - printf "Starting download...\n" - git clone https://github.com/cbdevnet/midimonster.git "$tmp_path" # Gets Midimonster - printf "\nInitializing repository...\n" - cd $tmp_path - git init $tmp_path - printf "\n" - ) - NIGHTLY_CHECK - printf "Preparation done.\n\n" - printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" - if [ -z "$VAR_PREFIX_I" ]; then - read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX then update containing vars - VAR_PREFIX="${input:-$VAR_PREFIX}" - VAR_PLUGINS="$VAR_PREFIX/lib/midimonster" # Update prefix-containing variables. - VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster" # Update prefix-containing variables. - fi +# Build and install the software +build(){ + # Export variables for make + export PREFIX="$VAR_PREFIX" + export PLUGINS="$VAR_PLUGINS" + export DEFAULT_CFG="$VAR_DEFAULT_CFG" + export EXAMPLES="$VAR_EXAMPLE_CFGS" - if [ -z "$VAR_PLUGINS_I" ]; then - read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS - VAR_PLUGINS="${input:-$VAR_PLUGINS}" - fi - - if [ -z "$VAR_DEFAULT_CFG_I" ]; then - read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG - VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}" - fi - - if [ -z "$VAR_EXAMPLE_CFGS_I" ]; then - read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS - VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}" - fi - - UPDATER_SAVE - - export PREFIX=$VAR_PREFIX - export PLUGINS=$VAR_PLUGINS - export DEFAULT_CFG=$VAR_DEFAULT_CFG - export DESTDIR=$VAR_DESTDIR - export EXAMPLES=$VAR_EXAMPLE_CFGS -} - -UPDATER-PREP () { - ( - printf "Starting download...\n" - git clone https://github.com/cbdevnet/midimonster.git "$tmp_path" # Gets Midimonster - printf "\nInitializing repository...\n" - cd $tmp_path - git init $tmp_path - ) - NIGHTLY_CHECK - printf "Preparation done.\n\n" - rm -rf "$VAR_PLUGINS/" - - UPDATER_SAVE - - export PREFIX=$VAR_PREFIX - export PLUGINS=$VAR_PLUGINS - export DEFAULT_CFG=$VAR_DEFAULT_CFG - export DESTDIR=$VAR_DESTDIR - export EXAMPLES=$VAR_EXAMPLE_CFGS -} - -UPDATER () { - installed_version="$(midimonster --version)" - #installed_version="MIDIMonster v0.3-40-gafed325" # FOR TESTING ONLY! - if [[ "$installed_version" =~ "$latest_version" ]]; then - printf "Newest Version is already installed! ${bold}($installed_version)${normal}\n\n" - ERROR - else - printf "The installed Version ${bold}´$installed_version´${normal} equals not the newest stable version ${bold}´$latest_version´${normal} (Maybe you are running a development(NIGHTLY) version?)\n\n" - fi - - UPDATER-PREP - INSTALL-RUN - DONE -} - -INSTALL-RUN () { # Build cd "$tmp_path" make clean - make $makeargs + make "$makeargs" make install } -UPDATER_SAVE () { # Saves file for the auto updater in this script +# Save data for the updater +save_config(){ rm -rf $updater_dir - printf "Saving updater to %s/updater.sh\n" "$update_dir" + printf "Copying updater to %s/updater.sh\n" "$updater_dir" mkdir -p "$updater_dir" - wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O $updater_dir/updater.sh - printf "Creating symlink to updater in /usr/bin/midimonster-updater\n" + cp "$0" "$updater_dir/updater.sh" + printf "Creating symlin /usr/bin/midimonster-updater\n" ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater" chmod +x "$updater_dir/updater.sh" - printf "Exporting updater config to %s\n" "$updater_file" - printf "VAR_PREFIX=%s\nVAR_PLUGINS=%s\nVAR_DEFAULT_CFG=%s\nVAR_DESTDIR=%s\nVAR_EXAMPLE_CFGS=%s\n" "$VAR_PREFIX" "$VAR_PLUGINS" "$VAR_DEFAULT_CFG" "$VAR_DESTDIR" "$VAR_EXAMPLE_CFGS" > $updater_file + printf "Exporting updater config\n" + printf "VAR_PREFIX=%s\nVAR_PLUGINS=%s\nVAR_DEFAULT_CFG=%s\nVAR_DESTDIR=%s\nVAR_EXAMPLE_CFGS=%s\n" "$VAR_PREFIX" "$VAR_PLUGINS" "$VAR_DEFAULT_CFG" "$VAR_DESTDIR" "$VAR_EXAMPLE_CFGS" > "$updater_dir/updater.conf" } -ERROR () { - printf "\nAborting...\n" - CLEAN - printf "Exiting...\n" +error_handler(){ + printf "\nAborting\n" exit 1 } -DONE () { - printf "\nDone.\n" - CLEAN - exit 0 -} - -CLEAN () { - printf "\nCleaning...\n" - rm -rf $tmp_path +cleanup() { + if [ -d "$tmp_path" ]; then + printf "Cleaning up temporary files...\n" + rm -rf "$tmp_path" + fi } -############################################## FUNCTIONS ############################################## - - ################################################ Main ################################################# -trap ERROR SIGINT SIGTERM SIGKILL -ARGS "$@" # Parse arguments +trap error_handler SIGINT SIGTERM +trap cleanup EXIT + +# Parse arguments +ARGS "$@" clear -# Check if $user = root! +# Check whether we have the privileges to install stuff if [ "$user" != "root" ]; then - printf "Installer must be run as root\n" - ERROR + printf "The installer requires root privileges to install the midimonster system-wide\n" + exit 1 fi -if [ $(wget -q --spider http://github.com) $? -eq 1 ]; then - printf "You need a connection to the internet\n" - ERROR +# Check if we can download the sources +if [ "$(wget -q --spider http://github.com)" ]; then + printf "The installer requires internet connectivity to download the midimonster sources\n" + exit 1 fi -# Forceupdate # Now only with default config because source imports all and overwrites the args.. [WIP!] -if [ "$UPDATER_FORCE" = "1" ]; then - printf "Forcing the updater to start...\n\n" - if [ -f $updater_file ]; then - . $updater_file - ARGS "$@" # Parse arguments again to compensate overwrite from source /\ - printf "Successfully imported settings from %s\n" "$updater_file" +# Check whether the updater needs to run +if [ -f "$updater_dir/updater.conf" ] || [ "$UPDATER_FORCE" = "1" ]; then + if [ -f "$updater_dir/updater.conf" ]; then + . "$updater_dir/updater.conf" + # Parse arguments again to compensate overwrite from source + ARGS "$@" + printf "Imported settings from %s/updater.conf\n" "$updater_dir" fi - UPDATER-PREP - INSTALL-RUN - DONE -fi - -# Check if updater config file exist and import it (overwrites default values!) -if [ -f $updater_file ]; then - printf "Starting updater...\n\n" - . $updater_file - ARGS "$@" # Parse arguments again to compensate overwrite from source /\ - printf "Successfully imported settings from %s\n" "$updater_file" - - # Check if binary $VAR_PREFIX/bin/midimonster exist. If yes start updater else skip. - if [ -x "$VAR_PREFIX/bin/midimonster" ]; then - UPDATER - else - printf "MIDIMonster binary not found, skipping updater.\nYou can force an update with --forceupdate\n" + if [ -n "$UPDATER_FORCE" ]; then + printf "Forcing the updater to start...\n\n" + elif [ -x "$VAR_PREFIX/bin/midimonster" ]; then + installed_version="$(midimonster --version)" + if [[ "$installed_version" =~ "$latest_version" ]]; then + printf "The installed version ${bold}$installed_version${normal} seems to be up to date\nDoing nothing\n\n" + exit 0 + else + printf "The installed version ${bold}$installed_version${normal} does not match the latest version ${bold}$latest_version${normal}\nMaybe you are running a development version?\n\n" + fi fi + + # Run updater steps + prepare_repo + build +else + # Run installer steps + install_dependencies + prepare_repo + ask_questions + save_config + build fi +exit 0 -#Normal install -INSTALL-DEPS -INSTALL-PREP -INSTALL-RUN -DONE -- cgit v1.2.3 From 9286bf43da5f6e87dfb20db50cf7c5ceaea925ba Mon Sep 17 00:00:00 2001 From: Spacelord Date: Wed, 11 Mar 2020 23:35:01 +0100 Subject: Installer: Fix name --- installer.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index b2ca958..843e6bc 100755 --- a/installer.sh +++ b/installer.sh @@ -210,13 +210,13 @@ clear # Check whether we have the privileges to install stuff if [ "$user" != "root" ]; then - printf "The installer requires root privileges to install the midimonster system-wide\n" + printf "The installer/updater requires root privileges to install the midimonster system-wide\n" exit 1 fi # Check if we can download the sources if [ "$(wget -q --spider http://github.com)" ]; then - printf "The installer requires internet connectivity to download the midimonster sources\n" + printf "The installer/updater requires internet connectivity to download the midimonster sources\n" exit 1 fi -- cgit v1.2.3 From 813c0587d6add1df302a9b0c88fdff4e111e391e Mon Sep 17 00:00:00 2001 From: Spacelord Date: Thu, 12 Mar 2020 13:58:43 +0100 Subject: Installer: Initial self update --- installer.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 17 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 843e6bc..56021c4 100755 --- a/installer.sh +++ b/installer.sh @@ -70,18 +70,38 @@ ARGS(){ ;; -fu|--forceupdate) UPDATER_FORCE="1" - ;; + ;; + -supd|--selfupdate) + NIGHTLY="" + self_update + rmdir "$tmp_path" + exit 0 + ;; + -insup|--installupdater) + NIGHTLY="" + install_updater + rmdir "$tmp_path" + exit 0 + ;; + -insdep|--installdeps) + install_dependencies + rmdir "$tmp_path" + exit 0 + ;; -h|--help|*) assign_defaults printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" - printf "\n\t${c_green}--prefix${normal} ${c_red}${normal}\t\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" - printf "\n\t${c_green}--plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" - printf "\n\t${c_green}--defcfg${normal} ${c_red}${normal}\t\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" - printf "\n\t${c_green}--examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" - printf "\n\t${c_green}--dev${normal}\t\t\tInstall nightly version" - printf "\n\t${c_green}-d, --default${normal}\t\tUse default values to install" - printf "\n\t${c_green}-h, --help${normal}\t\tShow this message" - printf "\n\t${c_green}-fu, --forceupdate${normal}\tForce the updater to update without a version check" + printf "\n\t${c_green} --prefix${normal} ${c_red}${normal}\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" + printf "\n\t${c_green} --plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" + printf "\n\t${c_green} --defcfg${normal} ${c_red}${normal}\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" + printf "\n\t${c_green} --examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" + printf "\n\t${c_green} --dev${normal}\t\t\tInstall nightly version" + printf "\n ${c_green}-d,\t --default${normal}\t\tUse default values to install" + printf "\n ${c_green}-fu,\t --forceupdate${normal}\t\tForce the updater to update without a version check" + printf "\n ${c_green}-supd,\t --selfupdate${normal}\t\tUpdates this script to the newest version" + printf "\n ${c_green}-insup, --installupdater${normal}\tInstall the updater (Run with midimonster-updater)" + printf "\n ${c_green}-insdep, --installdeps${normal}\t\tInstall dependencies and exit" + printf "\n ${c_green}-h,\t --help${normal}\t\tShow this message and exit" printf "\n\t${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" rmdir "$tmp_path" exit 1 @@ -105,7 +125,11 @@ install_dependencies(){ } ask_questions(){ - printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" + # Only say if necessary + if [ -n "$VAR_PREFIX" ] || [ -n "$VAR_PLUGINS" ] || [ -n "$VAR_DEFAULT_CFG" ] || [ -n "$VAR_EXAMPLE_CFGS" ]; then + printf "${bold}If you don't know what you're doing, just hit enter a few times.${normal}\n\n" + fi + if [ -z "$VAR_PREFIX" ]; then read -e -i "$DEFAULT_PREFIX" -p "PREFIX (Install root directory): " input VAR_PREFIX="${input:-$VAR_PREFIX}" @@ -177,17 +201,38 @@ build(){ # Save data for the updater save_config(){ - rm -rf $updater_dir - printf "Copying updater to %s/updater.sh\n" "$updater_dir" - mkdir -p "$updater_dir" - cp "$0" "$updater_dir/updater.sh" - printf "Creating symlin /usr/bin/midimonster-updater\n" - ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater" - chmod +x "$updater_dir/updater.sh" + rm -f "$updater_dir/updater.conf" + mkdir -p "$updater_dir" printf "Exporting updater config\n" printf "VAR_PREFIX=%s\nVAR_PLUGINS=%s\nVAR_DEFAULT_CFG=%s\nVAR_DESTDIR=%s\nVAR_EXAMPLE_CFGS=%s\n" "$VAR_PREFIX" "$VAR_PLUGINS" "$VAR_DEFAULT_CFG" "$VAR_DESTDIR" "$VAR_EXAMPLE_CFGS" > "$updater_dir/updater.conf" } +# Updates this script either from the downloaded sources or the remote repository. +self_update(){ + mkdir -p "$updater_dir" + if [ "$NIGHTLY" = "1" ]; then + cp -u "$tmp_path/installer.sh" "$0" + elif [ "$NIGHTLY" != "1" ]; then + wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O "$0" + fi + chmod +x "$0" +} + +install_updater(){ + mkdir -p "$updater_dir" + if [ "$NIGHTLY" = "1" ]; then + printf "Copying updater to %s/updater.sh\n" "$updater_dir" + cp -u "$tmp_path/installer.sh" "$updater_dir/updater.sh" + else + printf "Downloading updater to %s/updater.sh\n" "$updater_dir" + wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O "$updater_dir/updater.sh" + fi + chmod +x "$updater_dir/updater.sh" + printf "Creating symlink /usr/bin/midimonster-updater\n" + ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater" + printf "Done.\n" +} + error_handler(){ printf "\nAborting\n" exit 1 @@ -243,12 +288,15 @@ if [ -f "$updater_dir/updater.conf" ] || [ "$UPDATER_FORCE" = "1" ]; then # Run updater steps prepare_repo + install_updater + save_config build else # Run installer steps install_dependencies prepare_repo ask_questions + install_updater save_config build fi -- cgit v1.2.3 From 846a49199ba011a00e4814bacac524a6fe9b299a Mon Sep 17 00:00:00 2001 From: cbdev Date: Mon, 16 Mar 2020 22:19:27 +0100 Subject: Hash-index event routing table --- installer.sh | 87 ++++++++++++++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 56 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 56021c4..111c783 100755 --- a/installer.sh +++ b/installer.sh @@ -26,13 +26,13 @@ latest_version="$(curl --silent "https://api.github.com/repos/cbdevnet/midimonst # make invocation arguments makeargs="all" -normal=$(tput sgr0) -dim=$(tput dim) -bold=$(tput bold) -uline=$(tput smul) -c_red=$(tput setaf 1) -c_green=$(tput setaf 2) -c_mag=$(tput setaf 5) +normal="$(tput sgr0)" +dim="$(tput dim)" +bold="$(tput bold)" +uline="$(tput smul)" +c_red="$(tput setaf 1)" +c_green="$(tput setaf 2)" +c_mag="$(tput setaf 5)" DEFAULT_PREFIX="/usr" DEFAULT_PLUGINPATH="/lib/midimonster" @@ -49,7 +49,7 @@ assign_defaults(){ ARGS(){ for i in "$@"; do - case $i in + case "$i" in --prefix=*) VAR_PREFIX="${i#*=}" ;; @@ -71,37 +71,28 @@ ARGS(){ -fu|--forceupdate) UPDATER_FORCE="1" ;; - -supd|--selfupdate) - NIGHTLY="" - self_update - rmdir "$tmp_path" + --install-updater) + NIGHTLY=1 prepare_repo + install_script exit 0 ;; - -insup|--installupdater) - NIGHTLY="" - install_updater - rmdir "$tmp_path" - exit 0 - ;; - -insdep|--installdeps) + --install-dependencies) install_dependencies - rmdir "$tmp_path" exit 0 ;; -h|--help|*) assign_defaults printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" - printf "\n\t${c_green} --prefix${normal} ${c_red}${normal}\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" - printf "\n\t${c_green} --plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" - printf "\n\t${c_green} --defcfg${normal} ${c_red}${normal}\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" - printf "\n\t${c_green} --examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" - printf "\n\t${c_green} --dev${normal}\t\t\tInstall nightly version" - printf "\n ${c_green}-d,\t --default${normal}\t\tUse default values to install" - printf "\n ${c_green}-fu,\t --forceupdate${normal}\t\tForce the updater to update without a version check" - printf "\n ${c_green}-supd,\t --selfupdate${normal}\t\tUpdates this script to the newest version" - printf "\n ${c_green}-insup, --installupdater${normal}\tInstall the updater (Run with midimonster-updater)" - printf "\n ${c_green}-insdep, --installdeps${normal}\t\tInstall dependencies and exit" - printf "\n ${c_green}-h,\t --help${normal}\t\tShow this message and exit" + printf "\n\t${c_green}--prefix${normal} ${c_red}${normal}\t\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" + printf "\n\t${c_green}--plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" + printf "\n\t${c_green}--defcfg${normal} ${c_red}${normal}\t\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" + printf "\n\t${c_green}--examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" + printf "\n\t${c_green}--dev${normal}\t\t\t\tInstall nightly version" + printf "\n\t${c_green}-d, --default${normal}\t\t\tUse default values to install" + printf "\n\t${c_green}-fu, --forceupdate${normal}\t\tForce the updater to update without a version check" + printf "\n\t${c_green}--install-updater${normal}\t\tInstall the updater (Run with midimonster-updater)" + printf "\n\t${c_green}--install-dependencies${normal}\t\tInstall dependencies and exit" + printf "\n\t${c_green}-h, --help${normal}\t\t\tShow this message and exit" printf "\n\t${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" rmdir "$tmp_path" exit 1 @@ -116,7 +107,7 @@ install_dependencies(){ for dependency in ${deps[@]}; do if [ "$(dpkg-query -W -f='${Status}' "$dependency" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then printf "Installing %s\n" "$dependency" - apt-get install $dependency + apt-get install "$dependency" else printf "%s already installed!\n" "$dependency" fi @@ -181,7 +172,7 @@ prepare_repo(){ printf "Finding latest stable version...\n" last_tag=$(git describe --abbrev=0) printf "Checking out %s...\n" "$last_tag" - git checkout -f -q $last_tag + git checkout -f -q "$last_tag" fi } @@ -207,30 +198,14 @@ save_config(){ printf "VAR_PREFIX=%s\nVAR_PLUGINS=%s\nVAR_DEFAULT_CFG=%s\nVAR_DESTDIR=%s\nVAR_EXAMPLE_CFGS=%s\n" "$VAR_PREFIX" "$VAR_PLUGINS" "$VAR_DEFAULT_CFG" "$VAR_DESTDIR" "$VAR_EXAMPLE_CFGS" > "$updater_dir/updater.conf" } -# Updates this script either from the downloaded sources or the remote repository. -self_update(){ +# Updates this script using the one from the checked out repo (containing the requested version) +install_script(){ mkdir -p "$updater_dir" - if [ "$NIGHTLY" = "1" ]; then - cp -u "$tmp_path/installer.sh" "$0" - elif [ "$NIGHTLY" != "1" ]; then - wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O "$0" - fi - chmod +x "$0" -} - -install_updater(){ - mkdir -p "$updater_dir" - if [ "$NIGHTLY" = "1" ]; then - printf "Copying updater to %s/updater.sh\n" "$updater_dir" - cp -u "$tmp_path/installer.sh" "$updater_dir/updater.sh" - else - printf "Downloading updater to %s/updater.sh\n" "$updater_dir" - wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O "$updater_dir/updater.sh" - fi + printf "Copying updater to %s/updater.sh\n" "$updater_dir" + cp "$tmp_path/installer.sh" "$updater_dir/updater.sh" chmod +x "$updater_dir/updater.sh" printf "Creating symlink /usr/bin/midimonster-updater\n" ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater" - printf "Done.\n" } error_handler(){ @@ -238,7 +213,7 @@ error_handler(){ exit 1 } -cleanup() { +cleanup(){ if [ -d "$tmp_path" ]; then printf "Cleaning up temporary files...\n" rm -rf "$tmp_path" @@ -288,7 +263,7 @@ if [ -f "$updater_dir/updater.conf" ] || [ "$UPDATER_FORCE" = "1" ]; then # Run updater steps prepare_repo - install_updater + install_script save_config build else @@ -296,7 +271,7 @@ else install_dependencies prepare_repo ask_questions - install_updater + install_script save_config build fi -- cgit v1.2.3 From 4b991a31eed602070d241e77e98d62e06d647289 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Mon, 13 Apr 2020 23:54:33 +0200 Subject: Installer Update --- installer.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'installer.sh') diff --git a/installer.sh b/installer.sh index 111c783..66eef99 100755 --- a/installer.sh +++ b/installer.sh @@ -71,7 +71,7 @@ ARGS(){ -fu|--forceupdate) UPDATER_FORCE="1" ;; - --install-updater) + --install-updater|--selfupdate) NIGHTLY=1 prepare_repo install_script exit 0 @@ -83,19 +83,20 @@ ARGS(){ -h|--help|*) assign_defaults printf "${bold}Usage:${normal} ${0} ${c_green}[OPTIONS]${normal}" - printf "\n\t${c_green}--prefix${normal} ${c_red}${normal}\t\tSet the installation prefix\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" - printf "\n\t${c_green}--plugins${normal} ${c_red}${normal}\tSet the plugin install path\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" - printf "\n\t${c_green}--defcfg${normal} ${c_red}${normal}\t\tSet the default configuration path\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" - printf "\n\t${c_green}--examples${normal} ${c_red}${normal}\tSet the path for example configurations\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" - printf "\n\t${c_green}--dev${normal}\t\t\t\tInstall nightly version" - printf "\n\t${c_green}-d, --default${normal}\t\t\tUse default values to install" - printf "\n\t${c_green}-fu, --forceupdate${normal}\t\tForce the updater to update without a version check" - printf "\n\t${c_green}--install-updater${normal}\t\tInstall the updater (Run with midimonster-updater)" - printf "\n\t${c_green}--install-dependencies${normal}\t\tInstall dependencies and exit" - printf "\n\t${c_green}-h, --help${normal}\t\t\tShow this message and exit" - printf "\n\t${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!${normal}\n" + printf "\n\t${c_green}--prefix=${normal}${c_red}${normal}\t\tSet the installation prefix.\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PREFIX" + printf "\n\t${c_green}--plugins=${normal}${c_red}${normal}\tSet the plugin install path.\t\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_PLUGINS" + printf "\n\t${c_green}--defcfg=${normal}${c_red}${normal}\t\tSet the default configuration path.\t${c_mag}Default:${normal} ${dim}%s${normal}" "$VAR_DEFAULT_CFG" + printf "\n\t${c_green}--examples=${normal}${c_red}${normal}\tSet the path for example configurations.\t${c_mag}Default:${normal} ${dim}%s${normal}\n" "$VAR_EXAMPLE_CFGS" + printf "\n\t${c_green}--dev${normal}\t\t\tInstall nightly version." + printf "\n\t${c_green}-d,\t--default${normal}\tUse default values to install." + printf "\n\t${c_green}-fu,\t--forceupdate${normal}\tForce the updater to update without a version check." + printf "\n\t${c_green}--selfupdate${normal}\t\tUpdates this script to the newest version and exit." + printf "\n\t${c_green}--install-updater${normal}\tInstall the updater (Run with midimonster-updater) and exit." + printf "\n\t${c_green}--install-dependencies${normal}\tInstall dependencies and exit" + printf "\n\t${c_green}-h,\t--help${normal}\t\tShow this message and exit." + printf "\n\t${uline}${bold}${c_mag}Each argument can be overwritten by another, the last one is used!.${normal}\n" rmdir "$tmp_path" - exit 1 + exit 0 ;; esac shift -- cgit v1.2.3