Monday, April 13, 2026

bedrock linux: krusader in arch strata does not open files with "Open with" menu from strata

On Bedrock Linux (hijacked gentoo with xfce4) with a non-KDE host session, Krusader's (installed in the arch linux strata) "Open With" silently fails for apps in a guest stratum because KDE's KRun launcher depends on session services that are never started outside a KDE session. The fix is to override the affected .desktop files locally and prepend their Exec lines with strat:
cp /bedrock/strata/arch/usr/share/applications/appname.desktop ~/.local/share/applications/appname.desktop

sed -i 's|^Exec=|Exec=strat arch |' ~/.local/share/applications/appname.desktop

update-desktop-database ~/.local/share/applications/



The simble bash script to do it automatically (fix-strata-desktop.sh) is: #!/bin/bash

STRATA="arch"
STRATA_ROOT="/bedrock/strata/$STRATA"
SRC="$STRATA_ROOT/usr/share/applications"
SRC_CROSS="$STRATA_ROOT/bedrock/cross/applications"
DEST="$HOME/.local/share/applications"

# Icon search dirs within the stratum, in priority order
ICON_SEARCH_DIRS=(
"$STRATA_ROOT/usr/share/icons/hicolor"
"$STRATA_ROOT/usr/share/icons"
"$STRATA_ROOT/usr/share/pixmaps"
)
ICON_EXTENSIONS=("png" "svg" "xpm")
# Preferred sizes in descending order (hicolor subdirs)
ICON_SIZES=("256x256" "128x128" "96x96" "64x64" "48x48" "32x32" "scalable")

# Resolve an icon name to an absolute path inside the stratum.
# Returns the path on stdout, or nothing if not found.
resolve_icon() {
local icon_name="$1"

# Already an absolute path — verify it exists (possibly via stratum root)
if [[ "$icon_name" == /* ]]; then
[[ -f "$icon_name" ]] && echo "$icon_name" && return
[[ -f "$STRATA_ROOT$icon_name" ]] && echo "$STRATA_ROOT$icon_name" && return
return
fi

# Strip any accidental extension for a clean name-based search
local base_name="${icon_name%.*}"

# 1. Search hicolor theme with preferred sizes first
for size in "${ICON_SIZES[@]}"; do
for ext in "${ICON_EXTENSIONS[@]}"; do
local candidate="$STRATA_ROOT/usr/share/icons/hicolor/$size/apps/$base_name.$ext"
[[ -f "$candidate" ]] && echo "$candidate" && return
done
done

# 2. Check pixmaps directly (flat directory, no subdirs) — catches vscodium, cups, etc.
for ext in "${ICON_EXTENSIONS[@]}"; do
local candidate="$STRATA_ROOT/usr/share/pixmaps/$base_name.$ext"
[[ -f "$candidate" ]] && echo "$candidate" && return
done

# 3. Walk all icon theme dirs (any size/category subdir)
for icon_dir in "${ICON_SEARCH_DIRS[@]}"; do
for ext in "${ICON_EXTENSIONS[@]}"; do
# Direct file in dir (pixmaps style — already handled above, but kept for custom dirs)
local candidate="$icon_dir/$base_name.$ext"
[[ -f "$candidate" ]] && echo "$candidate" && return
# Subdir search (themes with size/category layout)
# Prefer largest size by sorting descending on the size component
while IFS= read -r found; do
echo "$found" && return
done < <(find "$icon_dir" -name "$base_name.$ext" 2>/dev/null \
| sort -t'/' -k1,1 -r | head -1)
done
done
}

mkdir -p "$DEST"

for src_file in "$SRC"/*.desktop "$SRC_CROSS"/*.desktop; do
# Skip broken symlinks or non-files
[[ ! -f "$src_file" ]] && echo "Skipping: $(basename "$src_file")" && continue

filename=$(basename "$src_file")
dest_file="$DEST/$filename"

# FIX 1: Remove existing file first so cp never hits a permission-denied
# on files previously written by root (e.g. from an earlier sudo run).
if [[ -e "$dest_file" && ! -w "$dest_file" ]]; then
echo "Warning: removing unwritable existing file: $dest_file"
rm -f "$dest_file" || { echo "Error: cannot remove $dest_file — skipping"; continue; }
fi

cp -- "$src_file" "$dest_file" || { echo "Error: cp failed for $filename"; continue; }

# Fix Exec= lines that don't already use strat
if ! grep -q "Exec=strat $STRATA" "$dest_file"; then
sed -i "s|^Exec=|Exec=strat $STRATA |" "$dest_file"
fi

# Fix Icon= lines — resolve to absolute path inside the stratum
icon_value=$(grep -m1 "^Icon=" "$dest_file" | cut -d'=' -f2-)
if [[ -n "$icon_value" ]]; then
resolved=$(resolve_icon "$icon_value")
if [[ -n "$resolved" ]]; then
# Escape any special characters for sed
escaped=$(printf '%s\n' "$resolved" | sed 's/[[\.*^$()+?{|]/\\&/g')
sed -i "s|^Icon=.*|Icon=$escaped|" "$dest_file"
echo "Processed: $filename (icon -> $resolved)"
else
echo "Processed: $filename (icon '$icon_value' not resolved — left as-is)"
fi
else
echo "Processed: $filename (no Icon= entry)"
fi
done

update-desktop-database "$DEST"
echo "Done."