aboutsummaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rwxr-xr-xscript/about3
-rwxr-xr-xscript/alert-comment-on-request9
-rwxr-xr-xscript/alert-new-response-reminders9
-rwxr-xr-xscript/alert-not-clarified-request9
-rwxr-xr-xscript/alert-overdue-requests7
-rwxr-xr-xscript/alert-tracks10
-rwxr-xr-xscript/annotate-models2
-rwxr-xr-xscript/autospec6
-rwxr-xr-xscript/breakpointer3
-rwxr-xr-x[-rw-r--r--]script/cache-incoming-emails4
-rwxr-xr-xscript/check-recent-requests-sent10
-rwxr-xr-xscript/clear-caches14
-rwxr-xr-xscript/compact-xapian-database2
-rwxr-xr-xscript/console3
-rwxr-xr-xscript/dbconsole3
-rwxr-xr-xscript/delete-old-things9
-rwxr-xr-xscript/destroy3
-rwxr-xr-xscript/direct-rspec8
-rwxr-xr-xscript/generate3
-rwxr-xr-xscript/generate_pot.sh22
-rwxr-xr-xscript/handle-mail-replies.rb9
-rwxr-xr-xscript/install-as-user159
-rwxr-xr-xscript/load-mail-server-logs4
-rwxr-xr-xscript/load-sample-data24
-rwxr-xr-xscript/mailin5
-rwxr-xr-xscript/make-crontab16
-rwxr-xr-xscript/mysociety-switch-to-shared71
-rwxr-xr-xscript/performance/benchmarker3
-rwxr-xr-xscript/performance/profiler3
-rwxr-xr-xscript/performance/request3
-rwxr-xr-xscript/plugin3
-rwxr-xr-xscript/process/inspector3
-rwxr-xr-xscript/process/reaper3
-rwxr-xr-xscript/process/spawner3
-rwxr-xr-xscript/purge-varnish7
-rwxr-xr-xscript/rails6
-rwxr-xr-xscript/rails-deploy-before-down148
-rwxr-xr-xscript/rails-deploy-while-down16
-rwxr-xr-xscript/rails-post-deploy93
-rwxr-xr-xscript/request-creation-graph2
-rwxr-xr-xscript/runner8
-rwxr-xr-xscript/send-batch-requests4
-rwxr-xr-xscript/server3
-rwxr-xr-xscript/site-specific-install.sh168
-rwxr-xr-xscript/spec10
-rwxr-xr-xscript/spec-all-pairs81
-rwxr-xr-xscript/spec_server116
-rwxr-xr-xscript/stop-new-responses-on-old-requests9
-rwxr-xr-xscript/switch-theme.rb133
-rwxr-xr-xscript/test-run5
-rwxr-xr-xscript/update-public-body-stats4
-rwxr-xr-xscript/user-use-graph2
-rwxr-xr-xscript/wraptest43
53 files changed, 791 insertions, 515 deletions
diff --git a/script/about b/script/about
deleted file mode 100755
index 49a7c2609..000000000
--- a/script/about
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-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 74782aa13..849f4a8d8 100755
--- a/script/alert-comment-on-request
+++ b/script/alert-comment-on-request
@@ -1,7 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'RequestMailer.alert_comment_on_request'
-
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'RequestMailer.alert_comment_on_request'
diff --git a/script/alert-new-response-reminders b/script/alert-new-response-reminders
index 59fa76df1..148706d49 100755
--- a/script/alert-new-response-reminders
+++ b/script/alert-new-response-reminders
@@ -1,7 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'RequestMailer.alert_new_response_reminders'
-
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'RequestMailer.alert_new_response_reminders'
diff --git a/script/alert-not-clarified-request b/script/alert-not-clarified-request
index a38fbc70e..8d61c1800 100755
--- a/script/alert-not-clarified-request
+++ b/script/alert-not-clarified-request
@@ -1,7 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'RequestMailer.alert_not_clarified_request'
-
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'RequestMailer.alert_not_clarified_request'
diff --git a/script/alert-overdue-requests b/script/alert-overdue-requests
index 46450f1f2..ebc2897a0 100755
--- a/script/alert-overdue-requests
+++ b/script/alert-overdue-requests
@@ -1,5 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'RequestMailer.alert_overdue_requests()'
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'RequestMailer.alert_overdue_requests'
diff --git a/script/alert-tracks b/script/alert-tracks
index 117f7a406..17426b4e0 100755
--- a/script/alert-tracks
+++ b/script/alert-tracks
@@ -1,11 +1,9 @@
#!/bin/bash
-
-LOC=`dirname $0`
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
if [ "$1" == "--loop" ]
then
- "$LOC/runner" 'TrackMailer.alert_tracks_loop'
+ bundle exec rails runner 'TrackMailer.alert_tracks_loop'
else
- "$LOC/runner" 'TrackMailer.alert_tracks'
+ bundle exec rails runner 'TrackMailer.alert_tracks'
fi
-
diff --git a/script/annotate-models b/script/annotate-models
index b6e01c010..7b6daa3c5 100755
--- a/script/annotate-models
+++ b/script/annotate-models
@@ -2,4 +2,4 @@
#
# annotates the models in app/ with schema information
-bundle exec annotate -m -p before --exclude tests,fixtures
+bundle exec annotate --show-migration --position before --exclude tests,fixtures
diff --git a/script/autospec b/script/autospec
deleted file mode 100755
index 837bbd7f4..000000000
--- a/script/autospec
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/env ruby
-gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
-ENV['RSPEC'] = 'true' # allows autotest to discover rspec
-ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
-system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
- $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
diff --git a/script/breakpointer b/script/breakpointer
deleted file mode 100755
index 46a01d1b2..000000000
--- a/script/breakpointer
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-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 0b3069bd7..b13efbd8c 100644..100755
--- a/script/cache-incoming-emails
+++ b/script/cache-incoming-emails
@@ -4,6 +4,4 @@
# Will take a while to run! Can use after clear-caches to refresh the database
# level caches if you like.
-cd "`dirname "$0"`"
-
-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" }'
+bundle exec rails 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 7840dba4a..8f21fb6e7 100755
--- a/script/check-recent-requests-sent
+++ b/script/check-recent-requests-sent
@@ -1,8 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'MailServerLog.check_recent_requests_have_been_sent'
-
-
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'MailServerLog.check_recent_requests_have_been_sent'
diff --git a/script/clear-caches b/script/clear-caches
index 43fec2811..20ee3df19 100755
--- a/script/clear-caches
+++ b/script/clear-caches
@@ -1,13 +1,11 @@
#!/bin/bash
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
# Clear the cache of attachment and body text.
-cd "`dirname "$0"`"
-
-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\")"
+bundle exec rails 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
-mv $LOC/../cache $LOC/../old-cache
-rm -fr $LOC/../old-cache
-
+rm -fr $TOP_DIR/old-cache
+mv $TOP_DIR/cache $TOP_DIR/old-cache
+rm -fr $TOP_DIR/old-cache
diff --git a/script/compact-xapian-database b/script/compact-xapian-database
index f1a6058b0..982c0e878 100755
--- a/script/compact-xapian-database
+++ b/script/compact-xapian-database
@@ -4,7 +4,7 @@ export RAILS_ENV=$1
set -e
if [ -x /usr/bin/xapian-compact ]; then
- XAPIAN_DB_DIR=$( cd "$( dirname "$0" )" && pwd )/../vendor/plugins/acts_as_xapian/xapiandbs
+ XAPIAN_DB_DIR=$( cd "$( dirname "$0" )" && pwd )/../lib/acts_as_xapian/xapiandbs
if [ -e "$XAPIAN_DB_DIR/$RAILS_ENV.new" ]; then
echo >&2 "Didn't compact Xapian database because there was an existing database at $XAPIAN_DB_DIR/$RAILS_ENV.new"
exit 1
diff --git a/script/console b/script/console
deleted file mode 100755
index 83386647f..000000000
--- a/script/console
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/console'
diff --git a/script/dbconsole b/script/dbconsole
deleted file mode 100755
index 39042fad3..000000000
--- a/script/dbconsole
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-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 063d85e1f..a97ba4869 100755
--- a/script/delete-old-things
+++ b/script/delete-old-things
@@ -1,6 +1,5 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'PostRedirect.delete_old_post_redirects()'
-bundle exec ./runner 'TrackThingsSentEmail.delete_old_track_things_sent_email()'
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'PostRedirect.delete_old_post_redirects'
+bundle exec rails runner 'TrackThingsSentEmail.delete_old_track_things_sent_email'
diff --git a/script/destroy b/script/destroy
deleted file mode 100755
index fddc5160d..000000000
--- a/script/destroy
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/destroy'
diff --git a/script/direct-rspec b/script/direct-rspec
deleted file mode 100755
index 50a1daba1..000000000
--- a/script/direct-rspec
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-./vendor/plugins/rspec/bin/spec $1
-
-# spec/controllers/request_controller_spec.rb
-
-#ruby -I/home/francis/keep/devel/mysociety/foi/vendor/plugins/rspec/lib /home/francis/keep/devel/mysociety/foi/vendor/plugins/rspec/bin/spec spec/controllers/admin_public_body_controller_spec.rb spec/controllers/application_spec.rb spec/controllers/request_controller_spec.rb spec/controllers/user_controller_spec.rb spec/controllers/admin_controller_spec.rb spec/controllers/body_controller_spec.rb spec/models/incoming_message_spec.rb spec/models/user_spec.rb spec/models/request_mailer_spec.rb spec/models/post_redirect_spec.rb spec/models/public_body_spec.rb spec/models/info_request_spec.rb spec/models/user_mailer_spec.rb spec/models/outgoing_message_spec.rb --options /home/francis/keep/devel/mysociety/foi/spec/spec.opts
-
diff --git a/script/generate b/script/generate
deleted file mode 100755
index fb8139d12..000000000
--- a/script/generate
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-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
deleted file mode 100755
index c0540c3d9..000000000
--- a/script/generate_pot.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-echo "This is NOT a completed script! Just use it as reference for what to do from the command line, or fix it until it works!"
-exit 1
-
-cd `dirname $0`
-# grab latest po files from Transifex
-tx pull -a -f
-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
-bundle exec rake gettext:store_model_attributes
-bundle exec rake gettext:findpot
-
-# upload the result to Transifex
-tx push -t
-
-# re-download (it removes the fuzzy strings and normalises it to the format last committed)
-tx pull -a -f
-git status | grep app.po | awk '{print $3}' | xargs git add
-git commit -m "Updated POT"
diff --git a/script/handle-mail-replies.rb b/script/handle-mail-replies.rb
index 4e35ee0cf..cbff03acb 100755
--- a/script/handle-mail-replies.rb
+++ b/script/handle-mail-replies.rb
@@ -14,12 +14,15 @@
# config file ourselves.
$alaveteli_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
$:.push(File.join($alaveteli_dir, "commonlib", "rblib"))
-load "config.rb"
+load 'config.rb'
$:.push(File.join($alaveteli_dir, "lib"))
$:.push(File.join($alaveteli_dir, "lib", "mail_handler"))
-require "configuration"
+load 'configuration.rb'
MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true)
MySociety::Config.load_default
+
+
+require 'active_support/all'
require 'mail_handler'
if RUBY_VERSION.to_f >= 1.9
# the default encoding for IO is utf-8, and we use utf-8 internally
@@ -165,7 +168,7 @@ def is_oof?(message)
end
def forward_on(raw_message)
- IO.popen("/usr/sbin/sendmail -i #{Configuration::forward_nonbounce_responses_to}", "w") do |f|
+ IO.popen("/usr/sbin/sendmail -i #{AlaveteliConfiguration::forward_nonbounce_responses_to}", "w") do |f|
f.write(raw_message);
f.close;
end
diff --git a/script/install-as-user b/script/install-as-user
new file mode 100755
index 000000000..aaad52145
--- /dev/null
+++ b/script/install-as-user
@@ -0,0 +1,159 @@
+#!/bin/bash
+
+set -e
+set -x
+
+if [ $# -ne 3 ]
+then
+ cat >&2 <<EOUSAGE
+Usage: $0 <UNIX-USER> <HOST> <INSTALLATION-DIRECTORY>
+EOUSAGE
+ exit 1
+fi
+
+UNIX_USER="$1"
+HOST="$2"
+DIRECTORY="$3"
+DB_NAME="alaveteli"
+
+# Check that the arguments we've been passed are sensible:
+
+IP_ADDRESS_FOR_HOST="$(dig +short $HOST)"
+
+if [ x = x"$IP_ADDRESS_FOR_HOST" ]
+then
+ echo "The hostname $HOST didn't resolve to an IP address"
+ exit 1
+fi
+
+if ! id "$UNIX_USER" 2> /dev/null > /dev/null
+then
+ echo "The user '$UNIX_USER' didn't exist."
+ exit 1
+fi
+
+if [ "$(whoami)" != "$UNIX_USER" ]
+then
+ echo "This script should be run by the user '$UNIX_USER'."
+ exit 1
+fi
+
+REPOSITORY="$DIRECTORY/alaveteli"
+LINK_DESTINATION="$HOME/alaveteli"
+
+ln -sfn "$REPOSITORY" $LINK_DESTINATION
+cd "$REPOSITORY"
+
+BASHRC="$HOME/.bashrc"
+
+BASHRC_GEM_COMMENT="Set up local gem directory for Alaveteli"
+BASHRC_START="# START $BASHRC_GEM_COMMENT"
+BASHRC_END="# END $BASHRC_GEM_COMMENT"
+
+# Remove the old lines we added:
+sed -ibackup "/$BASHRC_START/,/$BASHRC_END/d" "$BASHRC"
+
+# Create a temporary file, so we can prepend the lines we need. They
+# need to be prepended since the Ubuntu skeleton .bashrc begins with
+# '[ -z "$PS1" ] && return', skipping the rest of the .bashrc for
+# non-interactive use, but we need the gem settings when invoking
+# commands in the shell non-interactively.
+TMP_BASHRC="$(mktemp "$BASHRC.XXXXXXX")"
+
+cat >>$TMP_BASHRC <<EOBRC
+$BASHRC_START
+export GEM_HOME="$HOME/gems"
+mkdir -p "\$GEM_HOME"
+export GEM_PATH=
+export PATH="\$GEM_HOME/bin:\$PATH"
+$BASHRC_END
+EOBRC
+
+cat "$BASHRC" >> "$TMP_BASHRC"
+mv "$TMP_BASHRC" "$BASHRC"
+
+source "$BASHRC"
+
+# Speed up the installation of gems:
+echo 'gem: --no-ri --no-rdoc' > "$HOME/.gemrc"
+
+# Write sensible values into the config file:
+
+function random_alphanumerics() {
+ < /dev/urandom tr -dc A-Za-z0-9 | head -c$1
+}
+
+RANDOM_EMAIL_SECRET=$(random_alphanumerics 32)
+RANDOM_EMERGENCY_PASSWORD=$(random_alphanumerics 10)
+RANDOM_COOKIE_SECRET=$(random_alphanumerics 100)
+
+if ! [ -f config/general.yml ]
+then
+ sed -r \
+ -e "s,^( *DOMAIN:).*,\\1 '$HOST'," \
+ -e "s,^( *FORCE_SSL:).*,\\1 false," \
+ -e "s,^( *TIME_ZONE:).*,\\1 'Europe/London'," \
+ -e "s,^( *BLOG_FEED:).*,\\1 ''," \
+ -e "s,^( *TWITTER_USERNAME:).*,\\1 ''," \
+ -e "s,^( *INCLUDE_DEFAULT_LOCALE_IN_URLS:).*,\\1 false," \
+ -e "s,^( *INCOMING_EMAIL_DOMAIN:).*,\\1 '$HOST'," \
+ -e "s,^( *INCOMING_EMAIL_PREFIX:).*,\\1 'foi+'," \
+ -e "s,^( *INCOMING_EMAIL_SECRET:).*,\\1 '$RANDOM_EMAIL_SECRET'," \
+ -e "s,^( *ADMIN_USERNAME:).*,\\1 'emergency'," \
+ -e "s,^( *ADMIN_PASSWORD:).*,\\1 '$RANDOM_EMERGENCY_PASSWORD'," \
+ -e "s,^( *CONTACT_EMAIL:).*,\\1 'postmaster@$HOST'," \
+ -e "s,^( *TRACK_SENDER_EMAIL:).*,\\1 'postmaster@$HOST'," \
+ -e "s,^( *COOKIE_STORE_SESSION_SECRET:).*,\\1 '$RANDOM_COOKIE_SECRET'," \
+ -e "s,^( *FORWARD_NONBOUNCE_RESPONSES_TO:).*,\\1 'user-support@$HOST'," \
+ -e "s,^( *HTML_TO_PDF_COMMAND:).*,\\1 '/usr/bin/wkhtmltopdf-static'," \
+ -e "s,^( *EXCEPTION_NOTIFICATIONS_FROM:).*,\\1 'do-not-reply-to-this-address@$HOST'," \
+ -e "/EXCEPTION_NOTIFICATIONS_TO:/,/^$/c EXCEPTION_NOTIFICATIONS_TO:\n - team@$HOST\n" \
+ -e "s,^( *VARNISH_HOST:).*,\\1 null," \
+ -e "s,^( *MTA_LOG_PATH:).*,\\1 '/var/log/mail/mail.log-*'," \
+ -e "s,^( *MTA_LOG_TYPE:).*,\\1 'postfix'," \
+ -e "s,^( *DONATION_URL:).*,\\1 null," \
+ -e "s,^( *THEME_BRANCH:).*,\\1 'develop'," \
+ -e "s,^( *USE_MAILCATCHER_IN_DEVELOPMENT:).*,\\1 false," \
+ config/general.yml-example > config/general.yml
+fi
+
+# add database.yml
+sed -r \
+ -e "s,^( *database: *)foi_(.*),\\1${DB_NAME}_\\2," \
+ -e "s,^( *username: *).*,\\1${UNIX_USER}," \
+ -e "s,^( *password: *).*,\\1null," \
+ -e "s,^( *host: *).*,\\1/var/run/postgresql/," \
+ -e "s,# constraint_disabling: false, constraint_disabling: false," \
+ config/database.yml-example > config/database.yml
+
+for SUFFIX in production test development
+do
+ REAL_DB_NAME="${DB_NAME}_$SUFFIX"
+ echo Creating the database $REAL_DB_NAME
+ # Create each database if it doesn't exist:
+ if ! psql -l | egrep "^ *$REAL_DB_NAME *\|" > /dev/null
+ then
+ createdb -T template0 --owner "$UNIX_USER" "$REAL_DB_NAME"
+ fi
+done
+
+# Bundler isn't packaged on Debian squeeze, so we have to install it
+# as a gem:
+
+which bundle || gem install bundler
+
+echo Running rails-post-deploy
+script/rails-post-deploy
+
+LOADED_INDICATOR="$HOME/.alaveteli-sample-data-loaded"
+
+if [ ! -f "$LOADED_INDICATOR" ]
+then
+ echo Running load-sample-data
+ bundle exec script/load-sample-data
+
+ echo Running rebuild-xapian-index
+ script/rebuild-xapian-index
+
+ touch "$LOADED_INDICATOR"
+fi
diff --git a/script/load-mail-server-logs b/script/load-mail-server-logs
index 9ff7a1401..770bf7026 100755
--- a/script/load-mail-server-logs
+++ b/script/load-mail-server-logs
@@ -14,7 +14,7 @@ then
*) f=$(pwd)/$1 ;;
esac
cd "$LOC"
- bundle exec ./runner 'MailServerLog.load_file("'$f'")'
+ bundle exec rails runner 'MailServerLog.load_file("'$f'")'
exit
fi
@@ -23,5 +23,5 @@ cd "$LOC"
LATEST=$( ls $OPTION_MTA_LOG_PATH 2>/dev/null | sort | tail -3 )
for X in $LATEST
do
- bundle exec ./runner 'MailServerLog.load_file("'$X'")'
+ bundle exec rails runner 'MailServerLog.load_file("'$X'")'
done
diff --git a/script/load-sample-data b/script/load-sample-data
index 86e1af128..c9e5997f5 100755
--- a/script/load-sample-data
+++ b/script/load-sample-data
@@ -4,16 +4,26 @@
# the fact that the fixtures aren't aware of the fact that RawEmails
# have a filesystem representation of their contents
-LOC=`dirname "$0"`
+export LOC=`dirname "$0"`
+bundle exec rails runner /dev/stdin <<END
+require 'rspec/rails'
+require Rails.root.join("spec", "support", "load_file_fixtures")
+require Rails.root.join("spec", "support", "email_helpers")
-bundle exec rake --silent spec:db:fixtures:load
+RSpec.configure do |config|
+ config.fixture_path = Rails.root.join("spec","fixtures")
+end
-"$LOC/runner" /dev/stdin <<END
-env = ENV["RAILS_ENV"]
-require "spec/spec_helper.rb" # this sets RAILS_ENV to 'test'
-ENV["RAILS_ENV"] = env # so restore to what it was before
+# HACK: Normally to load fixtures you'd run `rake db:fixtures:load` but since we
+# have .csv files in the fixtures folder Rails tries to load those too. Therefore
+# we've pinched some code to load the fixtures:
+# https://github.com/rails/rails/blob/v3.1.11/activerecord/lib/active_record/railties/databases.rake#L311
+fixtures_dir = Rails.root.join("spec","fixtures").to_s
+Dir["#{fixtures_dir}/**/*.yml"].each do |fixture_file|
+ ActiveRecord::Fixtures.create_fixtures(fixtures_dir, fixture_file[(fixtures_dir.size + 1)..-5])
+end
load_raw_emails_data
END
-echo "Loaded fixtures. You may now wish to run $LOC/update-xapian-index"
+echo "Loaded fixtures. You may now wish to run $LOC/update-xapian-index"
diff --git a/script/mailin b/script/mailin
index b4d77f7a4..65f9d06f2 100755
--- a/script/mailin
+++ b/script/mailin
@@ -13,7 +13,7 @@ source commonlib/shlib/deployfns
read_conf config/general
-script/runner 'RequestMailer.receive(STDIN.read)' <"$INPUT" >"$OUTPUT" 2>&1
+bundle exec rails runner 'RequestMailer.receive(STDIN.read)' <"$INPUT" >"$OUTPUT" 2>&1
ERROR_CODE=$?
if [ ! "$ERROR_CODE" = "0" ]
then
@@ -22,7 +22,8 @@ then
# send error to administators (use mutt for MIME encoding)
SUBJ="Mail import error for $OPTION_DOMAIN"
BODY="There was an error code $ERROR_CODE returned by the RequestMailer.receive command in script/mailin. See attached for details. This might be quite serious, such as the database was down, or might be an email with corrupt headers that Rails is choking on. We returned the email with an exit code 75, which for Exim at least instructs the MTA to try again later. A well configured installation of this code will separately have had Exim make a backup copy of the email in a separate mailbox, just in case."
- /usr/bin/mutt -s "$SUBJ" -a "$OUTPUT" "$INPUT" -- "$OPTION_CONTACT_EMAIL" <<<"$BODY"
+ FROM="$OPTION_BLACKHOLE_PREFIX@$OPTION_INCOMING_EMAIL_DOMAIN"
+ /usr/bin/mutt -e "set use_envelope_from" -e "set envelope_from_address=$FROM" -s "$SUBJ" -a "$OUTPUT" "$INPUT" -- "$OPTION_FORWARD_NONBOUNCE_RESPONSES_TO" <<<"$BODY"
# tell exim error was temporary, so try again later (no point bouncing message to authority)
rm -f "$INPUT" "$OUTPUT"
diff --git a/script/make-crontab b/script/make-crontab
deleted file mode 100755
index 1b4fbabbd..000000000
--- a/script/make-crontab
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env python
-import re
-
-mailto = "recipient-of-any-errors@localhost"
-user = "user-to-run-as"
-location = "/path/to/alaveteli"
-
-template = open("config/crontab.ugly").read()
-template = re.sub(r"MAILTO=.*", "MAILTO=%s" % mailto, template)
-template = template.replace("!!(*= $user *)!!", user)
-template = re.sub(r"/data/vhost/.*/script", location + "/script", template)
-
-print template
-
-
-
diff --git a/script/mysociety-switch-to-shared b/script/mysociety-switch-to-shared
new file mode 100755
index 000000000..f82e77706
--- /dev/null
+++ b/script/mysociety-switch-to-shared
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+# This script is a one-off script to move the shared files on a
+# mySociety instance of Alaveteli out of the repository and into the
+# vhost's shared directory. This is specific to mySociety's servers -
+# the list of files and directories which are moved would be unlikely
+# to be correct in another environment.
+#
+# This should be run *before* the first time the site is deployed with
+# the timestamped_deploy option.
+
+set -e
+
+# (Using `pwd -P` here instead of readlink -f so that it works on Mac
+# OS as well, just in case that's required for testing on a laptop.)
+RAILS_ROOT="$(cd "$(dirname "$BASH_SOURCE")/.." && pwd -P)"
+VHOST_DIR="$(cd "$RAILS_ROOT/.." && pwd -P)"
+SHARED_DIR="$VHOST_DIR/shared"
+
+cd "$RAILS_ROOT"
+
+mkdir -p "$SHARED_DIR"
+
+for F in \
+ cache \
+ public/foi-live-creation.png \
+ public/foi-user-use.png \
+ config/aliases \
+ lib/acts_as_xapian/xapiandbs \
+ vendor/bundle
+do
+ SYMLINK_LOCATION="$F"
+ INTENDED_DESTINATION="$SHARED_DIR/$F"
+ echo "Switching to $SYMLINK_LOCATION -> $INTENDED_DESTINATION"
+ # If anything exists where the symlink should be:
+ if [ -e "$SYMLINK_LOCATION" ]
+ then
+ # First, if it's a symlink, check whether it's correct:
+ if [ -L "$SYMLINK_LOCATION" ]
+ then
+ SYMLINK_DESTINATION="$(readlink "$SYMLINK_LOCATION")"
+ if [ "$SYMLINK_DESTINATION" = "$INTENDED_DESTINATION" ]
+ then
+ echo " already correct!"
+ else
+ echo " ERROR: already symlinked to $INTENDED_DESTINATION"
+ fi
+ else
+ # So the file or directory is there, and it's not a
+ # symlink. Check first that that destination doesn't
+ # exist (in which case a move would either fail or
+ # overwrite what's there):
+ if [ -e "$INTENDED_DESTINATION" ]
+ then
+ echo " ERROR: would move, but something already existed at $INTENDED_DESTINATION"
+ else
+ # Otherwise (bar race condition) everything's fine,
+ # and we should be able to move the file or directory
+ # and create a symlink to its new location:
+ mkdir -p "$(dirname "$INTENDED_DESTINATION")"
+ mv "$SYMLINK_LOCATION" "$INTENDED_DESTINATION"
+ ln -snf "$INTENDED_DESTINATION" "$SYMLINK_LOCATION"
+ fi
+ fi
+ else
+ # This may not be anything to worry about, e.g. if the
+ # public/foi-user-use.png graph has never been generated:
+ echo " ERROR: nothing existed at $SYMLINK_LOCATION"
+ fi
+
+done
diff --git a/script/performance/benchmarker b/script/performance/benchmarker
deleted file mode 100755
index 28bfceea0..000000000
--- a/script/performance/benchmarker
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/performance/benchmarker'
diff --git a/script/performance/profiler b/script/performance/profiler
deleted file mode 100755
index 11baf44f2..000000000
--- a/script/performance/profiler
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/performance/profiler'
diff --git a/script/performance/request b/script/performance/request
deleted file mode 100755
index fff6fe660..000000000
--- a/script/performance/request
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/performance/request'
diff --git a/script/plugin b/script/plugin
deleted file mode 100755
index 49f5c441f..000000000
--- a/script/plugin
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/plugin'
diff --git a/script/process/inspector b/script/process/inspector
deleted file mode 100755
index 467962602..000000000
--- a/script/process/inspector
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/process/inspector'
diff --git a/script/process/reaper b/script/process/reaper
deleted file mode 100755
index 2eea898db..000000000
--- a/script/process/reaper
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/process/reaper'
diff --git a/script/process/spawner b/script/process/spawner
deleted file mode 100755
index ac417c3a7..000000000
--- a/script/process/spawner
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/process/spawner'
diff --git a/script/purge-varnish b/script/purge-varnish
index 932cf6635..abc6daeaf 100755
--- a/script/purge-varnish
+++ b/script/purge-varnish
@@ -1,11 +1,12 @@
#!/bin/bash
-LOC=`dirname $0`
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
if [ "$1" == "--loop" ]
then
- "$LOC/runner" 'PurgeRequest.purge_all_loop'
+ bundle exec rails runner 'PurgeRequest.purge_all_loop'
else
- "$LOC/runner" 'PurgeRequest.purge_all'
+ bundle exec rails runner 'PurgeRequest.purge_all'
fi
diff --git a/script/rails b/script/rails
new file mode 100755
index 000000000..f8da2cffd
--- /dev/null
+++ b/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
diff --git a/script/rails-deploy-before-down b/script/rails-deploy-before-down
new file mode 100755
index 000000000..ad1049e44
--- /dev/null
+++ b/script/rails-deploy-before-down
@@ -0,0 +1,148 @@
+#!/bin/bash
+#
+# rails-post-deploy
+# For Ruby on Rails, run this in exec_before_down in vhosts.pl.
+# This does all the tasks for a new deploying a new version that can
+# be done in a new directory before taking the site down; for example,
+# this is appropriate for long-running tasks like asset precompilation.
+#
+# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved.
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
+
+set -e
+#set -x # debug
+
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+
+# make sure that there is an app directory, so are in a rails app tree
+if ! [ -d app ]
+then
+ echo "Error: the 'app' directory didn't exist"
+ exit 1
+fi
+
+# read config file in for later (STAGING_SITE)
+if [ -e "config/general" ] || [ -e "config/general.yml" ]
+then
+ . commonlib/shlib/deployfns
+ read_conf config/general
+else
+ OPTION_DOMAIN=127.0.0.1:3000
+ OPTION_STAGING_SITE=1
+fi
+
+# create initial log files
+if [ -e $TOP_DIR/../logs ]
+then
+ # mySociety servers have logs dir in level above
+ if ! [ -h log ] && [ -d log ]
+ then
+ # If log is a directory rather than a symlink, move that
+ # directory out of the way:
+ mv log log.original
+ fi
+ ln -sfn $TOP_DIR/../logs log
+else
+ # otherwise just make the directory
+ if [ -h log ]
+ then
+ # remove any old-style symlink first
+ rm -f log
+ fi
+ mkdir -p log
+fi
+
+cd log
+touch development.log fastcgi.crash.log production.log test.log
+cd ..
+
+# Returns 0 if an element is present in a bash array, and 1 otherwise
+# Taken from: http://stackoverflow.com/a/8574392/223092
+contains () {
+ local E
+ for E in "${@:2}"
+ do
+ [ "$E" == "$1" ] && return 0
+ done
+ return 1
+}
+
+if [ x"$OPTION_SHARED_FILES_PATH" != x ]
+then
+ for F in "${OPTION_SHARED_FILES[@]}" "${OPTION_SHARED_DIRECTORIES[@]}"
+ do
+ # Remove any trailing slash from directories:
+ NORMALIZED_F="${F%/}"
+ RELATIVE_DIRECTORY="$(dirname $NORMALIZED_F)"
+ DESTINATION="$OPTION_SHARED_FILES_PATH/$NORMALIZED_F"
+ # Ensure that the directory in the shared path exists:
+ mkdir -p "$OPTION_SHARED_FILES_PATH/$RELATIVE_DIRECTORY"
+ # If it's a directory, and it doesn't exist, make sure that
+ # it's created:
+ if contains "$F" "${OPTION_SHARED_DIRECTORIES[@]}"
+ then
+ if [ ! -d "$DESTINATION" ]
+ then
+ mkdir -p "$DESTINATION"
+ fi
+ fi
+ # Make sure we won't overwrite a file because it hasn't been
+ # moved to the shared directory yet:
+ if [ -e "$NORMALIZED_F" ] && [ ! -L "$NORMALIZED_F" ]
+ then
+ cat <<EOF
+$F is a real file or directory, but is listed in SHARED_FILES or
+SHARED_DIRECTORIES and SHARED_FILES_PATH is set. $F should have
+been moved to $OPTION_SHARED_FILES_PATH/$F - for mySociety
+deployments you can use script/mysociety-switch-to-shared to automate
+this.
+EOF
+ exit 1
+ fi
+ ln -snf "$DESTINATION" "$NORMALIZED_F"
+ done
+fi
+
+# Force appropriate environment in production
+if [ "$OPTION_STAGING_SITE" = "0" ]
+then
+ cat <<-END
+
+ *****************************************************************
+ WARNING: About to make config/rails_env.rb which, via special
+ code in config/boot.rb, forces the Rails environment to be
+ "production". If this is a development system, please edit your
+ config/general.yml file and set the STAGING_SITE option to 1,
+ and also delete the generated config/rails_env.rb file.
+ Alternatively, you can override config/rails_env.rb at any time
+ with an environment variable.
+ *****************************************************************
+
+END
+ 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
+if [ "$OPTION_STAGING_SITE" = "1" ]
+then
+ bundle_install_options="--path vendor/bundle"
+fi
+if [ "$TRAVIS" = "true" ]
+then
+ bundle_install_options="--without development develop --deployment"
+fi
+bundle install $bundle_install_options
+
+bundle exec rake submodules:check
+
+bundle exec rake themes:install
+
+if [ "$OPTION_STAGING_SITE" = "0" ]
+then
+ bundle exec rake assets:precompile
+fi
diff --git a/script/rails-deploy-while-down b/script/rails-deploy-while-down
new file mode 100755
index 000000000..a5dc772d3
--- /dev/null
+++ b/script/rails-deploy-while-down
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# rails-deploy-while-down
+
+# For Ruby on Rails, run this in exec_while_down in vhosts.pl. It does
+# any deploy actions that should be done while the site is down;
+# typically this is the database migrations.
+#
+# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved.
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
+
+set -e
+#set -x # debug
+
+# upgrade database
+bundle exec rake db:migrate #--trace
diff --git a/script/rails-post-deploy b/script/rails-post-deploy
index a1c613312..f1c63965e 100755
--- a/script/rails-post-deploy
+++ b/script/rails-post-deploy
@@ -1,94 +1,19 @@
#!/bin/bash
#
# rails-post-deploy
-# For Ruby on Rails, run this in exec_extras in vhosts.pl. It makes symlinks
-# from vendor to the server version of rails, and migrates the db to the most
-# recent version.
+# For Ruby on Rails, this used to be run in exec_extras in vhosts.pl;
+# however, now we use exec_before_down and exec_while_down instead, so
+# this is here for compatability with alternative deploy scripts that
+# still call rails-post-deploy.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
set -e
#set -x # debug
-APP_DIR=`pwd`
-
-# make sure that there is an app directory, so are in a rails app tree
-cd app/..
-
-# read config file in for later (STAGING_SITE)
-if [ -e "config/general" ] || [ -e "config/general.yml" ]
-then
- . commonlib/shlib/deployfns
- read_conf config/general
-else
- OPTION_DOMAIN=127.0.0.1:3000
- OPTION_STAGING_SITE=1
-fi
-
-# create initial log files
-if [ -e $APP_DIR/../logs ]
-then
- # mySociety servers have logs dir in level above
- rm -f log
- ln -s $APP_DIR/../logs log
-else
- # otherwise just make the directory
- if [ -h log ]
- then
- # remove any old-style symlink first
- rm -f log
- fi
- mkdir -p log
-fi
-# link the "downloads" directory in the cache to somewhere it can be served
-if [ ! -e "$APP_DIR/public/download" ]
-then
- mkdir -p "$APP_DIR/cache/zips/download"
- ln -s "$APP_DIR/cache/zips/download" "$APP_DIR/public/"
-fi
-
-cd log
-touch development.log fastcgi.crash.log production.log test.log
-cd ..
-
-# Force appropriate environment in production
-if [ "$OPTION_STAGING_SITE" = "0" ]
-then
- cat <<-END
-
- *****************************************************************
- WARNING: About to make config/rails_env.rb which, via special
- code in config/boot.rb, forces the Rails environment to be
- "production". If this is a development system, please edit your
- config/general.yml file and set the STAGING_SITE option to 1,
- and also delete the generated config/rails_env.rb file.
- Alternatively, you can override config/rails_env.rb at any time
- with an environment variable.
- *****************************************************************
-
- END
- 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
-if [ "$OPTION_STAGING_SITE" = "1" ]
-then
- bundle_install_options="--path vendor/bundle"
-fi
-if [ "$TRAVIS" = "true" ]
-then
- bundle_install_options="--without development develop --deployment"
-fi
-bundle install $bundle_install_options
-
-bundle exec rake themes:install
-
-# upgrade database
-bundle exec rake db:migrate #--trace
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+"$TOP_DIR/script/rails-deploy-before-down"
+"$TOP_DIR/script/rails-deploy-while-down"
diff --git a/script/request-creation-graph b/script/request-creation-graph
index d49a361b8..ef1d2cf73 100755
--- a/script/request-creation-graph
+++ b/script/request-creation-graph
@@ -3,7 +3,7 @@
# Plot graph of rate of request creation
#
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org. WWW: http://www.mysociety.org/
+# Email: hello@mysociety.org. WWW: http://www.mysociety.org/
GPLOT_OUTPUT="set terminal png font 'Vera.ttf' 9 size 1600,600"
EXTENSION=".png"
diff --git a/script/runner b/script/runner
index 2bd5e9aa7..02735531a 100755
--- a/script/runner
+++ b/script/runner
@@ -6,7 +6,6 @@ script_dir = File.dirname(__FILE__)
alaveteli_dir = File.expand_path(File.join(script_dir, ".."))
Dir.chdir(alaveteli_dir) do
- require File.join(alaveteli_dir, 'config', 'boot')
if daemon_mode
# Run in daemon mode.
@@ -20,21 +19,22 @@ Dir.chdir(alaveteli_dir) do
# Load the runner in a subprocess
pid = fork do
- require 'commands/runner'
+ exec("bundle exec rails runner #{ARGV[1]}")
exit 0
end
# If the environment variable PIDFILE is present,
# write the pid of the daemon process to that file.
+
if ENV.has_key? "PIDFILE"
File.open(ENV["PIDFILE"], 'w') do |fh|
fh.puts pid
end
end
-
+
Process.detach(pid)
else
# Not daemon mode
- require 'commands/runner'
+ exec("bundle exec rails runner #{ARGV[0]}")
end
end
diff --git a/script/send-batch-requests b/script/send-batch-requests
new file mode 100755
index 000000000..794bab11f
--- /dev/null
+++ b/script/send-batch-requests
@@ -0,0 +1,4 @@
+#!/bin/bash
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'InfoRequestBatch.send_batches'
diff --git a/script/server b/script/server
deleted file mode 100755
index dc3edabd5..000000000
--- a/script/server
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.expand_path(File.dirname(__FILE__) + '/../config/boot.rb')
-require 'commands/server'
diff --git a/script/site-specific-install.sh b/script/site-specific-install.sh
new file mode 100755
index 000000000..7d47a5990
--- /dev/null
+++ b/script/site-specific-install.sh
@@ -0,0 +1,168 @@
+#!/bin/sh
+
+# Set IDEAL_VERSION to the commitish we want to check out; typically
+# this is the version tag. Since this may not exist before release,
+# fall back to the master branch:
+VERSIONS="origin/install-script 0.15 origin/master"
+
+PARENT_SCRIPT_URL=https://github.com/mysociety/commonlib/blob/master/bin/install-site.sh
+
+misuse() {
+ echo The variable $1 was not defined, and it should be.
+ echo This script should not be run directly - instead, please run:
+ echo $PARENT_SCRIPT_URL
+ exit 1
+}
+
+# Strictly speaking we don't need to check all of these, but it might
+# catch some errors made when changing install-site.sh
+
+[ -z "$DIRECTORY" ] && misuse DIRECTORY
+[ -z "$UNIX_USER" ] && misuse UNIX_USER
+[ -z "$REPOSITORY" ] && misuse REPOSITORY
+[ -z "$REPOSITORY_URL" ] && misuse REPOSITORY_URL
+[ -z "$BRANCH" ] && misuse BRANCH
+[ -z "$SITE" ] && misuse SITE
+[ -z "$DEFAULT_SERVER" ] && misuse DEFAULT_SERVER
+[ -z "$HOST" ] && misuse HOST
+[ -z "$DISTRIBUTION" ] && misuse DISTRIBUTION
+[ -z "$VERSIONS" ] && misuse VERSIONS
+[ -z "$DEVELOPMENT_INSTALL" ] && misuse DEVELOPMENT_INSTALL
+[ -z "$BIN_DIRECTORY" ] && misuse BIN_DIRECTORY
+
+update_mysociety_apt_sources
+
+if [ ! "$DEVELOPMENT_INSTALL" = true ]; then
+ install_nginx
+ add_website_to_nginx
+ # Check out the first available requested version:
+ su -l -c "cd '$REPOSITORY' && (for v in $VERSIONS; do git checkout $v && break; done)" \
+ "$UNIX_USER"
+fi
+
+install_postfix
+
+# Now there's quite a bit of Postfix configuration that we need to
+# make sure is present:
+
+ensure_line_present \
+ "^ *alaveteli *unix *" \
+ "alaveteli unix - n n - 50 pipe flags=R user=$UNIX_USER argv=$REPOSITORY/script/mailin" \
+ /etc/postfix/master.cf 644
+
+ensure_line_present \
+ "^ *transport_maps *=" \
+ "transport_maps = regexp:/etc/postfix/transports" \
+ /etc/postfix/main.cf 644
+
+ensure_line_present \
+ "^ *local_recipient_maps *=" \
+ "local_recipient_maps = proxy:unix:passwd.byname regexp:/etc/postfix/recipients" \
+ /etc/postfix/main.cf 644
+
+ensure_line_present \
+ "^ *mydestination *=" \
+ "mydestination = $HOST, $(hostname --fqdn), localhost.localdomain, localhost" \
+ /etc/postfix/main.cf 644
+
+ensure_line_present \
+ "^ *myhostname *=" \
+ "myhostname = $(hostname --fqdn)" \
+ /etc/postfix/main.cf 644
+
+ensure_line_present \
+ "^do-not-reply" \
+ "do-not-reply-to-this-address: :blackhole:" \
+ /etc/aliases 644
+
+ensure_line_present \
+ "^mail" \
+ "mail.* -/var/log/mail/mail.log" \
+ /etc/rsyslog.d/50-default.conf 644
+
+cat > /etc/postfix/transports <<EOF
+/^foi.*/ alaveteli
+EOF
+
+cat > /etc/postfix/recipients <<EOF
+/^foi.*/ this-is-ignored
+/^postmaster@/ this-is-ignored
+/^user-support@/ this-is-ignored
+/^team@/ this-is-ignored
+EOF
+
+if ! egrep '^ */var/log/mail/mail.log *{' /etc/logrotate.d/rsyslog
+then
+ cat >> /etc/logrotate.d/rsyslog <<EOF
+/var/log/mail/mail.log {
+ rotate 30
+ daily
+ dateext
+ missingok
+ notifempty
+ compress
+ delaycompress
+ sharedscripts
+ postrotate
+ reload rsyslog >/dev/null 2>&1 || true
+ endscript
+}
+EOF
+fi
+
+/etc/init.d/rsyslog restart
+
+newaliases
+postmap /etc/postfix/transports
+postmap /etc/postfix/recipients
+postfix reload
+
+# (end of the Postfix configuration)
+
+install_website_packages
+
+# Make the PostgreSQL user a superuser to avoid the irritating error:
+# PG::Error: ERROR: permission denied: "RI_ConstraintTrigger_16564" is a system trigger
+# This is only needed for loading the sample data, so the superuser
+# permissions are dropped below.
+add_postgresql_user --superuser
+
+export DEVELOPMENT_INSTALL
+su -l -c "$BIN_DIRECTORY/install-as-user '$UNIX_USER' '$HOST' '$DIRECTORY'" "$UNIX_USER"
+
+# Now that the install-as-user script has loaded the sample data, we
+# no longer need the PostgreSQL user to be a superuser:
+echo "ALTER USER \"$UNIX_USER\" WITH NOSUPERUSER;" | su -l -c 'psql' postgres
+
+if [ ! "$DEVELOPMENT_INSTALL" = true ]; then
+ install_sysvinit_script
+fi
+
+# Set up root's crontab:
+
+cd "$REPOSITORY"
+
+echo -n "Creating /etc/cron.d/alaveteli... "
+(su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_crontab DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' VCSPATH='$SITE' SITE='$SITE' CRONTAB=config/crontab-example" "$UNIX_USER") > /etc/cron.d/alaveteli
+# There are some other parts to rewrite, so just do them with sed:
+sed -r \
+ -e "/foi-purge-varnish/d" \
+ -e "s,^(MAILTO=).*,\1root@$HOST," \
+ -e "s,run-with-lockfile,$REPOSITORY/commonlib/bin/run-with-lockfile.sh,g" \
+ -i /etc/cron.d/alaveteli
+echo $DONE_MSG
+
+echo -n "Creating /etc/init.d/foi-alert-tracks... "
+(su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_init_script DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' SCRIPT_FILE=config/alert-tracks-debian.ugly" "$UNIX_USER") > /etc/init.d/foi-alert-tracks
+chmod a+rx /etc/init.d/foi-alert-tracks
+echo $DONE_MSG
+
+if [ $DEFAULT_SERVER = true ] && [ x != x$EC2_HOSTNAME ]
+then
+ # If we're setting up as the default on an EC2 instance, make sure
+ # that the /etc/rc.local is set up to run the install script again
+ # to update the hostname:
+ overwrite_rc_local
+fi
+
+done_msg "Installation complete"; echo
diff --git a/script/spec b/script/spec
deleted file mode 100755
index 46fdbe6e4..000000000
--- a/script/spec
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env ruby
-if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
- require 'rubygems' unless ENV['NO_RUBYGEMS']
-else
- gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
- ENV["RAILS_ENV"] ||= 'test'
- require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
-end
-require 'spec/autorun'
-exit ::Spec::Runner::CommandLine.run
diff --git a/script/spec-all-pairs b/script/spec-all-pairs
deleted file mode 100755
index 6d7bb17c4..000000000
--- a/script/spec-all-pairs
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/bin/bash
-
-# Try all ordered pairs of spec files,
-# to winkle out order-dependent failures.
-
-log_file=/dev/null
-
-test_pair () {
- bundle exec rake db:test:prepare > /dev/null 2>&1
- output=$(script/spec "$1" "$2" 2>&1)
- if [ $? -eq 0 ]
- then
- echo "OK: $1 $2"
- return 0
- else
- echo >> "$log_file" "FAILED: $1 $2"
- echo >> "$log_file" "======================================="
- echo >> "$log_file" "$output"
- echo >> "$log_file"
-
- echo "FAILED: $1 $2"
- return 1
- fi
-}
-
-all_pairs() {
- specs=spec/*/*.rb
-
- for spec1 in $specs
- do
- all_okay=true
- for spec2 in $specs
- do
- if ! test_pair "$spec1" "$spec2"
- then
- all_okay=false
- fi
- done
- done
-
- $all_okay
- return $?
-}
-
-pairs_from_stdin() {
- all_okay=true
- while read line
- do
- case "$line" in
- \*\ FAILED:\ *|\
- spec/*.rb\ spec/*.rb)
- line=${line#\* FAILED: }
- if ! test_pair $line
- then
- all_okay=false
- fi
- ;;
- *)
- echo "No match: $line"
- ;;
- esac
- done
-
- $all_okay
- return $?
-}
-
-if [ "$1" = --log ]
-then
- shift
- log_file=$1
- shift
- cp /dev/null "$log_file"
-fi
-if [ "$1" = "-" ]
-then
- pairs_from_stdin
-else
- all_pairs
-fi
-exit $?
diff --git a/script/spec_server b/script/spec_server
deleted file mode 100755
index dfdf8ff6c..000000000
--- a/script/spec_server
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/env ruby
-$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
-require 'rubygems'
-require 'drb/drb'
-require 'rbconfig'
-require 'spec'
-require 'optparse'
-
-# This is based on Florian Weber's TDDMate
-module Spec
- module Runner
- class RailsSpecServer
- def run(argv, stderr, stdout)
- $stdout = stdout
- $stderr = stderr
-
- base = ActiveRecord::Base
- def base.clear_reloadable_connections!
- active_connections.each do |name, conn|
- if conn.requires_reloading?
- conn.disconnect!
- active_connections.delete(name)
- end
- end
- end
-
- if ActionController.const_defined?(:Dispatcher)
- dispatcher = ::ActionController::Dispatcher.new($stdout)
- dispatcher.cleanup_application
- elsif ::Dispatcher.respond_to?(:reset_application!)
- ::Dispatcher.reset_application!
- else
- raise "Application reloading failed"
- end
- if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
- Fixtures.reset_cache
- end
-
- ::Dependencies.mechanism = :load
- require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
- load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
-
- if in_memory_database?
- load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
- ActiveRecord::Migrator.up('db/migrate') # use migrations
- end
-
- ::Spec::Runner::CommandLine.run(
- ::Spec::Runner::OptionParser.parse(
- argv,
- $stderr,
- $stdout
- )
- )
- end
-
- def in_memory_database?
- ENV["RAILS_ENV"] == "test" and
- ::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
- ::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
- end
- end
- end
-end
-puts "Loading Rails environment"
-
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'dispatcher'
-
-def restart_test_server
- puts "restarting"
- config = ::Config::CONFIG
- ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
- command_line = [ruby, $0, ARGV].flatten.join(' ')
- exec(command_line)
-end
-
-def daemonize(pid_file = nil)
- return yield if $DEBUG
- pid = Process.fork{
- Process.setsid
- Dir.chdir(Rails.root)
- trap("SIGINT"){ exit! 0 }
- trap("SIGTERM"){ exit! 0 }
- trap("SIGHUP"){ restart_test_server }
- File.open("/dev/null"){|f|
- STDERR.reopen f
- STDIN.reopen f
- STDOUT.reopen f
- }
- yield
- }
- puts "spec_server launched. (PID: %d)" % pid
- File.open(pid_file,"w"){|f| f.puts pid } if pid_file
- exit! 0
-end
-
-options = Hash.new
-opts = OptionParser.new
-opts.on("-d", "--daemon"){|v| options[:daemon] = true }
-opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
-opts.parse!(ARGV)
-
-puts "Ready"
-exec_server = lambda {
- trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
- DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
- DRb.thread.join
-}
-
-if options[:daemon]
- daemonize(options[:pid], &exec_server)
-else
- exec_server.call
-end
diff --git a/script/stop-new-responses-on-old-requests b/script/stop-new-responses-on-old-requests
index 1e325403e..07257d6b2 100755
--- a/script/stop-new-responses-on-old-requests
+++ b/script/stop-new-responses-on-old-requests
@@ -1,7 +1,4 @@
#!/bin/bash
-
-cd "`dirname "$0"`"
-
-bundle exec ./runner 'InfoRequest.stop_new_responses_on_old_requests()'
-
-
+TOP_DIR="$(dirname "$BASH_SOURCE")/.."
+cd "$TOP_DIR"
+bundle exec rails runner 'InfoRequest.stop_new_responses_on_old_requests'
diff --git a/script/switch-theme.rb b/script/switch-theme.rb
new file mode 100755
index 000000000..980853687
--- /dev/null
+++ b/script/switch-theme.rb
@@ -0,0 +1,133 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+# A simple script to swap around your Alaveteli themes when you're
+# hacking on Alaveteli. By default this assumes that you have an
+# 'alaveteli-themes' directory at the same level as your alaveteli git
+# repository, e.g.:
+#
+# alaveteli
+# ├── app
+# ├── cache
+# ...
+# └── vendor
+# alaveteli-themes/
+# ├── alavetelitheme
+# ├── asktheeu-theme
+# ├── chiediamo-theme
+# ├── ipvtheme
+# ├── queremossabertheme
+# ├── tuderechoasaber-theme
+# ├── whatdotheyknow-theme
+# └── yourrighttoknow
+#
+# However, you can override the location of your themes directory with
+# the environment variable ALAVETELI_THEMES_DIR.
+#
+# You need to have a corresponding general.yml file called, for example:
+#
+# config/general-whatdotheyknow-theme.yml
+# config/general-yourrighttoknow.yml
+
+require 'tempfile'
+
+$no_theme_name = 'none'
+theme_directory = ENV['ALAVETELI_THEMES_DIR']
+alaveteli_directory = File.expand_path(File.join(File.dirname(__FILE__),
+ ".."))
+unless theme_directory
+ theme_directory = File.expand_path File.join(alaveteli_directory,
+ '..',
+ 'alaveteli-themes')
+end
+
+unless File.exists? theme_directory
+ STDERR.puts "The theme directory '#{theme_directory}' didn't exist."
+ exit 1
+end
+
+# Assume that any directory directly under theme_directory is a theme:
+$available_themes = Dir.entries(theme_directory).find_all do |local_theme_name|
+ next if [".", ".."].index local_theme_name
+ next unless local_theme_name
+ full_path = File.join theme_directory, local_theme_name
+ next unless File.directory? full_path
+ next unless File.directory? File.join(full_path, '.git')
+ local_theme_name
+end.sort
+
+$available_themes.unshift $no_theme_name
+
+if $available_themes.empty?
+ STDERR.puts "There were no theme directories found in '#{theme_directory}'"
+ exit
+end
+
+def usage_and_exit
+ STDERR.puts "Usage: #{$0} <THEME-NAME>"
+ $available_themes.each do |theme_name|
+ STDERR.puts " #{theme_name}"
+ end
+ exit 1
+end
+
+usage_and_exit unless ARGV.length == 1
+requested_theme = ARGV[0]
+usage_and_exit unless $available_themes.include? requested_theme
+
+full_theme_path = File.join theme_directory, requested_theme
+
+config_directory = File.join alaveteli_directory, 'config'
+general_filename = File.join config_directory, "general.yml"
+theme_filename = File.join config_directory, "general-#{requested_theme}.yml"
+
+if File.exists?(general_filename) && ! (File.symlink? general_filename)
+ STDERR.puts "'#{general_filename}' exists, but isn't a symlink"
+ exit 1
+end
+
+unless File.exists? theme_filename
+ STDERR.puts "'#{theme_filename}' didn't exist"
+ exit 1
+end
+
+def symlink target, link_directory, link_name
+ tmp = Tempfile.new link_name, link_directory
+ if system("ln", "-sfn", target, tmp.path)
+ full_link_name = File.join(link_directory, link_name)
+ begin
+ File.rename tmp.path, full_link_name
+ rescue Errno::EISDIR
+ STDERR.puts "Couldn't overwrite #{full_link_name} since it's a directory"
+ exit 1
+ end
+ else
+ STDERR.puts "Failed to create a symlink from #{tmp.path} to #{target}"
+ exit 1
+ end
+end
+
+symlink(File.basename(theme_filename),
+ config_directory,
+ "general.yml")
+
+public_directory = File.join(alaveteli_directory, 'public')
+
+if requested_theme == $no_theme_name
+ File.unlink File.join(public_directory, 'alavetelitheme')
+else
+ symlink(File.join(full_theme_path, 'public'),
+ public_directory,
+ 'alavetelitheme')
+
+ symlink(full_theme_path,
+ File.join(alaveteli_directory, 'lib', 'themes'),
+ requested_theme)
+end
+
+STDERR.puts """Switched to #{requested_theme}!
+You will need to:
+ 1. restart any development server you have running.
+ 2. run: bundle exec rake assets:clean
+ 3. run: bundle exec rake assets:precompile
+"""
diff --git a/script/test-run b/script/test-run
deleted file mode 100755
index 7810b57d5..000000000
--- a/script/test-run
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-cd ../
-bundle exec rake spec
-
diff --git a/script/update-public-body-stats b/script/update-public-body-stats
new file mode 100755
index 000000000..71c2d248c
--- /dev/null
+++ b/script/update-public-body-stats
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+cd `dirname $0`
+bundle exec rake --silent stats:update_public_bodies_stats
diff --git a/script/user-use-graph b/script/user-use-graph
index 205e02416..f508c9cb6 100755
--- a/script/user-use-graph
+++ b/script/user-use-graph
@@ -3,7 +3,7 @@
# Plot graph of user use of site.
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org. WWW: http://www.mysociety.org/
+# Email: hello@mysociety.org. WWW: http://www.mysociety.org/
GPLOT_OUTPUT="set terminal png font 'Vera.ttf' 9 size 1200,400"
EXTENSION=".png"
diff --git a/script/wraptest b/script/wraptest
deleted file mode 100755
index 780c9b4a2..000000000
--- a/script/wraptest
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env ruby
-#
-# wraptest:
-# Test email wrapping function
-#
-# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-
-$:.push(File.join(File.dirname(__FILE__), '../../rblib'))
-load "format.rb"
-
-test_email = '''Dear Sir or Madam,
-
-Again and again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet
-
-Hey you.
-
-Yours faithfully,
-
-Boo!
-
---
-
-Sent using GovernmentSpy, a project of UKCOD, registered charity number
-1076346. Is frabcus@fastmail.fm the wrong
-address for Freedom of Information requests to The Geraldine Quango? If so please let us know by emailing
-team@governmentspy quoting reference PB2.
-We\'ll make sure future ones go to the right place.
-'''
-
-test_email.gsub!(/\n/, "\r\n")
-
-puts MySociety::Format.wrap_email_body(test_email)
-
-#puts MySociety::Format.wrap_email_body("Hello this is a string.
-#
-#And another.
-#And a third.")
-
-
-
-