2022-01-18 15:54:39 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#colors
|
2022-09-02 16:05:05 -05:00
|
|
|
|
|
|
|
# remove tput just use ansi
|
|
|
|
MAGENTA="\033[35m"
|
|
|
|
CYAN="\033[34m"
|
|
|
|
YELLOW="\033[33m"
|
|
|
|
RED="\033[31m"
|
|
|
|
GREEN="\033[32m"
|
|
|
|
NORMAL="\033[0m"
|
2022-01-18 15:54:39 -06:00
|
|
|
|
2022-01-22 16:47:19 -06:00
|
|
|
BIN_DIR=$HOME/bin
|
|
|
|
YAMLDOC="$DOTFILES_DIR/info/tools.yml"
|
|
|
|
INSTALL_YES=${GREEN}✓${NORMAL}
|
|
|
|
INSTALL_NO=${RED}✗${NORMAL}
|
|
|
|
|
|
|
|
# get current binary files
|
|
|
|
shopt -s nullglob
|
|
|
|
BINARY_FILES=($HOME/bin/*)
|
|
|
|
|
2022-09-02 16:05:05 -05:00
|
|
|
|
|
|
|
export EGET_BIN=$HOME/bin
|
2022-01-18 15:54:39 -06:00
|
|
|
alias eget="eget --system linux/amd64"
|
|
|
|
|
|
|
|
post_download_install() {
|
|
|
|
|
|
|
|
tool=$1
|
|
|
|
temp_file=$(mktemp -p . ${tool}.XXX.sh)
|
|
|
|
key=$tool yq e 'explode(.) | .[env(key)].post-download' $YAMLDOC >$temp_file
|
|
|
|
. $temp_file
|
|
|
|
rm $temp_file
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
eget_tool() {
|
|
|
|
|
|
|
|
tool=$1
|
|
|
|
|
|
|
|
echo -n $tool
|
|
|
|
|
|
|
|
user=$(key=$tool yq e 'explode(.) | .[env(key)].user' $YAMLDOC)
|
|
|
|
asset=$(key=$tool yq e 'explode(.) | .[env(key)].asset // ""' $YAMLDOC)
|
|
|
|
file=$(key=$tool yq e 'explode(.) | .[env(key)].file // ""' $YAMLDOC)
|
|
|
|
to=$(key=$tool yq e 'explode(.) | .[env(key)].to // ""' $YAMLDOC)
|
|
|
|
download_only=$(key=$tool yq e 'explode(.) | .[env(key)].download-only // ""' $YAMLDOC)
|
2022-07-29 09:44:46 -05:00
|
|
|
custom_flags=$(key=$tool yq e 'explode(.) | .[env(key)].custom_flags // ""' $YAMLDOC)
|
2022-01-18 15:54:39 -06:00
|
|
|
|
|
|
|
eget $user/$tool \
|
|
|
|
${asset:+--asset $asset} \
|
|
|
|
${file:+--file $file} \
|
|
|
|
${to:+--to $to} \
|
|
|
|
${download_only:+--download-only} \
|
2022-07-29 09:44:46 -05:00
|
|
|
${custom_flags} \
|
2022-01-18 15:54:39 -06:00
|
|
|
-q
|
|
|
|
|
|
|
|
if [[ $download_only ]]; then
|
|
|
|
echo -n ' --> '
|
2022-01-21 10:06:40 -06:00
|
|
|
echo -n 'running post-download script'
|
2022-01-18 15:54:39 -06:00
|
|
|
post_download_install $tool
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
deps_check() {
|
|
|
|
|
2022-01-22 16:47:19 -06:00
|
|
|
mkdir -p $BIN_DIR
|
2022-01-18 15:54:39 -06:00
|
|
|
if ! $(is-executable eget); then
|
|
|
|
echo "I don't see eget on your path..."
|
|
|
|
read -p "Do you want to download it to ${BIN_DIR}? " -n 1 -r
|
|
|
|
echo # (optional) move to a new line
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
curl https://zyedidia.github.io/eget.sh | sh
|
|
|
|
mv eget $BIN_DIR/eget
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! $(is-executable yq); then
|
|
|
|
eget mikefarah/yq --asset yq_linux_amd64
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-22 16:47:19 -06:00
|
|
|
get_days() {
|
|
|
|
install_date=$1
|
|
|
|
date_out=$(date -d @$1 +'%Y.%m.%d %R')
|
|
|
|
now=$(date +'%s')
|
|
|
|
days=$(((now - install_date) / 86400))
|
|
|
|
if ((days > 60)); then
|
|
|
|
echo "${RED}$date_out${NORMAL}"
|
|
|
|
elif ((days > 30)); then
|
|
|
|
echo "${YELLOW}$date_out${NORMAL}"
|
|
|
|
else
|
|
|
|
echo "$date_out"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_install() {
|
|
|
|
bin_name=$BIN_DIR/$1
|
|
|
|
if printf '%s\n' "${BINARY_FILES[@]}" | grep -Fxq "$bin_name"; then
|
|
|
|
modified=$(date -r $bin_name +'%s')
|
|
|
|
echo $(get_days $modified)
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:54:39 -06:00
|
|
|
list() {
|
2022-01-22 16:47:19 -06:00
|
|
|
|
2022-01-18 15:54:39 -06:00
|
|
|
deps_check
|
|
|
|
|
|
|
|
user_len=$(yq e '.[] | .user ' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1)
|
|
|
|
tool_len=$(yq e 'keys| .[]' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1)
|
2022-06-15 14:28:16 -05:00
|
|
|
table_width=$((user_len + tool_len + 25))
|
2022-01-22 16:47:19 -06:00
|
|
|
tool_cell=$(printf "%${tool_len}s" "")
|
|
|
|
user_cell=$(printf "%${user_len}s" "")
|
2022-01-18 15:54:39 -06:00
|
|
|
|
2022-09-02 16:05:05 -05:00
|
|
|
echo -e "${CYAN}CONFIGURED TOOLS${NORMAL}"
|
2022-01-18 15:54:39 -06:00
|
|
|
printf "%${table_width}s\n" "" | tr ' ' =
|
2022-01-22 16:47:19 -06:00
|
|
|
printf \
|
|
|
|
"${CYAN}tool${NORMAL}%s | \
|
|
|
|
${CYAN}author${NORMAL}%s | \
|
|
|
|
${CYAN} install date${NORMAL}\n" \
|
2022-06-15 14:28:16 -05:00
|
|
|
"${tool_cell:4}" "${user_cell:6}"
|
2022-01-18 15:54:39 -06:00
|
|
|
printf "%${table_width}s\n" "" | tr ' ' -
|
|
|
|
readarray tools < <(yq e 'keys | .[]' $YAMLDOC)
|
|
|
|
#sort tools for readability
|
|
|
|
tools=($(echo "${tools[@]:1}" | tr ' ' '\n' | sort | uniq))
|
|
|
|
for tool in "${tools[@]}"; do
|
2022-01-22 16:47:19 -06:00
|
|
|
|
2022-01-18 15:54:39 -06:00
|
|
|
user=$(key=$tool yq e 'explode(.) | .[env(key)].user' $YAMLDOC)
|
2022-01-22 16:47:19 -06:00
|
|
|
bin_name=$(key=$tool yq e 'explode(.) | .[env(key)].to' $YAMLDOC)
|
2022-06-15 14:28:16 -05:00
|
|
|
[[ $bin_name == "null" ]] && bin_name=$tool
|
2022-01-22 16:47:19 -06:00
|
|
|
|
|
|
|
modified=$(check_install $bin_name)
|
|
|
|
|
2022-06-15 14:28:16 -05:00
|
|
|
! [[ -z $modified ]] && installed=$INSTALL_YES || installed=$INSTALL_NO
|
2022-01-22 16:47:19 -06:00
|
|
|
|
|
|
|
printf \
|
|
|
|
"${MAGENTA}%s${NORMAL}%s | \
|
|
|
|
${YELLOW}%s${NORMAL}%s | \
|
|
|
|
$installed $modified\n" \
|
|
|
|
$tool "${tool_cell:${#tool}}" \
|
|
|
|
$user "${user_cell:${#user}}"
|
2022-01-18 15:54:39 -06:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
download() {
|
|
|
|
if ! [ -z "$1" ]; then
|
|
|
|
tool=$1
|
2022-01-21 10:06:40 -06:00
|
|
|
|
|
|
|
echo "installing $tool"
|
2022-01-18 15:54:39 -06:00
|
|
|
info=$(key=$tool yq e 'explode(.) | .[env(key)]' $YAMLDOC)
|
|
|
|
if [[ $info == "null" ]]; then
|
|
|
|
echo "$tool not found in $YAMLDOC"
|
|
|
|
echo "exiting"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
eget_tool $tool
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
download_all() {
|
|
|
|
|
|
|
|
echo "Downloading binaries to ${GREEN}$BIN_DIR${NORMAL}"
|
|
|
|
|
|
|
|
deps_check
|
|
|
|
|
|
|
|
readarray tools < <(yq e 'keys | .[]' $YAMLDOC)
|
|
|
|
echo "installing......"
|
|
|
|
|
|
|
|
for tool in "${tools[@]:1}"; do
|
|
|
|
eget_tool $tool
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
eget/yq powered binary downloader
|
|
|
|
|
|
|
|
usage: tools [tool tool2 ...]
|
|
|
|
|
|
|
|
optional flags:
|
|
|
|
-h, --help show this help text
|
|
|
|
-l, --list list all tools
|
|
|
|
-a, --all download all tools
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
for opt in "$@"; do
|
|
|
|
case $opt in
|
|
|
|
-h | --help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-l | --list)
|
|
|
|
list
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-a | --all)
|
|
|
|
download_all
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-* | --*)
|
|
|
|
echo "Invalid option: $opt"
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
args+=("$opt")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# if no args, show help
|
|
|
|
|
|
|
|
if [ -z "$args" ]; then
|
|
|
|
echo "${RED}No arguments supplied${NORMAL}"
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "Downloading binaries to ${GREEN}$BIN_DIR${NORMAL}"
|
|
|
|
deps_check
|
2022-09-02 16:05:05 -05:00
|
|
|
for tool in "${args[@]}"; do
|
|
|
|
download "$tool"
|
2022-01-18 15:54:39 -06:00
|
|
|
done
|
|
|
|
fi
|