Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamus03 committed May 9, 2023
0 parents commit 49485de
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nasa-apod-background.deb
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
nasa-apod-background.deb: $(wildcard src/**/*)
dpkg-deb --root-owner-group --build ./src nasa-apod-background.deb

clean:
rm -f nasa-apod-background.deb
.PHONY: clean

configure:

.PHONY: configure

install: nasa-apod-background.deb
apt-get install --reinstall ./nasa-apod-background.deb
.PHONY: install
6 changes: 6 additions & 0 deletions src/DEBIAN/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

. /usr/share/debconf/confmodule

db_input critical nasa-apod-background/api_key || :
db_go
7 changes: 7 additions & 0 deletions src/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Package: nasa-apod-background
Version: 1.0.0
Maintainer: Shamus <[email protected]>
Description: Automatically set your background to the NASA picture of the day
Homepage: https://github.com/Shamus03/nasa-apod-background
Architecture: all
Depends: curl, debconf (>= 0.2.17), fish, imagemagick, jp, logrotate
18 changes: 18 additions & 0 deletions src/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh -e

. /usr/share/debconf/confmodule

db_get nasa-apod-background/api_key

mkdir -p /opt/nasa-apod-background
printf '%s' "$RET" > /opt/nasa-apod-background/api.key

/usr/bin/fish /opt/nasa-apod-background/nasa-apod-background.fish

pid="$(pgrep gnome-session)"
export DBUS_SESSION_BUS_ADDRESS="$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | cut -d= -f2-)"

gsettings set org.gnome.desktop.background picture-uri file:///opt/nasa-apod-background/apod_desktop.jpg
gsettings set org.gnome.desktop.background picture-options wallpaper
gsettings set org.gnome.desktop.screensaver picture-uri file:///opt/nasa-apod-background/apod_lock.jpg
gsettings set org.gnome.desktop.screensaver picture-options wallpaper
8 changes: 8 additions & 0 deletions src/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -e

if [ "$1" = "purge" -a -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
db_purge
fi

rm -rf /opt/nasa-apod-background
3 changes: 3 additions & 0 deletions src/DEBIAN/templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Template: nasa-apod-background/api_key
Type: string
Description: Enter your NASA API key. Get one from https://api.nasa.gov/
2 changes: 2 additions & 0 deletions src/etc/cron.d/nasa-apod-background
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 * * * * root /usr/bin/fish /opt/nasa-apod-background/nasa-apod-background.fish >> /opt/nasa-apod-background/cron.log 2>&1
1 * * * * root logrotate -s /opt/nasa-apod-background/logrotate.status /opt/nasa-apod-background/logrotate.config
9 changes: 9 additions & 0 deletions src/opt/nasa-apod-background/logrotate.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/opt/nasa-apod-background/cron.log {
rotate 2
olddir oldlogs
createolddir
dateext
size 100k
create
nocompress
}
44 changes: 44 additions & 0 deletions src/opt/nasa-apod-background/nasa-apod-background.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/fish

argparse --name=nasa-apod-background 'f/force' -- $argv
or return

set config_dir /opt/nasa-apod-background
set date_file $config_dir/date.txt
set api_key_file $config_dir/api.key

set img_full $config_dir/apod_full.jpg
set img_desktop $config_dir/apod_desktop.jpg
set img_lock $config_dir/apod_lock.jpg

if not test -f $api_key_file
echo "Api key not found - please create a file $api_key_file containing your NASA API key"
exit 1
end
set api_key (cat $api_key_file)

set apod (curl -s "https://api.nasa.gov/planetary/apod?api_key=$api_key")
set apod_url (echo $apod | jp -u url)
set apod_hdurl (echo $apod | jp -u hdurl)
set apod_explanation (echo $apod | jp -u explanation)
set apod_date (echo $apod | jp -u date)

set last_downloaded_date (cat $date_file 2>/dev/null)

if string length -- $_flag_force; or test "$apod_date" != "$last_downloaded_date"
rm -f $date_file
if not wget -O $img_full $apod_hdurl
echo "HD image not found: $apod_hdurl"
echo "Will download low quality version"
wget -O $img_full $apod_url
end

# Resize full image to fit screen
and convert -background black -resize 1920 -extent 1920x1080 -gravity center -quiet $img_full $img_desktop

# Create captioned image for lock screen
and convert $img_desktop \( -background none -size 1920x -fill white -undercolor black -pointsize 20 caption:(string replace --all "'" "\'" $apod_explanation) \) -gravity southwest -compose over -composite $img_lock

and echo $apod_date > $date_file
end

22 changes: 22 additions & 0 deletions src/usr/share/gnome-background-properties/nasa-apod-background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>NASA APOD</name>
<name xml:lang="en">NASA APOD</name>
<filename>/opt/nasa-apod-background/apod_desktop.jpg</filename>
<options>zoom</options>
<shade_type>solid</shade_type>
<pcolor>#ffffff</pcolor>
<scolor>#000000</scolor>
</wallpaper>
<wallpaper deleted="false">
<name>NASA APOD (captioned)</name>
<name xml:lang="en">NASA APOD (captioned)</name>
<filename>/opt/nasa-apod-background/apod_lock.jpg</filename>
<options>zoom</options>
<shade_type>solid</shade_type>
<pcolor>#ffffff</pcolor>
<scolor>#000000</scolor>
</wallpaper>
</wallpapers>

0 comments on commit 49485de

Please sign in to comment.