If you run a custom theme for your Owncloud distribution, one of the things you know is that whenever you run an update of your Owncloud server it will automatically disable your theme as part of the update process. This is to keep things from blowing up in the event you have made a modification to a file that will break the updated version of Owncloud.

Themes can be used for more than just visual changes. For example, if you want to disable the “change password” button for users, this can be done by modifying some PHP files and dropping them in your theme. In my case, I added Piwik tracking code in several of my Owncloud files. I want to keep those modifications but I also want the updated code.

This has historically been a pain point during every Owncloud update. Every time I have run an update it has been a laborious process of comparing my theme files to the new stock files and looking for changes and then merging appropriately. So today, I decided to script part of that comparison process…

Here is the script:

tfiles=`find $trootdir$tname/ -type f -printf '%P\n' | grep -v .gif | grep -v .png | grep -v .svg | grep -v .css | grep -v .old | grep -v "tracking/"`
mkdir "$trootdir"diff

for tfile in $tfiles;
fname=`echo $tfile | sed -r 's/\//./g'`
diff -u $trootdir$tname/$tfile $orootdir$tfile > "$trootdir"diff/$fname-diff.txt

Very briefly, this script finds all files in my theme directory (with some exceptions, I filter out image files and the directory where I have some tracking code which isn’t part of stock), then uses DIFF in a loop to compare them with their stock counterparts. The output of diff is then fed to separate text files for each comparison in a directory (a directory called “diff” that is a sub directory of the Owncloud theme root directory). No more manually going through and running diff on every file.

The output file name of each text files includes the relative path, replacing “/” with “.” – the reason for doing this is in the event I ended up with identical file names in two different folders. It is also nice to know the relative path to the files that were diff’d.

Running two separate SSH sessions and this script I can much more quickly update my theme files after an upgrade and re-enable my theme!

If you want to use this yourself you only need update the theme name and possibly the root directory location of your owncloud install. Those are the tname and orootdir variables respectively. You may also want to adjust the grep filters.

Happy Friday!

1 of 1

This post has no comments. Be the first to leave one!

Leave a Reply