aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/install-as-user99
-rwxr-xr-xbin/install_perl_modules10
-rwxr-xr-xbin/problem-creation-graph8
-rw-r--r--bin/site-specific-install.sh24
-rwxr-xr-x[-rw-r--r--]bin/update-schema16
-rwxr-xr-xbin/zurich-overdue-alert4
-rwxr-xr-xbin/zurich/convert_internal_notes_to_comments73
7 files changed, 173 insertions, 61 deletions
diff --git a/bin/install-as-user b/bin/install-as-user
index 1d6cce982..b05616702 100755
--- a/bin/install-as-user
+++ b/bin/install-as-user
@@ -1,7 +1,10 @@
#!/bin/sh
set -e
-set -x
+error_msg() { printf "\033[31m%s\033[0m\n" "$*"; }
+notice_msg() { printf "\033[33m%s\033[0m " "$*"; }
+done_msg() { printf "\033[32m%s\033[0m\n" "$*"; }
+DONE_MSG=$(done_msg done)
if [ $# -ne 3 ]
then
@@ -14,6 +17,15 @@ fi
UNIX_USER="$1"
HOST="$2"
DIRECTORY="$3"
+
+misuse() {
+ echo The variable $1 was not defined, and it should be.
+ echo This script should not be run directly.
+ exit 1
+}
+
+[ -z "$DEVELOPMENT_INSTALL" ] && misuse DEVELOPMENT_INSTALL
+
DB_NAME="fixmystreet"
# Check that the arguments we've been passed are sensible:
@@ -22,19 +34,19 @@ 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"
+ error_msg "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."
+ error_msg "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'."
+ error_msg "This script should be run by the user '$UNIX_USER'."
exit 1
fi
@@ -44,24 +56,23 @@ LINK_DESTINATION="$HOME/fixmystreet"
ln -sfn "$REPOSITORY" $LINK_DESTINATION
cd "$REPOSITORY"
-# Add regularly scheduled tasks to cron:
-
-TEMPORARY_CRONTAB=$(mktemp)
-
-echo crontab file is $TEMPORARY_CRONTAB
-
-cp "$REPOSITORY"/conf/crontab.example "$TEMPORARY_CRONTAB"
-
-sed -i \
- -e 's,$FMS,'"$REPOSITORY,g" \
- -e 's,$LOCK_DIR,'"$DIRECTORY,g" \
- "$TEMPORARY_CRONTAB"
-
-crontab $TEMPORARY_CRONTAB
+if [ ! "$DEVELOPMENT_INSTALL" = true ]; then
+ echo -n "Adding crontab... "
+ # Add regularly scheduled tasks to cron:
+ TEMPORARY_CRONTAB=$(mktemp)
+ echo crontab file is $TEMPORARY_CRONTAB
+ cp "$REPOSITORY"/conf/crontab-example "$TEMPORARY_CRONTAB"
+ sed -i \
+ -e 's,$FMS,'"$REPOSITORY,g" \
+ -e 's,$LOCK_DIR,'"$DIRECTORY,g" \
+ "$TEMPORARY_CRONTAB"
+ crontab $TEMPORARY_CRONTAB
+ echo $DONE_MSG
+fi
# Install the compass gem locally - it's required for generating the
# CSS:
-
+echo "Setting up CSS... "
export GEM_HOME="$DIRECTORY/gems"
mkdir -p "$GEM_HOME"
export GEM_PATH=
@@ -77,29 +88,39 @@ export PATH="\$GEM_HOME/bin:\$PATH"
EOBRC
fi
-gem install --no-ri --no-rdoc compass
+gem install --conservative --no-ri --no-rdoc sass -v 3.2.14
+gem install --conservative --no-ri --no-rdoc compass -v 0.12.2
# Use compass to generate the CSS, if it doesn't seem to already
# exist:
-
if [ ! -f web/cobrands/default/base.css ]
then
bin/make_css
fi
+echo $DONE_MSG
+
+# Write sensible values into the config file, if it doesn't already exist
+if [ ! -f conf/general.yml ]; then
+ echo -n "Setting up default conf/general.yml file... "
+ sed -r \
+ -e "s,^( *FMS_DB_HOST:).*,\\1 ''," \
+ -e "s,^( *FMS_DB_NAME:).*,\\1 '$DB_NAME'," \
+ -e "s,^( *FMS_DB_USER:).*,\\1 '$UNIX_USER'," \
+ -e "s,^( *BASE_URL:).*,\\1 'http://$HOST'," \
+ -e "s,^( *EMAIL_DOMAIN:).*,\\1 '$HOST'," \
+ -e "s,^( *CONTACT_EMAIL:).*,\\1 'help@$HOST'," \
+ -e "s,^( *DO_NOT_REPLY_EMAIL:).*,\\1 'help@$HOST'," \
+ conf/general.yml-example > conf/general.yml
+ echo $DONE_MSG
+fi
-# Write sensible values into the config file:
-
-sed -r \
- -e "s,^( *FMS_DB_HOST:).*,\\1 ''," \
- -e "s,^( *FMS_DB_NAME:).*,\\1 '$DB_NAME'," \
- -e "s,^( *FMS_DB_USER:).*,\\1 '$UNIX_USER'," \
- -e "s,^( *BASE_URL:).*,\\1 'http://$HOST'," \
- -e "s,^( *EMAIL_DOMAIN:).*,\\1 '$HOST'," \
- -e "s,^( *CONTACT_EMAIL:).*,\\1 'help@$HOST'," \
- -e "s,^( *DO_NOT_REPLY_EMAIL:).*,\\1 'help@$HOST'," \
- conf/general.yml-example > conf/general.yml
+echo "Installing required Perl modules - this may take some time"
+cd "$REPOSITORY"
+bin/install_perl_modules
+echo $DONE_MSG
# Create the database if it doesn't exist:
+echo -n "Setting up database... "
if ! psql -l | egrep "^ *$DB_NAME *\|" > /dev/null
then
createdb --owner "$UNIX_USER" "$DB_NAME"
@@ -107,16 +128,16 @@ then
psql -U "$UNIX_USER" "$DB_NAME" < "$REPOSITORY"/db/schema.sql
psql -U "$UNIX_USER" "$DB_NAME" < "$REPOSITORY"/db/alert_types.sql
psql -U "$UNIX_USER" "$DB_NAME" < "$REPOSITORY"/db/generate_secret.sql
+else
+ bin/cron-wrapper update-schema --commit
fi
-
-# Install the required Perl modules - this may take a very long time:
-
-cd "$REPOSITORY"
-bin/install_perl_modules
+echo $DONE_MSG
# Generate po and mo files (these invocations taken from Kagee's script):
-
+echo "Creating locale .mo files"
bin/cron-wrapper bin/make_po FixMyStreet-EmptyHomes
bin/cron-wrapper bin/make_emptyhomes_welsh_po
-
commonlib/bin/gettext-makemo FixMyStreet
+echo $DONE_MSG
+
+bin/cron-wrapper update-all-reports
diff --git a/bin/install_perl_modules b/bin/install_perl_modules
index 2311ae5f1..883ced235 100755
--- a/bin/install_perl_modules
+++ b/bin/install_perl_modules
@@ -4,18 +4,18 @@ set -e
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd | sed -e 's/\/bin$//' )"
-$DIR/bin/cpanm -l $DIR/local Carton
+$DIR/bin/cpanm -l $DIR/local-carton Carton
-export PATH=$DIR/local/bin:$PATH
-export PERL5LIB=$DIR/local/lib/perl5
+export PATH=$DIR/local-carton/bin:$PATH
+export PERL5LIB=$DIR/local-carton/lib/perl5
-carton install --deployment
+carton install --deployment --without uk
if ! perl -MImage::Magick -e 'exit()' >/dev/null 2>&1
then
read -p "Image::Magick is not installed. Do you want to attempt to install it?" yn
case $yn in
- [Yy]* ) $DIR/local/bin/carton install Image::Magick;;
+ [Yy]* ) $DIR/local-carton/bin/carton install Image::Magick;;
* ) echo 'You will need to install it for FixMyStreet to work';;
esac
fi
diff --git a/bin/problem-creation-graph b/bin/problem-creation-graph
index b96d45540..2ee38783c 100755
--- a/bin/problem-creation-graph
+++ b/bin/problem-creation-graph
@@ -49,13 +49,13 @@ function grab_data {
grab_data "" $SOURCEA
grab_data "where state not in ('unconfirmed')" $SOURCEB
grab_data "where state not in ('unconfirmed', 'confirmed')" $SOURCEC
-grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed')" $SOURCED
-grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed', 'hidden')" $SOURCEE
+grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed', 'fixed - council', 'fixed - user')" $SOURCED
+grab_data "where state not in ('unconfirmed', 'confirmed', 'fixed', 'fixed - council', 'fixed - user', 'hidden')" $SOURCEE
#state = 'unconfirmed'
#or state = 'confirmed'
-#or state = 'fixed'
+#or state in ('fixed', 'fixed - council', 'fixed - user')
#or state = 'hidden'
#or state = 'partial'
@@ -96,7 +96,7 @@ if [ -s $SOURCED ]; then
echo -n >>$GPSCRIPT " \"$SOURCED\" using 1:2 with impulses lt 6 lw 15 title \"hidden\","
fi
if [ -s $SOURCEE ]; then
-echo -n >>$GPSCRIPT " \"$SOURCEE\" using 1:2 with impulses lt 7 lw 15 title \"partial (and any other types)\","
+echo -n >>$GPSCRIPT " \"$SOURCEE\" using 1:2 with impulses lt 7 lw 15 title \"any other type\","
fi
cat >>$GPSCRIPT <<END
"< awk 'BEGIN { n = 0 } { n += \$2; print \$1, \$2, n; }' $SOURCEA" using 1:3 axes x1y2 with lines lt 2 title "cumulative total number of problems"
diff --git a/bin/site-specific-install.sh b/bin/site-specific-install.sh
index d3da12104..3cc84007a 100644
--- a/bin/site-specific-install.sh
+++ b/bin/site-specific-install.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Set this to the version we want to check out
-VERSION=${VERSION_OVERRIDE:-v1.2.4}
+VERSION=${VERSION_OVERRIDE:-v1.3}
PARENT_SCRIPT_URL=https://github.com/mysociety/commonlib/blob/master/bin/install-site.sh
@@ -25,25 +25,33 @@ misuse() {
[ -z "$HOST" ] && misuse HOST
[ -z "$DISTRIBUTION" ] && misuse DISTRIBUTION
[ -z "$VERSION" ] && misuse VERSION
+[ -z "$DEVELOPMENT_INSTALL" ] && misuse DEVELOPMENT_INSTALL
-install_nginx
+add_locale cy_GB
+add_locale nb_NO
+add_locale de_CH
install_postfix
-# Check out the current released version
-su -l -c "cd '$REPOSITORY' && git checkout '$VERSION'" "$UNIX_USER"
+if [ ! "$DEVELOPMENT_INSTALL" = true ]; then
+ install_nginx
+ add_website_to_nginx
+ # Check out the current released version
+ su -l -c "cd '$REPOSITORY' && git checkout '$VERSION' && git submodule update" "$UNIX_USER"
+fi
install_website_packages
su -l -c "touch '$DIRECTORY/admin-htpasswd'" "$UNIX_USER"
-add_website_to_nginx
-
add_postgresql_user
-su -l -c "$REPOSITORY/bin/install-as-user '$UNIX_USER' '$HOST' '$DIRECTORY'" "$UNIX_USER"
+export DEVELOPMENT_INSTALL
+su -c "$REPOSITORY/bin/install-as-user '$UNIX_USER' '$HOST' '$DIRECTORY'" "$UNIX_USER"
-install_sysvinit_script
+if [ ! "$DEVELOPMENT_INSTALL" = true ]; then
+ install_sysvinit_script
+fi
if [ $DEFAULT_SERVER = true ] && [ x != x$EC2_HOSTNAME ]
then
diff --git a/bin/update-schema b/bin/update-schema
index 198fa6b8d..be5bc50e7 100644..100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -19,13 +19,14 @@ use mySociety::DBHandle qw(dbh);
use mySociety::MaPit;
mySociety::Config::set_file("$FindBin::Bin/../conf/general");
-mySociety::DBHandle::configure(
+my %args = (
Name => mySociety::Config::get('FMS_DB_NAME'),
User => mySociety::Config::get('FMS_DB_USER'),
Password => mySociety::Config::get('FMS_DB_PASS'),
- Host => mySociety::Config::get('FMS_DB_HOST', undef),
- Port => mySociety::Config::get('FMS_DB_PORT', undef)
);
+$args{Host} = mySociety::Config::get('FMS_DB_HOST', undef) if mySociety::Config::get('FMS_DB_HOST');
+$args{Port} = mySociety::Config::get('FMS_DB_PORT', undef) if mySociety::Config::get('FMS_DB_PORT');
+mySociety::DBHandle::configure( %args );
my $commit = 0;
$commit = 1 if @ARGV && $ARGV[0] eq '--commit';
@@ -85,6 +86,8 @@ print "Nothing to do\n" if $nothing;
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
return '0031' if column_exists('body', 'external_url');
+ return '0030' if ! constraint_exists('admin_log_action_check');
+ return '0029' if column_exists('body', 'deleted');
return '0028' if table_exists('body');
return '0027' if column_exists('problem', 'subcategory');
return '0026' if column_exists('open311conf', 'send_extended_statuses');
@@ -133,3 +136,10 @@ sub column_like {
my ( $table, $where, $column, $contents ) = @_;
return dbh()->selectrow_array("select count(*) from $table WHERE $where AND $column LIKE ?", {}, "%$contents%");
}
+
+# Returns true if a check constraint on a table exists
+sub constraint_exists {
+ my ( $constraint ) = @_;
+ return dbh()->selectrow_array('select count(*) from pg_constraint where conname = ?', {}, $constraint);
+}
+
diff --git a/bin/zurich-overdue-alert b/bin/zurich-overdue-alert
index 4a507c481..500c6b016 100755
--- a/bin/zurich-overdue-alert
+++ b/bin/zurich-overdue-alert
@@ -23,9 +23,9 @@ exit if FixMyStreet::Cobrand::Zurich::is_public_holiday($now) or FixMyStreet::Co
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('zurich')->new();
my %bodies = map { $_->id => $_ } FixMyStreet::App->model("DB::Body")->all;
-loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed', 'confirmed' ] );
+loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed' ] );
loop_through( 'alert-overdue.txt', 1, 6, 'in progress' );
-loop_through( 'alert-overdue.txt', 0, 6, 'planned' );
+loop_through( 'alert-overdue.txt', 0, 6, ['confirmed', 'planned'] );
sub loop_through {
my ( $template, $include_parent, $days, $states ) = @_;
diff --git a/bin/zurich/convert_internal_notes_to_comments b/bin/zurich/convert_internal_notes_to_comments
new file mode 100755
index 000000000..ddf74851f
--- /dev/null
+++ b/bin/zurich/convert_internal_notes_to_comments
@@ -0,0 +1,73 @@
+#!/usr/bin/env perl
+
+=head1 DESCRIPTION
+
+This is a Zurich specific migration script.
+
+It converts the internal notes that used to be stored on the problem in the
+extra hash into comments instead.
+
+ ./bin/zurich/convert_internal_notes_to_comments user_id
+
+You need to select a user to have the internal notes be associated with, perhaps
+the superuser, or one created just for this purpose?
+
+=cut
+
+use strict;
+use warnings;
+
+use FixMyStreet::App;
+
+# Because it is not possible to determine the user that last edited the
+# internal_notes we need require a user to assign all the comments to.
+my $comment_user_id = $ARGV[0]
+ || die "Usage: $0 id_of_user_for_comments";
+my $comment_user = FixMyStreet::App #
+ ->model('DB::User') #
+ ->find($comment_user_id)
+ || die "Could not find user with id '$comment_user_id'";
+
+# We use now as the time for the internal note. This is not the time it was
+# actually created, but I don't think that can be extracted from the problem.
+my $comment_timestamp = DateTime->now();
+
+# The state of 'hidden' seems most appropriate for these internal_notes - as
+# they should not be shown to the public. Certainly more suitable than
+# 'unconfirmed' or 'confirmed'.
+my $comment_state = 'hidden';
+
+# Load all the comments, more reliable than trying to search on the contents of
+# the extra field.
+my $problems = FixMyStreet::App->model('DB::Problem')->search();
+
+while ( my $problem = $problems->next() ) {
+
+ my $problem_id = $problem->id;
+
+ # Extract the bits we are interested in. May not exist, in which case
+ # skip on.
+ my $extra = $problem->extra || {};
+ next unless exists $extra->{internal_notes};
+
+ # If there is something to save create a comment with the notes in them
+ if ( my $internal_notes = $extra->{internal_notes} ) {
+ print "Creating internal note comment for problem '$problem_id'\n";
+ $problem->add_to_comments(
+ {
+ text => $internal_notes,
+ created => $comment_timestamp,
+ user => $comment_user,
+ state => $comment_state,
+ mark_fixed => 0,
+ anonymous => 1,
+ extra => { is_internal_note => 1 },
+ }
+ );
+ }
+
+ # Remove the notes from extra and save back to the problem
+ delete $extra->{internal_notes};
+ $problem->update({ extra => $extra });
+}
+