#!/bin/bash
# set to 1 if you want to get more information while rendering
DEBUG=1
# DEFAULT CONFIGURATION
# OVERWRITTEN WITH $CONFIGFILE
LANGUAGE="en"
TEMPLATE="default"
STYLE="default"
GEOMETRY="1920x1200"
CENTER="+960+600"
DELAY=1200
AUTOSTART=60
LOGGING=1
LONGITUDE=0
LATITUDE=0
LONROTATE=0
LATROTATE=0
BUMPCLOUDS=1
SPECULAR=1
POST=1
OVERLAY=0
CLOUDFACTOR=1.01
RADIUS=32
CORONA=1.03
CORONABLUR=5
SHOWDATE=0
DATE=0
GMT=0
OUTPUT=""
SCRIPT=""
PRESCRIPT=""
SEARCHMAPURL="http://www.informationfreeway.org/"
SHOWORBIT=1
ORBIT=-60
STARS=0
PREGRID=0
ATMOSPHERE=1
# END OF DEFAULT CONFIGURATION
# determine the working directory
#ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0#*/}")"
#WORKDIR=`dirname "$ABSPATH"`
WORKDIR=/usr/share/xplanetFX
USERDIR=$HOME/.xplanetFX
ACTDIR=`pwd`
# not neccessary to change anything below
MAPSIZE="2500x1250" # do not change except all base maps are resized, too
BACKGROUND=$USERDIR"/cache/background.png"
BASEIMAGE=$USERDIR"/base/canvas.png" # overall background, must be png
CONFIG=$USERDIR"/config/xplanet-final" # config for xplanet used in final rendering
INTERIM=$USERDIR"/cache/final.png"
OUTPUT1=$USERDIR"/output/xplanetFX1.png"
OUTPUT2=$USERDIR"/output/xplanetFX2.png"
FINAL="$USERDIR/Desktop/xplanetFX.png" # default output if SINGLE is set to 1
CONFIGFILE=$USERDIR"/xplanetFX.conf"
SINGLE=0 # default behavior, SINGLE=1 always creates single renderings and exits.
DESKTOP="" # "GNOME", "KDE", "XFCE", "FLUXBOX", determined by function later
XPLANETDEF="-num_times 1 -starfreq 0 -starmap false -glare 0"
function random2b () { dd if=/dev/random count=1 bs=2 2>/dev/null | hexdump -e '"%d"'; }
function random () { echo $(( `random2b`*$1/65536-$1/2)); }
function echo2 () { echo `date +"%x %X"` $@ | tee -a $USERDIR/logs/xplanetFX.log; }
function echo3 () { echo `date +"%x %X"` $@ >> $USERDIR/logs/xplanetFX.log; }
function echo4 () {
while read data; do
echo `date +"%x %X"` $data | tee -a $USERDIR/logs/xplanetFX.log;
done
}
function debug () {
if [ "$DEBUG" = "1" ]; then
echo2 \# DEBUG $1
fi
}
function round () { echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc)); }
function install_template() {
# massive cleanup
rm $USERDIR/overlays/* >/dev/null 2>&1
rm $USERDIR/temp/* >/dev/null 2>&1
mv $USERDIR/backgrounds/stars.png $USERDIR/backgrounds/black.png $USERDIR/backgrounds/white.png $USERDIR/backgrounds/transparent.png $USERDIR/temp >/dev/null 2>&1
rm $USERDIR/backgrounds/* >/dev/null 2>&1
mv $USERDIR/temp/* $USERDIR/backgrounds/ >/dev/null 2>&1
cd $USERDIR/templates
DESTSIZE=`cat $CONFIGFILE | grep --regexp="^GEOMETRY = " | awk -F " = " '{ print $2 }'`
if [ -f "$1/$2.tpl" -o -f "$1/$2" ]; then
if [ -f "$1/$2" ]; then
TEMPLATE="$1/$2"
else
TEMPLATE="$1/$2.tpl"
fi
TPL=`echo $TEMPLATE | sed "s/.tpl//" | awk -F '/' '{ print $1 }'`
sed -i -r "s/^TEMPLATE = .*/TEMPLATE = $TPL/" $CONFIGFILE
STY=`echo $TEMPLATE | sed "s/.tpl//" | awk -F '/' '{ print $2 }'`
sed -i -r "s/^STYLE = .*/STYLE = $STY/" $CONFIGFILE
echo "Please wait while images are prepared..."
echo ""
# copy all template files
#cp `dirname $TEMPLATE`/backgrounds/* ../backgrounds/ 2>/dev/null
cp `dirname $TEMPLATE`/config/* ../config/ 2>/dev/null
cp `dirname $TEMPLATE`/base/* ../base/ 2>/dev/null
#cp `dirname $TEMPLATE`/overlays/* ../overlays/ 2>/dev/null
DESTW=`echo $DESTSIZE | awk -F "x" '{ print $1 }'`
DESTH=`echo $DESTSIZE | awk -F "x" '{ print $2 }'`
# read template file
while read line; do
var=`echo $line | awk -F "#" '{ print $1 }'`
name=`echo $var | awk -F "=" '{ print $1 }'`
value=`echo $var | awk -F "=" '{ print $2 }'`
# treat special variables
if [ "$name" == "X0" ]; then
# we have to recalculate the final position set in the template
# as a percentual value. As the ratio changes, somewhere something
# gets cut off so the position in the template depending on 16:10
# doesn't fit any more.
# start with getting the output ratio set by the user
RATIOD=`echo "$DESTW / $DESTH" | bc -l`
# get the virtual size of the image if nothing would be cut off
DESTW1=`echo "$DESTW * 1.6 / $RATIOD" | bc -l`
# where the center would really be (in pixels) in the virtual size
DESTX1=`echo "$DESTW1 * (0$value) / 100" | bc -l`
# subtract the difference from the original position
DESTX=`echo "$DESTX1 - ($DESTW1 - $DESTW) / 2" | bc -l`
# and finally convert to an integer
DESTX=`round $DESTX 0`
if [ $DESTX -gt -1 ]; then
DESTX="+"$DESTX
fi
elif [ "$name" == "Y0" ]; then
DESTY=`echo "$DESTH/100*(0$value)" | bc -l`
DESTY=`round $DESTY 0`
if [ $DESTY -gt -1 ]; then
DESTY="+"$DESTY
fi
elif [ "$name" == "RADIUS" ]; then
rad=$value
elif [ "$name" == "CORONA" ]; then
cor=$value
elif [ "$name" == "BACKGROUND" -a "$2" != "--no-images" ]; then
cp "`dirname $TEMPLATE`/$value" "../$value" 2>/dev/null
if [ "$3" != "--no-images" ]; then
convert $USERDIR/$value \
-background transparent \
-resize $DESTSIZE^ \
-gravity center \
-extent $DESTSIZE \
$USERDIR/base/canvas.png
fi
TEMPLATEBG="$value"
elif [ "$name" == "OVERLAY" ]; then
if [ "$value" != "" ]; then
cp "`dirname $TEMPLATE`/$value" "../$value" 2>/dev/null
if [ "$3" != "--no-images" ]; then
convert $USERDIR/$value \
-background transparent \
-resize $DESTSIZE^ \
-gravity center \
-extent $DESTSIZE \
$USERDIR/cache/overlay.png
fi
sed -i -r "s/^OVERLAY = .*/OVERLAY = 1/" $CONFIGFILE
TEMPLATEOVER="cache/overlay.png"
else
sed -i -r "s/^OVERLAY = .*/OVERLAY = 0/" $CONFIGFILE
TEMPLATEOVER=""
fi
# treat any other variable
else
sed -i -r "s/^$name = .*/$name = $value/" $CONFIGFILE
fi
# set center
if [ "$DESTX" != "" -a "$DESTY" != "" ]; then
sed -i -r "s/^CENTER = .*/CENTER = $DESTX$DESTY/" $CONFIGFILE
DESTX=
DESTY=
fi
done < $TEMPLATE
# set radius and corona
if [ "$rad" != "" -a "$cor" == "" ]; then
cor=1.03
fi
if [ "$rad" != "" ]; then
sed -i -r "s/^RADIUS = .*/RADIUS = $rad/" $CONFIGFILE
fi
if [ "$cor" != "" ]; then
if [ "$cor" == "0" ]; then
cor="1.0"
fi
coro=`echo "if ($cor > 2) { $cor/$rad } else { $cor }" | bc -l`
sed -i -r "s/^CORONA = .*/CORONA = $coro/" $CONFIGFILE
fi
add=""
if [ "$3" == "--no-images" ]; then
add=" (without image conversion)"
fi
echo3 "Template "`echo $TEMPLATE | sed "s/.tpl//"`" was installed $add."
elif [ "$1" == "" -o "$2" == "" ]; then
echo "You must specify template and style, ex. --template default default"
else
echo "Template $1/$2 not available!"
fi
}
function update_template() {
if [ ! -f "templates/$1/config/xplanet-clouds-moon" ]; then
echo2 "Template $1 not available, no update possible."
else
echo2 "Updating template $1..."
rm "templates/$1/config/xplanet-clouds-moon.tmp" >/dev/null 2>&1
EARTH=0
MOON=0
MOONSHADE=0
DONE=0
while read line; do
if [ "$line" == "[earth]" ]; then
EARTH=1
MOON=0
elif [ "$line" == "[moon]" ]; then
EARTH=0
MOON=1
else
if [ $EARTH -eq 1 -a "$line" == "map=backgrounds/white.png" ]; then
line="map=base/black.png"
echo2 "Map for earth updated."
DONE=1
fi
if [ $EARTH -eq 1 -a "$line" == "color={255,255,255}" ]; then
line="color={0,0,0}"
echo2 "Color for earth updated."
DONE=1
fi
if [ $MOON -eq 1 -a "$line" == "map=base/black.png" ]; then
line="map=backgrounds/white.png"
echo2 "Map for moon updated."
DONE=1
fi
if [ $MOON -eq 1 -a "$line" == "color={0,0,0}" ]; then
line="color={255,255,255}"
echo2 "Color for moon updated."
DONE=1
fi
if [ $MOON -eq 1 -a "$line" == "orbit_color={0,0,0}" ]; then
line="orbit_color={255,255,255}"
echo2 "Moon's orbit color updated."
fi
if [ $MOON -eq 1 -a "$line" == "shade=100" ]; then
MOONSHADE=1
fi
fi
echo $line >> "templates/$1/config/xplanet-clouds-moon.tmp"
done < "templates/$1/config/xplanet-clouds-moon"
if [ $MOONSHADE -eq 0 ]; then
echo "shade=100" >> "templates/$1/config/xplanet-clouds-moon.tmp"
echo2 "Moon shade updated."
DONE=1
fi
mv -f "templates/$1/config/xplanet-clouds-moon.tmp" "templates/$1/config/xplanet-clouds-moon" >/dev/null 2>&1
if [ $DONE -eq 1 ]; then
echo2 "done."
else
echo2 "Nothing to do."
fi
fi
}
# DESKTOP ENVIRONMENT
# feh as a wallpaper switcher was mentioned by Alexander Batischev,
# thanks for pointing that out.
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DESKTOP="KDE";
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DESKTOP="GNOME";
elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DESKTOP="XFCE";
elif [ `ps aux | grep [f]luxbox 2>&1 > /dev/null; echo $?` -eq 0 ]; then DESKTOP="FLUXBOX";
elif [ `feh -h >/dev/null 2>&1; echo $?` -eq 0 ]; then DESKTOP="feh";
else DESKTOP="snafu";
fi
# BASIC INSTALLATION
if [ ! -d $USERDIR ]; then
cd $WORKDIR
mkdir $USERDIR
cp -R templates $USERDIR
cp -R base $USERDIR
cp -R backgrounds $USERDIR
cp -R config $USERDIR
cp -R cache $USERDIR
cp -R logs $USERDIR
cp -R output $USERDIR
cp -R overlays $USERDIR
cat $WORKDIR/xplanetFX.conf > $CONFIGFILE
fi
# create thumbcache if nonexistent
if [ ! -d $USERDIR/thumbcache ]; then
mkdir $USERDIR/thumbcache >/dev/null 2>&1
fi
# create temp if nonexistent
if [ ! -d $USERDIR/temp ]; then
mkdir $USERDIR/temp >/dev/null 2>&1
fi
# create preview if nonexistent v < 2.2.5
if [ ! -d $USERDIR/preview ]; then
mkdir $USERDIR/preview >/dev/null 2>&1
fi
# copy xplanet_stars.cfg v < 2.0.23
if [ ! -f $USERDIR"/config/xplanet_stars" ]; then
cp $WORKDIR"/config/xplanet_stars" $USERDIR"/config" >/dev/null 2>&1
fi
cd $USERDIR
# check lock file
if [ -f lock ]; then
pid=`cat lock`
if [ "`ps -p $pid -o comm=`" == "" ]; then
rm lock >/dev/null 2>&1
fi
fi
# CONFIG
for v in "`grep " = " "$CONFIGFILE" | awk -F " = " '{ printf "%s=%s\n",$1,$2 }'`"; do
eval "$v"
done
case $1 in
("--start")
# taken from xplanetconfig:
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
rm lock >/dev/null 2>&1
sleep 1
nice -n 19 $0 >/dev/null 2>&1 &
echo3 "xplanetFX was (re)started."
exit;;
("--stop")
# taken from xplanetconfig:
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
rm lock >/dev/null 2>&1
echo3 "xplanetFX was stopped."
exit;;
("--toggle")
if [ $DESKTOP == "GNOME" -o $DESKTOP == "XFCE" ]; then
zenity --question --title="Toggle xplanetFX" --text="[re-]start (yes) or stop (no) xplanetFX?"
elif [ $DESKTOP == "KDE" ] ; then
kdialog --yesno --title="Toggle xplanetFX" --text="[re-]start (yes) or stop (no) xplanetFX?"
fi
if [ $? == 0 ]; then
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
rm lock >/dev/null 2>&1
nice -n 19 $0 >/dev/null 2>&1 &
echo3 "xplanetFX was (re)started."
else
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
rm lock >/dev/null 2>&1
echo3 "xplanetFX was stopped."
fi
exit;;
("--single")
if [ "$2" == "" ] ; then
echo "You have to specify a filename to produce a single image."
exit
else
file=$2
if [ ${file:0:1} != "/" ]; then
file=$ACTDIR/$file
fi
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
rm lock >/dev/null 2>&1
sleep 1
nice -n 19 $0 --render-single "$file" >/dev/null 2>&1 &
echo3 "xplanetFX is creating single image @ $file"
exit 0
fi
;;
("--render-single")
if [ "$2" == "" ] ; then
echo "You have to specify a filename to produce a single image."
exit
else
file=$2
if [ ${file:0:1} != "/" ]; then
file=$ACTDIR/$file
fi
if [ ! -d `dirname "$file"` ]; then
echo3 "Couldn't find directory, exiting."
exit 1
else
FINAL="$file"
SINGLE=1
fi
fi
;;
("--log")
less logs/xplanetFX.log
exit;;
("--clearlog")
rm logs/*
exit;;
("--gui")
cd $WORKDIR
exec $WORKDIR/xplanetFX_gtk 2>&1 "$@"
exit;;
("--rclouds")
rm cache/clouds.jpg >/dev/null 2>&1
exit;;
("--install")
if [ "$2" == "" ] ; then
echo "You have to specify a file to install."
else
cd $ACTDIR
tar -C $USERDIR/templates -xzf "$2"
if [ $? -eq 0 ]; then
echo3 "Template $2 was installed."
else
echo3 "Installation of template $2 failed!!"
fi
fi
exit;;
("--autostart")
sleep $AUTOSTART
kill $(pidof -x -o %PPID $(basename $0)) 2>/dev/null
nice -n 19 $0 >/dev/null 2>&1 &
echo3 "xplanetFX was autostarted."
exit;;
("--geometry")
if [ "$2" == "" ] ; then
echo "You have to specify a geometry to set, ex. --geometry 1280x800"
elif [[ $2 =~ [0-9]+x[0-9]+ ]]; then
cd $USERDIR
for v in `cat $CONFIGFILE | grep " = " | awk -F " = " '{ printf "%s=%s\n",$1,$2 }'`; do
eval $v
done
for v in `cat templates/$TEMPLATE/$STYLE.tpl | awk -F '#' '{ print $1 }'`; do
eval $v
done
if [ "$BACKGROUND" != "" ]; then
convert $BACKGROUND -background transparent -resize $2^ -gravity center -extent $2 $USERDIR/base/canvas.png
fi
if [ "$OVERLAY" != "" ]; then
convert $OVERLAY -background transparent -resize $2^ -gravity center -extent $2 $USERDIR/cache/overlay.png
fi
DESTW=`echo $2 | awk -F "x" '{ print $1 }'`
DESTH=`echo $2 | awk -F "x" '{ print $2 }'`
# we have to recalculate the final position set in the template
# as a percentual value. As the ratio changes, somewhere something
# gets cut off so the position in the template depending on 16:10
# doesn't fit any more.
# start with getting the output ratio set by the user
RATIOD=`echo "$DESTW / $DESTH" | bc -l`
# get the virtual size of the image if nothing would be cut off
DESTW1=`echo "$DESTW * 1.6 / $RATIOD" | bc -l`
# where the center would really be (in pixels) in the virtual size
DESTX1=`echo "$DESTW1 * (0$X0) / 100" | bc -l`
# subtract the difference from the original position
DESTX=`echo "$DESTX1 - ($DESTW1 - $DESTW) / 2" | bc -l`
# and finally convert to an integer
DESTX=`round $DESTX 0`
if [ $DESTX -gt -1 ]; then
DESTX="+"$DESTX
fi
DESTY=`echo "$DESTH/100*(0$Y0)" | bc -l`
DESTY=`round $DESTY 0`
if [ $DESTY -gt -1 ]; then
DESTY="+"$DESTY
fi
if [ "$DESTX" != "" -a "$DESTY" != "" ]; then
sed -i "s/CENTER = $CENTER/CENTER = $DESTX$DESTY/" $CONFIGFILE
fi
sed -i "s/GEOMETRY = $GEOMETRY/GEOMETRY = $2/" $CONFIGFILE
echo3 "Geometry was set to $2"
else
echo "The format is --geometry [WIDTH]x[HEIGHT]"
fi
exit;;
("--template")
install_template "$2" "$3" $4
exit;;
("--random")
restart=0
if [ "`pidof -s -x -o %PPID xplanetFX`" != "" ]; then
restart=1
fi
while [ -f $USERDIR'/lock' ]; do sleep 2; done
dir=$USERDIR'/templates/'
file1=`/bin/ls -1 "$dir" | sort --random-sort | head -1`
path=`readlink --canonicalize "$dir/$file1"`
file2=`/bin/ls -1 "$path" | grep ".tpl" | sort --random-sort | head -1 `
echo "switching to $file1 `basename $file2 .tpl`..."
install_template "$file1" "`basename $file2 .tpl`"
if [ $restart -eq 1 ]; then
xplanetFX --start
fi
exit;;
("--update-templates")
for file in $(ls ./templates); do
update_template $file
done
update_template ".."
exit;;
("--setup")
echo ""
echo "Welcome to xplanetFX setup!"
echo ""
echo "This setup routine is able to install xplanet and imagemagic on your system, make some configurations and place a starter in your autostarted programs."
echo "The setup will ask for some values in this process. The actual values are shown in []. so hitting enter will choose this selection (in configuration no action will take place in that step)."
echo ""
# KILL RUNNING DAEMON
if [ `pidof -x -o %PPID xplanetFX` ]; then
echo -n "It seems there is an instance of xplanetFX running. Should it be killed? [y]: "
read KILL
echo ""
case "$KILL" in
"y" | "Y" | "j" | "J" | "" )
kill $(pidof -x -o %PPID xplanetFX) 2>/dev/null
;;
esac
fi
# INSTALL DEPENDENCIES
if [ -x /usr/bin/xplanet -a -x /usr/bin/convert ]; then
echo "Seems that xplanet and imagemagick are both installed. Nothing to do here."
else
echo "We'll begin with installing the software. Please enter your root password to gain access to your package manager if neccessary."
echo ""
inst=0
which apt-get >/dev/null
if [ $? -eq 0 ]; then
sudo apt-get install -y --force-yes xplanet imagemagick perlmagick &>/dev/null
inst=1
fi
if [ $inst -eq 0 ]; then
which rpm >/dev/null
if [ $? -eq 0 ]; then
su -c "rpm -i xplanet ImageMagick ImageMagick-perl &>/dev/null"
inst=1
fi
fi
if [ $inst -eq 0 ]; then
which yast >/dev/null
if [ $? -eq 0 ]; then
su -c "yast --install xplanet ImageMagick perl-PerlMagick &>/dev/null"
inst=1
fi
fi
if [ $inst -eq 0 ]; then
which yast2 >/dev/null
if [ $? -eq 0 ]; then
su -c "yast2 --install xplanet ImageMagick perl-PerlMagick &>/dev/null"
inst=1
fi
fi
if [ $inst -eq 0 ]; then
which yum >/dev/null
if [ $? -eq 0 ]; then
yum install xplanet ImageMagick ImageMagick-perl &>/dev/null
inst=1
fi
fi
if [ inst -eq 0 ]; then
echo "The installation of xplanet and imagemagick failed. Please install manually and run setup again."
exit 0
fi
fi
echo ""
# SCREENSIZE
ACTSCREEN=`cat $CONFIGFILE | grep --regexp="^GEOMETRY = " | awk -F " = " '{ print $2 }'`
XRANDR=`xrandr -q | grep "Screen 0:" | awk '{ print $8$9$10 }'`
DISP=${XRANDR%,*}
echo -n "Create images at this resolution (actually $ACTSCREEN) [$DISP]: "
read DESTSIZE
echo ""
if [ "$DESTSIZE" == "" ]; then
DESTSIZE=$DISP
fi
if [ "$ACTSCREEN" != "$DESTSIZE" ]; then
sed -i -r "s/^GEOMETRY = $ACTSCREEN/GEOMETRY = $DESTSIZE/" $CONFIGFILE
fi
echo ""
# TEMPLATE
echo "Please choose one of the following templates:"
echo ""
c=1
echo " [0] no template"
cd templates
for f in */*.tpl ; do
f2=`echo $f | sed "s/.tpl//"`
echo " [$c] template \"$f2\""
let c=$c+1
done
echo ""
echo -n "Which template should be used? If you want to see a preview please type a \"v\" in front of your choice (ex. v1) [0]: "
read SETUP
echo ""
while [ "${SETUP:0:1}" == "v" ]; do
c=1
for f in */*.png; do
if [ "$c" == "${SETUP:1}" ]; then
echo "pre-viewing template "`echo $f | sed "s/.tpl//"` &
display "$f"
fi
let c=$c+1
done
echo -n "Which template should be used? If you want to see a preview please type a \"v\" in front of your choice (ex. v1) [0]: "
read SETUP
echo ""
done
if [ "$SETUP" != "" -a "$SETUP" != "0" ]; then
c=1
TEMPLATE=
for f in */*.tpl; do
if [ "$c" == "$SETUP" ]; then
TEMPLATE=$f
fi
let c=$c+1
done
if [ $TEMPLATE != "" ]; then
TPL=`echo $TEMPLATE | sed "s/.tpl//" | awk -F '/' '{ print $1 }'`
STY=`echo $TEMPLATE | sed "s/.tpl//" | awk -F '/' '{ print $2 }'`
install_template "$TPL" "$STY"
fi
# EXIT?
echo -n "Do you want to go on with the configuration? (y/n) [n]: "
read EXIT
echo ""
case "$EXIT" in
"n" | "N" | "" )
# START NOW
echo -n "Do you want to start xplanetFX now? (y/n) [n]: "
read START
echo ""
case "$START" in
"y" | "Y" | "j" | "J" )
xplanetFX --start
;;
esac
exit 0
;;
esac
echo ""
fi
cd ..
# BACKGROUND
echo "Please choose one of the following background images:"
echo ""
c=0
cd backgrounds
for f in *.png; do
echo -n " [$c] $f "
if [ "backgrounds/$f" == "$TEMPLATEBG" ]; then
echo "(recommended by template)"
TBGID=$c
else
echo
fi
let c=$c+1
done
echo ""
echo -n "Which background should be used? (0-$c): "
if [ "$TBGID" != "" ]; then
echo -n " [$TBGID] "
fi
read BACKGR
echo ""
c=0
FILE=
for f in *.png; do
if [ "$c" == "$BACKGR" ]; then
FILE=$f
elif [ "$c" == "$TBGID" -a "$BACKGR" == "" ]; then
FILE=$f
fi
let c=$c+1
done
cd ..
if [ "$FILE" != "" ] ; then
convert $USERDIR/backgrounds/$FILE -resize $DESTSIZE^ -gravity center -extent $DESTSIZE $USERDIR/base/canvas.png
fi
echo ""
# POSITION
POS=`cat $CONFIGFILE | grep --regexp="^CENTER = " | awk -F " = " '{ print $2 }'`
echo -n "Center of the earth on the screen (ex. \"+800+600\") [$POS]: "
read CENTER
echo ""
if [ "$CENTER" != "" -a "$CENTER" != "$POS" ]; then
sed -i -r "s/^CENTER = .*/CENTER = $CENTER/" $CONFIGFILE
fi
echo ""
# REGION
echo "Next step is to determine the region to display. This is specified by longitude and latitude."
echo -n "Do you want to search for your values now? (This opens a browser window - y/n) [n]: "
read -n1 BROWSER
echo ""
case "$BROWSER" in
"y" | "Y" | "j" | "J" )
xdg-open $SEARCHMAPURL &>/dev/null
;;
esac
echo ""
# LONGITUDE
LONGITUDE=`cat $CONFIGFILE | grep --regexp="^LONGITUDE = " | awk -F " = " '{ print $2 }'`
echo -n "Display this longitude position (integer or enter \"random\") [$LONGITUDE]: "
read LONG
echo ""
if [ "$LONG" != "" -a "$LONGITUDE" != "$LONG" ]; then
sed -i -r "s/^LONGITUDE = .*/LONGITUDE = $LONG/" $CONFIGFILE
fi
echo ""
# LATITUDE
LATITUDE=`cat $CONFIGFILE | grep --regexp="^LATITUDE = " | awk -F " = " '{ print $2 }'`
echo -n "Display this latitude position (integer or enter \"random\") [$LATITUDE]: "
read LAT
echo ""
if [ "$LAT" != "" -a "$LATITUDE" != "$LAT" ]; then
sed -i -r "s/^LATITUDE = .*/LATITUDE = $LAT/" $CONFIGFILE
fi
echo ""
# SHOWORBIT
SHOWORBIT=`cat $CONFIGFILE | grep --regexp="^SHOWORBIT = " | awk -F " = " '{ print $2 }'`
echo -n "Should the view follow the sun? The day and night border will stay static while the earth turns. 0 = no, 1 = yes [$SHOWORBIT]: "
read SHO
echo ""
if [ "$SHO" != "" -a "$SHOWORBIT" != "$SHO" ]; then
cont="`cat $CONFIGFILE | grep SHOWORBIT`"
if [ -z "$cont" ]; then
echo "SHOWORBIT = $SHO" >> $CONFIGFILE
else
sed -i -r "s/^SHOWORBIT = .*/SHOWORBIT = $SHO/" $CONFIGFILE
fi
fi
echo ""
# ORBIT
ORBIT=`cat $CONFIGFILE | grep --regexp="^ORBIT = " | awk -F " = " '{ print $2 }'`
echo -n "Set the angle at which we follow the sun (-180 to 180) [$ORBIT]: "
read ORB
echo ""
if [ "$ORB" != "" -a "$ORBIT" != "$ORB" ]; then
cont="`cat $CONFIGFILE | grep ORBIT`"
if [ -z "$cont" ]; then
echo "ORBIT = $ORB" >> $CONFIGFILE
else
sed -i -r "s/^ORBIT = .*/ORBIT = $ORB/" $CONFIGFILE
fi
fi
echo ""
# SIZE
SIZE=`cat $CONFIGFILE | grep --regexp="^RADIUS = " | awk -F " = " '{ print $2 }'`
echo -n "Radiant of the earth in percent of the screen height [$SIZE]: "
read RAD
echo ""
if [ "$RAD" != "" -a "$RAD" != "$SIZE" ]; then
sed -i -r "s/^RADIUS = .*/RADIUS = $RAD/" $CONFIGFILE
fi
echo ""
# CORONA
CORONA=`cat $CONFIGFILE | grep --regexp="^CORONA = " | awk -F " = " '{ print $2 }'`
coro=`echo "if ($CORONA > 2) { $CORONA/$SIZE } else { $CORONA }" | bc -l`
echo -n "Size of the atmosphere FX, multiplier of the earth, 0 to disable, FLOAT between 1.00 and 1.10 (medium CPU usage) [$coro]: "
read COR
echo ""
if [ "$COR" != "" -a "$coro" != "$COR" -o "$coro" != "$CORONA" ]; then
sed -i -r "s/^CORONA = .*/CORONA = $COR/" $CONFIGFILE
fi
echo ""
# CORONABLUR
CORONABLUR=`cat $CONFIGFILE | grep --regexp="^CORONABLUR = " | awk -F " = " '{ print $2 }'`
echo -n "Blurring of the corona (0 - 50) [$CORONABLUR]: "
read CORB
echo ""
if [ "$CORB" != "" -a "$CORB" != "$CORONABLUR" ]; then
cont="`cat $CONFIGFILE | grep CORONABLUR`"
if [ -z "$cont" ]; then
echo "CORONABLUR = $CORB" >> $CONFIGFILE
else
sed -i -r "s/^CORONABLUR = .*/CORONABLUR = $CORB/" $CONFIGFILE
fi
fi
echo ""
# STARS
STARS=`cat $CONFIGFILE | grep --regexp="^STARS = " | awk -F " = " '{ print $2 }'`
echo -n "Draw a star field on the background image? 0 = no, 1 - 20 FOV (CPU usage depends on POST setting) [$STARS]: "
read STA
echo ""
if [ "$STA" != "" -a "$STA" != "$STARS" ]; then
cont="`cat $CONFIGFILE | grep STARS`"
if [ -z "$cont" ]; then
echo "STARS = $STA" >> $CONFIGFILE
else
sed -i.backup -r "s/^STARS = .*/STARS = $STA/" $CONFIGFILE
fi
fi
echo ""
# BUMPCLOUDS
BUMPCLOUDS=`cat $CONFIGFILE | grep --regexp="^BUMPCLOUDS = " | awk -F " = " '{ print $2 }'`
echo -n "Draw high quality clouds? 0 = no, 1 = yes (high CPU usage) [$BUMPCLOUDS]: "
read CLOUDS
echo ""
if [ "$CLOUDS" != "" -a "$CLOUDS" != "$BUMPCLOUDS" ]; then
sed -i -r "s/^BUMPCLOUDS = .*/BUMPCLOUDS = $CLOUDS/" $CONFIGFILE
fi
echo ""
## CLOUDFACTOR
#CLOUDFACTOR=`cat xplanetFX | grep --regexp="^CLOUDFACTOR=" | awk '{ print $1 }' | awk -F "=" '{ print $2 }'`
#echo -n "Resize the clouds by factor n (affects only HQ clouds) [$CLOUDFACTOR]: "
#read CLOUDF
#echo ""
#if [ "$CLOUDF" != "" -a "$CLOUDF" != "$CLOUDFACTOR" ]; then
# sed -i.backup -r "s/^CLOUDFACTOR=/CLOUDFACTOR=$CLOUDF # /" xplanetFX
# rm xplanetFX.backup
#fi
#echo ""
# SPECULAR
SPECULAR=`cat $CONFIGFILE | grep --regexp="^SPECULAR = " | awk -F " = " '{ print $2 }'`
echo -n "Draw high quality specular FX? 0 = no, 1 = yes (high CPU usage) [$SPECULAR]: "
read SPEC
echo ""
if [ "$SPEC" != "" -a "$SPEC" != "$SPECULAR" ]; then
sed -i.backup -r "s/^SPECULAR = .*/SPECULAR = $SPEC/" $CONFIGFILE
fi
echo ""
# MOON ORBIT
ORBIT=`cat config/xplanet-final | grep --regexp="^orbit_color=" | awk '{ print $1 }' | awk -F "=" '{ print $2 }'`
echo -n "Color of the moon's orbit - {R,G,B} 0-255 [$ORBIT]: "
read ORB
echo ""
if [ "$ORB" != "" -a "$ORB" != "$ORBIT" ]; then
sed -i -r "s/^orbit_color=/orbit_color=$ORB # /" cache/xplanet-final
rm cache/xplanet-final.backup
fi
echo ""
# POST
POST=`cat $CONFIGFILE | grep --regexp="^POST = " | awk -F " = " '{ print $2 }'`
echo -n "Render post production FX? 0 = no, 1 = yes (medium CPU usage) [$POST]: "
read POS
echo ""
if [ "$POS" != "" -a "$POS" != "$POST" ]; then
sed -i -r "s/^POST = .*/POST = $POS # /" $CONFIGFILE
fi
echo ""
# OVERLAY
OVERLAY=`cat $CONFIGFILE | grep --regexp="^OVERLAY = " | awk -F "=" '{ print $2 }'`
echo "Please choose one of the following overlay images:"
echo ""
c=1
cd overlays
echo " [0] none"
for f in *.png; do
echo " [$c] $f"
let c=$c+1
done
if [ "$OVERLAY" == "0" ]; then
ACTOVER=0
fi
if [ "$TEMPLATEOVER" != "" ]; then
ACTOVER=$c
echo " [$c] keep existing one from template ($TEMPLATEOVER)"
fi
echo ""
echo -n "Which overlay should be used? (low CPU usage) [$ACTOVER]: "
read OVER
echo ""
if [ "$OVER" != "" -a "$OVER" != "$ACTOVER" ]; then
if [ "$OVER" == "0" ]; then
sed -i -r "s/^OVERLAY = .*/OVERLAY = 0/" $CONFIGFILE
elif [ "$OVER" != "$c" ]; then
c=1
FILE=
for f in *.png; do
if [ "$c" == "$OVER" ]; then
FILE=$f
fi
let c=$c+1
done
convert $USERDIR/overlays/$FILE -background transparent -resize $DESTSIZE^ -gravity center -extent $DESTSIZE $USERDIR/cache/overlay.png
sed -i -r "s/^OVERLAY = .*/OVERLAY = 1/" $CONFIGFILE
fi
fi
cd ..
echo ""
# LOG FILES
LOG=`cat $CONFIGFILE | grep --regexp="^LOGGING = " | awk -F " = " '{ print $2 }'`
echo -n "Create logfiles? (0 = no, 1 = yes) [$LOG]: "
read LOGGING
echo ""
if [ "$LOGGING" != "" -a "$LOG" != "$LOGGING" ]; then
sed -i -r "s/^LOGGIN = .*/LOGGING = $LOGGING/" $CONFIGFILE
fi
echo ""
# CYCLE DELAY
CYCLE=`cat $CONFIGFILE | grep --regexp="^DELAY = " | awk -F " = " '{ print $2 }'`
echo -n "Reproduce every n seconds [$CYCLE]: "
read CYC
echo ""
if [ "$CYC" != "" -a "$CYC" != "$CYCLE" ]; then
sed -i -r "s/^DELAY = .*/DELAY = $CYC/" $CONFIGFILE
fi
echo ""
# DELAY
DELAY=`cat $CONFIGFILE | grep --regexp="^AUTOSTART = " | awk -F " = " '{ print $2 }'`
echo -n "Delay startup on autostart for n seconds [$DELAY]: "
read DEL
echo ""
if [ "$DEL" != "" -a "$DEL" != "$DELAY" ]; then
sed -i -r "s/^AUTOSTART = .*/AUTOSTART = $DEL/" $CONFIGFILE
fi
echo ""
# STARTER
echo -n "Do you want to create an autostart entry? Enter \"g\" for GNOME, \"k\" for KDE, \"x\" for XFCE >= 4.4, \"X\" for XFCE < 4.4, \"f\" for Fluxbox or leave blank for no autostart entry: "
read AUTO
echo ""
if [ "$AUTO" != "" ]; then
if [ "$AUTO" == "k" ]; then
ln -s /usr/bin/xplanetFX $HOME/.kde/Autostart/xplanetFX
elif [ "$AUTO" == "x" ]; then
ln -s /usr/bin/xplanetFX $HOME/.config/autostart/xplanetFX
elif [ "$AUTO" == "X" ]; then
ln -s /usr/bin/xplanetFX $HOME/Desktop/Autostart/xplanetFX
elif [ "$AUTO" == "g" ]; then
echo "[Desktop Entry]
Type=Application
Exec=xplanetFX --autostart
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=xplanetFX
Comment=Create photorealistic backgrounds of earth views" > $HOME/.config/autostart/xplanetFX.desktop
elif [ "$AUTO" == "f" ]; then
if [ "`grep -r 'xplanetFX --autostart &' $HOME/.fluxbox/startup`" == "" ]; then
echo "xplanetFX --autostart &" >> $HOME/.fluxbox/startup
fi
else
echo "WTF?! Knowing how to read is a great advantage."
fi
fi
echo ""
# OUTPUT
OUTPUT=`cat $CONFIGFILE | grep --regexp="^OUTPUT = " | awk -F " = " '{ print $2 }'`
echo "Choose a file to render to if your desktop environment couldn't be determined. Leave blank to let xplanetFX look for GNOME, KDE, XFCE or feh."
if [ -z $DESKTOP ]; then
echo -n "The desktop environment wasn't found. Enter a file [\"$OUTPUT\"]: "
else
echo -n "The determined desktop environment is: \"$DESKTOP\". [\"$OUTPUT\"]: "
fi
read OUT
echo ""
if [ "$OUT" != "" -a "$OUT" != "$OUTPUT" ]; then
cont="`cat $CONFIGFILE | grep OUTPUT`"
if [ -z "$cont" ]; then
echo "OUTPUT = $OUT" >> $CONFIGFILE
else
sed -i -r "s/^OUTPUT = .*/OUTPUT = $OUT/" $CONFIGFILE
fi
fi
echo ""
# SCRIPT
PRESCRIPT=`cat $CONFIGFILE | grep --regexp="^SCRIPT = " | awk -F " = " '{ print $2 }'`
echo -n "Script to execute before xplanetFX has rendered the image [$PRESCRIPT]: "
read PRS
echo ""
if [ "$PRS" != "" -a "$PRS" != "$PRESCRIPT" ]; then
cont="`cat $CONFIGFILE | grep PRESCRIPT`"
if [ -z "$cont" ]; then
echo "PRESCRIPT = $PRS" >> $CONFIGFILE
else
sed -i -r "s/^PRESCRIPT = .*/PRESCRIPT = $PRS/" $CONFIGFILE
fi
fi
echo ""
# SCRIPT
SCRIPT=`cat $CONFIGFILE | grep --regexp="^SCRIPT = " | awk -F " = " '{ print $2 }'`
echo -n "Script to execute after xplanetFX has rendered the image [$SCRIPT]: "
read SCR
echo ""
if [ "$SCR" != "" -a "$SCR" != "$SCRIPT" ]; then
cont="`cat $CONFIGFILE | grep SCRIPT`"
if [ -z "$cont" ]; then
echo "SCRIPT = $SCR" >> $CONFIGFILE
else
sed -i -r "s/^SCRIPT = .*/SCRIPT = $SCR/" $CONFIGFILE
fi
fi
echo ""
# START NOW
echo -n "Do you want to start xplanetFX now? [n]: "
read START
echo ""
case "$START" in
"y" | "Y" | "j" | "J" )
xplanetFX --start &
;;
esac
echo ""
echo "xplanetFX is now set up. You can close this terminal if you like."
echo "Call xplanetFX --help for rudimentary information about usage."
echo "Read the README for detailed instructions and further information."
exit;;
("")
;;
("--help"|*)
echo "xplanetFX - HQ renderings of mother earth for your desktop"
echo "Call: $0 [OPTION]"
echo " --help show this help."
echo " --setup configure xplanetFX step by step if you don't use the GUI"
echo " --start start in the background. A running script will be stopped."
echo " --stop stop a running instance."
echo " --toggle display a window asking for starting/stopping xplanetFX"
echo " --autostart start xplanetFX with the autostart delay"
echo " --single [file] create one single image and exit"
echo " --template [template] [style] activate an installed template"
echo " --random select a random template and restart a running xplanetFX"
echo " --log show the latest log file."
echo " --clearlog remove all log files"
echo " --gui open a GTK userinterface"
echo " --rclouds remove a corrupt clouds image"
echo " --install [file] install a template file (use absolute path)"
echo " --geometry [WIDTHxHEIGHT] set xplanetFX to specified size"
echo " --update-templates convert all templates for version >= 1.1"
echo "Without any option xplanetFX will run in this terminal."
echo ""
exit;;
esac
# clear log
if [ $LOGGING -eq 0 ]; then
rm logs/xplanetFX.log >/dev/null 2>&1
fi
while true;
do
XPLANETFLAGS="$LABEL"
# CONFIG
deb="config"
for v in "`grep " = " "$CONFIGFILE" | awk -F " = " '{ printf "%s=%s\n",$1,$2 }'`"; do
eval "$v"
deb="$deb | $v"
done
debug "$deb"
# update oldest background image
if [ $SINGLE -eq 0 ]; then
if [ ! -z "$OUTPUT" ]; then
FINAL="$OUTPUT"
elif [ "$OUTPUT1" -ot "$OUTPUT2" ]; then
FINAL="$OUTPUT1"
else
FINAL="$OUTPUT2"
fi
debug "output | file: $FINAL"
fi
# rotate the view
if [ $SHOWORBIT -eq 1 ]; then
if [ "$LONGITUDE" == "random" ]; then LONGITUDE=0; fi
# add suns position to longitude
hour=`date +%k`
min=`date +%M`
add=`echo "(($hour + $min / 60) / 12 - 1) * 180" | bc -l`
LONGITUDE=`echo "($LONGITUDE) - ($add)" | bc -l | sed -r "s/^\./0./" | sed -r "s/^\-\./-0./" | awk -F "." '{ print $1 }'`
LONGITUDE=`echo "($LONGITUDE) + ($ORBIT) * -1" | bc -l | sed -r "s/^\./0./" | sed -r "s/^\-\./-0./" | awk -F "." '{ print $1 }'`
debug "rotating view | hour: $hour | min: $min | add: $add | lon: $LONGITUDE | lat: $LATITUDE"
else
if [ "$LONGITUDE" == "random" ]; then
LONGITUDE=`random 360`
fi
fi
XPLANETFLAGS="$XPLANETFLAGS -longitude $LONGITUDE"
if [ "$LATITUDE" == "random" ]; then
#LATITUDE=`python -c "import math,random; print int(math.asin(random.random()*2-1)*180/3.141592654)"`
# SteveH mentioned this one for easier maintainace and installation on Arch - thanks!
LATITUDE=`perl -e 'use Math::Trig; print int(asin(rand()*2-1)*180/pi())'`
debug "random lat | lat: $LATITUDE"
fi
XPLANETFLAGS="$XPLANETFLAGS -latitude $LATITUDE"
# build commant options
#if [ ! -z $ORIGIN ]; then XPLANETFLAGS="$XPLANETFLAGS -origin $ORIGIN"; fi
#if [ ! -z $TARGET ]; then XPLANETFLAGS="$XPLANETFLAGS -target $TARGET"; fi
#if [ ! -z $RANGE ]; then XPLANETFLAGS="$XPLANETFLAGS -range $RANGE"; fi
if [ "$SHOWDATE" == "1" ]; then
DATE=`echo "$DATE+((0$GMT)*(0-1)*60*60)" | bc`
XPLANETFLAGS="$XPLANETFLAGS -date "`date --utc --date "1970-01-01 $DATE sec" "+%Y%m%d.%H%M00"`
debug "showdate | date: $DATE | gmt: $GMT"
fi
XPLANETFLAGSCORONA="$XPLANETFLAGS $XPLANETDEF"
if [ ! -z $GEOMETRY ]; then XPLANETFLAGS="$XPLANETFLAGS -geometry $GEOMETRY"; fi
XPLANETFLAGSCLOUDS="$XPLANETFLAGS $XPLANETDEF"
if [ ! -z $CENTER ]; then XPLANETFLAGS="$XPLANETFLAGS -center $CENTER"; fi
#if [ ! -z $CENTER ]; then XPLANETFLAGSCORONA="$XPLANETFLAGSCORONA -center $CENTER"; fi
if [ ! -z $RADIUS ]; then XPLANETFLAGS="$XPLANETFLAGS -radius $RADIUS"; fi
if [ ! -z $RADIUS ]; then XPLANETFLAGSCLOUDS="$XPLANETFLAGSCLOUDS -radius $RADIUS"; fi
XPLANETFLAGS="$XPLANETFLAGS $XPLANETDEF"
debug "xplanetflags | $XPLANETFLAGS"
debug "xplanetflagscorona | $XPLANETFLAGSCORONA"
debug "xplanetflagsclouds | $XPLANETFLAGSCLOUDS"
# tell everyone we're online
echo $$ > lock
echo "" | tee -a logs/xplanetFX.log
# SCRIPT TO CALL?
if [ -n "$PRESCRIPT" ] && [ $SINGLE -eq 0 ]; then
echo2 "Executing: $PRESCRIPT ..."
$PRESCRIPT
echo2 "done."
fi
VER="`cat $WORKDIR/version 2>/dev/null`"
if [ $SINGLE -eq 1 ]; then
echo2 "###### xplanetFX $VER starting single render ######"
else
echo2 "###### xplanetFX $VER starting render cycle ######"
fi
# HAVE A LOOK @ THE LOGS
rm logs/*.gz >/dev/null 2>&1
cat logs/xplanetFX.log | tail -n 1000 > logs/xplanetFX.log.bak
mv logs/xplanetFX.log.bak logs/xplanetFX.log
# moved config reading from here
# spit out some information
echo2 "final image @ "$FINAL
echo2 "location @ lon $LONGITUDE / lat $LATITUDE"
if [ "$SHOWDATE" == "1" ]; then
echo2 "time @ `date --utc --date "1970-01-01 $DATE sec" "+%Y/%m/%d.%H:%M:00"`"
fi
echo2 "screen size @ $GEOMETRY | center @ $CENTER | radius @ $RADIUS"
echo2 "special f/x @ clouds: $BUMPCLOUDS | specular: $SPECULAR | post: $POST"
# CREATE SINGLE IMAGE?
if [ $SINGLE -eq 1 ]; then
echo2 "creating a single image and exit."
fi
# calculate some position fixes - thx @ Chrischi
X0S=`echo $CENTER | sed -E 's/([+-])([0-9]+)([+-])([0-9]+)/\1/'`
Y0S=`echo $CENTER | sed -E 's/([+-])([0-9]+)([+-])([0-9]+)/\3/'`
X0=`echo $CENTER | sed -E 's/([+-])([0-9]+)([+-])([0-9]+)/\2/'`
Y0=`echo $CENTER | sed -E 's/([+-])([0-9]+)([+-])([0-9]+)/\4/'`
debug "positions 1 | x0: $X0S$X0 | y0: $Y0S$Y0"
if [ $X0S == "-" ]; then
CROPX="+0"
CENTERX=`echo "($X0-($X0*$CLOUDFACTOR-$X0))" | bc -l`
CENTERX="-"`round $CENTERX 0`
else
CROPX=`echo "($X0*$CLOUDFACTOR-$X0)" | bc -l`
CROPX="+"`round $CROPX 0`
CENTERX="+"$X0
fi
if [ $Y0S == "-" ]; then
CROPY="+0"
CENTERY=`echo "($Y0-($Y0*$CLOUDFACTOR-$Y0))" | bc -l`
CENTERY="-"`round $CENTERY 0`
else
CROPY=`echo "($Y0*$CLOUDFACTOR-$Y0)" | bc -l`
CROPY="+"`round $CROPY 0`
CENTERY="+"$Y0
fi
debug "positions 2 | centerx: $CENTERX | centery: $CENTERY | cropx: $CROPX | cropy: $CROPY"
# WIDTH & HEIGHT
WIDTH=`echo $GEOMETRY | awk -F "x" '{ print $1 }'`
HEIGHT=`echo $GEOMETRY | awk -F "x" '{ print $2 }'`
debug "geometry | width: $WIDTH | height: $HEIGHT | geometry: $GEOMETRY"
# BLURFACTOR
BLURFACTOR=`echo "($HEIGHT/1200)*($RADIUS/33)" | bc -l`
debug "blurfactor: $BLURFACTOR"
# fetch clouds image
echo2 "inspecting cloud map..."
cd cache
perl $WORKDIR/clouds/download_clouds.pl | echo4
DLOK=${PIPESTATUS[0]}
if [ $DLOK -eq 2 ]; then
# clouds are corrupt, use a default image
echo2 "using default clouds image..."
cp ../base/clouds.jpg clouds.jpg &>/dev/null 2>&1
# and set its time far in the past
touch -d "2000-01-01 00:00" clouds.jpg &>/dev/null 2>&1
fi
cd ..
echo2 "done."
# STARMAP
if [ $STARS -gt 0 ]; then
if [ $POST -eq 1 ]; then
echo2 "Rendering hi-quality stars on background..."
# render stars
xplanet -config $WORKDIR/config/xplanet-stars \
-output cache/stars.png \
$XPLANETFLAGS \
-radius 1 \
-range `echo "($STARS+1)^2" | bc` \
-starmap starmap \
-searchdir $WORKDIR &>/dev/null
# blur 1
blur=`echo "$BLURFACTOR*2" | bc -l`
debug "starblur 1: $blur"
convert $USERDIR/cache/stars.png \
\( +clone -blur 0x$blur -level 0%,70% \) \
-compose screen \
-composite \
$USERDIR/cache/stars.png
# blur 2
blur=`echo "$BLURFACTOR*5" | bc -l`
debug "starblur 2: $blur"
convert $USERDIR/cache/stars.png \
\( +clone -blur 0x$blur -level 0%,70% \) \
-compose screen \
-composite \
$USERDIR/cache/stars.png &>/dev/null
# compose with baseimage
convert $BASEIMAGE $USERDIR/cache/stars.png \
-compose screen \
-composite \
$BACKGROUND
else
# render stars on background
echo2 "Rendering simple stars on background..."
xplanet -config $WORKDIR/config/xplanet-stars \
-background $BASEIMAGE \
-output $BACKGROUND \
$XPLANETFLAGS \
-radius 1 \
-range `echo "($STARS+1)^2" | bc` \
-starmap starmap \
-searchdir $WORKDIR &>/dev/null
fi
echo2 "done."
else
cp $BASEIMAGE $BACKGROUND
fi
# CORONA
if [ "$CORONA" != "1.0" -a "$CORONA" != "0" ]; then
echo2 "creating corona on background..."
_CORONA=`echo "if ($CORONA > 2) { $CORONA/$RADIUS } else { $CORONA }" | bc -l`
_CORONABLUR=`echo "$BLURFACTOR*$CORONABLUR * $_CORONA" | bc -l`
_CORONASIZE=`echo "$HEIGHT.0 * ($RADIUS.0 / 100.0) * 2.0 * $_CORONA" | bc -l`
_CORONASIZE=`round $_CORONASIZE 0`
_CORONARADIANT=`echo "$_CORONASIZE/2" | bc`
_CORONAADD=`echo "$_CORONABLUR*2" | bc -l | xargs printf "%1.0f"`
_CORONAREP=`echo "$_CORONAADD+$_CORONAADD+$_CORONASIZE" | bc`
_CORONAPOSX=`echo "0$X0S$X0-$_CORONAREP/2" | bc -l | xargs printf "%1.0f"`
_CORONAPOSY=`echo "0$Y0S$Y0-$_CORONAREP/2" | bc -l | xargs printf "%1.0f"`
if [ $_CORONAPOSX -gt 0 ]; then
_CORONAPOSX="+$_CORONAPOSX"
fi
if [ $_CORONAPOSY -gt 0 ]; then
_CORONAPOSY="+$_CORONAPOSY"
fi
debug "corona: $_CORONA | coronablur: $_CORONABLUR | coronasize: $_CORONASIZE | coronaradiant: $_CORONARADIANT"
debug "coronaadd: $_CORONAADD | coronarep: $_CORONAREP | coronaposx: $_CORONAPOSX | coronaposy: $_CORONAPOSY"
# create corona
xplanet -config config/xplanet-corona \
-output cache/corona.png \
$XPLANETFLAGSCORONA \
-radius 50 \
-center +$_CORONARADIANT+$_CORONARADIANT \
-geometry $_CORONASIZE"x"$_CORONASIZE &>/dev/null
# blur corona and composit background and corona in one step
convert $BACKGROUND \
\( $USERDIR/cache/corona.png \
-level 0%,90% \
-background black \
-gravity center \
-extent $_CORONAREP"x"$_CORONAREP \
+repage \
-blur 0x$_CORONABLUR \) \
-gravity NorthWest \
-geometry $_CORONAPOSX$_CORONAPOSY \
-compose screen \
-composite \
$BACKGROUND
echo2 "done."
fi
# NORMAL CLOUDS
if [ $BUMPCLOUDS -eq 0 ]; then
sed -i.backup -r "s/^#cloud_map=cache\/clouds.png/cloud_map=cache\/clouds.png/" $CONFIG
sed -i.backup -r "s/^#cloud_gamma=1.2/cloud_gamma=1.2/" $CONFIG
sed -i.backup -r "s/^#cloud_ssec=false/cloud_ssec=false/" $CONFIG
sed -i.backup -r "s/^#cloud_threshold=70/cloud_threshold=70/" $CONFIG
rm $CONFIG.backup
echo2 "preparing clouds map..."
# clouds resize
convert $USERDIR/cache/clouds.jpg \
-resize $MAPSIZE \
$USERDIR/cache/clouds.png
echo2 "done."
else
sed -i.backup -r "s/^cloud_map=cache\/clouds.png/#cloud_map=cache\/clouds.png/" $CONFIG
sed -i.backup -r "s/^cloud_gamma=1.2/#cloud_gamma=1.2/" $CONFIG
sed -i.backup -r "s/^cloud_ssec=false/#cloud_ssec=false/" $CONFIG
sed -i.backup -r "s/^cloud_threshold=70/#cloud_threshold=70/" $CONFIG
rm $CONFIG.backup
fi
# FINAL XPLANET IMAGE
echo2 "rendering image via xplanet..."
if [ "$BACKGROUND" ]; then
xplanet -output $INTERIM \
-config config/xplanet-final \
$XPLANETFLAGS \
-background $BACKGROUND &>/dev/null
else
xplanet -output $INTERIM \
-config config/xplanet-final \
$XPLANETFLAGS &>/dev/null
fi
echo2 "done."
# BUMPCLOUDS
if [ $BUMPCLOUDS -eq 1 ]; then
echo2 "creating different renderings with clouds..."
# clouds resize and greyscale
convert $USERDIR/cache/clouds.jpg \
-level 10%,100% \
-resize $MAPSIZE \
$USERDIR/cache/clouds.png
# render cloud overlay
xplanet -config config/xplanet-clouds \
-output cache/clouds_render.png \
$XPLANETFLAGSCLOUDS \
-center $CENTERX$CENTERY &>/dev/null
# create final clouds
# Chrischi has helped figuring out how to crop at the correct position
scale=`echo $CLOUDFACTOR*100 | bc -l`
debug "cloudscale: $scale"
# possible filters:
#Bartlett
#Bessel (?)
#Blackman
#Bohman
#Box
#Catrom
#Cubic
#Gaussian
#Hamming (x)
#Hanning
#Hermite
#Kaiser
#Lagrange
#Lanczos
#Mitchell (?)
#Parzen
#Point
#Quadratic
#Sinc
#Triangle
#Welsh (x)
convert $USERDIR/cache/clouds_render.png \
-filter Welsh \
-resize $scale% \
-sharpen 0x0.5 \
-crop $GEOMETRY$CROPX$CROPY \
+repage \
-auto-level \
$USERDIR/cache/clouds_overlay.png
# cut moon from clouds
xplanet -config config/xplanet-clouds-moon \
-output cache/clouds_moon_mask.png \
$XPLANETFLAGSCLOUDS \
-center $CENTERX$CENTERY \
-background backgrounds/black.png &>/dev/null
convert \( $USERDIR/cache/clouds_moon_mask.png \
-level 40%,0%,1.5 \) \
$USERDIR/cache/clouds_moon_mask.png
convert $USERDIR/cache/clouds_overlay.png \
$USERDIR/cache/clouds_moon_mask.png \
-compose Multiply \
-composite \
$USERDIR/cache/clouds_overlay.png
# create shadows and cut moon from shadows
blur=`echo "$BLURFACTOR * 2.5 * (1 + ($CLOUDFACTOR - 1) * 20)" | bc -l`
debug "shadowblur: $blur"
convert \( $USERDIR/cache/clouds_render.png -level 80%,25% -blur 0x$blur \) \
\( $USERDIR/cache/clouds_moon_mask.png -negate \) \
-compose Screen \
-composite \
$USERDIR/cache/clouds_shadows.png
echo2 "done."
echo2 "compositing clouds with final image..."
# compose shadows with earth
convert $INTERIM \
$USERDIR/cache/clouds_shadows.png \
-compose Multiply \
-composite \
$INTERIM
# composit clouds with earth
convert $INTERIM \
$USERDIR/cache/clouds_overlay.png \
-compose Screen \
-composite \
$INTERIM
echo2 "done."
fi
# ATMOSPHERE
if [ $ATMOSPHERE -eq 1 ]; then
echo2 "creating atmosphere..."
_ATMOBLUR=`echo "$BLURFACTOR*40" | bc -l`
_ATMOSIZE=`echo "$HEIGHT.0 * ($RADIUS.0 / 100.0) * 2.0" | bc -l | xargs printf "%1.0f"`
_ATMOMASK=`echo "$HEIGHT.0 * ($RADIUS.0 / 100.0) * 0.95" | bc -l | xargs printf "%1.0f"`
_ATMORADIANT=`echo "$_ATMOSIZE/2" | bc`
_ATMOPOSX=`echo "0$X0S$X0-$_ATMOSIZE/2" | bc -l | xargs printf "%1.0f"`
_ATMOPOSY=`echo "0$Y0S$Y0-$_ATMOSIZE/2" | bc -l | xargs printf "%1.0f"`
if [ $_ATMOPOSX -gt 0 ]; then
_ATMOPOSX="+$_ATMOPOSX"
fi
if [ $_ATMOPOSY -gt 0 ]; then
_ATMOPOSY="+$_ATMOPOSY"
fi
debug "atmosphere | atmoblur: $_ATMOBLUR | atmosize: $_ATMOSIZE | atmoradiant: $_ATMORADIANT"
debug "atmoposx: $_ATMOPOSX | atmoposy: $_ATMOPOSY | atmomask: $_ATMOMASK"
xplanet -config config/xplanet-corona \
-transpng cache/atmosphere.png \
$XPLANETFLAGSCORONA \
-radius 50 \
-center +$_ATMORADIANT+$_ATMORADIANT \
-geometry $_ATMOSIZE"x"$_ATMOSIZE &>/dev/null
convert $INTERIM \
+matte \
\( $USERDIR/cache/atmosphere.png \
+matte \
\( +clone \
-level 0%,80% \
-fill rgb\(30,220,255\) \
-tint 80 \
-fill black \
-draw "ellipse $_ATMORADIANT,$_ATMORADIANT $_ATMOMASK,$_ATMOMASK 0,360" \
-channel RGBA \
-blur 0x$_ATMOBLUR \
-alpha off \
\) \
\( -clone 0 \
-alpha extract \
\) \
-delete 0 \
-compose Copy_Opacity \
-composite \
\) \
-gravity NorthWest \
-geometry $_ATMOPOSX$_ATMOPOSY \
-compose screen \
-composite \
$INTERIM
echo2 "done."
fi
# SPECULAR
if [ $SPECULAR -eq 1 ]; then
echo2 "creating specular image..."
# composit specular and clouds for spec fx
convert $USERDIR/base/earth_spec.jpg \
cache/clouds.png \
-compose Screen \
-composite \
-level -50%,100%,1.5 \
$USERDIR/cache/earth_spec2.png
# create specular b/w
xplanet -config config/xplanet-specular \
-output cache/specular_overlay.png \
$XPLANETFLAGS &>/dev/null
# curve and blur specular map blur
blur1=`echo "$BLURFACTOR*2.5" | bc -l`
blur2=`echo "$BLURFACTOR*5" | bc -l`
debug "specblur 1: $blur1"
debug "specblur 2: $blur2"
convert $INTERIM \
\( $USERDIR/cache/specular_overlay.png -level 5%,33% -blur 0x$blur2 \) \
-compose Color_Dodge \
-composite \
$INTERIM
echo2 "done."
fi
# OVERLAY
if [ "$OVERLAY" = "1" -a -f cache/overlay.png ]; then
echo2 "rendering overlay image..."
# composit background and overlay
convert $INTERIM \
$USERDIR/cache/overlay.png \
-composite \
$INTERIM
echo2 "done."
fi
# POST PRODUCTION
if [ $POST -eq 1 ]; then
echo2 "rendering post production..."
# clone a contrast map, rework and recompose
blur=`echo "$BLURFACTOR * 20" | bc -l`
debug "postblur: $blur"
convert $INTERIM \
\( +clone -blur 0x$blur -level 0%,90%,1.5 \) \
-compose Soft_Light \
-composite \
$INTERIM
echo2 "done."
fi
# MOVE INTERIM TO FINAL LOCATION
cp -f $INTERIM $FINAL >/dev/null 2>&1
# UPDATE BACKGROUND
if [ $SINGLE -eq 0 ] && [ -z $OUTPUT ]; then
echo2 "updating background for $DESKTOP environment..."
# We have a GNOME desktop - use gconf
if [ $DESKTOP = "GNOME" ]; then
gsettings set org.gnome.desktop.background picture-uri "$FINAL"
# $gconf -t str -s /desktop/gnome/background/picture_filename "$FINAL" hacked!!!!
fi
# The older KDE's can be switched by dcop, newer ones > 4.3 doesn't work this way.
# No soultion by now, try to use the OUTPUT config setting and invoke
# a script afterwards.
if [ $DESKTOP = "KDE" ]; then
dcop kdesktop KBackgroundIface setWallpaper "$FINAL" 5
fi
# XFCE desktops have to restart the mcs-manager with some changes
# in a XML file
if [ $DESKTOP = "XFCE" ]; then
killall xfce-mcs-manager
wait
CHANGE="$(cat $HOME/.config/xfce4/mcs_settings/desktop.xml | grep path_0_0 | cut -d\" -f 6 | sed 's/\//\\\//g')"
WITH=$FINAL
cat $HOME/.config/xfce4/mcs_settings/desktop.xml | sed 's/'$CHANGE'/'$WITH'/g' > xfce_desktop.xml
mv xfce_desktop.xml $HOME/.config/xfce4/mcs_settings/desktop.xml
xfce-mcs-manager &
fi
# Fluxbox uses fbsetbg by default but a bunch of users
# have feh installed.
if [ $DESKTOP = "FLUXBOX" -a `feh -h >/dev/null 2>&1; echo $?` -eq 0 ]; then
feh --bg-scale "$FINAL"
elif [ $DESKTOP = "FLUXBOX" ]; then
fbsetbg -f "$FINAL"
fi
# Thanks to Alexander Batischev who pointed this out!
# feh seems to be the only wallpaper setting program,
# if this doesn't work the user can set an image to
# copy the final to. But first we try Alexander's idea:
if [ $DESKTOP = "feh" ]; then
feh --bg-scale "$FINAL"
fi
echo2 "done."
fi
# CLEAN UP OLD SHITE v < 2.0.21
rm -f $USERDIR"/output/xplanet1.png" >/dev/null 2>&1
rm -f $USERDIR"/output/xplanet2.png" >/dev/null 2>&1
# SCRIPT TO CALL?
if [ -n "$SCRIPT" ] && [ $SINGLE -eq 0 ]; then
echo2 Executing: "$SCRIPT" ...
$SCRIPT &
echo2 "done."
fi
# EXIT AFTER SINGLE IMAGE?
if [ $SINGLE -eq 1 ]; then
exit 0
else
date=`date +"%Y-%m-%d %H:%M:%S"`
echo2 "next update: "`date --date "$date $DELAY sec" +"%X %x"`
fi
rm lock >/dev/null 2>&1
# go to bed
sleep $DELAY
done