qvm-template-repo-query 830 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. --releasever=*)
  13. OPTS+=("$line")
  14. ;;
  15. *)
  16. SPEC="$line"
  17. ;;
  18. esac
  19. done
  20. repodir=$(mktemp -d)
  21. cat > "$repodir/template.repo"
  22. OPTS+=("--setopt=reposdir=${repodir}")
  23. OPTS+=("--quiet")
  24. RET=0
  25. if [ "$1" = "query" ]; then
  26. dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
  27. RET="$?"
  28. elif [ "$1" = "download" ]; then
  29. curl --silent -L "$(dnf download "${OPTS[@]}" --url "$SPEC" | shuf -n 1)" -o -
  30. RET="$?"
  31. fi
  32. rm -r "$repodir"
  33. exit "$RET"