Hi,
For the last decade or so, I’ve been using a bone-headed shell script to install and customize my various Linux desktops. Like this one for Rocky Linux 8 and KDE, for example.
I’m currently rewriting all this stuff for Ansible, since this is the way.
I’ve already converted something like 80 % of my Rocky Linux 8 + KDE setup script into an Ansible playbook and a corresponding collection of roles.
Now I’ve got a challenging problem to solve. My [setup.sh](https://gitlab.com/kikinovak/rocky-8-desktop/-/blob/main/setup.sh)
script sports a replace_menus()
function that does what it says: rewrite some *.desktop files
in /usr/share/applications
using a personal collection of menu entry stubs.
Here’s the function:
# Custom menus
ENTRIESDIR="${CWD}/el8/menus"
ENTRIES=$(ls ${ENTRIESDIR})
MENUDIRS="/usr/share/applications \
/var/lib/flatpak/exports/share/applications"
...
replace_menus() {
echo " === Install custom desktop menu ==="
echo
sleep ${SLEEP}
for MENUDIR in ${MENUDIRS}
do
for ENTRY in ${ENTRIES}
do
if [ -r ${MENUDIR}/${ENTRY} ]
then
echo " Rewriting menu item: ${ENTRY}"
sed -i '/^#/d' ${MENUDIR}/${ENTRY}
sed -i '/^\[Desktop Action/Q' ${MENUDIR}/${ENTRY}
sed -i '/^\[X-Drawing/Q' ${MENUDIR}/${ENTRY}
sed -i '/^\[X-Property/Q' ${MENUDIR}/${ENTRY}
sed -i '/^GenericName/d' ${MENUDIR}/${ENTRY}
sed -i '/^Name/d' ${MENUDIR}/${ENTRY}
sed -i '/^Comment/d' ${MENUDIR}/${ENTRY}
sed -i '/^Keywords/d' ${MENUDIR}/${ENTRY}
sed -i '/^Actions/d' ${MENUDIR}/${ENTRY}
sed -i '/^Version/d' ${MENUDIR}/${ENTRY}
sed -i '/^Categories/d' ${MENUDIR}/${ENTRY}
sed -i '/^NoDisplay/d' ${MENUDIR}/${ENTRY}
sed -i '/^$/d' ${MENUDIR}/${ENTRY}
cat ${ENTRIESDIR}/${ENTRY} >> ${MENUDIR}/${ENTRY}
sleep 0.1
fi
done
done
And here’s the collection of menu stub files with improved translations and/or better categorizations.
Now I wonder how I could possibly translate this into Ansible’s way of doing things. I even wonder if Ansible is the right tool for doing this, or if I’m eventually better off with a simple menu_rewrite.sh
shell script.
So I thought: why not ask the Ansible gurus here in this forum ?