#!/bin/bash #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License version 2 as published by #the Free Software Foundation. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details: #http://www.gnu.org/copyleft/gpl.html #Any questions at all, email me at: dave@davidstark.name DONE=false SINGLE=false DEBUG=false while ! $DONE do case "$1" in -1) SINGLE=true shift;; -d) DEBUG=true shift;; *) DONE=true;; esac done if ! (echo "$1" | grep '^[0-9A-Fa-f]\{6,6\}$' &> /dev/null) || ! (echo "$2" | grep '^[0-9A-Fa-f]\{6,6\}$' &> /dev/null) then echo echo "Usage: `basename \"$0\"` [-1] [-d] " echo echo "Where <*-colour> is a 6 digit RGB hex colour (no leading # or 0x)." echo "The -1 flag runs the set operation once, then exits, otherwise" echo " the background colour is adjusted every $RATE seconds" echo "The -d flag prints an information message when the colour is set" exit 1 fi if [ -x /usr/bin/xsri ] then SETROOTCOM="xsri --color=" elif [ -x /usr/bin/xsetroot ] then SETROOTCOM="/usr/bin/xsetroot -solid " elif [ -x /usr/openwin/bin/xsetroot ] then SETROOTCOM="/usr/openwin/bin/xsetroot -solid " else echo "Couldn't find a utility to set the root window colour" exit 1 fi #Update rate in seconds RATE=60 #Make the hex uppercase (dc gets confused otherwise) A=`echo $1 | tr a-z A-Z` B=`echo $2 | tr a-z A-Z` #Split the 6 char string into 3 2 char hex values RAHEX=${A:0:2} GAHEX=${A:2:2} BAHEX=${A:4:2} RBHEX=${B:0:2} GBHEX=${B:2:2} BBHEX=${B:4:2} #Convert to decimal RA=$(echo -e "16\ni\n${RAHEX}\np" | dc) GA=$(echo -e "16\ni\n${GAHEX}\np" | dc) BA=$(echo -e "16\ni\n${BAHEX}\np" | dc) RB=$(echo -e "16\ni\n${RBHEX}\np" | dc) GB=$(echo -e "16\ni\n${GBHEX}\np" | dc) BB=$(echo -e "16\ni\n${BBHEX}\np" | dc) RRANGE=$(($RB - $RA)) GRANGE=$(($GB - $GA)) BRANGE=$(($BB - $BA)) while true do MINUTES=$(echo "((`date +%k` * 60) + `date +%M`)" | bc) MAG=$(echo "((c (($MINUTES * 0.00436332312998582394))) -1) * -0.5" | bc -l) RVAL=$(echo "($MAG * $RRANGE) + $RA + 0.5" | bc | awk -F'.' '{print $1}') GVAL=$(echo "($MAG * $GRANGE) + $GA + 0.5" | bc | awk -F'.' '{print $1}') BVAL=$(echo "($MAG * $BRANGE) + $BA + 0.5" | bc | awk -F'.' '{print $1}') # Convert back to hex RHEXVAL=$(echo -e "10\ni\n16\no\n${RVAL:-0}\np" | dc) if [ ${#RHEXVAL} -lt 2 ] then RHEXVAL=0$RHEXVAL fi GHEXVAL=$(echo -e "10\ni\n16\no\n${GVAL:-0}\np" | dc) if [ ${#GHEXVAL} -lt 2 ] then GHEXVAL=0$GHEXVAL fi BHEXVAL=$(echo -e "10\ni\n16\no\n${BVAL:-0}\np" | dc) if [ ${#BHEXVAL} -lt 2 ] then BHEXVAL=0$BHEXVAL fi $SETROOTCOM"#$RHEXVAL$GHEXVAL$BHEXVAL" if $DEBUG then echo -e "`date +%b" "%d" "%H:%M:%S` `hostname | awk -F'.' '{print $1}'` $0 $DISPLAY $RHEXVAL$GHEXVAL$BHEXVAL" fi if $SINGLE then exit 0 fi sleep $RATE done