]> Creatis software - cpPlugins.git/blobdiff - install/cpPlugins_Install_Functions.sh
...
[cpPlugins.git] / install / cpPlugins_Install_Functions.sh
diff --git a/install/cpPlugins_Install_Functions.sh b/install/cpPlugins_Install_Functions.sh
new file mode 100644 (file)
index 0000000..f69aca0
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+## =================================
+## == Compare two version strings ==
+## =================================
+
+function version_gt {
+    test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
+}
+
+# =======================
+# = Uncompress function =
+# =======================
+
+function uncompress {
+    z_file=$1
+    z_output=$2
+    z_mime=`file -b --mime-type $z_file`:`file -bz --mime-type $z_file`
+
+    uz_command=""
+    case $z_mime in
+        application/gzip:application/x-tar)
+        uz_command="tar xzf $z_file -C $z_output --strip-components=1"
+        ;;
+        application/x-bzip2:application/x-tar)
+        uz_command="tar xjf $z_file -C $z_output --strip-components=1"
+        ;;
+        application/x-compress:application/x-tar)
+        uz_command="zcat $z_file  | tar xf - -C $z_output --strip-components=1"
+        ;;
+        application/x-lzip:application/x-empty)
+        uz_command="tar --lzip xf $z_file -C $z_output --strip-components=1"
+        ;;
+        application/x-tar:application/x-tar)
+        uz_command="tar xf $z_file -C $z_output --strip-components=1"
+        ;;
+        application/x-xz:application/x-tar)
+        uz_command="tar xJf $z_file -C $z_output --strip-components=1"
+        ;;
+        application/zip:application/x-empty)
+        uz_command="unzip $z_file -d $z_output"
+        ;;
+        *)
+        (>&2 echo "====================================")
+        (>&2 echo "Unknown file format for \"$z_file\"")
+        (>&2 echo "MIME-TYPE: $z_mime")
+        (>&2 echo "====================================")
+        exit 1
+        ;;
+    esac
+    eval $uz_command
+}
+
+# =============================
+# = Find executables function =
+# =============================
+
+function find_executables {
+    exe=""
+    execs=`which -a $@`
+    if [ "${#execs[@]}" -gt "0" ]; then
+        (>&2 echo "--> I have found a(some) executable(s), please choose one:")
+        c=0
+        choices=()
+        for i in ${execs[@]}; do
+            (>&2 echo "  [$c] $i")
+            choices+=("$i")
+            c=$[$c+1]
+        done
+        (>&2 echo "  [$c] Manually choose another installation")
+        c=$[$c+1]
+        (>&2 echo "  [$c] Compile from source code")
+        (>&2 echo -n "  Please choose a number and press [ENTER]: ")
+        read choice
+        if [ "$choice" -lt "${#choices[@]}" ]; then
+            exe=${choices[$choice]}
+        elif [ "$choice" -eq "${#choices[@]}" ]; then
+            read -e -p "Please provide a valid location: " tmp
+            exe=`readlink -f ${tmp/#\~/$HOME}`
+        fi
+    else
+        (>&2 echo "--> I have not found any valid install, please choose:")
+        (>&2  echo "  [0] Manually choose an installation")
+        (>&2  echo "  [1] Compile from source code")
+        (>&2  echo -n "  Please choose a number and press [ENTER]: ")
+        read choice
+        if [ "$choice" -eq "0" ]; then
+            read -e -p "Please provide a valid location: " tmp
+            exe=`readlink -f ${tmp/#\~/$HOME}`
+        fi
+    fi
+    echo "$exe"
+}
+
+## eof - $RCSfile$