aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndrew Robbins <contact@andrewrobbins.info>2017-09-14 01:54:09 -0400
committerAndrew Robbins <contact@andrewrobbins.info>2017-09-14 02:03:10 -0400
commit14ff5c44ea1825aeefc92003a0545eff64726b53 (patch)
tree2da5555c307c057cf4deb9aedaa30cfc85815980 /tools
parent02570dfcaf8f7665db1c8be4b9365443d8579c9f (diff)
downloadlibrebootfr-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')
-rwxr-xr-xtools/dependencies/dependencies57
-rwxr-xr-xtools/dependencies/dependencies-helper73
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
+}