:: Re: [DNG] netman-autostart_0.1.1
Forside
Slet denne besked
Besvar denne besked
Skribent: Rainer Weikusat
Dato:  
Til: dng
Emne: Re: [DNG] netman-autostart_0.1.1
Edward Bartolo <edbarx@???> writes:
> Enjoy yourself, I am working on it. I think, I got a way of putting it
> right. There are two .desktop files that control how netman gui
> behaves:
> a) /etc/xdg/autostart/netman.desktop
> b) /usr/share/applications/netman.desktop
>
> The netman-gui.postinst script has to modify both of them.


In this case, you shouldn't copy the file but create a symlink to
it. This means there's only one copy which has to be modified.

[...]

> The sed command in the postinst script also has to
> make sure no multiple Exec= and Comment= lines are added to both
> .desktop files.


sed is generally the wrong choice for editing files (as it's the 'stream
editor'). ed can be used for that (needs to become a package dependency
as 'certain people in the Debian project' were hit by a pine at a
formative age and are thus opposed to using sensibly-working text
editors).

The following shell function should be sufficient for your use-case

-------
change_line()
{
    file="$1"
    new="`echo $2 | sed 's/\(.\)/\\\\\1/g'`"
    key=`expr "$2" : "\([^=]\+=\)."`
    ed "$file" <<EOF
/^$key/s/.*/$new
wq
EOF
}
-------


This takes a file as first argument and the new line as second
argument. If a line with the same 'keyword' (text before the first =)
already exists, it's replaced. Otherwise, nothing happens.

NB: Like all shell code (or most), this won't work with 'suitably
crafted input'. But shell programming is an exercise in inventing 'good
enough' solutions for fairly well-defined problems.