Useful CLI tools (bash) for Arch Linux administration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.5 KiB

  1. #!/bin/env sh
  2. # dummypkg - Create a dummy Arch Linux package
  3. #
  4. # Copyright (C) 2023 Pekka Helenius <pekka.helenius@fjordtek.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. . /usr/share/makepkg/util/message.sh
  19. colorize
  20. if [[ -z $1 ]]
  21. then
  22. error "Provide a package name"
  23. exit 1
  24. fi
  25. PKG=$1
  26. PKGBUILD_FILE="PKGBUILD.tmp"
  27. PACMAN_FILE="pacman.tmp"
  28. msg "Preparing dummy package: $PKG"
  29. description="dummy package"
  30. version="0.1"
  31. release="1"
  32. provides=($PKG)
  33. purge() {
  34. msg "Cleaning up..."
  35. pkgfile_prefix="$PKG-$version-$release-any.pkg.tar"
  36. pkgfile=$(find . -maxdepth 1 -type f -iname "${pkgfile_prefix}*" | head -1)
  37. [[ -f ${pkgfile} ]] && rm -f ${pkgfile}
  38. [[ -f ${PKGBUILD_FILE} ]] && rm -f ${PKGBUILD_FILE}
  39. [[ -f ${PACMAN_FILE} ]] && rm -f ${PACMAN_FILE}
  40. [[ -d src ]] && rm -rf src
  41. [[ -d pkg ]] && rm -rf pkg
  42. exit $1
  43. }
  44. remote_info() {
  45. pacman_info=$(pacman -Si $PKG > $PACMAN_FILE)
  46. if [[ $? -eq 0 ]]
  47. then
  48. # Description
  49. description=$(echo $(grep -oP "^Description.*: \K.*(?=.*)" $PACMAN_FILE) "("$description")")
  50. # Provides
  51. provides_pkgs=($(grep -oP "^Provides.*: \K[^A-Z]*(?=[^A-Z]*)" $PACMAN_FILE))
  52. provides=(${provides[@]} ${provides_pkgs[@]})
  53. # Version
  54. version_full=$(grep -oP "^Version.*: \K.*(?=.*)" $PACMAN_FILE)
  55. version=$(echo $version_full | awk '{sub(/-.*/,"",$0); print $0}')
  56. release=$(echo $version_full | awk '{sub(/.*-/,"",$0); print $0}')
  57. fi
  58. }
  59. trap "purge 1" SIGINT SIGKILL SIGABRT SIGTERM
  60. msg "Setting version number and provided packages information..."
  61. remote_info
  62. msg2 "Description: ${description}"
  63. msg2 "Provides: ${provides[*]}"
  64. msg2 "Version: $version"
  65. msg2 "Release: $release"
  66. cat <<EOF > ${PKGBUILD_FILE}
  67. pkgname="${PKG}"
  68. pkgver=$version
  69. pkgrel=$release
  70. pkgdesc="${description}"
  71. arch=(any)
  72. provides=(${provides[@]})
  73. groups=(dummy)
  74. EOF
  75. if [[ ! -f ${PKGBUILD_FILE} ]]
  76. then
  77. error "No PKGBUILD found"
  78. exit 1
  79. fi
  80. makepkg -Cfi -p ${PKGBUILD_FILE}
  81. purge 0