#!/bin/sh # icewm-demos-update [] -- rewrite the Demos submenu of # /etc/icewm/menu from the entry files in /etc/icewm/demos.d, one # per program, so that opening the submenu runs no program. Each package with # an entry runs this from its postinst and postrm; at image build the same # scripts run with set to the rootfs. root=${1:-} menu=$root/etc/icewm/menu dir=$root/etc/icewm/demos.d [ -f "$menu" ] || exit 0 LC_ALL=C export LC_ALL ent=$menu.ent.$$ new=$menu.new.$$ trap 'rm -f "$ent" "$new"' EXIT : > "$ent" || exit 1 for f in "$dir"/*.menu; do [ -r "$f" ] && cat "$f" >> "$ent" done awk -v ent="$ent" ' function entries( l) { while ((getline l < ent) > 0) print l; print "}"; done = 1 } skip { if ($0 == "}") skip = 0; next } /^menu +"Demos" +[^ ]+ +\{$/ && !done { print; entries(); skip = 1; next } { print } END { if (!done) { print "menu \"Demos\" folder {"; entries() } } ' "$menu" > "$new" || exit 1 chmod 0644 "$new" && mv -f "$new" "$menu"