batman
This commit is contained in:
commit
cc8ffcfcc2
38 changed files with 6046 additions and 0 deletions
71
installs/install-blesh.sh
Executable file
71
installs/install-blesh.sh
Executable file
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
#!/bin/bash
|
||||
# ─< Helper functions >─────────────────────────────────────────────────────────────────
|
||||
echo_error() { echo -e "\033[0;1;31mError: \033[0;31m\t${*}\033[0m"; }
|
||||
echo_binfo() { echo -e "\033[0;1;34mINFO:\033[0;34m\t${*}\033[0m"; }
|
||||
echo_info() { echo -e "\033[0;1;35mInfo: \033[0;35m${*}\033[0m"; }
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ─< Check root and set sudo variable if necessary >───────────────────────────────────────────────
|
||||
check_root() {
|
||||
if [[ "${EUID}" -ne 0 ]]; then
|
||||
if command_exists sudo; then
|
||||
echo_binfo "User is not root. Using sudo for privileged operations."
|
||||
_sudo="sudo"
|
||||
else
|
||||
echo_error "No sudo found and you're not root! Can't install packages."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo_binfo "Root access confirmed."
|
||||
_sudo=""
|
||||
fi
|
||||
}
|
||||
|
||||
install_pkg() {
|
||||
bash -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/snippets/install_pkg.sh)" -- "$@"
|
||||
}
|
||||
|
||||
i_blesh() {
|
||||
dir="$(mktemp -d)"
|
||||
local deps=("bash" "git" "make" "gawk")
|
||||
for pkg in "${deps[@]}"; do
|
||||
if ! command_exists "$pkg"; then
|
||||
install_pkg "$pkg"
|
||||
fi
|
||||
done &&
|
||||
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git "$dir" &&
|
||||
make -C "$dir" install PREFIX=$HOME/.local
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo_info "Do you want to clear the temp dir ($dir/) which was created for installation? [Y|n]" && read -r ask_dir
|
||||
case "$ask_dir" in
|
||||
[Nn])
|
||||
echo_info "All right, didn't clean anything!"
|
||||
;;
|
||||
[Yy] | *)
|
||||
$_sudo command rm -rf "$dir/"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main() {
|
||||
# Check root access and set _sudo
|
||||
if ! check_root; then
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -f $HOME/.local/share/blesh/ble.sh ]]; then
|
||||
i_blesh
|
||||
cleanup
|
||||
else
|
||||
echo_info "Blesh is already installed"
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue