Skip to content

Commit

Permalink
Run shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed May 21, 2024
1 parent ccf3575 commit 570f36b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 107 deletions.
14 changes: 7 additions & 7 deletions renderer/_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ LOCKFILE="/tmp/planet-render.lock"

# Check if lock file exists
if [ -e "${LOCKFILE}" ]; then
echo "A rendering process is already running."
exit 1
echo "A rendering process is already running."
exit 1
else
# Create a lock file
touch "${LOCKFILE}"
# Create a lock file
touch "${LOCKFILE}"

# Ensure the lock file is removed when we exit and when we receive signals
trap 'rm -f ${LOCKFILE}; trap - SIGTERM && kill -- -$$' SIGINT SIGTERM EXIT
# Ensure the lock file is removed when we exit and when we receive signals
trap 'rm -f ${LOCKFILE}; trap - SIGTERM && kill -- -$$' SIGINT SIGTERM EXIT
fi

# The local path to the tileservice repo
Expand All @@ -32,4 +32,4 @@ mkdir "$REPO_DIR"
git clone https://github.com/osmus/tileservice.git "$REPO_DIR"

# Start the render, assuming the directory format hasn't changed
"$REPO_DIR/renderer/render.sh"
"$REPO_DIR/renderer/render.sh"
2 changes: 1 addition & 1 deletion renderer/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Get the directory of the current script
DIR="$(dirname "$0")"

"$DIR/render_seashells.sh" "$1"
"$DIR/render_seashells.sh" "$1"
79 changes: 41 additions & 38 deletions renderer/render_once.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,63 @@ docker system prune --force
docker pull ghcr.io/onthegomap/planetiler:latest

docker run -e JAVA_TOOL_OPTIONS='-Xmx2g' \
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest --area=planet \
--download --download-only --only-fetch-wikidata
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest --area=planet \
--download --download-only --only-fetch-wikidata

# Remove default downloaded OSM file
rm -rf "$WORKING_DIR/data/sources/monaco.osm.pbf"

PLANET="$WORKING_DIR/data/planet.pmtiles"

docker run -e JAVA_TOOL_OPTIONS='-Xmx150g' \
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest --area=planet --bounds=world \
--output="/data/planet.pmtiles" \
--transportation_name_size_for_shield \
--transportation_name_limit_merge \
--boundary-osm-only \
--storage=ram --nodemap-type=array \
--max-point-buffer=4 \
--building_merge_z13=false \
--languages=ab,ace,af,als,am,an,ar,arz,as,ast,az,az-Arab,az-cyr,azb,ba,bar,bat-smg,be,be-tarask,ber,bg,bm,bn,bo,bpy,br,bs,bxr,ca,cdo,ce,ceb,cho,chr,chy,ckb,co,cr,crh,crh-cyr,crk,cs,csb,cv,cy,da,dak,de,dsb,dv,dz,ee,egl,el,en,eo,es,et,eu,fa,fi,fil,fit,fo,fr,frr,full,fur,fy,ga,gag,gan,gcf,gd,gl,gn,gr,grc,gsw,gu,gv,ha,hak,hak-HJ,haw,he,hi,hif,hr,hsb,ht,hu,hur,hy,ia,id,ie,ilo,int,io,is,it,iu,ja,ja_kana,ja_rm,ja-Hira,ja-Latn,jv,ka,kab,kbd,ki,kk,kk-Arab,kl,km,kn,ko,ko-Hani,ko-Latn,krc,krl,ks,ku,kv,kw,ky,la,lb,left,lez,li,lij,lld,lmo,ln,lo,lrc,lt,lv,lzh,md,mdf,mez,mg,mhr,mi,mia,mk,ml,mn,mo,moh,mr,mrj,ms,ms-Arab,mt,mwl,my,myv,mzn,nah,nan,nan-HJ,nan-POJ,nan-TL,nds,ne,nl,nn,no,nov,nv,oc,oj,old,or,os,ota,pa,pam,pcd,pfl,pl,pms,pnb,pot,ps,pt,pt-BR,pt-PT,qu,right,rm,ro,ru,rue,rw,sah,sat,sc,scn,sco,sd,se,sh,si,sju,sk,sl,sma,smj,so,sq,sr,sr-Latn,su,sv,sw,syc,szl,ta,te,TEC,tg,th,th-Latn,ti,tk,tl,tr,tt,tt-lat,udm,ug,uk,ur,uz,uz-Arab,uz-cyr,uz-Cyrl,uz-Latn,vec,vi,vls,vo,wa,war,win,wiy,wo,wuu,xmf,yi,yo,yue,yue-Hant,yue-Latn,za,zgh,zh,zh_pinyin,zh_zhuyin,zh-Hans,zh-Hant,zh-Latn-pinyin,zu,zza
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest --area=planet --bounds=world \
--output="/data/planet.pmtiles" \
--transportation_name_size_for_shield \
--transportation_name_limit_merge \
--boundary-osm-only \
--storage=ram --nodemap-type=array \
--max-point-buffer=4 \
--building_merge_z13=false \
--languages=ab,ace,af,als,am,an,ar,arz,as,ast,az,az-Arab,az-cyr,azb,ba,bar,bat-smg,be,be-tarask,ber,bg,bm,bn,bo,bpy,br,bs,bxr,ca,cdo,ce,ceb,cho,chr,chy,ckb,co,cr,crh,crh-cyr,crk,cs,csb,cv,cy,da,dak,de,dsb,dv,dz,ee,egl,el,en,eo,es,et,eu,fa,fi,fil,fit,fo,fr,frr,full,fur,fy,ga,gag,gan,gcf,gd,gl,gn,gr,grc,gsw,gu,gv,ha,hak,hak-HJ,haw,he,hi,hif,hr,hsb,ht,hu,hur,hy,ia,id,ie,ilo,int,io,is,it,iu,ja,ja_kana,ja_rm,ja-Hira,ja-Latn,jv,ka,kab,kbd,ki,kk,kk-Arab,kl,km,kn,ko,ko-Hani,ko-Latn,krc,krl,ks,ku,kv,kw,ky,la,lb,left,lez,li,lij,lld,lmo,ln,lo,lrc,lt,lv,lzh,md,mdf,mez,mg,mhr,mi,mia,mk,ml,mn,mo,moh,mr,mrj,ms,ms-Arab,mt,mwl,my,myv,mzn,nah,nan,nan-HJ,nan-POJ,nan-TL,nds,ne,nl,nn,no,nov,nv,oc,oj,old,or,os,ota,pa,pam,pcd,pfl,pl,pms,pnb,pot,ps,pt,pt-BR,pt-PT,qu,right,rm,ro,ru,rue,rw,sah,sat,sc,scn,sco,sd,se,sh,si,sju,sk,sl,sma,smj,so,sq,sr,sr-Latn,su,sv,sw,syc,szl,ta,te,TEC,tg,th,th-Latn,ti,tk,tl,tr,tt,tt-lat,udm,ug,uk,ur,uz,uz-Arab,uz-cyr,uz-Cyrl,uz-Latn,vec,vi,vls,vo,wa,war,win,wiy,wo,wuu,xmf,yi,yo,yue,yue-Hant,yue-Latn,za,zgh,zh,zh_pinyin,zh_zhuyin,zh-Hans,zh-Hant,zh-Latn-pinyin,zu,zza

# Check if the file exists and is at least 50GB
if [[ ! -f "$PLANET" ]]; then
echo "Error: File $PLANET does not exist."
exit 1
elif [[ $(stat -c %s "$PLANET") -lt $((50*1024*1024*1024)) ]]; then
echo "Error: File $PLANET is smaller than 50GB."
exit 1
echo "Error: File $PLANET does not exist."
exit 1
elif [[ $(stat -c %s "$PLANET") -lt $((50 * 1024 * 1024 * 1024)) ]]; then
echo "Error: File $PLANET is smaller than 50GB."
exit 1
fi

echo 'Uploading planet to s3 bucket in background'
aws s3 cp "$PLANET" s3://planet-pmtiles/ --only-show-errors &

# Render optional layers
for file in "$DIR/layers/"*.yml; do
# Get the base name of the file without the .yml extension
layer_name=$(basename "$file" .yml)

echo "Processing layer: $layer_name"

docker run -e JAVA_TOOL_OPTIONS='-Xmx24g' \
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest generate-custom \
--area=planet --bounds=world \
--output="/data/$layer_name.pmtiles" \
--schema="/layers/$layer_name.yml" \
--storage=mmap --nodemap-type=array \
--max-point-buffer=4

