#!/bin/bash | #!/bin/bash |
#this script should be run from a fresh git checkout from github | #this script should be run from a fresh git checkout from github |
#ami base must have yum install lighttpd-fastcgi, git, tomcat6 | #ami base must have yum install lighttpd-fastcgi, git, tomcat6 |
#php-cli php-gd tomcat6-webapps tomcat6-admin-webapps svn maven2 | #php-cli php-gd tomcat6-webapps tomcat6-admin-webapps svn maven2 |
#postgres postgres-server php-pg | #postgres postgres-server php-pg |
#http://www.how2forge.org/installing-lighttpd-with-php5-and-mysql-support-on-fedora-12 | #http://www.how2forge.org/installing-lighttpd-with-php5-and-mysql-support-on-fedora-12 |
cp /root/aws.php /tmp/ | sh busuiphp.sh |
mkdir /var/www/lib/staticmaplite/cache | sh busuidb.sh |
chcon -h system_u:object_r:httpd_sys_content_t /var/www | sh busuiotp.sh |
chcon -R -h root:object_r:httpd_sys_content_t /var/www/* | |
chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache | |
chmod -R 777 /var/www/lib/staticmaplite/cache | |
chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles | |
chmod -R 777 /var/www/labs/tiles | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ | |
-O /var/www/cbrfeed.zip | |
createdb transitdata | |
createlang -d transitdata plpgsql | |
psql -d transitdata -f /var/www/lib/postgis.sql | |
# curl https://github.com/maxious/ACTBus-ui/raw/master/transitdata.cbrfeed.sql.gz -o transitdata.cbrfeed.sql.gz | |
#made with pg_dump transitdata | gzip -c > transitdata.cbrfeed.sql.gz | |
gunzip /var/www/transitdata.cbrfeed.sql.gz | |
psql -d transitdata -f /var/www/transitdata.cbrfeed.sql | |
#createuser transitdata -SDRP | |
#password transitdata | |
#psql -d transitdata -c \"GRANT SELECT ON TABLE agency,calendar,calendar_dates,routes,stop_times,stops,trips TO transitdata;\" | |
#psql -d transitdata -c "GRANT SELECT,INSERT ON TABLE myway_observations,myway_routes,myway_stops,myway_timingdeltas TO transitdata;" | |
#psql -d transitdata -c "GRANT SELECT,INSERT,UPDATE ON TABLE myway_routes,myway_stops TO transitdata;" | |
##psql -d transitdata -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO transitdata;" | |
php /var/www/updatedb.php | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/Graph.obj \ | |
-O /tmp/Graph.obj | |
rm -rfv /usr/share/tomcat6/webapps/opentripplanner* | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-webapp.war | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-api-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war | |
/etc/init.d/tomcat6 restart | |
createdb transitdata | |
createlang -d transitdata plpgsql | |
psql -d transitdata -f /var/www/lib/postgis.sql | |
# curl https://github.com/maxious/ACTBus-ui/raw/master/transitdata.cbrfeed.sql.gz -o transitdata.cbrfeed.sql.gz | |
#made with pg_dump transitdata | gzip -c > transitdata.cbrfeed.sql.gz | |
gunzip /var/www/transitdata.cbrfeed.sql.gz | |
psql -d transitdata -f /var/www/transitdata.cbrfeed.sql | |
#createuser transitdata -SDRP | |
#password transitdata | |
#psql -d transitdata -c "GRANT SELECT ON TABLE agency,calendar,calendar_dates,routes,stop_times,stops,trips TO transitdata;" | |
#psql -d transitdata -c "GRANT SELECT,INSERT ON TABLE myway_observations,myway_routes,myway_stops,myway_timingdeltas TO transitdata;" | |
#psql -d transitdata -c "GRANT SELECT,INSERT,UPDATE ON TABLE myway_routes,myway_stops TO transitdata;" | |
##psql -d transitdata -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO transitdata;" | |
php /var/www/updatedb.php |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/Graph.obj \ | |
-O /tmp/Graph.obj | |
/etc/init.d/tomcat6 stop | |
rm -rfv /usr/share/tomcat6/webapps/opentripplanner* | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-webapp.war | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/opentripplanner-api-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war | |
/etc/init.d/tomcat6 restart | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/Graph.obj \ | |
-O /tmp/Graph.obj | |
/etc/init.d/tomcat6 stop | |
rm -rfv /usr/share/tomcat6/webapps/opentripplanner* | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/opentripplanner-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-webapp.war | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/testing/opentripplanner-api-webapp.war \ | |
-O /usr/share/tomcat6/webapps/opentripplanner-api-webapp.war | |
/etc/init.d/tomcat6 restart | |
cp /root/aws.php /tmp/ | |
mkdir /var/www/lib/staticmaplite/cache | |
chcon -h system_u:object_r:httpd_sys_content_t /var/www | |
chcon -R -h root:object_r:httpd_sys_content_t /var/www/* | |
chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache | |
chmod -R 777 /var/www/lib/staticmaplite/cache | |
chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles | |
chmod -R 777 /var/www/labs/tiles | |
wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ | |
-O /var/www/cbrfeed.zip |
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> | |
<!-- Single graph --> | |
<import resource="classpath:org/opentripplanner/api/application-context.xml" /> | |
<bean id="graphBundle" class="org.opentripplanner.model.GraphBundle"> | |
<property name="path" value="/tmp/" /> | |
</bean> | |
</beans> | |
<?php | <?php |
if ( php_sapi_name() == "cli") { | if ( php_sapi_name() == "cli") { |
include ('include/common.inc.php'); | include ('include/common.inc.php'); |
$conn = pg_connect("dbname=transitdata user=postgres password=snmc host=localhost") or die('connection failed'); | $conn = pg_connect("dbname=transitdata user=postgres password=snmc host=localhost") or die('connection failed'); |
$pdconn = new PDO("pgsql:dbname=transitdata;user=postgres;password=snmc;host=localhost"); | $pdconn = new PDO("pgsql:dbname=transitdata;user=postgres;password=snmc;host=localhost"); |
/* | |
delete from agency; | |
delete from calendar; | |
delete from calendar_dates; | |
delete from routes; | |
delete from shapes; | |
delete from stop_times; | |
delete from stops; | |
delete from trips; | |
*/ | |
// Unzip cbrfeed.zip, import all csv files to database | // Unzip cbrfeed.zip, import all csv files to database |
$unzip = true; | $unzip = true; |
$zip = zip_open(dirname(__FILE__) . "/cbrfeed.zip"); | $zip = zip_open(dirname(__FILE__) . "/cbrfeed.zip"); |
$tmpdir = "/tmp/cbrfeed/"; | $tmpdir = "/tmp/cbrfeed/"; |
mkdir($tmpdir); | mkdir($tmpdir); |
if ($unzip) { | if ($unzip) { |
if (is_resource($zip)) { | if (is_resource($zip)) { |
while ($zip_entry = zip_read($zip)) { | while ($zip_entry = zip_read($zip)) { |
$fp = fopen($tmpdir . zip_entry_name($zip_entry) , "w"); | $fp = fopen($tmpdir . zip_entry_name($zip_entry) , "w"); |
if (zip_entry_open($zip, $zip_entry, "r")) { | if (zip_entry_open($zip, $zip_entry, "r")) { |
echo "Extracting " . zip_entry_name($zip_entry) . "\n"; | echo "Extracting " . zip_entry_name($zip_entry) . "\n"; |
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); | $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
fwrite($fp, "$buf"); | fwrite($fp, "$buf"); |
zip_entry_close($zip_entry); | zip_entry_close($zip_entry); |
fclose($fp); | fclose($fp); |
} | } |
} | } |
zip_close($zip); | zip_close($zip); |
} | } |
} | } |
foreach (scandir($tmpdir) as $file) { | foreach (scandir($tmpdir) as $file) { |
if (!strpos($file, ".txt") === false) { | if (!strpos($file, ".txt") === false) { |
$fieldseparator = ","; | $fieldseparator = ","; |
$lineseparator = "\n"; | $lineseparator = "\n"; |
$tablename = str_replace(".txt", "", $file); | $tablename = str_replace(".txt", "", $file); |
echo "Opening $file \n"; | echo "Opening $file \n"; |
$line = 0; | $line = 0; |
$handle = fopen($tmpdir . $file, "r"); | $handle = fopen($tmpdir . $file, "r"); |
if ($tablename =="stop_times") { | if ($tablename =="stop_times") { |
$stmt = $pdconn->prepare("insert into stop_times (trip_id,stop_id,stop_sequence) values(:trip_id, :stop_id, :stop_sequence);"); | $stmt = $pdconn->prepare("insert into stop_times (trip_id,stop_id,stop_sequence,arrival_time,departure_time) values(:trip_id, :stop_id, :stop_sequence,:arrival_time,:departure_time);"); |
$stmt->bindParam(':trip_id',$trip_id); | $stmt->bindParam(':trip_id',$trip_id); |
$stmt->bindParam(':stop_id',$stop_id); | $stmt->bindParam(':stop_id',$stop_id); |
$stmt->bindParam(':stop_sequence',$stop_sequence); | $stmt->bindParam(':stop_sequence',$stop_sequence); |
$stmt->bindParam(':arrival_time',$time); | |
$stmt->bindParam(':departure_time',$time); | |
} | } |
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { |
if ($line == 0) { | if ($line == 0) { |
} else { | } else { |
$query = "insert into $tablename values("; | $query = "insert into $tablename values("; |
$valueCount = 0; | $valueCount = 0; |
foreach ($data as $value) { | foreach ($data as $value) { |
$query.=($valueCount >0 ? "','" :"'").pg_escape_string($value); | $query.=($valueCount >0 ? "','" :"'").pg_escape_string($value); |
$valueCount++; | $valueCount++; |
} | } |
if ($tablename == "stops") { | if ($tablename == "stops") { |
$query.= "', ST_GeographyFromText('SRID=4326;POINT({$data[2]} {$data[0]})'));"; | $query.= "', ST_GeographyFromText('SRID=4326;POINT({$data[2]} {$data[0]})'));"; |
} else { | } else { |
$query.= "');"; | $query.= "');"; |
} | } |
if ($tablename =="stop_times" && $data[1] == "") { | if ($tablename =="stop_times") { |
// $query = "insert into $tablename (trip_id,stop_id,stop_sequence) values('{$data[0]}','{$data[3]}','{$data[4]}');"; | // $query = "insert into $tablename (trip_id,stop_id,stop_sequence) values('{$data[0]}','{$data[3]}','{$data[4]}');"; |
$trip_id=$data[0]; | $trip_id=$data[0]; |
$stop_id=$data[3]; | $stop_id=$data[3]; |
$stop_sequence=$data[4]; | $stop_sequence=$data[4]; |
$time=($data[1] == "" ? null : $data[1]); | |
} | } |
} | } |
if ($tablename =="stop_times") { | if ($tablename =="stop_times") { |
$stmt->execute(); | $stmt->execute(); |
} | } |
else { | else { |
$result = pg_query($conn, $query); | $result = pg_query($conn, $query); |
} | } |
$line++; | $line++; |
if ($line % 10000 == 0) echo "$line records... ".date('c')."\n"; | if ($line % 10000 == 0) echo "$line records... ".date('c')."\n"; |
} | } |
fclose($handle); | fclose($handle); |
echo "Found a total of $line records in $file.\n"; | echo "Found a total of $line records in $file.\n"; |
} | } |
} | } |
} | } |
?> | ?> |