You are not logged in.

#1 Yesterday 23:20:04

greenjeans
Member
Registered: 2025-01-18
Posts: 343
Website

Firemenu, yad/bash frontend for Firejail

Hey guys, so this is not one of my apps, this is the work of my brilliant buddy fsmithred, we were talking on IRC last night and he mentioned a small issue with detecting the users text-editor for manual editing of the menu file, I took a look at the script and it was just singing the song of my people, yad, bash, tiny amount of code, gui frontend for cli app and I couldn't help myself. I re-wrote it to use a yad text-info dialog rather than a text editor and added some functions. I submitted a pull request and fsmithred said it was working on his end. But caveat is: this is hot off the presses, I don't normally use Firejail or other containment methods so have no experience with them. But it's working great on my machine and I thought it might be of interest to the *box folks like me. I know there's a QT frontend for it, probably very nice and feature complete, but this is not that, if you've tried some of my other scripts you know I like simple and quick.

Here's the link to fsmithred's repo: https://git.devuan.org/fsmithred/firemenu

And this is my testing fork: https://git.devuan.org/greenjeans/firemenu

But i'm going to just post the code here as it's so tiny, like ~100 lines of code or so, you can just paste that into a text-editor and save it, make it executable and run it from anywhere. If anyone who uses firejail had some time to test it and offer feedback that would be awesome. You'll need yad, firejail, and firejail-profiles to run it, the last one is optional but it has a mountain of already-written profiles which is good because I don't know squat about writing one. wink

#!/usr/bin/env bash
#
# firemenu v.1.6 (yad-native edit)
# Based on fsmithred's original, with mods by greenjeans
# License: GPL-3
# This is free software with NO WARRANTY. Use at your own risk!

applist="${HOME}/.config/firemenu.list"
backup_dir="${HOME}/.local/share/firemenu"

make_menu() {
    mkdir -p "$backup_dir"
    rm -f "$applist"
    echo "# Comment out any apps you don't want to show in the menu." > "$applist"
    for file in /etc/firejail/*.profile; do
        app=$(basename "${file%.profile}")
        if [ -e "/var/lib/dpkg/info/${app}.list" ]; then
            echo "$app" >> "$applist"
        fi
    done
    edit_list
    show_menu
}

comment_all() {
    sed -i 's/^\([^#].*\)/# \1/g' "$applist"
}

edit_list() {
    local backup_dir="${HOME}/.local/share/firemenu"
    local backup="${backup_dir}/firemenu.list.bak.$(date +%Y%m%d-%H%M%S)"
    
    mkdir -p "$backup_dir"
    
    # Make new backup
    cp "$applist" "$backup" 2>/dev/null || true
    
    # Keep only the 3 most recent backups
    find "$backup_dir" -name "firemenu.list.bak.*" -type f -printf '%T@ %p\n' 2>/dev/null \
        | sort -nr | tail -n +4 | cut -d' ' -f2- | xargs -r rm -f --
    
    # Capture edited content from yad
    local edited_content
    edited_content=$(yad --text-info --editable --text-align=center \
        --text="<span line_height='1.2'>Delete the entire line to remove an app.\n Comment out lines with # (or # followed by space) to hide them.\n Add apps only if they have a matching profile in /etc/firejail/.\n\nA backup was saved as: ~/.local/share/firemenu/firemenu.list.bak.*</span>" \
        --window-icon=preferences-system \
        --borders=10 --margins=8 \
        --filename="$applist" \
        --title="Edit Firemenu List" \
        --width=600 --height=500 \
        --button=Cancel:1 --button=OK:0)
    
    local yad_exit=$?
    
    if [ $yad_exit -eq 0 ] && [ -n "$edited_content" ]; then
        printf '%s\n' "$edited_content" > "$applist"
        sed -i '/^$/d' "$applist" 2>/dev/null || true
    else
        yad --title="Edit Cancelled" --text="<span line_height='1.2'>No changes were saved.\nBackup remains available.</span>" \
            --button=OK:0 --center --window-icon=gtk-cancel --text-align=center --center --borders=10 --width=300 --fixed
    fi
}

show_menu() {
    local menu_text="<span line_height='1.2'>Some profiles may not appear in this list.\n(See ${HOME}/.config/firemenu.list)\nSelect an app from the list and click the run button to begin.</span>"
    
    selection=$(grep -v "^#" "$applist" 2>/dev/null | yad --list --height 420 --title="FireMenu" \
        --text="${menu_text}" --separator="" --column="Application" \
        --window-icon=gtk-edit --center --borders=10 --text-align=center \
        --button="Edit!gtk-edit!Edit firemenu.list manually in a new window:4" \
        --button="Reset!gtk-refresh!Scan system for all eligible apps and add them to list:3" \
        --button="Unset!edit-undo!Comment out all apps in firemenu.list:2" \
        --button="Cancel!gtk-cancel!Cancel and exit:1" \
        --button="Run!gtk-execute!Run selected app in Firejail:0")
    
    ans=$?
    
    if [ $ans -eq 1 ]; then
        exit 0
    fi
    
    if [ $ans -eq 2 ]; then
        # Unset
        comment_all
        edit_list
        show_menu
        return
    fi
    
    if [ $ans -eq 3 ]; then
        # Reset
        make_menu
        return
    fi
    
    if [ $ans -eq 4 ]; then
        # Edit
        edit_list
        show_menu
        return
    fi
    
    if [ $ans -eq 0 ] && [ -n "$selection" ]; then
        firejail --seccomp "$selection" &
        exit 0
    fi
}

# Main flow
if [ ! -f "$applist" ]; then
    make_menu
else
    show_menu
fi

exit 0

2026-06-13-175639-506x466-scrot.png

2026-06-13-175753-622x546-scrot-resized.png

Offline

Board footer

Powered by FluxBB