check_ubuntu 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. autoload -Uz log_debug log_group
  2. log_group 'Check Ubuntu build requirements'
  3. log_debug 'Checking Ubuntu distribution name and version...'
  4. if [[ -f /etc/os-release ]] {
  5. local dist_name
  6. local dist_version
  7. read -r dist_name dist_version <<< "$(source /etc/os-release; print "${NAME} ${VERSION_ID}")"
  8. if [[ ${dist_name} != Ubuntu ]] {
  9. log_error "Not running on an Ubuntu distribution. Aborting"
  10. log_group
  11. return 2
  12. }
  13. autoload -Uz is-at-least && if ! is-at-least 24.04 ${dist_version}; then
  14. log_error "Not running on a recent-enough Ubuntu distribution. Aborting"
  15. log_group
  16. return 2
  17. fi
  18. } else {
  19. log_error "Unable to determine local Linux distribution, but Ubuntu is required. Aborting"
  20. log_group
  21. return 2
  22. }
  23. local -a dependencies=("${(fA)$(<${SCRIPT_HOME}/.Aptfile)}")
  24. local -a install_list
  25. local binary
  26. sudo apt-get update -qq
  27. for dependency (${dependencies}) {
  28. local -a tokens=(${=dependency//(,|:|\')/})
  29. if [[ ! ${tokens[1]} == package ]] continue
  30. if [[ ${#tokens} -gt 2 && ${tokens[3]} == bin ]] {
  31. binary=${tokens[4]}
  32. } else {
  33. binary=${tokens[2]}
  34. }
  35. if (( ! ${+commands[${binary}]} )) install_list+=(${tokens[2]})
  36. }
  37. log_debug "List of dependencies to install: ${install_list}"
  38. if (( #install_list )) {
  39. sudo apt-get -y --no-install-recommends install ${install_list}
  40. }
  41. rehash
  42. log_group