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://free.nchc.org.tw/osm.planet/${web_path}" \
86 -w "https://ftp.fau.de/osm-planet/${web_path}" \
87 -w "https://ftp.spline.de/pub/openstreetmap/${web_path}" \
88 -w "https://osm.openarchive.site/${name}" \
89 -w "https://downloads.opencagedata.com/planet/${name}" \
90 -w "https://planet.osm-hr.org/${web_path}" \
91 -w "https://planet.maps.mail.ru/${web_path}" \
92 -c "OpenStreetMap ${type} data export, licensed under https://opendatacommons.org/licenses/odbl/ by OpenStreetMap contributors" \
93 -o "${torrent_file}" > /dev/null
95 # create .xml global RSS headers if missing
96 torrent_time_rfc="$(date -R -r ${torrent_file})"
97 test -f "${rss_file}" || echo "<x/>" | xmlstarlet select --xml-decl --indent \
98 -N "atom=http://www.w3.org/2005/Atom" \
99 -N "dcterms=http://purl.org/dc/terms/" \
100 -N "content=http://purl.org/rss/1.0/modules/content/" \
105 --attr "version" --output "2.0" --break \
106 --attr "atom:DUMMY" --break \
108 --elem "title" --output "OpenStreetMap ${type} ${format} torrent RSS" --break \
109 --elem "link" --output "${rss_web_dir}" --break \
111 --attr "href" --output "${rss_web_dir}/${rss_file}" --break \
112 --attr "rel" --output "self" --break \
113 --attr "type" --output "application/rss+xml" --break \
115 --elem "description" --output "${type}.osm.${format}.torrent RSS feed" --break \
116 --elem "copyright" --output "Source: OpenStreetMap contributors, under ODbL 1.0 licence" --break \
117 --elem "generator" --output "OpenStreetMap xmlstarlet powered shell script v1.0" --break \
118 --elem "language" --output "en" --break \
119 --elem "lastBuildDate" --output "${torrent_time_rfc}" \
122 # add newly created .torrent file as new entry to .xml RSS feed, removing excess entries
123 torrent_size="$(stat --format="%s" ${torrent_file})"
124 xmlstarlet edit --inplace \
125 -a "//lastBuildDate" -t elem -n item -v "" \
126 -s "//item[1]" -t elem -n "title" -v "${torrent_file}" \
127 -s "//item[1]" -t elem -n "guid" -v "${torrent_url}" \
128 -s "//item[1]" -t elem -n "link" -v "${torrent_url}" \
129 -s "//item[1]" -t elem -n "pubDate" -v "${torrent_time_rfc}" \
130 -s "//item[1]" -t elem -n "category" -v "OpenStreetMap data" \
131 -s "//item[1]" -t elem -n "enclosure" \
132 -s "//item[1]"/enclosure -t attr -n "type" -v "application/x-bittorrent" \
133 -s "//item[1]"/enclosure -t attr -n "length" -v "${torrent_size}" \
134 -s "//item[1]"/enclosure -t attr -n "url" -v "${torrent_url}" \
135 -s "//item[1]" -t elem -n "description" -v "OpenStreetMap torrent ${torrent_file}" \
136 -u /rss/channel/lastBuildDate -v "${torrent_time_rfc}" \
137 -d /rss/@atom:DUMMY \
138 -d "//item[position()>5]" \
142 # Function to install a dump in place
143 function install_dump {
148 name="${type}-${date}.osm.${format}"
149 latest="${type}-latest.osm.${format}"
150 rss_file="${type}-${format}-rss.xml"
152 md5sum "${name}" > "${name}.md5"
153 mkdir -p "${dir}/${year}"
154 mv "${name}" "${name}.md5" "${dir}/${year}"
155 ln -sf "${year:-.}/${name}" "${dir}/${latest}"
156 test -f "${name}.torrent" && mv "${name}.torrent" "${dir}/${year}" && ln -sf "${year:-.}/${name}.torrent" "${dir}/${latest}.torrent"
157 test -f "${rss_file}" && xmllint --noout "${rss_file}" && cp -f "${rss_file}" "${dir}"
158 rm -f "${dir}/${latest}.md5"
159 sed -e "s/${name}/${latest}/" "${dir}/${year}/${name}.md5" > "${dir}/${latest}.md5"
162 # Create *.torrent files
163 mk_torrent "changesets" "bz2" "planet" "/${year}"
164 mk_torrent "discussions" "bz2" "planet" "/${year}"
165 mk_torrent "planet" "bz2" "planet" "/${year}"
166 mk_torrent "history" "bz2" "planet/full-history" "/${year}"
167 mk_torrent "planet" "pbf" "pbf"
168 mk_torrent "history" "pbf" "pbf/full-history"
170 # Move dumps into place
171 install_dump "changesets" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
172 install_dump "discussions" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
173 install_dump "planet" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
174 install_dump "history" "bz2" "<%= node[:planet][:dump][:xml_history_directory] %>" "${year}"
175 install_dump "planet" "pbf" "<%= node[:planet][:dump][:pbf_directory] %>"
176 install_dump "history" "pbf" "<%= node[:planet][:dump][:pbf_history_directory] %>"