redmine & chruby (fetch emails)

Mon, 11. May 2015

Categories: en sysadmin Tags: chruby Email redmine Ruby

 1#!/bin/bash
 2# chruby needs bash
 3#
 4#
 5# redmine email import with chruby.
 6#
 7#
 8# Put this script into <redmine_dir>/script and a set crontab like
 9#   $ sudo -u www-data crontab -l
10#   */15 * * * * <redmine_dir>/script/fetch-email.sh
11#
12cd "$(dirname "$0")/.."
13
14log="log/$(basename "$0" .sh).log"
15cat >> "$log" <<EOF
16
17$(date --rfc-3339=seconds) $0
18EOF
19
20# https://github.com/postmodern/chruby
21source /usr/local/share/chruby/chruby.sh
22source /usr/local/share/chruby/auto.sh
23
24# in case we use rbx in .ruby-version, we need to explicitly set ruby in
25# script/fetch-email.sh due to
26# https://github.com/rubinius/rubinius/issues/2916
27chruby ruby || { echo "Failed to change ruby." 1>> "$log" && exit 1; }
28
29bundle --version 1>/dev/null || { nice gem install bundle 1>> "$log" 2>> "$log" ; }
30bundle check 1>/dev/null 2>/dev/null || { nice bundle install 1>> "$log" 2>> "$log" ; }
31
32# http://www.redmine.org/projects/redmine/wiki/RedmineReceivingEmails
33nice bundle exec rake redmineโœ‰๏ธreceive_imap \
34  RAILS_ENV="production" \
35  host=<foo> \
36  ssl=1 \
37  port=993 \
38  username=<bar> \
39  password=<foobar> \
40  unknown_user=accept \
41  1>> "$log" \
42  2>> "$log"