From 6553443d91f249685ebabce75eccd5745b7b4486 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Sat, 23 Dec 2023 16:20:09 +0200 Subject: [PATCH] 1 --- Makefile | 22 ++++++++++++++++++++++ add-blesh-to-bashrc.sh | 37 +++++++++++++++++++++++++++++++++++++ bashrc.head | 1 + bashrc.tail | 1 + 4 files changed, 61 insertions(+) create mode 100644 Makefile create mode 100755 add-blesh-to-bashrc.sh create mode 100644 bashrc.head create mode 100644 bashrc.tail diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dacbda4 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +all: + echo OK + +download-blesh: + wget "https://github.com/akinomyoga/ble.sh/releases/download/v0.3.4/ble-0.3.4.tar.xz" -O "ble-0.3.4.tar.xz" + +extract-blesh: + tar xvf ble-0.3.4.tar.xz + +cleanup: + rm -vf ble-0.3.4.tar.xz + rm -vfr ./ble-0.3.4 + +install-blesh: + mkdir -p /usr/local/share/blesh + rsync -av ./ble-0.3.4/ /usr/local/share/blesh/ + chown -R root:root /usr/local/share/blesh/ + chmod -R o-w /usr/local/share/blesh/ + bash add-blesh-to-bashrc.sh + +set-shell-to-bash: + usermod --shell "/bin/bash" $$(whoami) diff --git a/add-blesh-to-bashrc.sh b/add-blesh-to-bashrc.sh new file mode 100755 index 0000000..7092591 --- /dev/null +++ b/add-blesh-to-bashrc.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +H=$(head -1 bashrc.head) +T=$(head -1 bashrc.tail) + +BASHRC_FILENAME="${HOME}/.bashrc" + +HEAD_EXISTS="0" +TAIL_EXISTS="0" + +grep --fixed-strings "${H}" "${BASHRC_FILENAME}" +if [ "$?" -eq "0" ] +then + HEAD_EXISTS="1" +fi + +grep --fixed-strings "${T}" "${BASHRC_FILENAME}" +if [ "$?" -eq "0" ] +then + TAIL_EXISTS="1" +fi + + +if [ "${HEAD_EXISTS}" -eq "0" ] +then + cat bashrc.head "${BASHRC_FILENAME}" > "${BASHRC_FILENAME}.in" + cat "${BASHRC_FILENAME}.in" > "${BASHRC_FILENAME}" + rm -vf "${BASHRC_FILENAME}.in" +fi + +if [ "${TAIL_EXISTS}" -eq "0" ] +then + cat "${BASHRC_FILENAME}" bashrc.tail > "${BASHRC_FILENAME}.in" + cat "${BASHRC_FILENAME}.in" > "${BASHRC_FILENAME}" + rm -vf "${BASHRC_FILENAME}.in" +fi + diff --git a/bashrc.head b/bashrc.head new file mode 100644 index 0000000..bf886c1 --- /dev/null +++ b/bashrc.head @@ -0,0 +1 @@ +[[ $- == *i* ]] && source /usr/local/share/blesh/ble.sh --attach=none diff --git a/bashrc.tail b/bashrc.tail new file mode 100644 index 0000000..282264d --- /dev/null +++ b/bashrc.tail @@ -0,0 +1 @@ +[[ ${BLE_VERSION-} ]] && ble-attach