#!/bin/bash
#  tool - Tool script support

set -e


######
# Public interface

tool_category() { [ "${1/\//}" = "$1" ] || echo "${1%/*}"; }

tool_cats() {
	local -a cats=( "$@" )
	[ "${cats[*]}" ] || cats=( "${APPS[@]}" )
	list_map tool_category cats
	list_filter_empty cats
	list_unique cats
	qsort_list cats
	local IFS=$'\n'
	echo "${cats[*]}"
}

tool_name() { echo "${1##*/}"; }

tool_names() {
	local -a names=( "$@" )
	[ "${names[*]}" ] || names=( "${APPS[@]}" )
	list_map tool_name names
	qsort_list cats
	local IFS=$'\n'
	echo "${names[*]}"
}

tool_symbol() { echo "tool_$1"; }

is_tool() { in_list $1 "${package_apps[@]}"; }

for_each_tool() { run_for_each "$*" "${package_tools[@]}"; }

run_each_tool() {

	local -a tool_args=( "$@" )
	for_each _run_each_tool "${package_tools[@]}"
}
_run_each_tool() {
	min_args 1 "$@"
	local -a args=( "$@" )

	local last=$((${#args[*]} - 1))
	local tool=${args[@]:$last}
	args=( "${args[@]:0:$last}" )
	run $tool "${args[@]}"
}

run_tool_version() { quiet=true run $1 version; }


######
# Tool library commands (e.g. config, client, server)

#  $1 - package name
tool_class_deps() {
	local class=$1
	run_each_tool $class deps | xargs -n 1 echo | sort -u
}

#  $1 - library name
tool_class_install() {
	local class=$1
	local -a deps
	deps=( $(tool_class_deps $class) )
	apt_install "${deps[@]}"
}

View the Script Reference Index


Generated on Tue Apr 25 21:20:19 PDT 2017 by mcsh i7 v0.18.0.