2022-02-03

This commit is contained in:
Louis Seubert 2022-02-03 19:33:04 +01:00
parent f86b8496ec
commit db393215ce
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
55 changed files with 1907 additions and 0 deletions

View file

@ -0,0 +1,31 @@
# -*- mode: bash -*-
function abort() {
local status="${1:?"abort requires status"}"
local reason="${2:?"abort requires reason"}"
shift 2
# here we want the string as template
# shellcheck disable=SC2059
printf "error: ${reason}\n" "$@" >&2
exit "${status}"
}
function has_software() {
for software in "$@"; do
type "${software}" >/dev/null 2>&1 ||
abort 1 $"%s not found in path\n" "${software}"
done
}
function import() {
local name path file
for name in "$@"; do
local IFS=:; set -o noglob
for path in ${IMPORTPATH}; do
file="${path}/${name}"
[[ -e "${file}" && -r "${file}" ]] && {
source "${file}" && continue 2 || return 1
}
done
done
}

View file

@ -0,0 +1,20 @@
# -*- mode: bash -*-
[[ ! "${LIB_SHELL_GITHUB}" ]] && LIB_SHELL_GITHUB="Y" || return
has_software 'jq' 'curl'
function github_api() {
curl -L --silent -H "Accept: application/vnd.github.v3.raw+json" \
${TOKEN:+ -H "Authorization: Token ${TOKEN}"} "$@"
}
github_get_latest_release() {
local user="${1:?'require name'}" repo="${2:-"$1"}"
github_api "https://api.github.com/repos/${user}/${repo}/releases/latest"
}
github_latest_release_assets() {
local name="\$doc.tag_name"
local link="(\$doc.assets[] | select(.name ${SUFFIX:+"| endswith(\"${SUFFIX}\")"}).browser_download_url)"
github_get_latest_release "$@" | jq -r ". as \$doc | ${name} + \" \" + ${link}"
}

View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Shell options which will be like a strict mode
set -${DEBUG:+x}euo pipefail
# This script should be sourced before any of
# the other scripts in this repo. Other scripts
# make use of ${BASH_LIB_DIR} to find each other.
# Get the relative path to the repo root
# shellcheck disable=SC2086
BASH_LIB_DIR_RELATIVE="$(dirname ${BASH_SOURCE[0]})"
# Must be set in order to load the filehandling
# module. Will be updated when abs_path is available.
BASH_LIB_DIR="${BASH_LIB_DIR_RELATIVE}"
for name in common; do
source "${BASH_LIB_DIR_RELATIVE}/${name}/${name}.sh"
done
# Filter functions and re export only bash-lib functions to subshells
eval "$(declare -F | sed -e 's/-f /-fx /' | grep 'x bl_')"
# Export the absolute path
# shellcheck disable=SC2086
BASH_LIB_DIR="$(realpath ${BASH_LIB_DIR_RELATIVE})"
export BASH_LIB_DIR
MODULEPATH="${MODULEPATH:+"${MODULEPATH}:"}"

View file

@ -0,0 +1,41 @@
# -*- mode: bash -*-
# shellcheck disable=SC2059
[[ ! "${LIB_SHELL_INTERACTION}" ]] && LIB_SHELL_INTERACTION="Y" || return
SYMBOL_SUCCESS="✔"
SYMBOL_FAILURE="✘"
SYMBOL_ARROW="➜"
COLOR_NORMAL="\\e[00m"
# check if stdout is a tty so we can use color code
if [[ -t 1 ]]; then
SH_LIB_PREFIX_WARN="[ \\[\\e[01;33m\\]WARN\\[\\e[00;00m\\] ] "
SH_LIB_PREFIX_INFO="[ \\[\\e[01;34m\\]INFO\\[\\e[00;00m\\] ] "
SH_LIB_PREFIX_SUCCESS="[ \\[\\e[01;31m\\]FAILURE\\[\\e[00;00m\\] ] "
SH_LIB_PREFIX_FAILURE="[ \\[\\e[01;32m\\]SUCCESS\\[\\e[00;00m\\] ] "
fi
function @warn() {
local format="${1:?"require format"}" && shift
printf "${SH_LIB_PREFIX_WARN@P}${format}\n" "${@}"
}
function @info() {
local format="${1:?"require format"}" && shift
printf "${SH_LIB_PREFIX_INFO@P}${format}\n" "${@}"
}
function @success() {
local format="${1:?"require format"}" && shift
printf "${SH_LIB_PREFIX_SUCCESS@P}${format}\n" "${@}"
}
function @failure() {
local format="${1:?"require format"}" && shift
printf "${SH_LIB_PREFIX_FAILURE@P}${format}\n" "${@}"
}
# ➜