sync-liferea.sh syncing script


I wrote this liferea syncing script for liferea yesterday. It seems to work as I wanted.. When I’ve got some problems, the backup that this script implements helps me solving the issues. I’m pleased with how this script makes my RSS more joyful.

I hope you can get some good ideas or that this script helps you sync your RSS feeds.

#!/bin/bash
 
# Change DIR for where your liferea.db file is.
DIR=/home/rolf/.liferea_1.4
BACKUPDIR=$DIR/backup/`date +%s`
REMOTE="xxx.xxx.xxx.xxx" # ip of remote machine
REMOTEDIR=$DIR
 
if [ "xrolf" = "x`whoami`" ]; then
        echo "User is rolf: OK"
else
        echo "Only run as user rolf"
        exit 1
fi
 
# [ "x$DISPLAY" != "x" ] && zenity --info --text="hei" || echo AA
 
pgrep liferea-bin && {
        zenity "Liferea is running. Stopp it before starting liferea-sync"
        echo "Liferea is running. Stopp it before starting liferea-sync"
        exit 1
 
        #pkill liferea
        #sleep 5
}
 
dbus-send --session --dest=org.gnome.feed.Reader \
  --print-reply=litereal --type=method_call \
  /org/gnome/feed/Reader \
  org.gnome.feed.Reader.Ping && {
        zenity "Liferea is running. Stopp it before starting liferea-sync"
        echo "Liferea is running. Stopp it before starting liferea-sync"
        exit 1
}
 
test -e $DIR/liferea.db || {
        echo "ERROR: $DIR/liferea.db does not exist"
        exit 1
}
test -e $DIR/feedlist.opml || {
        echo "ERROR: $DIR/feedlist.opml does not exist"
        exit 1
}
 
echo "Making $BACKUPDIR/self/ + $BACKUPDIR/remote/"
mkdir -p $BACKUPDIR/self
mkdir -p $BACKUPDIR/remote
mkdir -p $BACKUPDIR/remote-scp
 
echo "Making backup to $BACKUPDIR/self/"
cp -v $DIR/feedlist.opml $BACKUPDIR/self/
cp -v $DIR/liferea.db $BACKUPDIR/self/
cp -v $DIR/liferea.db-journal $BACKUPDIR/self/
cp -v $DIR/feedlist.opml.backup $BACKUPDIR/self/
 
echo "killing remote liferea"
ssh $REMOTE "pkill liferea && echo Killed remote liferea"
 
#echo "SCP: Copying from remote to $BACKUPDIR/remote-scp/"
#scp $REMOTE:$REMOTEDIR/{feedlist.opml*,liferea.db*} $BACKUPDIR/remote-scp/
 
echo "RSYNC-SSH: Copying from remote to $BACKUPDIR/remote/"
 
# Using rsync to preserve when file was last changed..
rsync -vaz -e "ssh" $REMOTE:$REMOTEDIR/feedlist.opml $BACKUPDIR/remote/
rsync -vaz -e "ssh" $REMOTE:$REMOTEDIR/liferea.db-journal $BACKUPDIR/remote/
rsync -vaz -e "ssh" $REMOTE:$REMOTEDIR/liferea.db $BACKUPDIR/remote/
rsync -vaz -e "ssh" $REMOTE:$REMOTEDIR/feedlist.opml.backup $BACKUPDIR/remote/
 
test -e $BACKUPDIR/remote/liferea.db || {
        echo "ERROR: Remote liferea.db does not exist in $BACKUPDIR/remote/"
        exit 1
}
test -e $BACKUPDIR/remote/feedlist.opml || {
        echo "ERROR: Remote feedlist.opml does not exist in $BACKUPDIR/remote/"
        exit 1
}
test -e $DIR/liferea.db-journal && {
        echo "ERROR: liferea.db-journal exists in $DIR/"
        echo "Unclean shutdown or is liferea still running? Find out/fix, then rerun liferea-sync."
        exit 1
}
test -e $BACKUPDIR/remote/liferea.db-journal && {
        echo "ERROR: liferea.db-journal exists in $BACKUPDIR/remote/"
        echo "Unclean REMOTE shutdown or is liferea still running? Find out/fix, then rerun liferea-sync."
        exit 1
}
 
