aboutsummaryrefslogtreecommitdiffhomepage
path: root/installer.sh
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-12-18 22:47:57 +0100
committercbdev <cb@cbcdn.com>2019-12-18 22:47:57 +0100
commitafe2f2a9cb809e4a28ae519db239fa0e4f136685 (patch)
tree08f5e9d899d719c42ec0b7b35cd1c75988fb3af9 /installer.sh
parent65501fcd14f347c8e1438fd2e7d6b88b642e4fe7 (diff)
downloadmidimonster-afe2f2a9cb809e4a28ae519db239fa0e4f136685.tar.gz
midimonster-afe2f2a9cb809e4a28ae519db239fa0e4f136685.tar.bz2
midimonster-afe2f2a9cb809e4a28ae519db239fa0e4f136685.zip
Style fixes in installer
Diffstat (limited to 'installer.sh')
-rwxr-xr-xinstaller.sh281
1 files changed, 143 insertions, 138 deletions
diff --git a/installer.sh b/installer.sh
index d131234..c17d847 100755
--- a/installer.sh
+++ b/installer.sh
@@ -6,7 +6,7 @@ user=$(whoami) # for bypassing user check replace "$(whoami)" w
tmp_path=$(mktemp -d) # Repo download path
updater_dir=/etc/midimonster-updater # Updater download + config path
-updater_file=$updater_dir/updater.conf #
+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/')
@@ -26,154 +26,153 @@ normal=$(tput sgr0)
############################################## FUNCTIONS ##############################################
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 "\nInstalling "$t"";
- apt-get install $t;
- printf "\nDone.";
- else
- printf "\n"$t" already installed!"
- fi
-done
-printf "\n"
+ 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
+ done
+ printf "\n"
}
NIGHTLY_CHECK () {
-read -p "Do you want to install the latest developement version? (y/n)? " magic #Asks for nightly version
-case "$magic" in
- y|Y ) printf "\nOK! You´re a risky person ;D"
- NIGHTLY=1
- ;;
- n|N ) printf "\nThat´s ok I´ll install the latest stable version for you ;-)"
- NIGHTLY=0
- ;;
- * ) printf "\nInvalid input"
- ERROR
- ;;
-esac
-
-if [ $NIGHTLY != 1 ] # Git checkout if NIGHTLY !=1
-then
- printf "\nFinding latest stable version..."
- Iversion=$(git describe --abbrev=0)
- printf "\nStarting Git checkout to "$Iversion"..."
- git checkout -f -q $Iversion
-fi
+ #Asks for nightly version
+ read -p "Do you want to install the latest developement 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
+
+ # Roll back to last tag if we're not on a nightly build
+ if [ "$NIGHTLY" != 1 ]; then
+ printf "Finding latest stable version...\n"
+ Iversion=$(git describe --abbrev=0)
+ printf "Starting Git checkout to %s...\n" "$Iversion"
+ git checkout -f -q $Iversion
+ fi
}
INSTALL-PREP () {
-(#### Subshell make things like cd $tmp_path easier to revert
- printf "\nStarting download..."
- git clone https://github.com/cbdevnet/midimonster.git "$tmp_path" # Gets Midimonster
- printf "\n\n\nInitializing repository...\n"
- cd $tmp_path
- git init $tmp_path
- printf "\n"
-)
-NIGHTLY_CHECK
-printf "\nPreparing Done.\n\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}"
-
-read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS
-VAR_PLUGINS="${input:-$VAR_PLUGINS}"
-
-read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG
-VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}"
-
-read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS
-VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}"
-
-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
+ (
+ 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 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}"
+
+ read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS
+ VAR_PLUGINS="${input:-$VAR_PLUGINS}"
+
+ read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG
+ VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}"
+
+ read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS
+ VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}"
+
+ 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 () {
-(#### Subshell make things like cd $tmp_path easier to revert
-
-
- printf "\nStarting download..."
- git clone https://github.com/cbdevnet/midimonster.git "$tmp_path" # Gets Midimonster
- printf "\n\n"
- printf "\nInitializing repository..."
- cd $tmp_path
- git init $tmp_path
- printf "\nSucessfully imported Updater settings from $updater_file.\n\n\n"
- )
-NIGHTLY_CHECK
-printf "\nPreparing Done.\n\n\n"
-
-rm -f "$VAR_PREFIX/bin/midimonster"
-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
+ (
+ 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 "Sucessfully imported settings from %s\n" "$updater_file"
+ )
+ NIGHTLY_CHECK
+ printf "Preparation successful\n\n"
+
+ rm -f "$VAR_PREFIX/bin/midimonster"
+ 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! (or bypassing updater version check)
- if [[ "$installed_version" =~ "$latest_version" ]]; then
- printf "\nNewest Version is already installed! ${bold}($installed_version)${normal}\n\n"
- ERROR
- else
- printf "\nThe installed Version ${bold}´$installed_version´${normal} equals not the newest stable version ${bold}´$latest_version´${normal} ( Maybe you are running a developement version? )\n\n"
- fi
-
- UPDATER-PREP
- INSTALL-RUN
- DONE
- }
+ installed_version="$(midimonster --version)"
+ #installed_version="MIDIMonster v0.3-40-gafed325" # FOR TESTING ONLY! (or bypassing updater version check)
+ 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 developement version? )\n\n"
+ fi
+
+ UPDATER-PREP
+ INSTALL-RUN
+ DONE
+}
INSTALL-RUN () { # Build
- cd "$tmp_path"
- make clean
- make $makeargs
- make install
+ cd "$tmp_path"
+ make clean
+ make $makeargs
+ make install
}
UPDATER_SAVE () { # Saves file for the auto updater in this script
- rm -rf $updater_dir
- printf "\nSaving updater to $updater_dir/updater.sh"
- mkdir -p "$updater_dir"
- wget https://raw.githubusercontent.com/cbdevnet/midimonster/master/installer.sh -O $updater_dir/updater.sh
- printf "\nCreating symlink to updater in /usr/bin/midimonster-updater"
- ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater"
- chmod +x "$updater_dir/updater.sh"
- printf "\nExporting updater config to $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
+ rm -rf $updater_dir
+ printf "Saving updater to %s/updater.sh\n" "$update_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"
+ ln -s "$updater_dir/updater.sh" "/usr/bin/midimonster-updater\n"
+ 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
}
ERROR () {
- printf "\nAborting..."
- CLEAN
- printf "Exiting...\n\n\n"
- exit 1
+ printf "\nAborting...\n"
+ CLEAN
+ printf "Exiting...\n"
+ exit 1
}
DONE () {
- printf "\n\nDone."
- CLEAN
- exit 0
+ printf "\nDone.\n"
+ CLEAN
+ exit 0
}
CLEAN () {
- printf "\nCleaning...\n\n"
- rm -rf $tmp_path
+ printf "\nCleaning...\n"
+ rm -rf $tmp_path
}
############################################## FUNCTIONS ##############################################
@@ -183,26 +182,32 @@ CLEAN () {
trap ERROR SIGINT SIGTERM SIGKILL
clear
-if [ "$user" != "root" ]; then printf "\nInstaller must be run as root"; ERROR; fi # Check if $user = root!
-if [ $(wget -q --spider http://github.com) $? -eq 1 ]; then printf "\nYou need connection to the internet"; ERROR; fi
-
-if [ -f $updater_file ] # Checks if updater config file exist and import it(overwrite default values!)
-then
-
- printf "\nStarting updater...\n\n"
- . $updater_file
+# Check if $user = root!
+if [ "$user" != "root" ]; then
+ printf "Installer must be run as root\n"
+ ERROR
+fi
- if [ -x "$VAR_PREFIX/bin/midimonster" ] # Check if binary $updater/bin/midimonster exist. If yes start updater else skip.
- then
- UPDATER
- else
- printf "\nMidimonster binary not found, skipping updater.\n"
- fi
+if [ $(wget -q --spider http://github.com) $? -eq 1 ]; then
+ printf "You need connection to the internet\n"
+ ERROR
+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
+
+ # Check if binary $updater/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.\n"
+ fi
fi
INSTALL-DEPS
INSTALL-PREP
printf "\n"
INSTALL-RUN
-DONE \ No newline at end of file
+DONE