2020-04-02 08:38:36 +00:00
|
|
|
#!/bin/zsh
|
|
|
|
|
|
|
|
source ${$(realpath "$0"):h}/lib/common.zsh
|
|
|
|
|
|
|
|
typeset -A interpreter_checked
|
2020-08-11 10:09:05 +00:00
|
|
|
have_dependency() {
|
2020-04-02 08:38:36 +00:00
|
|
|
if [[ ! $interpreter_checked[$1] ]]; then
|
|
|
|
check "Checking for $1… "
|
2020-11-24 21:47:03 +00:00
|
|
|
if which $1 &> /dev/null; then
|
2020-04-02 08:38:36 +00:00
|
|
|
succeed
|
|
|
|
interpreter_checked[$1]=1
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
fail "not found in path"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uses_interpreter() {
|
|
|
|
head -n 1 $2 | grep -q $1
|
|
|
|
}
|
|
|
|
|
2020-08-11 10:09:05 +00:00
|
|
|
get_dependencies() {
|
|
|
|
sed -n '2{/^#dep:/{s/^#dep://;p;q}}' $1
|
|
|
|
}
|
|
|
|
|
2020-04-02 08:38:36 +00:00
|
|
|
if [[ -z $1 ]]; then
|
|
|
|
<<-HELP
|
2020-11-27 13:34:41 +00:00
|
|
|
Usage: $0 [opts] <program_names>
|
|
|
|
Options:
|
|
|
|
-p, --path PATH target directory to install into (defaults to ~/.local/bin)
|
|
|
|
-f, --force overwrite existing files in the same dir
|
|
|
|
-s, --skip when installing several scripts, skip scripts with unmet
|
|
|
|
dependencies instead of aborting.
|
2020-04-02 08:38:36 +00:00
|
|
|
HELP
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-11-27 13:34:41 +00:00
|
|
|
zparseopts -D -E p:=install_path -path:=install_path f=force -force=force \
|
|
|
|
s=skip -skip=skip
|
2020-04-02 08:38:36 +00:00
|
|
|
|
|
|
|
if [[ ! $install_path ]]; then
|
|
|
|
install_path=$HOME/.local/bin
|
2020-11-24 21:54:06 +00:00
|
|
|
else
|
|
|
|
install_path=${install_path[2]}
|
2020-04-02 08:38:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
for prog in $@; do
|
2020-08-11 10:09:05 +00:00
|
|
|
for lang in zsh ruby python amm; do
|
2020-04-02 08:38:36 +00:00
|
|
|
if uses_interpreter $lang $prog; then
|
2020-08-11 10:09:05 +00:00
|
|
|
have_dependency $lang || exit 1
|
2020-04-02 08:38:36 +00:00
|
|
|
fi
|
|
|
|
done
|
2020-08-11 10:09:05 +00:00
|
|
|
for dep in $(get_dependencies $prog); do
|
2021-01-11 09:35:04 +00:00
|
|
|
if ! have_dependency $dep; then
|
2020-11-27 13:34:41 +00:00
|
|
|
if [[ $skip ]]; then
|
|
|
|
continue 2
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2020-08-11 10:09:05 +00:00
|
|
|
done
|
2020-04-02 08:38:36 +00:00
|
|
|
if [[ -e $install_path/${prog:t} && ! $force ]]; then
|
2020-04-02 08:43:50 +00:00
|
|
|
warning "$prog already exists at $install_path. Skipping."
|
2020-04-02 08:38:36 +00:00
|
|
|
else
|
2020-11-24 21:54:06 +00:00
|
|
|
check "Installing $prog… "
|
|
|
|
ln -fsr $prog $install_path || fail
|
|
|
|
succeed
|
2020-04-02 08:38:36 +00:00
|
|
|
fi
|
|
|
|
done
|