3 # DO NOT EDIT - This file is being maintained by Chef
8 # Get the name of the file and the expected pattern
10 pattern="^osm-([0-9]{4})-([0-9]{2})-([0-9]{2})\.dmp$"
12 # Give up now if the file isn't a database dump
13 [[ $file =~ $pattern ]] || exit 0
15 # Save the year and date from the file name
16 year="${BASH_REMATCH[1]}"
17 date="${year:2:2}${BASH_REMATCH[2]}${BASH_REMATCH[3]}"
20 if [ -f /tmp/planetdump.lock ]; then
21 if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
22 echo "Error: Another planetdump is running"
25 rm /tmp/planetdump.lock
30 echo $$ > /tmp/planetdump.lock
32 # Define cleanup function
34 # Remove the lock file
35 rm /tmp/planetdump.lock
41 # Change to working directory
46 rm -rf changesets changeset_tags changeset_comments
47 rm -rf nodes node_tags
48 rm -rf ways way_tags way_nodes
49 rm -rf relations relation_tags relation_members
52 time nice -n 19 /opt/planet-dump-ng/planet-dump-ng \
54 -c "pbzip2 -c" -f "/store/backup/${file}" --dense-nodes=1 \
55 -C "changesets-${date}.osm.bz2" \
56 -D "discussions-${date}.osm.bz2" \
57 -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
58 -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
60 # Function to create bittorrent files
66 web_dir="${dir}${s_year}"
67 name="${type}-${date}.osm.${format}"
68 web_path="${web_dir}/${name}"
69 rss_web_dir="https://planet.openstreetmap.org/${dir}"
70 rss_file="${type}-${format}-rss.xml"
71 torrent_file="${name}.torrent"
72 torrent_url="${rss_web_dir}${s_year}/${torrent_file}"
74 # create .torrent file
75 mktorrent -l 22 "${name}" \
76 -a udp://tracker.opentrackr.org:1337 \
77 -a udp://tracker.datacenterlight.ch:6969/announce,http://tracker.datacenterlight.ch:6969/announce \
78 -a udp://tracker.torrent.eu.org:451 \
79 -a udp://tracker-udp.gbitt.info:80/announce,http://tracker.gbitt.info/announce,https://tracker.gbitt.info/announce \
80 -a http://retracker.local/announce \
81 -w "https://planet.openstreetmap.org/${web_path}" \
82 -w "https://ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org/${web_path}" \
83 -w "https://ftpmirror.your.org/pub/openstreetmap/${web_path}" \
84 -w "https://mirror.init7.net/openstreetmap/${web_path}" \
85 -w "https://ftp.fau.de/osm-planet/${web_path}" \
86 -w "https://ftp.spline.de/pub/openstreetmap/${web_path}" \
87 -w "https://downloads.opencagedata.com/planet/${name}" \
88 -w "https://planet.osm-hr.org/${web_path}" \
89 -w "https://planet.maps.mail.ru/${web_path}" \
90 -c "OpenStreetMap ${type} data export, licensed under https://opendatacommons.org/licenses/odbl/ by OpenStreetMap contributors" \
91 -o "${torrent_file}" > /dev/null
93 # create .xml global RSS headers if missing
94 torrent_time_rfc="$(date -R -r ${torrent_file})"
95 test -f "${rss_file}" || echo "<x/>" | xmlstarlet select --xml-decl --indent \
96 -N "atom=http://www.w3.org/2005/Atom" \
97 -N "dcterms=http://purl.org/dc/terms/" \
98 -N "content=http://purl.org/rss/1.0/modules/content/" \
103 --attr "version" --output "2.0" --break \
104 --attr "atom:DUMMY" --break \
106 --elem "title" --output "OpenStreetMap ${type} ${format} torrent RSS" --break \
107 --elem "link" --output "${rss_web_dir}" --break \
109 --attr "href" --output "${rss_web_dir}/${rss_file}" --break \
110 --attr "rel" --output "self" --break \
111 --attr "type" --output "application/rss+xml" --break \
113 --elem "description" --output "${type}.osm.${format}.torrent RSS feed" --break \
114 --elem "copyright" --output "Source: OpenStreetMap contributors, under ODbL 1.0 licence" --break \
115 --elem "generator" --output "OpenStreetMap xmlstarlet powered shell script v1.0" --break \
116 --elem "language" --output "en" --break \
117 --elem "lastBuildDate" --output "${torrent_time_rfc}" \
120 # add newly created .torrent file as new entry to .xml RSS feed, removing excess entries
121 torrent_size="$(stat --format="%s" ${torrent_file})"
122 xmlstarlet edit --inplace \
123 -a "//lastBuildDate" -t elem -n item -v "" \
124 -s "//item[1]" -t elem -n "title" -v "${torrent_file}" \
125 -s "//item[1]" -t elem -n "guid" -v "${torrent_url}" \
126 -s "//item[1]" -t elem -n "link" -v "${torrent_url}" \
127 -s "//item[1]" -t elem -n "pubDate" -v "${torrent_time_rfc}" \
128 -s "//item[1]" -t elem -n "category" -v "OpenStreetMap data" \
129 -s "//item[1]" -t elem -n "enclosure" \
130 -s "//item[1]"/enclosure -t attr -n "type" -v "application/x-bittorrent" \
131 -s "//item[1]"/enclosure -t attr -n "length" -v "${torrent_size}" \
132 -s "//item[1]"/enclosure -t attr -n "url" -v "${torrent_url}" \
133 -s "//item[1]" -t elem -n "description" -v "OpenStreetMap torrent ${torrent_file}" \
134 -u /rss/channel/lastBuildDate -v "${torrent_time_rfc}" \
135 -d /rss/@atom:DUMMY \
136 -d "//item[position()>5]" \
140 # Function to install a dump in place
141 function install_dump {
146 name="${type}-${date}.osm.${format}"
147 latest="${type}-latest.osm.${format}"
148 rss_file="${type}-${format}-rss.xml"
150 md5sum "${name}" > "${name}.md5"
151 mkdir -p "${dir}/${year}"
152 mv "${name}" "${name}.md5" "${dir}/${year}"
153 ln -sf "${year:-.}/${name}" "${dir}/${latest}"
154 test -f "${name}.torrent" && mv "${name}.torrent" "${dir}/${year}" && ln -sf "${year:-.}/${name}.torrent" "${dir}/${latest}.torrent"
155 test -f "${rss_file}" && xmllint --noout "${rss_file}" && cp -f "${rss_file}" "${dir}"
156 rm -f "${dir}/${latest}.md5"
157 sed -e "s/${name}/${latest}/" "${dir}/${year}/${name}.md5" > "${dir}/${latest}.md5"
160 # Create *.torrent files
161 mk_torrent "changesets" "bz2" "planet" "/${year}"
162 mk_torrent "discussions" "bz2" "planet" "/${year}"
163 mk_torrent "planet" "bz2" "planet" "/${year}"
164 mk_torrent "history" "bz2" "planet/full-history" "/${year}"
165 mk_torrent "planet" "pbf" "pbf"
166 mk_torrent "history" "pbf" "pbf/full-history"
168 # Move dumps into place
169 install_dump "changesets" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
170 install_dump "discussions" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
171 install_dump "planet" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
172 install_dump "history" "bz2" "<%= node[:planet][:dump][:xml_history_directory] %>" "${year}"
173 install_dump "planet" "pbf" "<%= node[:planet][:dump][:pbf_directory] %>"
174 install_dump "history" "pbf" "<%= node[:planet][:dump][:pbf_history_directory] %>"