2020-01-11 19:26:24 +00:00
|
|
|
{ pkgs, ... }:
|
2020-03-23 08:57:54 +00:00
|
|
|
pkgs.writers.writeDashBin "generate-wallpaper" ''
|
2020-01-11 19:26:24 +00:00
|
|
|
set -euf
|
|
|
|
|
|
|
|
# usage: getimg FILENAME URL
|
|
|
|
fetch() {
|
|
|
|
echo "fetch $1"
|
|
|
|
curl -LsS -z "$1" -o "$1" "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
# usage: check_type FILENAME TYPE
|
|
|
|
check_type() {
|
|
|
|
if ! file -ib "$1" | grep -q "^$2/"; then
|
|
|
|
echo "$1 is not of type $2" >&2
|
|
|
|
rm "$1"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
# check if file exists and fetch only if missing
|
|
|
|
fetch_once() {
|
|
|
|
name=$1
|
|
|
|
url=$2
|
|
|
|
test -e "$name" || fetch "$name" "$url"
|
2020-01-11 19:26:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
fetch_older_min() {
|
|
|
|
min=$1
|
|
|
|
name=$2
|
|
|
|
url=$3
|
|
|
|
if ! test "$(find $name -mmin -$min)"; then
|
|
|
|
fetch "$name" "$url"
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
fetch_older_days() {
|
|
|
|
days=$1
|
|
|
|
name=$2
|
|
|
|
url=$3
|
2020-03-25 18:11:53 +00:00
|
|
|
if ! test "$(find $name -mtime -$days)"; then
|
2020-03-25 14:39:25 +00:00
|
|
|
fetch "$name" "$url"
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# usage: needs_rebuild DST SRC...
|
|
|
|
needs_rebuild() {
|
|
|
|
a="$1"
|
|
|
|
shift
|
|
|
|
if ! test -e "$a"; then
|
|
|
|
#echo " $a does not exist" >&2
|
|
|
|
result=0
|
|
|
|
else
|
|
|
|
result=1
|
|
|
|
for b; do
|
2020-04-11 15:07:30 +00:00
|
|
|
if check_type "$b" image; then
|
|
|
|
if test "$b" -nt "$a"; then
|
|
|
|
#echo " $b is newer than $a" >&2
|
|
|
|
result=0
|
|
|
|
fi
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
#case $result in
|
|
|
|
# 0) echo "$a needs rebuild" >&2;;
|
|
|
|
#esac
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
get_neo_url() {
|
|
|
|
url=$1
|
|
|
|
curl -Ss "$url" | grep '3600 x 1800' | sed 's/.*href="\([^"]*\)".*/\1/'
|
|
|
|
}
|
|
|
|
|
2020-01-11 19:26:24 +00:00
|
|
|
main() {
|
|
|
|
cd "$working_dir"
|
|
|
|
|
|
|
|
# fetch source images in parallel
|
2020-03-25 14:39:25 +00:00
|
|
|
fetch_once nightmap-raw.jpg \
|
|
|
|
'https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_3km.jpg' &
|
|
|
|
fetch_once daymap-raw.tif \
|
|
|
|
'https://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_8192.tif' &
|
|
|
|
|
2020-03-25 17:14:04 +00:00
|
|
|
fetch_once mercury-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/2/2e/Mercury_symbol.svg' &
|
|
|
|
fetch_once venus-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/6/66/Venus_symbol.svg' &
|
|
|
|
fetch_once mars-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/b/b7/Mars_symbol.svg' &
|
|
|
|
fetch_once jupiter-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/2/26/Jupiter_symbol.svg' &
|
|
|
|
fetch_once saturn-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/7/74/Saturn_symbol.svg' &
|
|
|
|
fetch_once uranus-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/f/f1/Uranus_symbol.svg' &
|
|
|
|
fetch_once neptune-raw.svg \
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/4/47/Neptune_symbol.svg' &
|
|
|
|
|
|
|
|
fetch_once krebs-raw.svg \
|
|
|
|
'https://raw.githubusercontent.com/krebs/painload/master/cholerab/bling/krebs_aquarium.svg' &
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
fetch_older_min 720 ice-raw.jpg $(get_neo_url \
|
|
|
|
'https://neo.sci.gsfc.nasa.gov/view.php?datasetId=NISE_D') &
|
|
|
|
fetch_older_days 3 snow-raw.jpg $(get_neo_url \
|
|
|
|
'https://neo.sci.gsfc.nasa.gov/view.php?datasetId=MOD10C1_E_SNOW') &
|
|
|
|
fetch_older_days 7 chlora-raw.jpg $(get_neo_url \
|
|
|
|
'https://neo.sci.gsfc.nasa.gov/view.php?datasetId=MY1DMM_CHLORA') &
|
2020-09-27 13:14:51 +00:00
|
|
|
fetch_older_days 7 fire-raw.jpg $(get_neo_url \
|
2020-03-25 14:39:25 +00:00
|
|
|
'https://neo.sci.gsfc.nasa.gov/view.php?datasetId=MOD14A1_E_FIRE') &
|
2020-03-23 12:05:43 +00:00
|
|
|
|
|
|
|
# regular fetches
|
2020-11-26 18:53:55 +00:00
|
|
|
fetch marker.json.tmp "$marker_url"
|
|
|
|
if [ -s marker.json.tmp ]; then
|
|
|
|
mv marker.json.tmp marker.json
|
|
|
|
fi
|
2020-03-31 15:26:09 +00:00
|
|
|
fetch sun-raw.jpg 'https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_0171.jpg' &
|
2020-03-24 09:12:23 +00:00
|
|
|
|
2020-01-11 19:26:24 +00:00
|
|
|
wait
|
|
|
|
|
2020-03-23 12:05:55 +00:00
|
|
|
# fetch clouds if they are older than 3h
|
|
|
|
if ! test "$(find clouds-raw.png -mmin -180)"; then
|
|
|
|
${pkgs.nomads-cloud}/bin/nomads-cloud clouds-raw.png
|
|
|
|
fi
|
2020-03-23 08:57:54 +00:00
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
in_size=3600x1800
|
2020-03-25 18:12:18 +00:00
|
|
|
xplanet_out_size=3200x2500
|
2020-03-25 19:07:45 +00:00
|
|
|
out_geometry=3200x1800+0+350
|
2020-01-11 19:26:24 +00:00
|
|
|
|
|
|
|
for raw in \
|
|
|
|
nightmap-raw.jpg \
|
2020-03-25 14:39:25 +00:00
|
|
|
daymap-raw.tif \
|
2020-03-24 09:12:23 +00:00
|
|
|
chlora-raw.jpg \
|
2020-03-25 14:39:25 +00:00
|
|
|
clouds-raw.png \
|
2020-01-11 19:26:24 +00:00
|
|
|
;
|
|
|
|
do
|
|
|
|
normal=''${raw%-raw.*}.png
|
|
|
|
if needs_rebuild $normal $raw; then
|
|
|
|
echo "make $normal; normalize $raw" >&2
|
|
|
|
convert $raw -scale $in_size $normal
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
# remove snow from ice map
|
|
|
|
if needs_rebuild ice.png ice-raw.jpg; then
|
2020-04-18 12:37:15 +00:00
|
|
|
convert ice-raw.jpg -fuzz 20% -fill black -opaque white -colorspace gray -blur 0x6 -scale "$in_size" ice.png
|
2020-03-25 14:39:25 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-25 19:08:03 +00:00
|
|
|
if needs_rebuild snow.png snow-raw.jpg; then
|
|
|
|
convert snow-raw.jpg -fuzz 20% -fill '#DEDEDE' -opaque white -scale "$in_size" snow.png
|
|
|
|
fi
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
# make fire more red
|
|
|
|
if needs_rebuild fire.png fire-raw.jpg; then
|
|
|
|
convert fire-raw.jpg -fuzz 20% -fill '#ef840c' -opaque white -scale "$in_size" fire.png
|
|
|
|
fi
|
|
|
|
|
2020-03-31 15:26:09 +00:00
|
|
|
# cut out sun with alpha transparency
|
|
|
|
if needs_rebuild sun.png sun-raw.jpg; then
|
|
|
|
convert sun-raw.jpg \
|
|
|
|
\( +clone -colorspace HSB -fill white -draw "circle 256,256 256,54" -separate -delete 0,1 \) \
|
|
|
|
-compose copyopacity -composite -crop 512x472+0+20 -scale "100x100" sun.png
|
2020-03-24 09:12:23 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-25 17:14:04 +00:00
|
|
|
if needs_rebuild krebs.png krebs-raw.svg; then
|
|
|
|
inkscape -z -e krebs.png -w 16 -h 16 krebs-raw.svg
|
2020-03-24 09:12:23 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-30 16:45:28 +00:00
|
|
|
# -- Planets --
|
|
|
|
for planet in mercury venus mars jupiter saturn uranus neptune; do
|
|
|
|
if needs_rebuild "$planet".png "$planet"-raw.svg; then
|
2020-03-31 15:26:09 +00:00
|
|
|
sed -i 's/#000/#FE8019/g' "$planet"-raw.svg
|
2020-03-30 16:45:28 +00:00
|
|
|
inkscape -z -e "$planet".png -w 40 -h 40 "$planet"-raw.svg
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-03-24 09:12:23 +00:00
|
|
|
# -- Daymap --
|
|
|
|
|
|
|
|
# merge with water chlora layer
|
2020-03-25 14:39:25 +00:00
|
|
|
if needs_rebuild daymap-final.png daymap.png fire.png snow.png ice.png chlora.png; then
|
|
|
|
convert daymap.png fire.png -compose lighten -composite daymap-1.png
|
|
|
|
convert daymap-1.png ice.png -compose lighten -composite daymap-2.png
|
|
|
|
convert daymap-2.png snow.png -compose lighten -composite daymap-3.png
|
|
|
|
convert daymap-3.png chlora.png -compose lighten -composite daymap-final.png
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
# -- Nightmap --
|
2020-03-23 12:05:43 +00:00
|
|
|
|
2020-03-25 14:39:25 +00:00
|
|
|
if needs_rebuild nightmap-final.png nightmap.png fire.png snow.png ice.png chlora.png; then
|
|
|
|
convert nightmap.png fire.png -compose lighten -composite nightmap-1.png
|
|
|
|
convert nightmap-1.png \( -fill black -colorize 70% ice.png \) -compose lighten -composite nightmap-2.png
|
|
|
|
convert nightmap-2.png \( -fill black -colorize 70% snow.png \) -compose lighten -composite nightmap-3.png
|
|
|
|
convert nightmap-3.png \( -fill black -colorize 70% chlora.png \) -compose lighten -composite nightmap-final.png
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-25 17:14:04 +00:00
|
|
|
# create marker file from json
|
|
|
|
if [ -s marker.json ]; then
|
|
|
|
jq -r 'to_entries[] | @json "\(.value.latitude) \(.value.longitude) image=krebs.png"' marker.json > marker_file
|
|
|
|
echo 'position=sun image=sun.png' >> marker_file
|
|
|
|
echo 'position=moon image=moon.png' >> marker_file
|
|
|
|
echo 'position=mercury image=mercury.png' >> marker_file
|
|
|
|
echo 'position=venus image=venus.png' >> marker_file
|
|
|
|
echo 'position=mars image=mars.png' >> marker_file
|
|
|
|
echo 'position=jupiter image=jupiter.png' >> marker_file
|
2020-03-25 19:08:18 +00:00
|
|
|
echo 'position=saturn image=saturn.png' >> marker_file
|
2020-03-25 17:14:04 +00:00
|
|
|
echo 'position=uranus image=uranus.png' >> marker_file
|
|
|
|
echo 'position=neptune image=neptune.png' >> marker_file
|
|
|
|
fi
|
|
|
|
|
2020-03-30 16:45:28 +00:00
|
|
|
# generate moon
|
|
|
|
xplanet -body moon --num_times 1 -origin earth \
|
|
|
|
--transpng moon.png --geometry 50x50 \
|
|
|
|
-config ${pkgs.writeText "moon.config" ''
|
|
|
|
[moon]
|
|
|
|
shade=10
|
|
|
|
''}
|
|
|
|
|
2020-01-11 19:26:24 +00:00
|
|
|
# rebuild every time to update shadow
|
|
|
|
xplanet --num_times 1 --geometry $xplanet_out_size \
|
|
|
|
--output xplanet-output.png --projection merc \
|
|
|
|
-config ${pkgs.writeText "xplanet.config" ''
|
|
|
|
[earth]
|
|
|
|
"Earth"
|
|
|
|
map=daymap-final.png
|
|
|
|
night_map=nightmap-final.png
|
2020-03-25 14:39:25 +00:00
|
|
|
cloud_map=clouds.png
|
2020-03-23 19:28:29 +00:00
|
|
|
cloud_threshold=1
|
2020-03-26 16:00:27 +00:00
|
|
|
cloud_gamma=10
|
2020-01-11 19:26:24 +00:00
|
|
|
shade=15
|
|
|
|
''}
|
|
|
|
|
|
|
|
xplanet --num_times 1 --geometry $xplanet_out_size \
|
|
|
|
--output xplanet-krebs-output.png --projection merc \
|
|
|
|
-config ${pkgs.writeText "xplanet-krebs.config" ''
|
|
|
|
[earth]
|
|
|
|
"Earth"
|
|
|
|
map=daymap-final.png
|
|
|
|
night_map=nightmap-final.png
|
2020-03-25 14:39:25 +00:00
|
|
|
cloud_map=clouds.png
|
2020-03-23 19:28:29 +00:00
|
|
|
cloud_threshold=1
|
2020-03-26 16:00:27 +00:00
|
|
|
cloud_gamma=10
|
2020-01-11 19:26:24 +00:00
|
|
|
marker_file=marker_file
|
|
|
|
shade=15
|
|
|
|
''}
|
|
|
|
|
|
|
|
# trim xplanet output
|
|
|
|
if needs_rebuild realwallpaper.png xplanet-output.png; then
|
|
|
|
convert xplanet-output.png -crop $out_geometry \
|
|
|
|
realwallpaper-tmp.png
|
|
|
|
mv realwallpaper-tmp.png realwallpaper.png
|
|
|
|
fi
|
|
|
|
|
|
|
|
if needs_rebuild realwallpaper-krebs.png xplanet-krebs-output.png; then
|
|
|
|
convert xplanet-krebs-output.png -crop $out_geometry \
|
|
|
|
realwallpaper-krebs-tmp.png
|
|
|
|
mv realwallpaper-krebs-tmp.png realwallpaper-krebs.png
|
2020-03-31 15:26:28 +00:00
|
|
|
mkdir -p archive
|
|
|
|
convert realwallpaper-krebs.png archive/"$(date -Is)".jpg
|
2020-01-11 19:26:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|
|
|
|
''
|