tmux, bash, mgmt fiddling
This commit is contained in:
parent
6649cfc78d
commit
c653422734
11 changed files with 160 additions and 11 deletions
35
private_dot_config/private_mgmt/fns/bin_from.bash
Normal file
35
private_dot_config/private_mgmt/fns/bin_from.bash
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# shellcheck shell=bash
|
||||
bin_from() {
|
||||
name="$1"
|
||||
url="$2"
|
||||
flag="$3"
|
||||
|
||||
if [[ -z "$name" || -z "$url" ]]; then
|
||||
diag "$(red "error: missing name ($name) or url ($url)!")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$url" == *.tar.gz || "$url" == *.tgz ]]; then
|
||||
dir=$(mktemp -d)
|
||||
if curl -sSL "$url" | tar -C "$dir" -xz 2>&1 | grep -q 'not in gzip format'; then
|
||||
diag "$(red "error: file from $url not in gzip format")"
|
||||
exit 1
|
||||
fi
|
||||
file=$(find "$dir" -type f -name "$name")
|
||||
elif [[ "$url" == *.tar.xz ]]; then
|
||||
dir=$(mktemp -d)
|
||||
curl -sSL "$url" | tar -C "$dir" -xJ
|
||||
file=$(find "$dir" -type f -name "$name")
|
||||
elif [[ "$url" == *.zip ]]; then
|
||||
zip=$(mktemp --suffix=.zip)
|
||||
dir=$(mktemp -d)
|
||||
curl -sSL "$url" > "$zip"
|
||||
unzip -qq "$zip" -d "$dir"
|
||||
file=$(find "$dir" -type f -name "$name")
|
||||
else
|
||||
file="$(mktemp)"
|
||||
curl -sSLo "$file" "$url" || diag "$(red "error from url [$url]")"
|
||||
fi
|
||||
|
||||
install_bin "$name" "$file" "$url" "$flag"
|
||||
}
|
||||
40
private_dot_config/private_mgmt/fns/current.bash
Normal file
40
private_dot_config/private_mgmt/fns/current.bash
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# shellcheck shell=bash
|
||||
#================================================================
|
||||
#% SYNOPSIS
|
||||
#+ current <cmd> [-f <flag>] [-r <regex>]
|
||||
#%
|
||||
#% OPTIONS
|
||||
#% -f set command-line args to pass to <cmd>; single string.
|
||||
#% Default: [--version]
|
||||
#% -r set regex used to extract version string from cmd output
|
||||
#% Default: [v?(\d+\.\d+\.\d+)]
|
||||
#================================================================
|
||||
current() {
|
||||
flag="--version"
|
||||
regex='v?(\d+\.\d+\.\d+)'
|
||||
declare -a args
|
||||
OPTIND=1
|
||||
while [ $OPTIND -le "$#" ]; do
|
||||
if getopts :f:r: opt; then
|
||||
case "$opt" in
|
||||
\?)
|
||||
diag "$(red "error: called 'current' badly")"
|
||||
;;
|
||||
f) flag="$OPTARG" ;;
|
||||
r) regex="$OPTARG" ;;
|
||||
esac
|
||||
else
|
||||
args+=("${!OPTIND}")
|
||||
(( OPTIND++ ))
|
||||
fi
|
||||
done
|
||||
set -- "${args[@]}"
|
||||
|
||||
cmd="$1"
|
||||
|
||||
if command -v "$cmd" >/dev/null; then
|
||||
bash -c "$cmd $flag" | perl -ne 'm/'"$regex"'/ && print "$1\n"' || true
|
||||
else
|
||||
true
|
||||
fi
|
||||
}
|
||||
18
private_dot_config/private_mgmt/fns/github_latest.bash
Normal file
18
private_dot_config/private_mgmt/fns/github_latest.bash
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
github_latest() {
|
||||
repo="$1"
|
||||
tag="${2:-latest}"
|
||||
if [ "$tag" = "--no-latest-tag" ]; then
|
||||
curl -sfSL "https://github.com/$repo/tags" \
|
||||
| perl -ne 'm,a href="/'"$repo"'/releases/tag/v(\d\.\d(?:.\d)?)", && print "$1\n"' \
|
||||
| sort -V \
|
||||
| tail -n1 || echo "[github error]"
|
||||
else
|
||||
curl -sfSI "https://github.com/$repo/releases/$tag" \
|
||||
| grep '^location' \
|
||||
| awk -F/ '{print $NF}' \
|
||||
| sed 's/\s\+$//' || echo "[github error]"
|
||||
fi
|
||||
}
|
||||
|
||||
17
private_dot_config/private_mgmt/fns/install_bin.bash
Normal file
17
private_dot_config/private_mgmt/fns/install_bin.bash
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# shellcheck shell=bash
|
||||
install_bin() {
|
||||
name="$1"
|
||||
file="$2"
|
||||
source="$3"
|
||||
flag="$4"
|
||||
|
||||
if file "$file" | grep -Eqv 'ELF|executable'; then
|
||||
diag "$(red "error: file from $source not an executable")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$flag" != "--no-backup" ] && [ -f "/usr/local/bin/$name" ]; then
|
||||
sudo cp "/usr/local/bin/$name" "/usr/local/bin/$name.old"
|
||||
fi
|
||||
sudo install -m 755 "$file" "/usr/local/bin/$name"
|
||||
}
|
||||
17
private_dot_config/private_mgmt/fns/is_latest.bash
Normal file
17
private_dot_config/private_mgmt/fns/is_latest.bash
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
is_latest() {
|
||||
exe="$1"
|
||||
latest="$2"
|
||||
installed="$3"
|
||||
silent="$4"
|
||||
if ! command -v "$exe" > /dev/null; then
|
||||
diag "$exe not installed; $latest available"
|
||||
return 1
|
||||
elif [ "$latest" = "$installed" ]; then
|
||||
test "$silent" = "silent" || diag "$exe already up to date"
|
||||
elif [ "$latest" = "" ]; then
|
||||
diag "[warn] 'latest' $exe is empty string"
|
||||
else
|
||||
diag "$exe $installed installed, but $latest available"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue