Skip to content

Add install script with GIMP version detection#190

Open
oxidworks wants to merge 6 commits into
Diolinux:masterfrom
oxidworks:fix/gimp-version-detection
Open

Add install script with GIMP version detection#190
oxidworks wants to merge 6 commits into
Diolinux:masterfrom
oxidworks:fix/gimp-version-detection

Conversation

@oxidworks

Copy link
Copy Markdown

Problem

PhotoGIMP config is hardcoded to ~/.config/GIMP/3.0/. When GIMP updates to 3.2, it looks in ~/.config/GIMP/3.2/ and the PhotoGIMP layout is gone. The .desktop file has StartupWMClass=gimp-3.0 which also breaks.

This comes up in #166 and #181 - and it will happen again with every GIMP minor version bump.

Solution

A simple install.sh that:

  • Finds the active GIMP config directory (newest 3.x folder)
  • Creates a timestamped backup before copying
  • Adjusts StartupWMClass in the .desktop file to match the installed version
  • Works with native packages, Flatpak, and AppImage

Usage:

git clone https://github.com/Diolinux/PhotoGIMP.git
cd PhotoGIMP
./install.sh

Fixes #166, fixes #181

The current installation method requires users to manually extract
files into ~/.config/GIMP/3.0/. When GIMP updates to 3.2+, the config
directory changes (e.g. ~/.config/GIMP/3.2/) and PhotoGIMP stops
working. The .desktop file also has a hardcoded StartupWMClass=gimp-3.0.

This install script:
- Detects the active GIMP config directory (3.0, 3.2, etc.)
- Creates an automatic backup before overwriting
- Adjusts StartupWMClass in the .desktop file to match
- Works with native packages, Flatpak, and AppImage

Fixes Diolinux#166, fixes Diolinux#181
@emsspree

emsspree commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Hi.

Line 13: It only works when GIMP uses $HOME/.config/GIMP.
Line 18: -name '3.*' finds all dirs with names starting with '3.' incl ones named like '3.0 Copy'.

The following script finds all dirs with paths ending with 'gimp/‹number›.‹number›'. So in a next step, the user can be asked to choose the right one if there’s more than one found.

REGEX='.*/[Gg][Ii][Mm][Pp]/[0-9]+\.[0-9]+'
OS_NAME="$(uname | tr '[:upper:]' '[:lower:]')"
case "$OS_NAME" in
    linux)
        ADD_GNU='-regextype posix-egrep' ;;
    darwin|dragonfly|*bsd)
        ADD_BSD='-E' ;;
    *)
        echo "$OS_NAME is not supported." >&2 ; exit 1 ;;
esac
find $ADD_BSD "$HOME" -type d $ADD_GNU -regex "$REGEX" 2>/dev/null

@oxidworks

Copy link
Copy Markdown
Author

Thanks for the feedback! Both points are addressed in the latest commit:

  • $HOME/.config${XDG_CONFIG_HOME:-$HOME/.config} so custom config locations are respected
  • -name '3.*' replaced with a -regex pattern matching only [0-9]+\.[0-9]+, avoiding false matches like 3.0 Copy

@emsspree

Copy link
Copy Markdown
Contributor

When you let find search in base="$config_home/GIMP" then
regex='.*/[Gg][Ii][Mm][Pp]/[0-9]+\.[0-9]+' can be just
regex='.*/[0-9]+\.[0-9]+'

Sure, GIMP is always uppercase?

@oxidworks

Copy link
Copy Markdown
Author

Simplified the regex to .*/[0-9]+\.[0-9]+ since find already starts in the GIMP directory.

GIMP always creates its config folder as uppercase GIMP. It's hardcoded in the source (libgimpbase/gimpenv.c), not derived from anything dynamic.

Your review made me look at the script more carefully. Found a few more problems:

  • grep -oP and sort -V are GNU-only, both break on macOS
  • set -euo pipefail kills the script silently when grep finds no match in the version fallback
  • Flatpak stores config in ~/.var/app/org.gimp.GIMP/config/GIMP/, not in ~/.config/GIMP/ - the current fallback gets the version but writes to the wrong path

