update-pkgbuild.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. # Produce a working PKGBUILD for the AUR from a template given a tarball.
  3. # Requirements: mzx source tarball named in typical megazeux fashion like so: mzx(version)src.tar.xz, bash, getopt.
  4. # e.g., mzx291gsrc.tar.xz
  5. MYFN=`basename "$0"`
  6. _V=0
  7. function usage () {
  8. cat <<EOUSAGE
  9. Usage:
  10. $MYFN <path>
  11. Creates a PKGBUILD by sha256summing specified MegaZeux tarball and editing a template.
  12. Options:
  13. -h, --help display this help and exit"
  14. EOUSAGE
  15. }
  16. function log () {
  17. if [[ $_V -eq 1 ]]; then
  18. echo "$@"
  19. fi
  20. }
  21. while getopts :hv opt ; do
  22. case $opt in
  23. v)
  24. _V=1
  25. ;;
  26. h)
  27. usage
  28. exit 1
  29. ;;
  30. *)
  31. echo "Invalid option: -$OPTARG" >&2
  32. usage
  33. exit 2
  34. ;;
  35. esac
  36. done
  37. shift $((OPTIND - 1))
  38. if [[ "$1" == "" ]]
  39. then
  40. usage
  41. exit 1
  42. else
  43. log "Generating PKGBUILD..."
  44. sha256sum=($(sha256sum "$1"))
  45. log "Our checksum is $sha256sum"
  46. regex="mzx([0-9])([0-9a-z]+)src\.tar.+"
  47. if [[ $1 =~ $regex ]]
  48. then
  49. version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
  50. log "Our version is $version"
  51. cp PKGBUILD.template PKGBUILD
  52. sed -i "s/pkgver=UNSET/pkgver=$version/g" PKGBUILD
  53. sed -i "s/_sha256sum=UNSET/_sha256sum=$sha256sum/g" PKGBUILD
  54. echo "Done."
  55. else
  56. echo "Error: Tarball does not appear to be MegaZeux. Read script for requirements."
  57. fi
  58. fi