Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
TT-RSS Updater

TT-RSS Updater

I've been a somewhat casual user of TT-RSS for several years, since Google Reader shut down (basically), but I only noticed this week that there had been no updates.

Turns out that there have been no packaged updates for a while... Two years in fact. Turns out that this forum post provided a script for performing updates, but it only pulled a couple of lines of config.

This updated script fixes that (with the config file 26).

So, this is heavily based on came88's post, and basically just fixes up some sed and adds some slightly better searching for existing values.

In your crontab, add this line (or something like it)

7 * * * * /var/www/sources/upgrade-tt-rss.sh

#!/bin/bash
### CONFIGURATIONS ###
# Directory configuration
DIRGIT=/var/www/sources/tt-rss/
DIRTT=/PATH/TO/YOUR/tt-rss/
DIRBK=/PATH/TO/YOUR/backups/
# Database configurations
DB_TYPE="`grep DB_TYPE ${DIRTT}/config.php | cut -d\' -f4`"
DB_HOST="`grep DB_HOST ${DIRTT}/config.php | cut -d\' -f4`"
DB_USER="`grep DB_USER ${DIRTT}/config.php | cut -d\' -f4`"
DB_NAME="`grep DB_NAME ${DIRTT}/config.php | cut -d\' -f4`"
DB_PASS="`grep DB_PASS ${DIRTT}/config.php | cut -d\' -f4`"
DB_PORT="`grep DB_PORT ${DIRTT}/config.php | cut -d\' -f4`"
# Other configurations as at config file version 26
MYSQL_CHARSET="`grep MYSQL_CHARSET ${DIRTT}/config.php | cut -d\' -f4`"
SELF_URL_PATH="`grep SELF_URL_PATH ${DIRTT}/config.php | cut -d\' -f4`"
FEED_CRYPT_KEY="`grep FEED_CRYPT_KEY ${DIRTT}/config.php | cut -d\' -f4`"
SINGLE_USER_MODE="`grep SINGLE_USER_MODE ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
SIMPLE_UPDATE_MODE="`grep SIMPLE_UPDATE_MODE ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
PHP_EXECUTABLE="`grep PHP_EXECUTABLE ${DIRTT}/config.php | cut -d\' -f4`"
LOCK_DIRECTORY="`grep LOCK_DIRECTORY ${DIRTT}/config.php | cut -d\' -f4`"
CACHE_DIR="`grep CACHE_DIR ${DIRTT}/config.php | cut -d\' -f4`"
ICONS_DIR="`grep ICONS_DIR ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
ICONS_URL="`grep ICONS_URL ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
AUTH_AUTO_CREATE="`grep AUTH_AUTO_CREATE ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
AUTH_AUTO_LOGIN="`grep AUTH_AUTO_LOGIN ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
FORCE_ARTICLE_PURGE="`grep FORCE_ARTICLE_PURGE ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
SPHINX_SERVER="`grep SPHINX_SERVER ${DIRTT}/config.php | cut -d\' -f4`"
SPHINX_INDEX="`grep SPHINX_INDEX ${DIRTT}/config.php | cut -d\' -f4`"
ENABLE_REGISTRATION="`grep ENABLE_REGISTRATION ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
REG_NOTIFY_ADDRESS="`grep REG_NOTIFY_ADDRESS ${DIRTT}/config.php | cut -d\' -f4`"
REG_MAX_USERS="`grep REG_MAX_USERS ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
SESSION_COOKIE_LIFETIME="`grep SESSION_COOKIE_LIFETIME ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
SMTP_FROM_NAME="`grep SMTP_FROM_NAME ${DIRTT}/config.php | cut -d\' -f4`"
SMTP_FROM_ADDRESS="`grep SMTP_FROM_ADDRESS ${DIRTT}/config.php | cut -d\' -f4`"
DIGEST_SUBJECT="`grep DIGEST_SUBJECT ${DIRTT}/config.php | cut -d\' -f4`"
SMTP_SERVER="`grep SMTP_SERVER ${DIRTT}/config.php | cut -d\' -f4`"
SMTP_LOGIN="`grep SMTP_LOGIN ${DIRTT}/config.php | cut -d\' -f4`"
SMTP_PASSWORD="`grep SMTP_PASSWORD ${DIRTT}/config.php | cut -d\' -f4`"
SMTP_SECURE="`grep SMTP_SECURE ${DIRTT}/config.php | cut -d\' -f4`"
CHECK_FOR_UPDATES="`grep CHECK_FOR_UPDATES ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
ENABLE_GZIP_OUTPUT="`grep ENABLE_GZIP_OUTPUT ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
PLUGINS="`grep PLUGINS ${DIRTT}/config.php | cut -d\' -f4`"
LOG_DESTINATION="`grep LOG_DESTINATION ${DIRTT}/config.php | cut -d\' -f4`"
CONFIG_VERSION="`grep CONFIG_VERSION ${DIRTT}/config.php | cut -d, -f 2 | cut -d\ -f 2 | cut -d\) -f 1`"
### SCRIPT ###
DATE=$(date +%F)
# check if the daemon is running
if [ -f "$DIRTT/lock/update_daemon.lock" ] ; then
STARTSTOPDAEMON="true"
else
STARTSTOPDAEMON="false"
fi
cd $DIRGIT
git fetch origin
reslog=$(git log HEAD..origin/master --oneline)
if [[ "${reslog}" != "" ]] ; then
# there are new changes: completing the pull
git merge origin/master
# shut down the update daemon if needed
$($STARTSTOPDAEMON) && /sbin/start-stop-daemon -K -p $DIRTT/lock/update_daemon.lock
cd $(dirname $DIRTT)
# back up current install files...
tar -czf $DIRBK/tt-rss-${DATE}.tar.gz $(basename $DIRTT)
# ... and database...
if [ "$DB_TYPE" == "mysql" -a "$DB_PORT" != "" ] ; then
MYSQL_PWD="$DB_PASS" mysqldump -h $DB_HOST -P $DB_PORT -u $DB_USER $DB_NAME | gzip > $DIRBK/tt-rss-${DATE}.sql.gz
elif [ "$DB_TYPE" == "mysql" ] ; then
MYSQL_PWD="$DB_PASS" mysqldump -h $DB_HOST -u $DB_USER $DB_NAME | gzip > $DIRBK/tt-rss-${DATE}.sql.gz
elif [ "$DB_PORT" != "" ] ; then
PGPASSWORD="$DB_PASS" pg_dump -w -h $DB_HOST -U $DB_USER $DB_NAME | gzip > $DIRBK/tt-rss-${DATE}.sql.gz
else
PGPASSWORD="$DB_PASS" pg_dump -w -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME | gzip > $DIRBK/tt-rss-${DATE}.sql.gz
fi
# ... and delete backups older than 2 weeks
find $DIRBK -mtime +14 -exec rm {} \;
# copy only modified files, except git related
rsync -rvch --exclude=.git/ --exclude=.buildpath --exclude=.gitignore --exclude=.project $DIRGIT/ $DIRTT
# always use new config file, maybe there are new parameters
# change config file to personalized settings
sed $DIRGIT/config.php-dist -r \
-e "s/define\('DB_TYPE', .*/define('DB_TYPE', '${DB_TYPE}');/" \
-e "s/define\('DB_HOST', .*/define('DB_HOST', '${DB_HOST}');/" \
-e "s/define\('DB_USER', .*/define('DB_USER', '${DB_USER}');/" \
-e "s/define\('DB_NAME', .*/define('DB_NAME', '${DB_NAME}');/" \
-e "s/define\('DB_PASS', .*/define('DB_PASS', '${DB_PASS}');/" \
-e "s/define\('DB_PORT', .*/define('DB_PORT', '${DB_PORT}');/" \
-e "s/define\('MYSQL_CHARSET', .*/define('MYSQL_CHARSET', '${MYSQL_CHARSET}');/" \
-e "s#define\('SELF_URL_PATH', .*#define('SELF_URL_PATH', '${SELF_URL_PATH}');#" \
-e "s/define\('FEED_CRYPT_KEY', .*/define('FEED_CRYPT_KEY', '${FEED_CRYPT_KEY}');/" \
-e "s/define\('SINGLE_USER_MODE', .*/define('SINGLE_USER_MODE', ${SINGLE_USER_MODE});/" \
-e "s/define\('SIMPLE_UPDATE_MODE', .*/define('SIMPLE_UPDATE_MODE', ${SIMPLE_UPDATE_MODE});/" \
-e "s#define\('PHP_EXECUTABLE', .*#define('PHP_EXECUTABLE', '${PHP_EXECUTABLE}');#" \
-e "s#define\('LOCK_DIRECTORY', .*#define('LOCK_DIRECTORY', '${LOCK_DIRECTORY}');#" \
-e "s#define\('CACHE_DIR', .*#define('CACHE_DIR', '${CACHE_DIR}');#" \
-e "s#define\('ICONS_DIR', .*#define('ICONS_DIR', ${ICONS_DIR});#" \
-e "s#define\('ICONS_URL', .*#define('ICONS_URL', ${ICONS_URL});#" \
-e "s/define\('AUTH_AUTO_CREATE', .*/define('AUTH_AUTO_CREATE', ${AUTH_AUTO_CREATE});/" \
-e "s/define\('AUTH_AUTO_LOGIN', .*/define('AUTH_AUTO_LOGIN', ${AUTH_AUTO_LOGIN});/" \
-e "s/define\('FORCE_ARTICLE_PURGE', .*/define('FORCE_ARTICLE_PURGE', ${FORCE_ARTICLE_PURGE});/" \
-e "s/define\('SPHINX_SERVER', .*/define('SPHINX_SERVER', '${SPHINX_SERVER}');/" \
-e "s/define\('SPHINX_INDEX', .*/define('SPHINX_INDEX', '${SPHINX_INDEX}');/" \
-e "s/define\('ENABLE_REGISTRATION', .*/define('ENABLE_REGISTRATION', ${ENABLE_REGISTRATION});/" \
-e "s/define\('REG_NOTIFY_ADDRESS', .*/define('REG_NOTIFY_ADDRESS', '${REG_NOTIFY_ADDRESS}');/" \
-e "s/define\('REG_MAX_USERS', .*/define('REG_MAX_USERS', ${REG_MAX_USERS});/" \
-e "s/define\('SESSION_COOKIE_LIFETIME', .*/define('SESSION_COOKIE_LIFETIME', ${SESSION_COOKIE_LIFETIME});/" \
-e "s/define\('SMTP_FROM_NAME', .*/define('SMTP_FROM_NAME', '${SMTP_FROM_NAME}');/" \
-e "s/define\('SMTP_FROM_ADDRESS', .*/define('SMTP_FROM_ADDRESS', '${SMTP_FROM_ADDRESS}');/" \
-e "s/define\('DIGEST_SUBJECT', .*/define('DIGEST_SUBJECT', '${DIGEST_SUBJECT}');/" \
-e "s/define\('CONFIG_VERSION', .*/define('CONFIG_VERSION', ${CONFIG_VERSION});/" \
> $DIRTT/config.php
# start the update daemon if needed
$($STARTSTOPDAEMON) && /sbin/start-stop-daemon -b -c www-data:www-data -S -x /usr/bin/php $DIRTT/update_daemon2.php -- --feeds --quiet
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment