archlinuxpkgbuildpacman-package-manager

How to include static data files into Archlinux AUR package?


I have a small script that uses some static text files as data source. I want to make Archlinux AUR package for this script. I plan to install the script into /usr/bin/ and static text files somewhere locally ~/.data_files

I have several static files: data1.txt, data2.txt, data3.txt. Basically, I need the package manager to install the script into /usr/bin/, create ~/.data_files directory and copy the static files there.

How should I configure my PKGBUILD in such case?

Here is my current version:

# Maintainer: john doe
pkgname=myscript
pkgver=1.0
pkgrel=1
pkgdesc="test script"
arch=(any)
url="https://github.com/me/myscript"
license=('MIT')
depends=('file')
source=('https://raw.githubusercontent.com/me/myscript/master/myscript')
md5sums=('1fa410f1647700a6da3ab0ebyc52465d')

package() {
  install -D -m 755 myscript ${pkgdir}/usr/bin/myscript
}

Solution

  • Let me quote one of the most active moderator of Archlinux Forum when he said here :

    Do not touch the users home directory in a PKGBUILD, especially do not delete things because weird bugs can do bad things.

    Now as a maintainer in AUR, I would suggest to add your statics files in the folder /usr/share/${pkgname}/ as it's also suggested in Arch Packaging Standards

    Here's my suggestion (open for editions, suggestions, advices...):

    # Maintainer: john doe <john at doe dot com>
    pkgname=myscript
    pkgver=1.0
    pkgrel=1
    pkgdesc="test script"
    arch=(any)
    url="https://github.com/me/myscript"
    license=('MIT')
    depends=('file')
    source=('https://raw.githubusercontent.com/me/myscript/master/myscript'
          'data1.txt'
          'data2.txt'
          'data3.txt')
    sha256sums=('77eff738ea7fdeee5f5707cafdf34f74e3bf8df3b8b656a08a8740a45a7e22c45a7e60c31b13c71f5ee04aff9c82ac43abb39c37b2ea6b02a6454e262f336f73'
           'sha256Ofdata1.txt'
           'sha256Ofdata2.txt'
           'sha256Ofdata3.txt')
    
    package() {
      install -Dm755 myscript "${pkgdir}/usr/share/${pkgname}/myscript"
      install -Dm644 data1.txt "${pkgdir}/usr/share/${pkgname}/data1.txt"
      install -Dm644 data2.txt "${pkgdir}/usr/share/${pkgname}/data2.txt"
      install -Dm644 data3.txt "${pkgdir}/usr/share/${pkgname}/data3.txt"
    }
    

    Because of md5 known vulnerabilities, I used sha256 but you can choose to use other sha* for integrity check.