deb-package.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash -e
  2. REPO_URL="https://github.com/eza-community/eza"
  3. NAME="eza"
  4. DESTDIR=/usr/bin
  5. DOCDIR=/usr/share/man/
  6. COMMIT=$(git rev-parse --abbrev-ref HEAD)
  7. TAG=$(git describe --tags "$(git rev-list --tags --max-count=1)")
  8. if [ -n "$1" ]; then
  9. TAG=$1
  10. fi
  11. VERSION=${TAG:1}
  12. echo "checkout tag ${TAG}"
  13. git checkout --quiet "${TAG}"
  14. echo "build man pages"
  15. just man
  16. declare -A TARGETS
  17. TARGETS["amd64"]="x86_64-unknown-linux-musl"
  18. TARGETS["arm64"]="aarch64-unknown-linux-gnu"
  19. TARGETS["armhf"]="arm-unknown-linux-gnueabihf"
  20. echo "download release notes"
  21. RELEASE_NOTES=$(curl -s "${REPO_URL}/releases/tag/${TAG}")
  22. for ARCH in "${!TARGETS[@]}"; do
  23. echo "building ${ARCH} package:"
  24. DEB_TMP_DIR="${NAME}_${VERSION}_${ARCH}"
  25. DEB_PACKAGE="${NAME}_${VERSION}_${ARCH}.deb"
  26. TARGET=${TARGETS[$ARCH]}
  27. echo " -> downloading ${TARGET} archive"
  28. wget -q -O "${ARCH}.tar.gz" "${REPO_URL}/releases/download/${TAG}/${NAME}_${TARGET}.tar.gz"
  29. echo " -> verifying ${TARGET} archive"
  30. CHECKSUM=$(md5sum "${ARCH}.tar.gz" | cut -d ' ' -f 1)
  31. echo " checksum: ${CHECKSUM}"
  32. grep -q "${CHECKSUM}" <<< "${RELEASE_NOTES}" \
  33. || (echo "checksum mismatch" && exit 1)
  34. echo " checksum ok"
  35. echo " -> creating directory structure"
  36. mkdir -p "${DEB_TMP_DIR}"
  37. mkdir -p "${DEB_TMP_DIR}${DESTDIR}"
  38. mkdir -p "${DEB_TMP_DIR}${DOCDIR}"
  39. mkdir -p "${DEB_TMP_DIR}${DOCDIR}/man1"
  40. mkdir -p "${DEB_TMP_DIR}${DOCDIR}/man5"
  41. mkdir -p "${DEB_TMP_DIR}/DEBIAN"
  42. mkdir -p "${DEB_TMP_DIR}/usr/share/doc/${NAME}"
  43. mkdir -p "${DEB_TMP_DIR}/usr/share/bash-completion/completions/"
  44. mkdir -p "${DEB_TMP_DIR}/usr/share/fish/vendor_completions.d/"
  45. mkdir -p "${DEB_TMP_DIR}/usr/share/zsh/vendor-completions/"
  46. chmod 755 -R "${DEB_TMP_DIR}"
  47. echo " -> extract executable"
  48. tar -xzf "${ARCH}.tar.gz"
  49. cp ${NAME} "${DEB_TMP_DIR}${DESTDIR}"
  50. chmod 755 "${DEB_TMP_DIR}${DESTDIR}/${NAME}"
  51. echo " -> compress man pages"
  52. gzip -cn9 target/man/eza.1 > "${DEB_TMP_DIR}${DOCDIR}man1/eza.1.gz"
  53. gzip -cn9 target/man/eza_colors.5 > "${DEB_TMP_DIR}${DOCDIR}man5/eza_colors.5.gz"
  54. gzip -cn9 target/man/eza_colors-explanation.5 > "${DEB_TMP_DIR}${DOCDIR}man5/eza_colors-explanation.5.gz"
  55. chmod 644 "${DEB_TMP_DIR}${DOCDIR}"/**/*.gz
  56. echo " -> copy completions"
  57. cp completions/bash/eza "${DEB_TMP_DIR}/usr/share/bash-completion/completions/"
  58. cp completions/fish/eza.fish "${DEB_TMP_DIR}/usr/share/fish/vendor_completions.d/"
  59. cp completions/zsh/_eza "${DEB_TMP_DIR}/usr/share/zsh/vendor-completions/"
  60. echo " -> create control file"
  61. touch "${DEB_TMP_DIR}/DEBIAN/control"
  62. cat > "${DEB_TMP_DIR}/DEBIAN/control" <<EOM
  63. Package: ${NAME}
  64. Version: ${VERSION}
  65. Section: utils
  66. Priority: optional
  67. Architecture: ${ARCH}
  68. Depends: libc6
  69. Maintainer: Sandro-Alessio Gierens <sandro@gierens.de>
  70. Description: Modern replacement for ls
  71. eza is a modern replacement for ls. It uses colours for information by
  72. default, helping you distinguish between many types of files, such as whether
  73. you are the owner, or in the owning group.
  74. .
  75. It also has extra features not present in the original ls, such as viewing the
  76. Git status for a directory, or recursing into directories with a tree view.
  77. EOM
  78. chmod 644 "${DEB_TMP_DIR}/DEBIAN/control"
  79. echo " -> copy changelog"
  80. cp CHANGELOG.md "${DEB_TMP_DIR}/usr/share/doc/${NAME}/changelog"
  81. gzip -cn9 "${DEB_TMP_DIR}/usr/share/doc/${NAME}/changelog" > "${DEB_TMP_DIR}/usr/share/doc/${NAME}/changelog.gz"
  82. rm "${DEB_TMP_DIR}/usr/share/doc/${NAME}/changelog"
  83. chmod 644 "${DEB_TMP_DIR}/usr/share/doc/${NAME}/changelog.gz"
  84. echo " -> create copyright file"
  85. touch "${DEB_TMP_DIR}/usr/share/doc/${NAME}/copyright"
  86. cat > "${DEB_TMP_DIR}/usr/share/doc/${NAME}/copyright" << EOM
  87. Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
  88. Upstream-Name: ${NAME}
  89. Upstream-Contact: Christina Sørensen <christina@cafkafk.com>
  90. Source: https://github.com/eza-community/eza/releases
  91. Files: *
  92. License: MIT
  93. Copyright: 2023 Christina Sørensen <christina@cafkafk.com>
  94. Files: debian/*
  95. License: MIT
  96. Copyright: 2023 Christina Sørensen <christina@cafkafk.com>
  97. License: MIT
  98. Permission is hereby granted, free of charge, to any person obtaining a copy
  99. of this software and associated documentation files (the "Software"), to deal
  100. in the Software without restriction, including without limitation the rights
  101. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  102. copies of the Software, and to permit persons to whom the Software is
  103. furnished to do so, subject to the following conditions:
  104. .
  105. The above copyright notice and this permission notice shall be included in all
  106. copies or substantial portions of the Software.
  107. .
  108. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  109. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  110. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  111. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  112. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  113. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  114. SOFTWARE.
  115. EOM
  116. chmod 644 "${DEB_TMP_DIR}/usr/share/doc/${NAME}/copyright"
  117. echo " -> build ${ARCH} package"
  118. dpkg-deb --build --root-owner-group "${DEB_TMP_DIR}" > /dev/null
  119. echo " -> cleanup"
  120. rm -rf "${DEB_TMP_DIR}" "${ARCH}.tar.gz" "${NAME}"
  121. # gierens: this does not work on my arch at the moment and
  122. # i'm verifying on the repo host anyway thus the || true
  123. echo " -> lint ${ARCH} package"
  124. lintian "${DEB_PACKAGE}" || true
  125. done
  126. echo "return to original commit"
  127. git checkout --quiet "${COMMIT}"