delfi/gtfs/dload.sh

61 lines
1.5 KiB
Bash

#!/bin/bash
#
echo "Started..."
#Started...
#
# special variable $# is the number of arguments
if [ $# -lt 2 ] ; then
echo 'Call ./<script> <work dir> <dload URL>'
exit 1
fi
#
WORK_DIR="$1"
echo "WORK_DIR: $WORK_DIR"
dloadDir=${WORK_DIR}/gtfs
echo "dloadDir: $dloadDir"
# rm -rf: descend into write-protected directory
rm -rf $dloadDir
mkdir -p $dloadDir
logFile=${dloadDir}/wget-log.txt
echo "logFile: $logFile"
dloadFile=${dloadDir}/gtfs.zip
echo "dloadFile: $dloadFile"
dloadUrl=$2
echo "dloadUrl: $dloadUrl"
wget -o $logFile -O $dloadFile $dloadUrl
#
unzipDir=${dloadDir}/unzip
echo "unzipDir: $unzipDir"
mkdir -p $unzipDir
unzip -qq -d $unzipDir $dloadFile
#
# add file feed_info.txt if not present so that gtfs-sql-importer git repo is not complaining
#
if [ $(unzip -Z -1 "$dloadFile" | grep feed_info.txt) ];
then
echo "feed_info.txt present"
else
echo "feed_info.txt NOT present"
# (): replaces the shell without creating a new process
BASEDIR=$(dirname $0)
echo "BASEDIR: ${BASEDIR}"
(sh ./${BASEDIR}/feed_info.sh $unzipDir)
zip -jr ${dloadFile}-feed_info.zip ${unzipDir}
fi
#
# add file stops_zhv.txt if not present so that gtfs-sql-importer git repo can consider
#
if [ $(unzip -Z -1 "$dloadFile" | grep stops_zhv.txt) ];
then
echo "stops_zhv.txt present"
else
echo "stops_zhv.txt NOT present"
# (): replaces the shell without creating a new process
BASEDIR=$(dirname $0)
echo "BASEDIR: ${BASEDIR}"
(sh ./${BASEDIR}/stops_zhv.sh $WORK_DIR)
zip -jr ${dloadFile}-stops_zhv.zip ${unzipDir}
fi
echo "Done."
#done.