Files
2026-09-24 22:03:58 +02:00

97 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
# Installs SaraFem's AppImage on a fresh machine: moves the AppImage into
# place, writes the desktop entry + icon, and sets up the file-picker portal
# integration — everything that was done by hand on the dev machine,
# scripted here for reuse elsewhere. Run this from inside the same folder
# as SaraFem-x86_64.AppImage, Icon.png and SaraFem.portal (copy the whole
# Packaging/appimage/ folder over, not just this script).
set -euo pipefail
ScriptDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AppImageSource="$ScriptDir/SaraFem-x86_64.AppImage"
IconSource="$ScriptDir/Icon.png"
PortalSource="$ScriptDir/SaraFem.portal"
InstallDir="$HOME/Applications/SaraFem"
AppImageDest="$InstallDir/SaraFem.AppImage"
for Required in "$AppImageSource" "$IconSource" "$PortalSource"; do
if [ ! -f "$Required" ]; then
echo "Error: $(basename "$Required") not found next to this script ($ScriptDir)." >&2
echo "Copy the whole Packaging/appimage/ folder over, not just Install.sh." >&2
exit 1
fi
done
echo "Installing SaraFem to $InstallDir ..."
mkdir -p "$InstallDir"
cp "$AppImageSource" "$AppImageDest"
chmod +x "$AppImageDest"
echo "Installing icon..."
mkdir -p "$HOME/.local/share/icons/hicolor/256x256/apps"
cp "$IconSource" "$HOME/.local/share/icons/hicolor/256x256/apps/sarafem.png"
echo "Installing desktop entry..."
mkdir -p "$HOME/.local/share/applications"
cat > "$HOME/.local/share/applications/SaraFem.desktop" << EOF
[Desktop Entry]
Type=Application
Name=SaraFem
Comment=A file manager for the SaraSuite
Exec=$AppImageDest %f
Icon=sarafem
Terminal=false
Categories=System;FileManager;
MimeType=inode/directory;
StartupNotify=true
EOF
update-desktop-database "$HOME/.local/share/applications" &>/dev/null || true
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true
echo "Installing file-picker D-Bus service..."
mkdir -p "$HOME/.local/share/dbus-1/services"
cat > "$HOME/.local/share/dbus-1/services/org.freedesktop.impl.portal.desktop.SaraFem.service" << EOF
[D-BUS Service]
Name=org.freedesktop.impl.portal.desktop.SaraFem
Exec=$AppImageDest --portal-service
EOF
# The preference file is named after the desktop environment (see
# portals.conf(5)) — read from $XDG_CURRENT_DESKTOP so this works on
# whatever DE the other machine runs, not just COSMIC.
DesktopEnv="$(echo "${XDG_CURRENT_DESKTOP:-}" | cut -d: -f1 | tr '[:upper:]' '[:lower:]')"
if [ -z "$DesktopEnv" ]; then
echo "Warning: \$XDG_CURRENT_DESKTOP isn't set — skipping the file-picker preference file."
echo "Set it by hand later: ~/.config/xdg-desktop-portal/<your-desktop>-portals.conf, containing:"
echo " [preferred]"
echo " org.freedesktop.impl.portal.FileChooser=SaraFem;<your-desktop>;gtk;"
else
echo "Setting SaraFem as the preferred file picker for $DesktopEnv..."
mkdir -p "$HOME/.config/xdg-desktop-portal"
PrefFile="$HOME/.config/xdg-desktop-portal/${DesktopEnv}-portals.conf"
if [ -f "$PrefFile" ] && grep -q "FileChooser" "$PrefFile" 2>/dev/null; then
echo " $PrefFile already has a FileChooser preference — leaving it as-is."
echo " Add SaraFem to it yourself if you want it preferred: org.freedesktop.impl.portal.FileChooser=SaraFem;..."
else
printf '[preferred]\norg.freedesktop.impl.portal.FileChooser=SaraFem;%s;gtk;\n' "$DesktopEnv" >> "$PrefFile"
fi
fi
echo
echo "One step needs root — placing the portal descriptor in a system directory:"
echo " sudo cp \"$PortalSource\" /usr/share/xdg-desktop-portal/portals/SaraFem.portal"
read -r -p "Run that now? [y/N] " Reply
if [[ "$Reply" =~ ^[Yy]$ ]]; then
sudo cp "$PortalSource" /usr/share/xdg-desktop-portal/portals/SaraFem.portal
systemctl --user restart xdg-desktop-portal.service &>/dev/null || true
echo "Done — SaraFem is registered as a file-picker option."
else
echo "Skipped. SaraFem still works as a normal app; run that command later for the picker integration."
fi
echo
echo "Install complete. Launch SaraFem from your application menu, or directly:"
echo " $AppImageDest"