-
Notifications
You must be signed in to change notification settings - Fork 621
Add install script with GIMP version detection #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oxidworks
wants to merge
6
commits into
Diolinux:master
Choose a base branch
from
oxidworks:fix/gimp-version-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb90ff9
Add install script with GIMP version detection
8b25e94
install.sh: respect XDG_CONFIG_HOME, use regex for version dir detection
oxidworks c46689d
install.sh: respect XDG_CONFIG_HOME, use regex for version dir detection
oxidworks 6df3fc2
install.sh: fix macOS compatibility, Flatpak path, pipefail crash
43a447c
Drop pipefail, use POSIX-compatible redirects
1e69370
Drop unnecessary stderr redirect from command -v
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/bin/bash | ||
| # PhotoGIMP installer for Linux | ||
| # Detects the installed GIMP version and copies config files accordingly. | ||
|
|
||
| set -eu | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| CONFIG_SRC="$SCRIPT_DIR/.config/GIMP/3.0" | ||
|
|
||
| # --- Detect GIMP config directory --- | ||
|
|
||
| detect_gimp_config_dir() { | ||
| local config_home="${XDG_CONFIG_HOME:-$HOME/.config}" | ||
| local flatpak_config="$HOME/.var/app/org.gimp.GIMP/config" | ||
| local regex='.*/[0-9]+\.[0-9]+' | ||
| local newest | ||
|
|
||
| # Search native and Flatpak config locations | ||
| for base in "$config_home/GIMP" "$flatpak_config/GIMP"; do | ||
| [ -d "$base" ] || continue | ||
| case "$(uname)" in | ||
| Linux) | ||
| newest=$(find "$base" -maxdepth 1 -type d -regextype posix-egrep -regex "$regex" 2>/dev/null | sort -t. -k1,1n -k2,2n | tail -1) ;; | ||
| Darwin|*BSD|DragonFly) | ||
| newest=$(find -E "$base" -maxdepth 1 -type d -regex "$regex" 2>/dev/null | sort -t. -k1,1n -k2,2n | tail -1) ;; | ||
| esac | ||
| if [ -n "${newest:-}" ]; then | ||
| echo "$newest" | ||
| return | ||
| fi | ||
| done | ||
|
|
||
| # Fallback: try to get version from gimp binary | ||
| local version | ||
| for cmd in gimp gimp-3.2 gimp-3.0; do | ||
| if command -v "$cmd" >/dev/null; then | ||
| version=$("$cmd" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+' | head -1 || true) | ||
| [ -n "${version:-}" ] && break | ||
| fi | ||
| done | ||
|
|
||
| # Flatpak fallback | ||
| if [ -z "${version:-}" ] && command -v flatpak >/dev/null; then | ||
| version=$(flatpak run org.gimp.GIMP --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+' | head -1 || true) | ||
| fi | ||
|
|
||
| if [ -n "${version:-}" ]; then | ||
| # Prefer Flatpak path if it exists | ||
| if [ -d "$flatpak_config/GIMP" ]; then | ||
| echo "$flatpak_config/GIMP/$version" | ||
| else | ||
| echo "$config_home/GIMP/$version" | ||
| fi | ||
| else | ||
| echo "$config_home/GIMP/3.0" | ||
| fi | ||
| } | ||
|
|
||
| # --- Detect StartupWMClass --- | ||
|
|
||
| detect_wm_class() { | ||
| local config_dir="$1" | ||
| local version | ||
| version=$(basename "$config_dir") # e.g. "3.2" | ||
| echo "gimp-$version" | ||
| } | ||
|
|
||
| # --- Main --- | ||
|
|
||
| echo "PhotoGIMP Installer" | ||
| echo "===================" | ||
|
|
||
| # Check that GIMP has been run at least once | ||
| GIMP_CONFIG=$(detect_gimp_config_dir) | ||
| echo "GIMP config directory: $GIMP_CONFIG" | ||
|
|
||
| if [ ! -d "$GIMP_CONFIG" ]; then | ||
| echo "" | ||
| echo "Config directory does not exist yet." | ||
| echo "Please start GIMP once, close it, then run this script again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Backup existing config | ||
| BACKUP="$GIMP_CONFIG.backup-$(date +%Y%m%d-%H%M%S)" | ||
| echo "Backing up current config to: $BACKUP" | ||
| cp -a "$GIMP_CONFIG" "$BACKUP" | ||
|
|
||
| # Copy PhotoGIMP config files | ||
| echo "Installing PhotoGIMP config..." | ||
| cp -a "$CONFIG_SRC"/. "$GIMP_CONFIG"/ | ||
|
|
||
| # Install desktop file with correct WMClass | ||
| DESKTOP_SRC="$SCRIPT_DIR/.local/share/applications/org.gimp.GIMP.desktop" | ||
| DESKTOP_DST="$HOME/.local/share/applications/org.gimp.GIMP.desktop" | ||
|
|
||
| if [ -f "$DESKTOP_SRC" ]; then | ||
| mkdir -p "$(dirname "$DESKTOP_DST")" | ||
| WM_CLASS=$(detect_wm_class "$GIMP_CONFIG") | ||
| sed "s/StartupWMClass=gimp-3\.0/StartupWMClass=$WM_CLASS/" \ | ||
| "$DESKTOP_SRC" > "$DESKTOP_DST" | ||
| echo "Desktop file installed (StartupWMClass=$WM_CLASS)" | ||
| fi | ||
|
|
||
| # Install icons | ||
| if [ -d "$SCRIPT_DIR/.local/share/icons" ]; then | ||
| cp -a "$SCRIPT_DIR/.local/share/icons"/. "$HOME/.local/share/icons"/ | ||
| echo "Icons installed." | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "Done! Start GIMP to use PhotoGIMP." | ||
| echo "To restore your previous settings: cp -a '$BACKUP'/. '$GIMP_CONFIG'/" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the literal
gimpcommand 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.2andgimp-3.0should be removed altogether as I'm not sure anybody's going to have an installation, wheregimp-3.2orgimp-3.0work butgimpdoesn'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):