test $BACKUPDIR/remote/liferea.db -nt $DIR/liferea.db && {
        echo "TEST: remote/liferea.db is newer than current liferea.db"
        echo ""
        echo "DO YOU WANT TO INSTALL THE NEW LIFEREA DB-file? <y>"
        valid=false
        while [ $valid = false ]
        do
        echo -n "Answer y or n: "
                read answer
                case $answer in
                        y*|Y*) echo Yes!
                                valid=true
                                cp -i -v $BACKUPDIR/remote/liferea.db $DIR/
                                cp -i -v $BACKUPDIR/remote/feedlist.opml $DIR/
                                cp -i -v $BACKUPDIR/remote/feedlist.opml.backup $DIR/
                                exit 0
                                ;;
 
                        n*|N*) echo No
                                valid=true
                                exit 0
                                ;;
                        esac
                done
}
test $BACKUPDIR/remote/liferea.db -ot $DIR/liferea.db && {
        echo "Already current! : $BACKUPDIR/remote/liferea.db is NOT newer than existing $DIR/liferea.db"
        exit 0
}
</y>

To make it work automaticly when starting up liferea, i changed the start-wrappar /usr/bin/liferea. Before modifying it, I copyed /usr/bin/liferea to /usr/bin/liferea-nosync .

This is what I added to /usr/bin/liferea to start the syncing in a terminal. When the syncing is done, you have to press enter in the xterm window to close it.

rm -f /tmp/liferea.sync.ok
xterm -e "/home/rolf/bin/sync_liferea.sh && touch /tmp/liferea.sync.ok ; read a"
test \! -f /tmp/liferea.sync.ok && exit 1

I also changed the liferea-add-feed script to look like this (It adds startup of liferea if it does not run and waits for liferea to start before it adds/sends the rss-feed to it.

#!/bin/sh
 
# This script can be used to automatically add
# subscriptions to Liferea. Just supply a valid
# and correctly escaped feed URL as parameter.
 
if [ $# -ne 1 ]; then
        echo "Wrong parameter count!"
        echo ""
        echo "Syntax: $0 <feed>"
        echo ""
        exit 1
fi
 
URL=$1
 
if ! which dbus-send >/dev/null 2>&1; then
        echo "Unable to locate the 'dbus-send' tool."
        echo "You need DBUS installed!"
        zenity --error --text="Unable to find dbus-send tool, you need DBUS installed."
        exit 1
fi
 
if ! pgrep -x "(liferea|liferea-bin)" >/dev/null 2>&1; then
        echo "Liferea is not running! You need to start it first."
        zenity --info --text="Liferea is not running! Starting it first..."
        liferea &
        isnotrunning=true
        while [ $isnotrunning = "true" ]
        do
        sleep 5
        dbus-send --session --dest=org.gnome.feed.Reader \
          --print-reply=litereal --type=method_call \
            /org/gnome/feed/Reader \
              org.gnome.feed.Reader.Ping && isnotrunning=false
        done
        dbus-send --session --dest=org.gnome.feed.Reader /org/gnome/feed/Reader org.gnome.feed.Reader.Subscribe string:$URL
        exit 0
fi
 
isnotrunning=true
while [ $isnotrunning = "true" ]
do
sleep 5
dbus-send --session --dest=org.gnome.feed.Reader \
  --print-reply=litereal --type=method_call \
    /org/gnome/feed/Reader \
      org.gnome.feed.Reader.Ping && isnotrunning=false
done
dbus-send --session --dest=org.gnome.feed.Reader /org/gnome/feed/Reader org.gnome.feed.Reader.Subscribe string:$URL

And I did this on both machines. It makes life easyer if you use SSH-keys for login.

1 Response to “sync-liferea.sh syncing script”


  1. Gravatar Icon 1 Julien

    Thanks for this script ! It was not exactly what I was looking for, because I use a server to store and get liferea files between my two systems, but it was really easy to adapt your work in order to suit my needs.

    The result can be seen here (in french) :

    http://blog.nozav.org/post/2009/03/04/Synchroniser-Liferea-entre-deux-systèmes

    Thanks again for sharing this,

    Julien

Leave a Reply