Help with my first PKGBUILD

I found a text editor here : https://gitlab.com/hamadmarri/gamma-text-editor which is not yet available on AUR. I decided to try writing a PKGBUILD for this - which is my first one. There is an installer script with the repo at https://gitlab.com/hamadmarri/gamma-text-editor/-/blob/master/setup.sh
I am replicating the setup.sh in my PKGBUILD

The problem I’m facing is that I cannot figure out where to keep application data. The application has a plugins directory, where it modifies a few files at runtime. So the application data cannot be stored at /usr/share/app-name/ or /var/lib/app-name/ since that directory is not writable by normal users. One solution to this is to separate the plugins folder and keep it in the user home directory, but that would require patching the software code - and that doesn’t sound like a real solution to me. (honestly, nothing in my PKGBUILD looks right to me)

This is a python application. Works fine if I follow the manual install instructions given in the README. Note that the application requires the source files to be persistently be there on the system at a directory writable by the user.
My current PKGBUILD is as follows

pkgname=gamma-text-editor
pkgver=0.0.2
pkgrel=1
pkgdesc="Lightweight text editor, alternative to Gedit or Notepad++"
arch=('any')
url="https://gitlab.com/hamadmarri/gamma-text-editor"
license=("GPL3")
depends=("python3" "gtk3" "gtksourceview4" "gobject-introspection")
source=(${url}/-/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz)
sha256sums=("SKIP")

