dependencies-helper 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. # Copyright (C) 2017 Andrew Robbins <contact@andrewrobbins.info>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. dependencies_print() {
  17. local distro="$1"
  18. shift
  19. if [[ "$distro" == 'parabola' ]]; then
  20. printf '%s\n' 'Enable the multilib repository in /etc/pacman.conf'
  21. printf '\n%s\n' 'Then, run the following command as root:'
  22. printf '\n%s%s\n' 'pacman -S --needed ' "$*"
  23. else
  24. printf '%s\n' 'You will need to run the following command as root:'
  25. printf '\n%s%s\n' 'apt-get -y install ' "$*"
  26. fi
  27. }
  28. dependencies_host_supported() {
  29. local distro="$1"
  30. local arch="$2"
  31. dependencies_distro_supported "$distro" || return
  32. dependencies_arch_supported "$distro" "$arch" || return
  33. }
  34. dependencies_arch_supported() {
  35. local distro="$1"
  36. local arch="$2"
  37. local tool_path="$(tool_path "$tool")"
  38. local distro_dir="$tool_path/$CONFIGS/$distro"
  39. if ! [[ -d "$distro_dir/$arch" ]]; then
  40. printf '%s\n' "Architecture \"$arch\" is not supported" 1>&2
  41. return 1
  42. fi
  43. }
  44. dependencies_distro_supported() {
  45. local distro="$1"
  46. local tool_path="$(tool_path "$tool")"
  47. local targets_path="$tool_path/$CONFIGS/$TARGETS"
  48. local -a targets_list
  49. mapfile -t targets_list < "$targets_path"
  50. # Necessary to properly format the string for extglob use below
  51. IFS='|' eval 'local distro_list="${targets_list[*]}"'
  52. if [[ "$distro" != @($distro_list) ]]; then
  53. printf '%s' "Argument \"$distro\" is not supported. " 1>&2
  54. printf '%s\n' 'Check spelling?' 1>&2
  55. usage
  56. return 1
  57. fi
  58. }