|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -e |
3 | | -export VOLUME_DIR=/mnt/data |
4 | 3 |
|
5 | 4 | # osmosis tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html |
6 | 5 | if [ -z "$MEMORY_JAVACMD_OPTIONS" ]; then |
7 | | - echo JAVACMD_OPTIONS=\"-server\" >~/.osmosis |
| 6 | + echo JAVACMD_OPTIONS="-server" >~/.osmosis |
8 | 7 | else |
9 | 8 | memory="${MEMORY_JAVACMD_OPTIONS//i/}" |
10 | | - echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" >~/.osmosis |
| 9 | + echo JAVACMD_OPTIONS="-server -Xmx$memory" >~/.osmosis |
11 | 10 | fi |
12 | 11 |
|
13 | | -# Fixing name for historical file |
| 12 | +export VOLUME_DIR=/mnt/data |
| 13 | +export PLANET_EPOCH_DATE="${PLANET_EPOCH_DATE:-2004-01-01}" |
14 | 14 | date=$(date '+%y%m%d_%H%M') |
15 | | -local_fullHistoryFile=$VOLUME_DIR/history-${date}.osh.pbf |
16 | | -cloud_fullHistoryFile=planet/full-history/history-${date}.osh.pbf |
17 | | - |
18 | | -# In case overwrite the file |
19 | | -if [ "$OVERWRITE_FHISTORY_FILE" == "true" ]; then |
20 | | - local_fullHistoryFile=$VOLUME_DIR/history-latest.osh.pbf |
21 | | - cloud_fullHistoryFile=planet/full-history/history-latest.osh.pbf |
22 | | -fi |
23 | 15 |
|
24 | | -# State file nname |
| 16 | +local_planetHistoryPBFFile=$VOLUME_DIR/planet-history-${date}.osm.pbf |
| 17 | +cloud_planetHistoryPBFFile=planet/full-history/planet-history-${date}.osm.pbf |
25 | 18 | stateFile="$VOLUME_DIR/state.txt" |
26 | | -osm_tmp_file="osm_tmp.osm" |
27 | | - |
28 | | -# Creating full history |
29 | | -osmosis --read-apidb-change \ |
30 | | - host=$POSTGRES_HOST \ |
31 | | - database=$POSTGRES_DB \ |
32 | | - user=$POSTGRES_USER \ |
33 | | - password=$POSTGRES_PASSWORD \ |
34 | | - validateSchemaVersion=no \ |
35 | | - readFullHistory=yes \ |
36 | | - --write-xml-change \ |
37 | | - compressionMethod=auto \ |
38 | | - $osm_tmp_file |
39 | | - |
40 | | -# Convert file to PBF file |
41 | | -osmium cat $osm_tmp_file -o $local_fullHistoryFile |
42 | | -osmium fileinfo $local_fullHistoryFile |
43 | | - |
44 | | -# Remove full-hitory osm file, keep only history-latest.osh.pbf files |
45 | | -rm $osm_tmp_file |
46 | | - |
47 | | -# AWS |
48 | | -if [ $CLOUDPROVIDER == "aws" ]; then |
49 | | - AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
50 | | - echo "$AWS_URL.s3.amazonaws.com/$cloud_fullHistoryFile" >$stateFile |
51 | | - # Upload history-planet.osm.pbf |
52 | | - aws s3 cp $local_fullHistoryFile $AWS_S3_BUCKET/$cloud_fullHistoryFile --acl public-read |
53 | | - # Upload state.txt |
54 | | - aws s3 cp $stateFile $AWS_S3_BUCKET/planet/full-history/state.txt --acl public-read |
55 | | -fi |
| 19 | +dumpFile="$VOLUME_DIR/input-latest.dump" |
| 20 | + |
56 | 21 |
|
57 | | -# Google Storage |
58 | | -if [ $CLOUDPROVIDER == "gcp" ]; then |
59 | | - echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_fullHistoryFile" >$stateFile |
60 | | - # Upload history-planet.osm.pbf |
61 | | - gsutil cp -a public-read $local_fullHistoryFile $GCP_STORAGE_BUCKET/$cloud_fullHistoryFile |
62 | | - # Upload state.txt |
63 | | - gsutil cp -a public-read $stateFile $GCP_STORAGE_BUCKET/planet/full-history/state.txt |
| 22 | +# If overwrite flag is enabled, use fixed filenames |
| 23 | +if [ "$OVERWRITE_PLANET_FILE" == "true" ]; then |
| 24 | + local_planetHistoryPBFFile=$VOLUME_DIR/planet-history-latest.osm.pbf |
| 25 | + cloud_planetHistoryPBFFile=planet/planet-history-latest.osm.pbf |
64 | 26 | fi |
65 | 27 |
|
66 | | -# Azure |
67 | | -if [ $CLOUDPROVIDER == "azure" ]; then |
68 | | - # Save the path file |
69 | | - echo "https://$AZURE_STORAGE_ACCOUNT.blob.core.windows.net/$AZURE_CONTAINER_NAME/$cloud_fullHistoryFile" >$stateFile |
70 | | - # Upload history-planet.osm.pbf |
71 | | - az storage blob upload \ |
72 | | - --container-name $AZURE_CONTAINER_NAME \ |
73 | | - --file $local_fullHistoryFile \ |
74 | | - --name $cloud_fullHistoryFile \ |
75 | | - --output table |
76 | | - # Upload state.txt |
77 | | - az storage blob upload \ |
78 | | - --container-name $AZURE_CONTAINER_NAME \ |
79 | | - --file $stateFile \ |
80 | | - --name planet/full-history/state.txt \ |
81 | | - --output table |
| 28 | + |
| 29 | +# =============================== |
| 30 | +# Download db .dump file |
| 31 | +# =============================== |
| 32 | +download_dump_file() { |
| 33 | + echo "Downloading db .dump file from cloud..." |
| 34 | + |
| 35 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 36 | + if [[ "$DUMP_CLOUD_URL" == *.txt ]]; then |
| 37 | + temp_txt="$VOLUME_DIR/tmp_dump_url.txt" |
| 38 | + aws s3 cp "$DUMP_CLOUD_URL" "$temp_txt" |
| 39 | + |
| 40 | + # Get the first line (S3 URL to the .dump or .dump.gz file) |
| 41 | + first_line=$(head -n 1 "$temp_txt") |
| 42 | + echo "Found dump URL in txt: $first_line" |
| 43 | + |
| 44 | + # Set dump file name based on extension |
| 45 | + if [[ "$first_line" == *.gz ]]; then |
| 46 | + dumpFile="${dumpFile}.gz" |
| 47 | + fi |
| 48 | + |
| 49 | + aws s3 cp "$first_line" "$dumpFile" |
| 50 | + if [[ "$dumpFile" == *.gz ]]; then |
| 51 | + echo "Decompressing gzip file..." |
| 52 | + gunzip -f "$dumpFile" |
| 53 | + dumpFile="${dumpFile%.gz}" |
| 54 | + fi |
| 55 | + rm -f "$temp_txt" |
| 56 | + |
| 57 | + else |
| 58 | + # Set dump file name based on extension |
| 59 | + if [[ "$DUMP_CLOUD_URL" == *.gz ]]; then |
| 60 | + dumpFile="${dumpFile}.gz" |
| 61 | + fi |
| 62 | + aws s3 cp "$DUMP_CLOUD_URL" "$dumpFile" |
| 63 | + if [[ "$dumpFile" == *.gz ]]; then |
| 64 | + echo "Decompressing gzip file..." |
| 65 | + gunzip -f "$dumpFile" |
| 66 | + dumpFile="${dumpFile%.gz}" |
| 67 | + fi |
| 68 | + fi |
| 69 | + |
| 70 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 71 | + gsutil cp "$DUMP_CLOUD_URL" "$dumpFile" |
| 72 | + else |
| 73 | + echo "Unsupported CLOUDPROVIDER: $CLOUDPROVIDER" |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + |
| 77 | + echo "Dump file ready at: $dumpFile" |
| 78 | +} |
| 79 | + |
| 80 | +# =============================== |
| 81 | +# Upload planet + state |
| 82 | +# =============================== |
| 83 | +upload_planet_file() { |
| 84 | + echo "Uploading history planet file and updating state.txt..." |
| 85 | + |
| 86 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 87 | + AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
| 88 | + echo "$AWS_URL.s3.amazonaws.com/$cloud_planetHistoryPBFFile" > "$stateFile" |
| 89 | + aws s3 cp "$local_planetHistoryPBFFile" "$AWS_S3_BUCKET/$cloud_planetHistoryPBFFile" --acl public-read |
| 90 | + aws s3 cp "$stateFile" "$AWS_S3_BUCKET/planet/state.txt" --acl public-read |
| 91 | + |
| 92 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 93 | + echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_planetHistoryPBFFile" > "$stateFile" |
| 94 | + gsutil cp -a public-read "$local_planetHistoryPBFFile" "$GCP_STORAGE_BUCKET/$cloud_planetHistoryPBFFile" |
| 95 | + gsutil cp -a public-read "$stateFile" "$GCP_STORAGE_BUCKET/planet/state.txt" |
| 96 | + fi |
| 97 | +} |
| 98 | + |
| 99 | +# =============================== |
| 100 | +# Generate planet file |
| 101 | +# =============================== |
| 102 | + |
| 103 | +if [ "$PLANET_EXPORT_METHOD" == "planet-dump-ng" ]; then |
| 104 | + download_dump_file |
| 105 | + echo "Generating history planet file with planet-dump-ng..." |
| 106 | + export PLANET_EPOCH_DATE="$PLANET_EPOCH_DATE" |
| 107 | + planet-dump-ng \ |
| 108 | + --dump-file "$dumpFile" \ |
| 109 | + --history-pbf "$local_planetHistoryPBFFile" |
| 110 | + |
| 111 | +elif [ "$PLANET_EXPORT_METHOD" == "osmosis" ]; then |
| 112 | + echo "Generating history planet file with osmosis..." |
| 113 | + # Creating full history |
| 114 | + osmosis --read-apidb-change \ |
| 115 | + host=$POSTGRES_HOST \ |
| 116 | + database=$POSTGRES_DB \ |
| 117 | + user=$POSTGRES_USER \ |
| 118 | + password=$POSTGRES_PASSWORD \ |
| 119 | + validateSchemaVersion=no \ |
| 120 | + readFullHistory=yes \ |
| 121 | + --write-xml-change \ |
| 122 | + compressionMethod=auto \ |
| 123 | + $local_planetHistoryPBFFile |
| 124 | +else |
| 125 | + echo "Error: Unknown PLANET_EXPORT_METHOD value. Use 'planet-dump-ng' or 'osmosis'." |
| 126 | + exit 1 |
82 | 127 | fi |
| 128 | + |
| 129 | +# Upload results |
| 130 | +upload_planet_file |
0 commit comments