Replace text in XML

rskolden
New Contributor III

Maybe not the best place to put this but i've seen some talented people here so let's give it a shot.

We are looking into deploying LogMeIn on our PCs and Macs, and of course it works as intended on PC but not on Mac...

For those familiar with LogMeIn they have this "host preference" that pre-defines the settings on the host computer.
This doesn't work at all on Mac, and because of that I'm looking into setting the settings manually via scripts and so on.

Long story short, they use this XML which contains the settings, and what I want/trying to do is to find the following line:

<dword name="AllowLoopback">0x0</dword>

When this is found, I want to add the following lines under this line:

<dword name="AskForPermissionDefault">0x0</dword>
<dword name="FullCtrlBypassUsrPerm">0x0</dword>
<dword name="PermissionTimeout">0x1e</dword>
<string name="PermissionText">Lots and lots of text</string>

I have used sed before but I can't for the life of me get this to work, either it's an escape char error or I don't get the "" in the dword/string name.

Added a picture of the result I'm after, which I did manually in a text editor.

All suggestions appreciated!06d3addccd404045ac29663909e54027

2 ACCEPTED SOLUTIONS

dzogrim
New Contributor III

Hi,
You can install and use xmlstarlet (http://xmlstar.sourceforge.net).
For example if you have Mac Port it's easy to install it:

sudo port install xmlstarlet

Should be easy to add wanted lines in the good key with a bash script.

View solution in original post

rskolden
New Contributor III

Awesome tips, haven't looked into what this would mean to deploy, xcode and stuff, but I just wanted to show the results, which actually worked for me:

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword1 -v '0x0' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword1" -t attr -n 'name' -v 'AskForPermissionDefault' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword1" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword2 -v '0x0' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword2" -t attr -n 'name' -v 'FullCtrlBypassUsrPerm' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword2" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword3 -v '0x1e' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword3" -t attr -n 'name' -v 'PermissionTimeout' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword3" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n string -v 'Some Text' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/string1" -t attr -n 'name' -v 'PermissionText' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/string1" -v 'string' config.xml

So this is the "Host Preferences" for LogMeIn on Mac, I also sent a request to LogMeIn that they need to start with PLISTs or something not frankensteined from a PC...

View solution in original post

2 REPLIES 2

dzogrim
New Contributor III

Hi,
You can install and use xmlstarlet (http://xmlstar.sourceforge.net).
For example if you have Mac Port it's easy to install it:

sudo port install xmlstarlet

Should be easy to add wanted lines in the good key with a bash script.

rskolden
New Contributor III

Awesome tips, haven't looked into what this would mean to deploy, xcode and stuff, but I just wanted to show the results, which actually worked for me:

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword1 -v '0x0' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword1" -t attr -n 'name' -v 'AskForPermissionDefault' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword1" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword2 -v '0x0' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword2" -t attr -n 'name' -v 'FullCtrlBypassUsrPerm' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword2" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n dword3 -v '0x1e' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/dword3" -t attr -n 'name' -v 'PermissionTimeout' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/dword3" -v 'dword' config.xml

xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']" -t elem -n string -v 'Some Text' config.xml
xmlstarlet ed -L -s "/key/key/key/key/key/key[@name='RemoteControl']/string1" -t attr -n 'name' -v 'PermissionText' /Library/Application Support/LogMeIn/config.xml
xmlstarlet ed -L -r "/key/key/key/key/key/key[@name='RemoteControl']/string1" -v 'string' config.xml

So this is the "Host Preferences" for LogMeIn on Mac, I also sent a request to LogMeIn that they need to start with PLISTs or something not frankensteined from a PC...