check_ubuntu 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. } else {
  14. log_error "Unable to determine local Linux distribution, but Ubuntu is required. Aborting"
  15. log_group
  16. return 2
  17. }
  18. local -a dependencies=("${(fA)$(<${SCRIPT_HOME}/.Aptfile)}")
  19. local -a install_list
  20. local binary
  21. sudo apt-get update -qq
  22. for dependency (${dependencies}) {
  23. local -a tokens=(${=dependency//(,|:|\')/})
  24. if [[ ! ${tokens[1]} == package ]] continue
  25. if [[ ${#tokens} -gt 2 && ${tokens[3]} == bin ]] {
  26. binary=${tokens[4]}
  27. } else {
  28. binary=${tokens[2]}
  29. }
  30. if (( ! ${+commands[${binary}]} )) install_list+=(${tokens[2]})
  31. }
  32. log_debug "List of dependencies to install: ${install_list}"
  33. if (( #install_list )) {
  34. sudo apt-get -y --no-install-recommends install ${install_list}
  35. }
  36. rehash
  37. log_group