Skip to content

Instantly share code, notes, and snippets.

@junichim

junichim/README.md

Last active Apr 17, 2021
Embed
What would you like to do?
オフラインマップ生成用のスクリプト類(2021/4/16 更新版)

ブログ記事

OpenStreetMap オフラインマップ作成用サーバーの再セットアップ

で参考にしているスクリプト群

  • createOfflineMap : 全体制御スクリプト
  • doMapCreator : map-creator 実行スクリプト
  • uploadS3 : S3 へのアップロードスクリプト

参考情報

過去のブログ記事とそれに対応する gist は下記の通り

#!/bin/bash
#
# create files for offline map.
#
# Junichi MORI, 2019/5/1
# modified, 2021/4/16
function log()
{
echo `date +"%F %T %Z"`": "$*
}
function send_msg()
{
TOPIC_ARN="SNSトピックのARN"
PROFILE_SEND="SNS発行用のユーザー名"
SUBJECT="failed offline map creation"
aws sns publish --topic-arn $TOPIC_ARN --subject "$SUBJECT" --message "$*" --profile $PROFILE_SEND
}
HOME_DIR=/home/ubuntu
BIN_DIR="$HOME_DIR/bin/offlinemap"
MAP_SCRIPT=doMapCreator
UPLOAD_SCRIPT=uploadS3
WORK_DIR="$HOME_DIR/work/offlinemap"
MAP_DIR="$WORK_DIR/maps/v4/asia/japan"
MAP_FILE=kansai.map
MAP_OUT=ise.map
GH_DIR="$WORK_DIR/graphs/asia/japan/"
GH_FILE=kansai.zip
GH_OUT=ise.ghz
TS_FILE=map_timestamp
RESULT_DIR=$WORK_DIR/result
### main process start ###
log "start createOfflineMap script."
if [ ! -f $BIN_DIR/$MAP_SCRIPT ]; then
log "no "$MAP_SCRIPT" file"
send_msg "no map script: check configuration"
exit 1
fi
# 1. craete map file
log create map file
log $BIN_DIR/$MAP_SCRIPT
$BIN_DIR/$MAP_SCRIPT
if [ $? != 0 ]; then
log "error in map-creation"
send_msg "failed map-creation: check log file"
exit 1
fi
# 2. copy created file
log copy created files
# prepare to copy
if [ ! -d $RESULT_DIR ]; then
mkdir -p $RESULT_DIR
fi
if [ -f $RESULT_DIR/$TS_FILE ]; then
TS_OLD=`cat $RESULT_DIR/$TS_FILE`
else
TS_OLD=`date --iso-8601=seconds`
fi
# file copy
if [ -f $MAP_DIR/$MAP_FILE ]; then
cp -p $MAP_DIR/$MAP_FILE $RESULT_DIR/$MAP_OUT
# timestamp file
date --reference=$RESULT_DIR/$MAP_OUT --iso-8601=seconds > $RESULT_DIR/$TS_FILE
fi
if [ -f $GH_DIR/$GH_FILE ]; then
cp -p $GH_DIR/$GH_FILE $RESULT_DIR/$GH_OUT
fi
# 3. upload to S3 bucket
if [ $TS_OLD == `cat $RESULT_DIR/$TS_FILE` ]; then
log "map file timestamp is not updated. so skip S3 upload."
else
log upload S3 bucket
log $BIN_DIR/$UPLOAD_SCRIPT
$BIN_DIR/$UPLOAD_SCRIPT
if [ $? != 0 ]; then
log "error to upload S3"
send_msg "error to upload S3"
exit 1
fi
fi
log "finished createOfflineMap script."
exit 0
#!/bin/bash
#
# do mapsforge/map-creator
#
# written by Junichi MORI
# 2019/4/23
# modified by Junichi MORI, 2021/4/16
HOME_DIR=/home/ubuntu
BIN_DIR="$HOME_DIR/bin/mapsforge-creator"
MAP_CREATOR="map-creator.sh"
POLY_FILE="$HOME_DIR/work/offlinemap/ise.poly"
$BIN_DIR/$MAP_CREATOR asia/japan/kansai ram ja 1 $POLY_FILE
exit $?
#!/bin/bash
#
# upload map and ghz file to S3 bucket
#
# Junichi MORI, 2019/5/2
# modified by Junichi MORI, 2021/4/16
function log()
{
echo `date +"%F %T %Z"`": "$*
}
WORK_DIR=/home/ubuntu/work/offlinemap
SRC_DIR=$WORK_DIR/result
MAP_FILE=ise.map
GHZ_FILE=ise.ghz
TS_FILE=map_timestamp
BUCKET="s3://バケット名"
DST_FOLDER=/v1/
DST=$BUCKET$DST_FOLDER
IAM_PROFILE=ユーザー名
cd $SRC_DIR
if [ -f $MAP_FILE ]; then
aws s3 cp $MAP_FILE $DST --profile=$IAM_PROFILE
RES=$?
if [ $RES != 0 ]; then
log $MAP_FILE" ファイルのアップロードに失敗しました。"
exit $RES
fi
else
log $MAP_FILE" ファイルがありません。"
fi
if [ -f $TS_FILE ]; then
aws s3 cp $TS_FILE $DST --profile=$IAM_PROFILE
RES=$?
if [ $RES != 0 ]; then
log $TS_FILE" ファイルのアップロードに失敗しました。"
exit $RES
fi
else
log $TS_FILE" ファイルがありません。"
fi
if [ -f $GHZ_FILE ]; then
aws s3 cp $GHZ_FILE $DST --profile=$IAM_PROFILE
RES=$?
if [ $RES != 0 ]; then
log $GHZ_FILE" ファイルのアップロードに失敗しました。"
exit $RES
fi
else
log $GHZ_FILE" ファイルがありません。"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment