aboutsummaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rwxr-xr-xscript/about2
-rwxr-xr-xscript/alert-comment-on-request4
-rwxr-xr-xscript/alert-new-response-reminders4
-rwxr-xr-xscript/alert-not-clarified-request4
-rwxr-xr-xscript/alert-overdue-requests6
-rwxr-xr-xscript/alert-tracks-daemon4
-rwxr-xr-xscript/annotate-models5
-rwxr-xr-xscript/breakpointer2
-rw-r--r--script/cache-incoming-emails4
-rwxr-xr-xscript/check-recent-requests-sent4
-rwxr-xr-xscript/clear-caches4
-rwxr-xr-xscript/dbconsole2
-rwxr-xr-xscript/delete-old-things9
-rwxr-xr-xscript/destroy2
-rwxr-xr-xscript/generate2
-rwxr-xr-xscript/generate_pot.sh4
-rwxr-xr-xscript/handle-mail-replies166
-rwxr-xr-xscript/handle-mail-replies.rb180
-rwxr-xr-xscript/load-exim-logs13
-rwxr-xr-xscript/load-sample-data2
-rwxr-xr-xscript/performance/benchmarker2
-rwxr-xr-xscript/performance/profiler2
-rwxr-xr-xscript/performance/request2
-rwxr-xr-xscript/plugin2
-rwxr-xr-xscript/process/inspector2
-rwxr-xr-xscript/process/reaper2
-rwxr-xr-xscript/process/spawner2
-rwxr-xr-xscript/purge-varnish11
-rwxr-xr-xscript/rails-post-deploy29
-rwxr-xr-xscript/rebuild-xapian-index2
-rwxr-xr-xscript/runner2
-rwxr-xr-xscript/spec-all-pairs2
-rwxr-xr-xscript/spec_server4
-rwxr-xr-xscript/stop-new-responses-on-old-requests4
-rwxr-xr-xscript/test-run2
-rwxr-xr-xscript/update-xapian-index2
36 files changed, 272 insertions, 223 deletions
diff --git a/script/about b/script/about
index f2b98742d..49a7c2609 100755
--- a/script/about
+++ b/script/about
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/about'
diff --git a/script/alert-comment-on-request b/script/alert-comment-on-request
index bfca2663f..74782aa13 100755
--- a/script/alert-comment-on-request
+++ b/script/alert-comment-on-request
@@ -1,7 +1,7 @@
#!/bin/bash
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'RequestMailer.alert_comment_on_request'
+bundle exec ./runner 'RequestMailer.alert_comment_on_request'
diff --git a/script/alert-new-response-reminders b/script/alert-new-response-reminders
index d52381750..59fa76df1 100755
--- a/script/alert-new-response-reminders
+++ b/script/alert-new-response-reminders
@@ -1,7 +1,7 @@
#!/bin/bash
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'RequestMailer.alert_new_response_reminders'
+bundle exec ./runner 'RequestMailer.alert_new_response_reminders'
diff --git a/script/alert-not-clarified-request b/script/alert-not-clarified-request
index bfdbeaff5..a38fbc70e 100755
--- a/script/alert-not-clarified-request
+++ b/script/alert-not-clarified-request
@@ -1,7 +1,7 @@
#!/bin/bash
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'RequestMailer.alert_not_clarified_request'
+bundle exec ./runner 'RequestMailer.alert_not_clarified_request'
diff --git a/script/alert-overdue-requests b/script/alert-overdue-requests
index f6549e5b6..46450f1f2 100755
--- a/script/alert-overdue-requests
+++ b/script/alert-overdue-requests
@@ -1,7 +1,5 @@
#!/bin/bash
-LOC=`dirname $0`
-
-"$LOC/runner" 'RequestMailer.alert_overdue_requests()'
-
+cd "`dirname "$0"`"
+bundle exec ./runner 'RequestMailer.alert_overdue_requests()'
diff --git a/script/alert-tracks-daemon b/script/alert-tracks-daemon
index 9064eaa05..43712ae68 100755
--- a/script/alert-tracks-daemon
+++ b/script/alert-tracks-daemon
@@ -1,6 +1,6 @@
#!/bin/sh
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" --daemon TrackMailer.alert_tracks_loop
+bundle exec ./runner --daemon TrackMailer.alert_tracks_loop
diff --git a/script/annotate-models b/script/annotate-models
new file mode 100755
index 000000000..b6e01c010
--- /dev/null
+++ b/script/annotate-models
@@ -0,0 +1,5 @@
+#!/bin/bash
+#
+# annotates the models in app/ with schema information
+
+bundle exec annotate -m -p before --exclude tests,fixtures
diff --git a/script/breakpointer b/script/breakpointer
index 609564148..46a01d1b2 100755
--- a/script/breakpointer
+++ b/script/breakpointer
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/breakpointer'
diff --git a/script/cache-incoming-emails b/script/cache-incoming-emails
index a84a713d6..0b3069bd7 100644
--- a/script/cache-incoming-emails
+++ b/script/cache-incoming-emails
@@ -4,6 +4,6 @@
# Will take a while to run! Can use after clear-caches to refresh the database
# level caches if you like.
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'IncomingMessage.find_each() { |im| print "info request " + im.info_request.id.to_s + ", incoming message " + im.id.to_s + ": " + im.extract_attachments!.count.to_s + " attachments extracted to " + im.foi_attachments[0].directory + "; main body folded: " + im.get_main_body_text_folded.size.to_s + " attachment clipped:" + im.get_attachment_text_clipped.size.to_s + "\n" }'
+bundle exec ./runner 'IncomingMessage.find_each() { |im| print "info request " + im.info_request.id.to_s + ", incoming message " + im.id.to_s + ": " + im.extract_attachments!.count.to_s + " attachments extracted to " + im.foi_attachments[0].directory + "; main body folded: " + im.get_main_body_text_folded.size.to_s + " attachment clipped:" + im.get_attachment_text_clipped.size.to_s + "\n" }'
diff --git a/script/check-recent-requests-sent b/script/check-recent-requests-sent
index df5baf10a..588c6b73a 100755
--- a/script/check-recent-requests-sent
+++ b/script/check-recent-requests-sent
@@ -1,8 +1,8 @@
#!/bin/bash
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'EximLog.check_recent_requests_have_been_sent'
+bundle exec ./runner 'EximLog.check_recent_requests_have_been_sent'
diff --git a/script/clear-caches b/script/clear-caches
index be1d3d017..43fec2811 100755
--- a/script/clear-caches
+++ b/script/clear-caches
@@ -2,9 +2,9 @@
# Clear the cache of attachment and body text.
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" "ActiveRecord::Base.connection.execute(\"update incoming_messages set cached_attachment_text_clipped = null, cached_main_body_text_unfolded = null, cached_main_body_text_folded = null, sent_at = null, subject = null, mail_from = null, mail_from_domain = null, valid_to_reply_to = null, last_parsed = null\")"
+bundle exec ./runner "ActiveRecord::Base.connection.execute(\"update incoming_messages set cached_attachment_text_clipped = null, cached_main_body_text_unfolded = null, cached_main_body_text_folded = null, sent_at = null, subject = null, mail_from = null, mail_from_domain = null, valid_to_reply_to = null, last_parsed = null\")"
# Remove page cache (do it in two stages so live site gets cache cleared faster)
rm -fr $LOC/../old-cache
diff --git a/script/dbconsole b/script/dbconsole
index c25c5afcd..39042fad3 100755
--- a/script/dbconsole
+++ b/script/dbconsole
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/dbconsole'
diff --git a/script/delete-old-things b/script/delete-old-things
index 1d8cf645b..063d85e1f 100755
--- a/script/delete-old-things
+++ b/script/delete-old-things
@@ -1,9 +1,6 @@
#!/bin/bash
-LOC=`dirname $0`
-
-"$LOC/runner" 'PostRedirect.delete_old_post_redirects()'
-
-"$LOC/runner" 'TrackThingsSentEmail.delete_old_track_things_sent_email()'
-
+cd "`dirname "$0"`"
+bundle exec ./runner 'PostRedirect.delete_old_post_redirects()'
+bundle exec ./runner 'TrackThingsSentEmail.delete_old_track_things_sent_email()'
diff --git a/script/destroy b/script/destroy
index e63ac0ef5..fddc5160d 100755
--- a/script/destroy
+++ b/script/destroy
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/destroy'
diff --git a/script/generate b/script/generate
index 8c0486a09..fb8139d12 100755
--- a/script/generate
+++ b/script/generate
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/generate'
diff --git a/script/generate_pot.sh b/script/generate_pot.sh
index f6c82dda7..c0540c3d9 100755
--- a/script/generate_pot.sh
+++ b/script/generate_pot.sh
@@ -10,8 +10,8 @@ git status | grep app.po | awk '{print $3}' | xargs git add
git commit -m "Backup latest po files from Transifex"
# now regenerate POT and PO files from Alaveteli source
-rake gettext:store_model_attributes
-rake gettext:findpot
+bundle exec rake gettext:store_model_attributes
+bundle exec rake gettext:findpot
# upload the result to Transifex
tx push -t
diff --git a/script/handle-mail-replies b/script/handle-mail-replies
index 68cab9035..7006b83dd 100755
--- a/script/handle-mail-replies
+++ b/script/handle-mail-replies
@@ -1,164 +1,4 @@
-#!/usr/bin/env ruby
-# -*- coding: utf-8 -*-
+#!/bin/bash
-# Handle email responses sent to us.
-#
-# This script is invoked as a pipe command, i.e. with the raw email message on stdin.
-# - If a message is identified as a permanent bounce, the user is marked as having a
-# bounced address, and will not be sent any more messages.
-# - If a message is identified as an out-of-office autoreply, it is discarded.
-# - Any other messages are forwarded to config.get("FORWARD_NONBOUNCE_RESPONSES_TO")
-
-
-# We want to avoid loading rails unless we need it, so we start by just loading the
-# config file ourselves.
-$alaveteli_dir = File.join(File.dirname(__FILE__), '..')
-$:.push(File.join($alaveteli_dir, "commonlib", "rblib"))
-load "config.rb"
-MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true)
-MySociety::Config.load_default
-
-require 'rubygems'
-if File.exist? File.join($alaveteli_dir,'vendor','rails','Rakefile')
- $:.push(File.join($alaveteli_dir, "vendor", "rails", "actionmailer", "lib", "action_mailer", "vendor", "tmail-1.2.7"))
- require 'tmail'
-else
- require 'action_mailer'
-end
-
-def main(in_test_mode)
- Dir.chdir($alaveteli_dir) do
- raw_message = $stdin.read
- begin
- message = TMail::Mail.parse(raw_message)
- rescue
- # Error parsing message. Just pass it on, to be on the safe side.
- forward_on(raw_message) unless in_test_mode
- return 0
- end
-
- pfas = permanently_failed_addresses(message)
- if !pfas.empty?
- if in_test_mode
- puts pfas
- else
- pfas.each do |pfa|
- record_bounce(pfa, raw_message)
- end
- end
- return 1
- end
-
- if is_oof? message
- # Discard out-of-office messages
- return 2
- end
-
- # Otherwise forward the message on
- forward_on(raw_message) unless in_test_mode
- return 0
- end
-end
-
-def permanently_failed_addresses(message)
- if message.header_string("Return-Path") == "<>"
- # Some sort of auto-response
-
- # Check for Exim’s X-Failed-Recipients header
- failed_recipients = message.header_string("X-Failed-Recipients")
- if !failed_recipients.nil?
- # The X-Failed-Recipients header contains the email address that failed
- # Check for the words "This is a permanent error." in the body, to indicate
- # a permanent failure
- if message.body =~ /This is a permanent error./
- return failed_recipients.split(/,\s*/)
- end
- end
-
- # Next, look for multipart/report
- if message.content_type == "multipart/report"
- permanently_failed_recipients = []
- message.parts.each do |part|
- if part.content_type == "message/delivery-status"
- sections = part.body.split(/\r?\n\r?\n/)
- # The first section is a generic header; subsequent sections
- # represent a particular recipient. Since we
- sections[1..-1].each do |section|
- if section !~ /^Status: (\d)/ || $1 != '5'
- # Either we couldn’t find the Status field, or it was a transient failure
- break
- end
- if section =~ /^Final-Recipient: rfc822;(.+)/
- permanently_failed_recipients.push($1)
- end
- end
- end
- end
- if !permanently_failed_recipients.empty?
- return permanently_failed_recipients
- end
- end
- end
-
- return []
-end
-
-def is_oof?(message)
- # Check for out-of-office
-
- if message.header_string("X-POST-MessageClass") == "9; Autoresponder"
- return true
- end
-
- subject = message.header_string("Subject").downcase
- if message.header_string("Return-Path") == "<>"
- if subject.start_with? "out of office: "
- return true
- end
- if subject.start_with? "automatic reply: "
- return true
- end
- end
-
- if message.header_string("Auto-Submitted") == "auto-generated"
- if subject =~ /out of( the)? office/
- return true
- end
- end
-
- if subject.start_with? "out of office autoreply:"
- return true
- end
- if subject == "out of office"
- return true
- end
- if subject == "out of office reply"
- return true
- end
- if subject.end_with? "is out of the office"
- return true
- end
- return false
-end
-
-def forward_on(raw_message)
- forward_non_bounces_to = MySociety::Config.get("FORWARD_NONBOUNCE_RESPONSES_TO", "user-support@localhost")
- IO.popen("/usr/sbin/sendmail -i #{forward_non_bounces_to}", "w") do |f|
- f.write(raw_message);
- f.close;
- end
-end
-
-def load_rails
- require File.join('config', 'boot')
- require RAILS_ROOT + '/config/environment'
-end
-
-def record_bounce(email_address, bounce_message)
- load_rails
- User.record_bounce_for_email(email_address, bounce_message)
-end
-
-in_test_mode = (ARGV[0] == "--test")
-status = main(in_test_mode)
-exit(status) if in_test_mode
+cd "`dirname "$0"`"
+exec bundle exec ./handle-mail-replies.rb $@
diff --git a/script/handle-mail-replies.rb b/script/handle-mail-replies.rb
new file mode 100755
index 000000000..eba6f44cf
--- /dev/null
+++ b/script/handle-mail-replies.rb
@@ -0,0 +1,180 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+# Handle email responses sent to us.
+#
+# This script is invoked as a pipe command, i.e. with the raw email message on stdin.
+# - If a message is identified as a permanent bounce, the user is marked as having a
+# bounced address, and will not be sent any more messages.
+# - If a message is identified as an out-of-office autoreply, it is discarded.
+# - Any other messages are forwarded to config.get("FORWARD_NONBOUNCE_RESPONSES_TO")
+
+
+# We want to avoid loading rails unless we need it, so we start by just loading the
+# config file ourselves.
+$alaveteli_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+$:.push(File.join($alaveteli_dir, "commonlib", "rblib"))
+load "config.rb"
+MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true)
+MySociety::Config.load_default
+
+require 'action_mailer'
+
+def main(in_test_mode)
+ Dir.chdir($alaveteli_dir) do
+ raw_message = $stdin.read
+ begin
+ message = TMail::Mail.parse(raw_message)
+ rescue
+ # Error parsing message. Just pass it on, to be on the safe side.
+ forward_on(raw_message) unless in_test_mode
+ return 0
+ end
+
+ pfas = permanently_failed_addresses(message)
+ if !pfas.empty?
+ if in_test_mode
+ puts pfas
+ else
+ pfas.each do |pfa|
+ record_bounce(pfa, raw_message)
+ end
+ end
+ return 1
+ end
+
+ # If we are still here, there are no permanent failures,
+ # so if the message is a multipart/report then it must be
+ # reporting a temporary failure. In this case we discard it
+ if message.content_type == "multipart/report"
+ return 1
+ end
+
+ # Another style of temporary failure message
+ subject = message.header_string("Subject")
+ if message.content_type == "multipart/mixed" && subject == "Delivery Status Notification (Delay)"
+ return 1
+ end
+
+ # Discard out-of-office messages
+ if is_oof?(message)
+ return 2 # Use a different return code, to distinguish OOFs from bounces
+ end
+
+ # Otherwise forward the message on
+ forward_on(raw_message) unless in_test_mode
+ return 0
+ end
+end
+
+def permanently_failed_addresses(message)
+ if message.header_string("Return-Path") == "<>"
+ # Some sort of auto-response
+
+ # Check for Exim’s X-Failed-Recipients header
+ failed_recipients = message.header_string("X-Failed-Recipients")
+ if !failed_recipients.nil?
+ # The X-Failed-Recipients header contains the email address that failed
+ # Check for the words "This is a permanent error." in the body, to indicate
+ # a permanent failure
+ if message.body =~ /This is a permanent error./
+ return failed_recipients.split(/,\s*/)
+ end
+ end
+
+ # Next, look for multipart/report
+ if message.content_type == "multipart/report"
+ permanently_failed_recipients = []
+ message.parts.each do |part|
+ if part.content_type == "message/delivery-status"
+ sections = part.body.split(/\r?\n\r?\n/)
+ # The first section is a generic header; subsequent sections
+ # represent a particular recipient. Since we
+ sections[1..-1].each do |section|
+ if section !~ /^Status: (\d)/ || $1 != '5'
+ # Either we couldn’t find the Status field, or it was a transient failure
+ break
+ end
+ if section =~ /^Final-Recipient: rfc822;(.+)/
+ permanently_failed_recipients.push($1)
+ end
+ end
+ end
+ end
+ if !permanently_failed_recipients.empty?
+ return permanently_failed_recipients
+ end
+ end
+ end
+
+ subject = message.header_string("Subject")
+ # Then look for the style we’ve seen in WebShield bounces
+ # (These do not have a return path of <> in the cases I have seen.)
+ if subject == "Returned Mail: Error During Delivery"
+ if message.body =~ /^\s*---- Failed Recipients ----\s*((?:<[^>]+>\n)+)/
+ return $1.scan(/<([^>]+)>/).flatten
+ end
+ end
+
+ return []
+end
+
+def is_oof?(message)
+ # Check for out-of-office
+
+ if message.header_string("X-POST-MessageClass") == "9; Autoresponder"
+ return true
+ end
+
+ subject = message.header_string("Subject").downcase
+ if message.header_string("Return-Path") == "<>"
+ if subject.start_with? "out of office: "
+ return true
+ end
+ if subject.start_with? "automatic reply: "
+ return true
+ end
+ end
+
+ if message.header_string("Auto-Submitted") == "auto-generated"
+ if subject =~ /out of( the)? office/
+ return true
+ end
+ end
+
+ if subject.start_with? "out of office autoreply:"
+ return true
+ end
+ if subject == "out of office"
+ return true
+ end
+ if subject == "out of office reply"
+ return true
+ end
+ if subject.end_with? "is out of the office"
+ return true
+ end
+ return false
+end
+
+def forward_on(raw_message)
+ forward_non_bounces_to = MySociety::Config.get("FORWARD_NONBOUNCE_RESPONSES_TO", "user-support@localhost")
+ IO.popen("/usr/sbin/sendmail -i #{forward_non_bounces_to}", "w") do |f|
+ f.write(raw_message);
+ f.close;
+ end
+end
+
+def load_rails
+ require File.join('config', 'boot')
+ require File.join('config', 'environment')
+end
+
+def record_bounce(email_address, bounce_message)
+ load_rails
+ User.record_bounce_for_email(email_address, bounce_message)
+end
+
+in_test_mode = (ARGV[0] == "--test")
+status = main(in_test_mode)
+exit(status) if in_test_mode
diff --git a/script/load-exim-logs b/script/load-exim-logs
index 7e7f37a35..5ca0c66f8 100755
--- a/script/load-exim-logs
+++ b/script/load-exim-logs
@@ -1,21 +1,20 @@
#!/bin/bash
-LOC=`dirname $0`
+LOC=`dirname "$0"`
# Specific file if specified
if [ x$1 != x ]
then
- "$LOC/runner" 'EximLog.load_file("'$1'")'
+ f=`abspath "$1"`
+ cd "$LOC"
+ bundle exec ./runner 'EximLog.load_file("'$f'")'
exit
fi
# Load in last three days worth of logs (if they've been modified)
+cd "$LOC"
LATEST=$( ls /var/log/exim4/exim-mainlog-* 2>/dev/null | sort | tail -3 )
for X in $LATEST
do
- # echo "doing $X"
- "$LOC/runner" 'EximLog.load_file("'$X'")'
+ bundle exec ./runner 'EximLog.load_file("'$X'")'
done
-
-
-
diff --git a/script/load-sample-data b/script/load-sample-data
index e5f1be4cd..86e1af128 100755
--- a/script/load-sample-data
+++ b/script/load-sample-data
@@ -6,7 +6,7 @@
LOC=`dirname "$0"`
-rake --silent spec:db:fixtures:load
+bundle exec rake --silent spec:db:fixtures:load
"$LOC/runner" /dev/stdin <<END
env = ENV["RAILS_ENV"]
diff --git a/script/performance/benchmarker b/script/performance/benchmarker
index a94253aba..28bfceea0 100755
--- a/script/performance/benchmarker
+++ b/script/performance/benchmarker
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/performance/benchmarker'
diff --git a/script/performance/profiler b/script/performance/profiler
index e9e5b071d..11baf44f2 100755
--- a/script/performance/profiler
+++ b/script/performance/profiler
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/performance/profiler'
diff --git a/script/performance/request b/script/performance/request
index 658c80ef2..fff6fe660 100755
--- a/script/performance/request
+++ b/script/performance/request
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/performance/request'
diff --git a/script/plugin b/script/plugin
index 18ae72620..49f5c441f 100755
--- a/script/plugin
+++ b/script/plugin
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/plugin'
diff --git a/script/process/inspector b/script/process/inspector
index 696551c6b..467962602 100755
--- a/script/process/inspector
+++ b/script/process/inspector
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/process/inspector'
diff --git a/script/process/reaper b/script/process/reaper
index a03da9387..2eea898db 100755
--- a/script/process/reaper
+++ b/script/process/reaper
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/process/reaper'
diff --git a/script/process/spawner b/script/process/spawner
index 6852fba27..ac417c3a7 100755
--- a/script/process/spawner
+++ b/script/process/spawner
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot.rb'
+require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
require 'commands/process/spawner'
diff --git a/script/purge-varnish b/script/purge-varnish
new file mode 100755
index 000000000..932cf6635
--- /dev/null
+++ b/script/purge-varnish
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+LOC=`dirname $0`
+
+if [ "$1" == "--loop" ]
+then
+ "$LOC/runner" 'PurgeRequest.purge_all_loop'
+else
+ "$LOC/runner" 'PurgeRequest.purge_all'
+fi
+
diff --git a/script/rails-post-deploy b/script/rails-post-deploy
index d9e9bb3f1..193d0bbec 100755
--- a/script/rails-post-deploy
+++ b/script/rails-post-deploy
@@ -45,10 +45,10 @@ else
mkdir -p log
fi
# link the "downloads" directory in the cache to somewhere it can be served
-if [ ! -e $APP_DIR/public/download ]
+if [ ! -e "$APP_DIR/public/download" ]
then
- mkdir -p $APP_DIR/cache/zips/download
- ln -s $APP_DIR/cache/zips/download $APP_DIR/public/
+ mkdir -p "$APP_DIR/cache/zips/download"
+ ln -s "$APP_DIR/cache/zips/download" "$APP_DIR/public/"
fi
cd log
@@ -74,12 +74,31 @@ then
echo "ENV['RAILS_ENV'] ||= 'production'" > config/rails_env.rb
fi
+bundle_install_options=""
+if [ "$OPTION_STAGING_SITE" = "0" ]
+then
+ bundle_install_options="--without development:test --deployment"
+fi
+
+bundle install $bundle_install_options
+
+if [ -n "$OPTION_THEME_URLS" ]
+then
+ for THEME in "${OPTION_THEME_URLS[@]}"
+ do
+ echo "Installing $THEME..."
+ script/plugin install --force $THEME
+ done
+fi
+
+# Old version of the above, for backwards compatibility
if [ -n "$OPTION_THEME_URL" ]
then
- script/plugin install --force $OPTION_THEME_URL
+ echo "Installing $OPTION_THEME_URL using deprecated THEME_URL..."
+ script/plugin install --force $OPTION_THEME_URL
fi
# upgrade database
-rake db:migrate #--trace
+bundle exec rake db:migrate #--trace
diff --git a/script/rebuild-xapian-index b/script/rebuild-xapian-index
index 5986f5259..3012511de 100755
--- a/script/rebuild-xapian-index
+++ b/script/rebuild-xapian-index
@@ -1,4 +1,4 @@
#!/bin/bash
cd `dirname $0`
-rake --silent "$@" xapian:rebuild_index models="PublicBody User InfoRequestEvent"
+bundle exec rake --silent "$@" xapian:rebuild_index models="PublicBody User InfoRequestEvent"
diff --git a/script/runner b/script/runner
index 6b0bc0a08..2bd5e9aa7 100755
--- a/script/runner
+++ b/script/runner
@@ -3,7 +3,7 @@
daemon_mode = !ARGV.empty? && ARGV[0] == "--daemon"
script_dir = File.dirname(__FILE__)
-alaveteli_dir = File.join(script_dir, "..")
+alaveteli_dir = File.expand_path(File.join(script_dir, ".."))
Dir.chdir(alaveteli_dir) do
require File.join(alaveteli_dir, 'config', 'boot')
diff --git a/script/spec-all-pairs b/script/spec-all-pairs
index 5b6439a4e..6d7bb17c4 100755
--- a/script/spec-all-pairs
+++ b/script/spec-all-pairs
@@ -6,7 +6,7 @@
log_file=/dev/null
test_pair () {
- rake db:test:prepare > /dev/null 2>&1
+ bundle exec rake db:test:prepare > /dev/null 2>&1
output=$(script/spec "$1" "$2" 2>&1)
if [ $? -eq 0 ]
then
diff --git a/script/spec_server b/script/spec_server
index 1e839355f..dfdf8ff6c 100755
--- a/script/spec_server
+++ b/script/spec_server
@@ -41,7 +41,7 @@ module Spec
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
if in_memory_database?
- load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
+ load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
ActiveRecord::Migrator.up('db/migrate') # use migrations
end
@@ -80,7 +80,7 @@ def daemonize(pid_file = nil)
return yield if $DEBUG
pid = Process.fork{
Process.setsid
- Dir.chdir(RAILS_ROOT)
+ Dir.chdir(Rails.root)
trap("SIGINT"){ exit! 0 }
trap("SIGTERM"){ exit! 0 }
trap("SIGHUP"){ restart_test_server }
diff --git a/script/stop-new-responses-on-old-requests b/script/stop-new-responses-on-old-requests
index 77189cf0b..1e325403e 100755
--- a/script/stop-new-responses-on-old-requests
+++ b/script/stop-new-responses-on-old-requests
@@ -1,7 +1,7 @@
#!/bin/bash
-LOC=`dirname $0`
+cd "`dirname "$0"`"
-"$LOC/runner" 'InfoRequest.stop_new_responses_on_old_requests()'
+bundle exec ./runner 'InfoRequest.stop_new_responses_on_old_requests()'
diff --git a/script/test-run b/script/test-run
index 4c7a0e3ec..7810b57d5 100755
--- a/script/test-run
+++ b/script/test-run
@@ -1,5 +1,5 @@
#!/bin/bash
cd ../
-rake spec
+bundle exec rake spec
diff --git a/script/update-xapian-index b/script/update-xapian-index
index 6ece02de0..e365e2fec 100755
--- a/script/update-xapian-index
+++ b/script/update-xapian-index
@@ -1,5 +1,5 @@
#!/bin/bash
cd `dirname $0`
-rake --silent xapian:update_index "$@"
+bundle exec rake --silent xapian:update_index "$@"