diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2017-09-14 01:54:09 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2017-09-14 02:03:10 -0400 |
commit | 14ff5c44ea1825aeefc92003a0545eff64726b53 (patch) | |
tree | 2da5555c307c057cf4deb9aedaa30cfc85815980 /tools/dependencies | |
parent | 02570dfcaf8f7665db1c8be4b9365443d8579c9f (diff) | |
download | librebootfr-14ff5c44ea1825aeefc92003a0545eff64726b53.tar.gz librebootfr-14ff5c44ea1825aeefc92003a0545eff64726b53.zip |
Create 'dependencies' tool to print dependencies
Mostly reimplements the old dependency-fetching scripts from
resources/scripts/helpers/build/dependencies, though instead of
fetching the requisite dependencies for the user, it prints them to
stdout.
The scripts do not perform any downloading/installation due to root
privileges being necessary to carry it out.
Diffstat (limited to 'tools/dependencies')
-rwxr-xr-x | tools/dependencies/dependencies | 57 | ||||
-rwxr-xr-x | tools/dependencies/dependencies-helper | 73 |
2 files changed, 130 insertions, 0 deletions
diff --git a/tools/dependencies/dependencies b/tools/dependencies/dependencies new file mode 100755 index 00000000..13d56f74 --- /dev/null +++ b/tools/dependencies/dependencies @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Copyright (C) 2017 Andrew Robbins <contact@andrewrobbins.info> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +arguments() { + tool_arguments_targets "${tool}" "$@" +} + +usage() { + tool_usage_actions "${tool}" 'print' + tool_usage_arguments "${tool}" "$@" +} + +print() { + local distro="$1" + + local arch="$(uname -i || uname -m)" + local tool_path="$(tool_path "${tool}")" + + if [[ -z "${arch}" ]]; then + printf '\n%s\n' 'uname(1) produced no output. Exiting' 1>&2 + + return 1 + fi + + dependencies_host_supported "${distro}" "${arch}" || return + + local -a dependencies + + for dependency_file in "${tool_path}/${CONFIGS}/${distro}/${arch}"/*; do + if [[ "${dependency_file##*/}" != 'README' ]]; then + local -i origin="${#dependencies[@]}" + + mapfile -tO "${origin}" dependencies < "${dependency_file}" + else + continue + fi + done + + local -a sorted + mapfile -t sorted < <(printf '%s\n' "${dependencies[@]}" | sort | uniq) + + dependencies_print "${distro}" "${sorted[@]}" +} diff --git a/tools/dependencies/dependencies-helper b/tools/dependencies/dependencies-helper new file mode 100755 index 00000000..36d2f3ea --- /dev/null +++ b/tools/dependencies/dependencies-helper @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Copyright (C) 2017 Andrew Robbins <contact@andrewrobbins.info> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +dependencies_print() { + local distro="$1" + shift + + if [[ "${distro}" == 'parabola' ]]; then + printf '\n%s\n' 'Enable the multilib repository in /etc/pacman.conf' + printf '\n%s\n' 'Then, run the following command as root:' + printf '\n%s%s\n' 'pacman -S --needed ' "$*" + else + printf '\n%s\n' 'You will need to run the following command as root:' + printf '\n%s%s\n' 'apt-get -y install ' "$*" + fi +} + +dependencies_host_supported() { + local distro="$1" + local arch="$2" + + dependencies_distro_supported "${distro}" || return + dependencies_arch_supported "${distro}" "${arch}" || return +} + +dependencies_arch_supported() { + local distro="$1" + local arch="$2" + + local tool_path="$(tool_path "${tool}")" + local distro_dir="${tool_path}/${CONFIGS}/${distro}" + + if ! [[ -d "${distro_dir}/${arch}" ]]; then + printf '\n%s\n' "Architecture \"${arch}\" is not supported" 1>&2 + + return 1 + fi +} + +dependencies_distro_supported() { + local distro="$1" + + local tool_path="$(tool_path "${tool}")" + local targets_path="${tool_path}/${CONFIGS}/${TARGETS}" + + local -a targets_list + mapfile -t targets_list < "${targets_path}" + + # Necessary to properly format the string for extglob use below + IFS='|' eval 'local distro_list="${targets_list[*]}"' + + if [[ "${distro}" != @(${distro_list}) ]]; then + printf '\n%s' "Argument \"${distro}\" is not supported. " 1>&2 + printf '%s\n' 'Check spelling?' 1>&2 + + usage + return 1 + fi +} |