Commit d7134524dbde1380452c58f34cce3f237f21b2ae

Thomas de Grivel 2023-02-22T14:35:21

rbpkg_bootstrap

diff --git a/bin/rbpkg_bootstrap b/bin/rbpkg_bootstrap
new file mode 100755
index 0000000..08774d2
--- /dev/null
+++ b/bin/rbpkg_bootstrap
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+set -e
+
+usage () {
+    {
+        echo 'Usage :'
+        echo '  rbpkg_bootstrap [-f] [RBPKG_DIR]'
+        echo '  RBPKG_DIR=~/rbpkg rbpkg_bootstrap [-f]'
+        echo '                Installs rbpkg into RBPKG_DIR.'
+        echo 'Options :'
+        echo '  -f            Clear RBPKG_DIR before installing.'
+        echo 'Environment variables :'
+        echo '  HOME          Home directory.'
+        echo '  PATH          Binaries path.'
+        echo '  RBPKG_DIR     Target installation directory.'
+    } >&2
+    exit 1
+}
+
+# config
+FORCE=No
+while [ $# -gt 0 ]; do
+    if [ "x$1" = "x-h" ]; then
+        usage
+    elif [ "x$1" = "x-f" ]; then
+        FORCE=Yes
+        shift
+    else
+        RBPKG_DIR="$1"
+        shift
+    fi
+done
+
+if [ "x${RBPKG_DIR}" = "x" ]; then
+    if [ "x${HOME}" = "x" ]; then
+        echo "HOME is not set" >&2
+        exit 1
+    fi
+    RBPKG_DIR="${HOME}/rbpkg"
+fi
+
+# clone
+if [ -d "${RBPKG_DIR}" ]; then
+    if [ "x$FORCE" = "xYes" ]; then
+        rm -rf "${RBPKG_DIR}"
+        git clone https://git.kmx.io/kmx.io/rbpkg.git "${RBPKG_DIR}"
+    fi
+else
+    git clone https://git.kmx.io/kmx.io/rbpkg.git "${RBPKG_DIR}"
+fi
+
+# profile
+mkdir -p "${RBPKG_DIR}/etc/rbpkg"
+{
+    echo "export RBPKG_DIR='${RBPKG_DIR}'"
+    echo "export PATH='${RBPKG_DIR}/bin:${PATH}'"
+    echo "export LD_LIBRARY_PATH='${RBPKG_DIR}/lib'"
+} > "${RBPKG_DIR}/etc/rbpkg/profile"
+
+# source profile
+echo ". ${RBPKG_DIR}/etc/rbpkg/profile"
+. "${RBPKG_DIR}/etc/rbpkg/profile"