dotfiles/tools.sh

87 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2021-12-08 09:38:24 -06:00
BIN_DIR=$HOME/bin
mkdir -p $BIN_DIR
EGET_BIN=$BIN_DIR
2022-01-04 13:45:12 -06:00
YAMLDOC="info/tools.yml"
alias eget="eget --system linux/amd64"
post_download_install() {
2022-01-09 18:16:55 -06:00
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
}
2021-12-08 09:38:24 -06:00
2022-01-04 13:45:12 -06:00
eget_tool() {
2022-01-09 18:16:55 -06:00
tool=$1
2022-01-04 13:45:12 -06:00
2022-01-09 18:16:55 -06:00
echo -n $tool
2022-01-04 13:45:12 -06:00
2022-01-09 18:16:55 -06:00
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-01-04 13:45:12 -06:00
2022-01-09 18:16:55 -06:00
eget $user/$tool \
${asset:+--asset $asset} \
${file:+--file $file} \
${to:+--to $to} \
${download_only:+--download-only} \
-q
2022-01-04 13:45:12 -06:00
2022-01-09 18:16:55 -06:00
if [[ $download_only ]]; then
echo -n ' --> '
echo -n 'running post-download script'
post_download_install $tool
fi
2022-01-04 13:45:12 -06:00
2022-01-09 18:16:55 -06:00
echo
2022-01-04 13:45:12 -06:00
}
2021-12-08 09:38:24 -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
2022-01-09 18:16:55 -06:00
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
2021-12-08 09:38:24 -06:00
exit 1
else
curl https://zyedidia.github.io/eget.sh | sh
mv eget $BIN_DIR/eget
fi
fi
echo "downloading binaries from github to $EGET_BIN"
if ! $(is-executable yq); then
2022-01-09 18:16:55 -06:00
eget mikefarah/yq --asset yq_linux_amd64
fi
2022-01-04 13:45:12 -06:00
if ! [ -z "$1" ]; then
2022-01-09 18:16:55 -06:00
tool=$1
echo "installing $tool"
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
exit
2022-01-04 13:45:12 -06:00
fi
2021-12-08 09:38:24 -06:00
2022-01-04 13:45:12 -06:00
echo "no tool specified installing everything"
2021-12-08 09:38:24 -06:00
2022-01-04 13:45:12 -06:00
readarray tools < <(yq e 'keys | .[]' $YAMLDOC)
2021-12-08 09:38:24 -06:00
2022-01-09 18:16:55 -06:00
for tool in "${tools[@]:1}"; do
eget_tool $tool
done