]> gitweb @ CieloNegro.org - autobuild.git/blobdiff - lib/setPath.bash
Split the script to several files.
[autobuild.git] / lib / setPath.bash
diff --git a/lib/setPath.bash b/lib/setPath.bash
new file mode 100644 (file)
index 0000000..5158dd6
--- /dev/null
@@ -0,0 +1,28 @@
+function setPath () {
+    if (( $# == 0 )); then
+        echo "Usage: $0 VAR [PATH, ...]" >&2
+        return 1
+    fi
+
+    local -r var="$1"
+    local paths=("${@:2}")
+
+    case ${#paths[@]} in
+        0)
+            unset $var;;
+        1)
+            export $var="$paths";;
+        *)
+            export $var="${paths[0]}"
+            local path
+            for path in "${paths[@]:1}"; do
+                local val=$(eval echo \$$var)
+                export $var="$val:$path"
+            done
+    esac
+
+    # THINKME: Special case for PATH: we prepend "$prefix/bin" to it.
+    if [[ $var = "PATH" ]]; then
+        PATH="$prefix/bin:$PATH"
+    fi
+}