#!/bin/zsh source ${$(realpath "$0"):h}/lib/common.zsh typeset -A interpreter_checked have_dependency() { if [[ ! $interpreter_checked[$1] ]]; then check "Checking for $1… " for variant in ${(s.|.)1}; do if which $variant &> /dev/null; then succeed interpreter_checked[$1]=1 return 0 fi done fail "not found in path" return 1 fi } uses_interpreter() { head -n 1 $2 | grep -q $1 } get_interpreter() { parts=(${(s: :)$(head -n 1 $1)}) main=${parts[1]:t} shift 1 parts if [[ $main == 'env' ]]; then while [[ ${parts[1][1]} == '-' ]]; do shift 1 parts; done echo ${parts[1]} else echo $main fi } get_dependencies() { sed -n '2,4{/^#dep:/{s/^#dep://;p;q}}' $1 } get_flatpak_dependencies() { sed -n '2,4{/^#flatpak:/{s/^#flatpak://;p;q}}' $1 } have_flatpak() { check "Checking for flatpak: $1… " flatpak info "$@" &> /dev/null } install_flatpak() { if [[ ! -e flatpaks/.repos/$1 ]]; then fail "Unknown flatpak repo: $1. Add its URL in flatpaks/.repos/$1" else flatpak --user remote-add --if-not-exists $1 $( Options: -a, --all install all scripts (except flatpaks) -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. --no-flatpak do not automatically install flatpak deps (still checks for them) HELP exit 1 } [[ -z $1 ]] && usage zparseopts -D -E p:=install_path -path:=install_path f=force -force=force \ s=skip -skip=skip -no-flatpak=noflatpakinstall a=all -all=all l=list -list=list -help=help h=help [[ $help ]] && usage if [[ ! $install_path ]]; then install_path=$HOME/.local/bin else install_path=${install_path[2]} fi if [[ $list ]]; then all_scripts=( devel/* flatpaks/* misc/* void/* xdg-wrappers/* ) installed=() not_installed=() for script in $all_scripts; do if [[ -e $install_path/${script:t} ]]; then installed+=($script) else not_installed+=($script) fi done printf "\e[4;34mInstalled:\e[0m\n" for script in $installed; do printf " %s\n" $script done printf "\e[4;34mNot installed:\e[0m\n" for script in $not_installed; do printf " %s\n" $script done exit 0 fi if [[ $all ]]; then set - devel/* flatpaks/* misc/* void/* xdg-wrappers/* fi for prog in $@; do install_prog $prog done