package() {
  install -D "$PWD/${pkgname}-v${pkgver}/bin/icon.svg" "${pkgdir}/usr/share/icons/io.gitlab.hamadmarri.gamma.svg"
  cp "$PWD/${pkgname}-v${pkgver}/bin/io.gitlab.hamadmarri.gamma.desktop.bak" "$PWD/${pkgname}-v${pkgver}/bin/io.gitlab.hamadmarri.gamma.desktop"
  sed -i -e "s,\[gamma path placeholder\],$PWD/${pkgname}-v${pkgver}/bin/gamma," "$PWD/${pkgname}-v${pkgver}/bin/io.gitlab.hamadmarri.gamma.desktop"
  install -D "$PWD/${pkgname}-v${pkgver}/bin/io.gitlab.hamadmarri.gamma.desktop" "${pkgdir}/usr/share/applications/io.gitlab.hamadmarri.gamma.desktop"
  install -d "$PWD/${pkgname}-v${pkgver}/gtksourceview_styles/*" "${pkgdir}/usr/share/gtksourceview-4/styles/"
  install -Dm644 "$PWD/${pkgname}-v${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  mkdir -p "${pkgdir}/usr/bin/"
  mkdir -p "${pkgdir}/var/lib/${pkgname}/"
  cp $PWD/${pkgname}-v${pkgver}/* "${pkgdir}/var/lib/${pkgname}/" -r 
  ln -s "/var/lib/${pkgname}/bin/gamma" ${pkgdir}/usr/bin/gamma-editor
}

This installs fine with makepkg -si. But during runtime, throws an error PermissionError: [Errno 13] Permission denied: '/var/lib/gamma-text-editor/plugins/welcome/first_time' -> '/var/lib/gamma-text-editor/plugins/welcome/not_first_time', ofcourse because /var/lib/ directory is not writeable by normal user.

Any help, or links to articles, blog is appreciated! :smile:
If it goes right, I’ll probably publish it on the AUR.

1 Like

not sure how to help, but nice find. i’ve been building gedit myself to disable history completion, so this might be for me.

1 Like

I would probably install it to /opt instead of /var/lib. Of course, you will still have the same permissions problem.

From your description, this seems like more of an application issue where the application should be creating and writing to the users home directory at runtime.

Has this been packaged for any other distros? If so, you might look and see how they overcame it.

If not, you might open an issue with the author explaining that it is difficult to package the app for a distribution because it requires writing to the application directory.

Lastly, if that is the only time that the application needs to write to the plugins directory you could always rename gamma-text-editor/plugins/welcome/first_time to gamma-text-editor/plugins/welcome/not_first_time in your PKGBUILD.

3 Likes

Looking around I didn’t find this application packaged for any distro. Its a new application, just eight months old. I was wanting to get this on the AUR because I personally liked the concept of this application.

Thanks for the suggestion. I’ll play around with the source code some more and if I get no solution, I’ll open a issue with the author.

Of course, you could also patch it yourself which would be pretty easy since that code is so isolated.

1 Like

Here’s a different approach. Instead of copying files to personal folders, this copies them to system folders, and most files under /opt.

Note that I didn’t test this, so it may contain bugs…

pkgname=gamma-text-editor
pkgver=0.0.2
pkgrel=1
pkgdesc="Lightweight text editor, alternative to Gedit or Notepad++"
arch=('any')
url="https://gitlab.com/hamadmarri/gamma-text-editor"
license=("GPL3")
depends=("python3" "gtk3" "gtksourceview4" "gobject-introspection")
source=(git+https://gitlab.com/hamadmarri/gamma-text-editor.git)
sha256sums=("SKIP")

package() {
    local item items

    items="$(find $pkgname -type d | grep -v "/\.git")"
    for item in $items ; do
        install -d $pkgdir/opt/$item
    done

    items="$(find $pkgname -type f | grep -v "/\.git")"
    for item in $items ; do
        install $item $pkgdir/opt/$item
    done

    cd $pkgdir/opt/$pkgname

    local string=io.gitlab.hamadmarri.gamma
    local styles=(
        chocolateicecream.xml
        covid19.xml
        darkchocolateicecream.xml
        icecream.xml
    )
    
    install -Dm644 bin/icon.svg            $pkgdir/usr/share/icons/$string.svg
    install -Dm644 bin/$string.desktop.bak $pkgdir/usr/share/applications/$string.desktop

    sed -i $pkgdir/usr/share/applications/$string.desktop \
        -e "s,\[gamma path placeholder\],/usr/bin/gamma-editor,"

    for item in "${styles[@]}" ; do
        install -Dm644 gtksourceview_styles/$item   $pkgdir/usr/share/gtksourceview-4/styles/$item
    done

    install -d $pkgdir/usr/bin
    ln -s /opt/$pkgname/bin/gamma          $pkgdir/usr/bin/gamma-editor
}
5 Likes

Thanks for your time!
Your approach gives the same error I mentioned in my original post. The application tries to modify its source files at runtime, which crashes it since it does not have superuser permissions. The same happens with the config file. The user cannot modify the config without superuser rights - which isn’t the right way.

I’ll open an issue with the developer regarding this. The way I see it, the application should fetch plugins and configs from the user home directory instead of the system directories.

Hello everyone,

The problem with gamma-text-editor is that almost every file might require to be edited by the user for customization purposes. If we consider all gamma files are data. Is it possible to place gamma under user’s home dir with PKGBUILD? and create a symbolic link to it?

Thanks

2 Likes

Hi! Thanks for dropping a reply. I opened a similar issue on your git repo.

The way I understand pacman package manager is that it cannot modify the user home folder. All installation files go to one of the system directories and the installation is system-wide i.e. every user has access to the application.

The config and plugins are preferred to be stored in user home directory because every user might want a different configuration. Also because the application should be able to edit the config during runtime.

I don’t think it would be possible to place something in the user home directory during package installation. (maybe I’ll need an experienced member of our forum to comment on this)

By the way, Welcome to the forum! :wave:

PKGBUILD cannot install to user folders directly, but of course PKGBUILD could install an additional small “installer” program/script which, when run separately after package install, will copy files to user folders.

3 Likes

@dalto @manuel Thanks for your inputs!

I placed all application data at /opt/. I added a script that will copy the required files from there to the user home directory under .config and modified the application source code to read the plugins and config from ~/.config/gamma-text-editor
I’ve pushed the PKGBUILD at https://aur.archlinux.org/packages/gamma-text-editor/

Again, thanks for helping me with my first contribution to the linux world! :smiley:

2 Likes

A couple things:

  • Any modifications you are making should probably happen in prepare(), not in package()
  • You shouldn’t write or modify the home directory in a PKGBUILD. Above any beyond it being poor form, many systems have more than one user and/or use a different user to install packages than run software.

As a side note, why not patch that code so instead of switching the location, it checks if the file exists, and if it doesn’t, it creates it? That would be better than moving it from one name to another anyway.

1 Like

I tried this, but it seemed like the source code file isn’t extracted by then. So I moved it to package(). I was probably doing something wrong. Will read more about this tomorrow and try fixing.

The PKGBUILD doesn’t write to home directory. It puts a script in /usr/bin/ and the user needs to invoke that script after install to copy the required files.

Yes this looks like a lot more refined option. Also, since the dev himself is okay with modifying the source code, I guess we could make this functionality a part of the application itself. If at all, things don’t work out, I’ll make a patch.
Thanks! I’ll look into these matters tomorrow.

1 Like

I followed your suggestions. Created a pull request to the repository and now this functionality is a part of the program itself. Some remaining modifications are now done in prepare(). package() is now only copying files, not editing any of them.

Thanks for guiding me on my first PKGBUILD, that eventually lead to my first legitimate git pull request! :smiley:

2 Likes