qvm-template-repo-query 861 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/bash
  2. OPTS=()
  3. SPEC=
  4. while IFS= read -r line; do
  5. if [ "$line" = "---" ]; then
  6. break
  7. fi
  8. case "$line" in
  9. --enablerepo=*|\
  10. --disablerepo=*|\
  11. --repoid=*|\
  12. --repofrompath=*|\
  13. --releasever=*)
  14. OPTS+=("$line")
  15. ;;
  16. *)
  17. SPEC="$line"
  18. ;;
  19. esac
  20. done
  21. repodir=$(mktemp -d)
  22. cat > "$repodir/template.repo"
  23. OPTS+=("--setopt=reposdir=${repodir}")
  24. OPTS+=("--quiet")
  25. RET=0
  26. if [ "$1" = "query" ]; then
  27. # shellcheck disable=SC2068
  28. dnf repoquery ${OPTS[@]} --qf='%{name}:%{epoch}:%{version}:%{release}:%{reponame}:%{downloadsize}:%{summary}' "$SPEC"
  29. RET="$?"
  30. elif [ "$1" = "download" ]; then
  31. # shellcheck disable=SC2068
  32. curl -L "$(dnf download ${OPTS[@]} --url "$SPEC" | shuf -n 1)" -o -
  33. RET="$?"
  34. fi
  35. rm -r "$repodir"
  36. exit "$RET"