- Simplify regex (GIMP dir already in search base)
- Replace GNU-only grep -oP and sort -V with POSIX equivalents
- Prevent set -e crash when grep finds no version match
- Search Flatpak config path ~/.var/app/org.gimp.GIMP/config/GIMP/
@emsspree

Copy link
Copy Markdown
Contributor
  • set -euo pipefail

Do you need it?

But nevertheless, I think, to be compatible with as many unixy operating systems, the script should be POSIX-compliant anyway.

@emsspree

Copy link
Copy Markdown
Contributor
  • BSD find/grep/sort/etc.

No problem. Just prepare the cases where needed. We fill the gaps later.

@oxidworks

Copy link
Copy Markdown
Author

Thanks for you comment, yes, pipefail is bash-only and not needed here. Dropped it, switched to set -eu. Also replaced &>/dev/null with >/dev/null 2>&1.

For BSD: leaving the uname cases in place so the structure is ready.

@emsspree

Copy link
Copy Markdown
Contributor
  • >/dev/null 2>&1 ???

2>&1 means: redirect 2’s output to 1, where 2 is STDERR and 1 is STDOUT. But command does not print any errors, so nothing goes to 2/STDERR which could be redirected to 1/STDOUT.
Or do I miss something?

@oxidworks

Copy link
Copy Markdown
Author

You're right, command -v only writes to stdout. Dropped the 2>&1.

command -v only writes to stdout, so 2>&1 is not needed.
@digitalica

Copy link
Copy Markdown

just did a quick test of this install script in my old Ubuntu 24.04 with gimp 3.2, after copy didn't work (of course). No errors, looked good. Didn't do much testing though. I think the idea is great. Script looks good.

Comment thread install.sh

# Fallback: try to get version from gimp binary
local version
for cmd in gimp gimp-3.2 gimp-3.0; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the literal gimp command with the version number (e.g. gimp-3.2) shouldn't be hardcoded.

If the goal's to get it straight from the binaries, then future versions should be acccounted for, otherwise the same issue of updating the script will keep coming up.

Perhaps the hardcoded gimp-3.2 and gimp-3.0 should be removed altogether as I'm not sure anybody's going to have an installation, where gimp-3.2 or gimp-3.0 work but gimp doesn't.

If there's a reason to keep those numbered versions, then I suggest defining a global variable like MAJOR_VERSION=3, and then using a POSIX compliant function to run down the $PATH and find all possible commands for this major version (and also remove all duplicate finds, as I've had those show up on my system):

GIMP_MAJOR_VERSION=3

get_gimp_binaries_from_path() {
	OLD_IFS=$IFS
	IFS=:

	(
		for dir in $PATH; do
			[ -d "$dir" ] || continue

			for f in "$dir"/gimp*; do
				[ -f "$f" ] || continue
				[ -x "$f" ] || continue

				bin=$(basename -- "$f")

				case "$bin" in
				gimp | gimp-$GIMP_MAJOR_VERSION*)
					printf '%s\n' "$bin"
					;;
				esac
			done
		done
	) | sort -u

	IFS=$OLD_IFS
}

@oxidworks

oxidworks commented May 20, 2026

Copy link
Copy Markdown
Author

Thanks for the read.

You're right that the version list is hardcoded. I left it in as a small safety net for systems where only a versioned binary like gimp-3.0 is on PATH (some older RPM-based distros, custom builds). That fallback path is mostly defensive though: if no GIMP config directory exists yet, the script exits below with a "start GIMP once" message anyway.

I'm happy to refactor along your lines if @Diolinux wants to broaden the scope. My intent with this PR was a minimal, low-risk fix for #166 / #181.

@tadghh

tadghh commented Jun 27, 2026

Copy link
Copy Markdown

this is not needed, the user will know (because gimp will appear entirely fucked up).

Simply update the installer to not version the .desktop

run --file-forwarding org.gimp.GIMP @@u %U @@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does not work on Linux Flatpak Photogimp Won't Start With Newest Gimp Update (Linux Mint)

5 participants