PDA

View Full Version : Script to easily change slimserver libraries?



gharris999
2007-07-05, 17:45
Is it just me, or is the forum search facility broken?

I'm pretty ignorant about Linux matters, so I'm wondering if there is a much easier way to accomplish what I'm trying to do here. My method seems pretty primitive-Pete-ish to me. Any comments or advice from any of you Linux script-mavens would be greatly appreciated.

Anyway..I want to be able to reconfigure slimserver quickly to use one of three different libraries using a script. The libraries are: 'slimserverdata' which is my "production" library with real music and real data; 'slimtestntfs' which is a test library of problematic files on a ntfs drive mounted with ntfs-3g; 'simtestext2fs' which are problematic files in a folder on the system drive.

I'm running the trunk code, so the preferences are stored in /usr/local/slimserver_trunk/server/prefs/server.pref. I'm also running a separate instance of MySQL and I've created schemas for each of the libraries.

I need to change 3 entries in the server.pref file: the 'audiodir' line, the 'dbsource' line and the 'playlistdir' line.

I assumed that I would use 'patch' to fixup server.prefs and that my script would go something like this:


#!/bin/sh

if [ ! -n "$1" ]
then
patchfile='slimserverdata'
else
patchfile=$1
fi

if [ ! -e /usr/local/slimserver_trunk/server/prefs/$patchfile.patch ]
then
echo $patchfile 'library does not exist!'
exit 1
fi

pushd . >/dev/null
cd /usr/local/slimserver_trunk/server/prefs
service slimserver stop
echo 'Changing slimserver data library to ' $patchfile
patch -p0 -f -i $patchfile.patch >/dev/null
service slimserver start
popd >/dev/null
I assume the patchfile will look something like this:


--- server.prefs
+++ server.prefs
@@ -660,7 +660,7 @@
_version: 1
allowedHosts: 127.0.0.1,192.168.0.*
artfolder: ''
-audiodir: /mnt/media/Music
+audiodir: /slimtest/music
authorize: 0
bandInArtists: 0
browseagelimit: 100
@@ -674,7 +674,7 @@
coverArt: ''
csrfProtectionLevel: 1
dbpassword: slimserver
-dbsource: dbi:mysql:hostname=127.0.0.1;port=3306;database=sl imserverdata
+dbsource: dbi:mysql:hostname=127.0.0.1;port=3306;database=sl imtestext2fs
dbusername: slimserver
disableStatistics: 1
disabledextensionsaudio: ''
@@ -702,7 +702,7 @@
noupnp: 1
password: ''
persistPlaylists: 1
-playlistdir: /mnt/media/Playlists
+playlistdir: /slimtest/playlists
playtrackalbum: 1
rank-PLUGIN_PICKS_MODULE_NAME: 4
refreshRate: 60
My problem is that the "change from" data on the lines in question is unknown. The server.prefs file could be configured for any of the three libraries. I've managed to make this work by using 'intermediate' patch files that change the 'audiodir', 'dbsource' and 'playlistdir' all to 'DUMMYDATA' and then patching again against that, but that seems like a kludge to me.

Is there a way to make 'patch' "forgiving" about the "change from" lines? Or can anyone suggest an alternative approach (short of any actual perl script) here? Perhaps I ought to be using some combination of echo, cat, grep magic to produce the appropriate patch file on the fly?

Robin Bowes
2007-07-06, 00:01
gharris999 wrote:
> Is there a way to make 'patch' "forgiving" about the "change from"
> lines? Or can anyone suggest an alternative approach (short of any
> actual perl script) here? Perhaps I ought to be using some combination
> of echo, cat, grep magic to produce the appropriate patch file on the

Too complex!

This will do what you want:

perl -pi -e 's!^audiodir: .*$!audiodir: /path/to/new/audio/dir!'
server.prefs
perl -pi -e 's!^playlistdir: .*$!playlist: /path/to/new/playlist/dir!'
server.prefs
perl -pi -e 's!database=.*$!database=newdbname!' server.prefs

(There are three commands listed above, each on a separate line)

Remember to stop slimserver first.

R.

gharris999
2007-07-06, 11:32
Robin: you are undermining my determination to avoid at all costs learning anything about perl. Now you've got me thinking about how to do this in a plug-in. Do you suppose it's possible? would a call to fork("service slimserver restart"); work inside a plugin?

Robin Bowes
2007-07-06, 12:34
gharris999 wrote:
> Robin: you are undermining my determination to avoid at all costs
> learning anything about perl. Now you've got me thinking about how to
> do this in a plug-in. Do you suppose it's possible? would a call to
> fork("service slimserver restart"); work inside a plugin?

Probably not as "service" is a super-user command. It might if you use
the full path to it, e.g. "/sbin/service" but I wouldn't be confident.

Besides, if you're changing stuff while slimserver is still running then
it is liable to overwrite your changes at any time.

R.