echo "Uploading $layer_name to s3 bucket in background"
{ aws s3 cp "$WORKING_DIR/data/$layer_name.pmtiles" s3://planet-pmtiles/ --only-show-errors; rm -rf "$WORKING_DIR/data/$layer_name.pmtiles"; } &
# Get the base name of the file without the .yml extension
layer_name=$(basename "$file" .yml)

echo "Processing layer: $layer_name"

docker run -e JAVA_TOOL_OPTIONS='-Xmx24g' \
-v "$WORKING_DIR/data":/data \
-v "$DIR/layers":/layers \
ghcr.io/onthegomap/planetiler:latest generate-custom \
--area=planet --bounds=world \
--output="/data/$layer_name.pmtiles" \
--schema="/layers/$layer_name.yml" \
--storage=mmap --nodemap-type=array \
--max-point-buffer=4

echo "Uploading $layer_name to s3 bucket in background"
{
aws s3 cp "$WORKING_DIR/data/$layer_name.pmtiles" s3://planet-pmtiles/ --only-show-errors
rm -rf "$WORKING_DIR/data/$layer_name.pmtiles"
} &
done

echo 'Waiting for all background jobs to finish'
Expand All @@ -89,4 +92,4 @@ echo 'Invalidating the CDN cache'
aws cloudfront create-invalidation --distribution-id E1E7N0LWX2WY4E --invalidation-batch "{\"Paths\": {\"Quantity\": 1, \"Items\": [\"/*\"]}, \"CallerReference\": \"invalidation-$DATE\"}"

echo 'Render Complete'
date -u '+%Y-%m-%d %H:%M:%S'
date -u '+%Y-%m-%d %H:%M:%S'
80 changes: 40 additions & 40 deletions renderer/render_seashells.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ LOG_TIMESTAMP=$(date +%Y%m%d%H%M%S)
LOG_FILE="/var/log/render/logs_$LOG_TIMESTAMP.txt"

touch "$LOG_FILE"
tail -f "$LOG_FILE" | nc seashells.io 1337 > /tmp/seashells_render & sleep 10
tail -f "$LOG_FILE" | nc seashells.io 1337 >/tmp/seashells_render &
sleep 10

# Get the size of the file in bytes
OSM_PLANET_SIZE=$(stat -c%s "$WORKING_DIR/data/sources/planet.osm.pbf")
Expand All @@ -31,44 +32,43 @@ PLANET="$WORKING_DIR/data/planet.pmtiles"
"$DIR/rss_update.sh" "$RSS_FILE" "Build Started." "The OSM planet file is ${OSM_PLANET_SIZE} bytes."

run() {
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
START_TIME=$(date +%s)

if "$DIR/render_once.sh" "$WORKING_DIR"
then
# Record the end time
END_TIME=$(date +%s)

# Calculate the time difference
TIME_DIFF=$((END_TIME - START_TIME))

# Convert the time difference to hours and minutes
HOURS=$((TIME_DIFF / 3600))
MINUTES=$(((TIME_DIFF / 60) % 60))

# Format hours and minutes with singular or plural as appropriate
HOUR_TEXT="hours"
MINUTE_TEXT="minutes"
if [ "$HOURS" -eq 1 ]; then
HOUR_TEXT="hour"
fi
if [ "$MINUTES" -eq 1 ]; then
MINUTE_TEXT="minute"
fi

# Get the size of the file in bytes
PMTILES_PLANET_SIZE=$(stat -c%s "$PLANET")

# Print the size with comma separators
PMTILES_PLANET_SIZE=$(printf "%'d" "$PMTILES_PLANET_SIZE")

"$DIR/rss_update.sh" "$RSS_FILE" "Build Complete" "Tiles are up to date as of ${TIMESTAMP}Z. Render took ${HOURS} ${HOUR_TEXT} and ${MINUTES} ${MINUTE_TEXT}. The planet PMTiles file is ${PMTILES_PLANET_SIZE} bytes."
else
"$DIR/rss_update.sh" "$RSS_FILE" "Build Failed" "Review the build log to find out why."
fi

echo 'Removing local planet file'
rm -rf "$PLANET"
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
START_TIME=$(date +%s)

if "$DIR/render_once.sh" "$WORKING_DIR"; then
# Record the end time
END_TIME=$(date +%s)

# Calculate the time difference
TIME_DIFF=$((END_TIME - START_TIME))

# Convert the time difference to hours and minutes
HOURS=$((TIME_DIFF / 3600))
MINUTES=$(((TIME_DIFF / 60) % 60))

# Format hours and minutes with singular or plural as appropriate
HOUR_TEXT="hours"
MINUTE_TEXT="minutes"
if [ "$HOURS" -eq 1 ]; then
HOUR_TEXT="hour"
fi
if [ "$MINUTES" -eq 1 ]; then
MINUTE_TEXT="minute"
fi

# Get the size of the file in bytes
PMTILES_PLANET_SIZE=$(stat -c%s "$PLANET")

# Print the size with comma separators
PMTILES_PLANET_SIZE=$(printf "%'d" "$PMTILES_PLANET_SIZE")

"$DIR/rss_update.sh" "$RSS_FILE" "Build Complete" "Tiles are up to date as of ${TIMESTAMP}Z. Render took ${HOURS} ${HOUR_TEXT} and ${MINUTES} ${MINUTE_TEXT}. The planet PMTiles file is ${PMTILES_PLANET_SIZE} bytes."
else
"$DIR/rss_update.sh" "$RSS_FILE" "Build Failed" "Review the build log to find out why."
fi

echo 'Removing local planet file'
rm -rf "$PLANET"
}

run 2>&1 | tee -a "$LOG_FILE"
run 2>&1 | tee -a "$LOG_FILE"
42 changes: 21 additions & 21 deletions renderer/rss_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Check for input parameter (the message to be added)
if [ $# -lt 1 ]; then
echo "Usage: $0 <message>"
exit 1
echo "Usage: $0 <message>"
exit 1
fi

RSS_FILE=$1
Expand All @@ -16,42 +16,42 @@ MESSAGE=$(echo "$MESSAGE" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&q

# Check if the RSS file exists
if [ -f "$RSS_FILE" ]; then
# Get the size of the RSS file
FILE_SIZE=$(stat -c%s "$RSS_FILE")

# If the size of the RSS file is more than 100KB, remove it
if [ "$FILE_SIZE" -gt 102400 ]; then
echo "The RSS file is larger than 100KB. Removing the file..."
rm "$RSS_FILE"
fi
# Get the size of the RSS file
FILE_SIZE=$(stat -c%s "$RSS_FILE")

# If the size of the RSS file is more than 100KB, remove it
if [ "$FILE_SIZE" -gt 102400 ]; then
echo "The RSS file is larger than 100KB. Removing the file..."
rm "$RSS_FILE"
fi
fi

# If the RSS file doesn't exist, create a new one
if [ ! -f "$RSS_FILE" ]; then
echo '<?xml version="1.0" encoding="UTF-8"?>
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<author><name>OpenStreetMap US</name></author>
<title type="text">tile.ourmap.us Planet Build</title>
<link>https://tile.ourmap.us/</link>
<description>Planet build status</description>
</channel>
</rss>' > "$RSS_FILE"
</rss>' >"$RSS_FILE"
fi

# Read the URL from /tmp/seashells_render and extract it using grep
URL=$(grep -o 'https://[^ ]*' /tmp/seashells_render)

# Add the new item entry to the RSS file
xmlstarlet ed --inplace \
-s "//channel" -t elem -n "item" -v "" \
-s "//channel/item[last()]" -t elem -n "title" -v "$TITLE" \
-s "//channel/item[last()]" -t elem -n "author" -v "tech@openstreetmap.us" \
-s "//channel/item[last()]" -t elem -n "link" -v "$URL" \
-s "//channel/item[last()]" -t elem -n "pubDate" -v "$CURRENT_DATE" \
-s "//channel/item[last()]" -t elem -n "content:encoded" -v "$MESSAGE" \
-i "//channel/item[last()]/content:encoded" -t attr -n "type" -v "html" \
"$RSS_FILE"
-s "//channel" -t elem -n "item" -v "" \
-s "//channel/item[last()]" -t elem -n "title" -v "$TITLE" \
-s "//channel/item[last()]" -t elem -n "author" -v "tech@openstreetmap.us" \
-s "//channel/item[last()]" -t elem -n "link" -v "$URL" \
-s "//channel/item[last()]" -t elem -n "pubDate" -v "$CURRENT_DATE" \
-s "//channel/item[last()]" -t elem -n "content:encoded" -v "$MESSAGE" \
-i "//channel/item[last()]/content:encoded" -t attr -n "type" -v "html" \
"$RSS_FILE"

echo "New entry added to $RSS_FILE"
aws s3 cp "$RSS_FILE" s3://tileserver-static/
aws s3 cp "$RSS_FILE" s3://tileserver-static/

0 comments on commit 570f36b

Please sign in to comment.