#!/bin/bash # This script counts down the time to March 1, 2013. This is the month Ouya is supposed to be released to Kickstarter backers. # Press ^C to quit. # Date format yyyy-mm-dd # # $release and $now variables. # They represent the number of seconds since 1970-01-01 00:00:00 UTC, # for present time and release date respectively. now=$(date "+%s") release=$(date --date="2013-03-01" "+%s") function tleft { # Check the current date/time and compare with release date. now=$(date "+%s") diff=$(( release - now )) # This for loop takes care of dividing the total number of seconds into days, hours, minutes and seconds. for t in d h m s; do case $t in 'd') n=86400 d=$(( diff / n )) printf 'days:\t%12ds\n' $(( d * n )) ;; 'h') n=3600 h=$(( diff / n )) printf 'hrs:\t%12ds\n' $(( h * n )) ;; 'm') n=60 m=$(( diff / n )) printf 'min:\t%12ds\n' $(( m * n )) ;; 's') s=$diff printf 'sec:\t%12ds\n' $s ;; esac # Sets the diff to the remainder after each run of the loop. diff=$(( diff % n )) done # Prints out the time left. printf '\n%s days, %02d:%02d:%02d left\n' $d $h $m $s } # Quit if the current date is greater than the release date. if [[ $now -ge $release ]]; then echo "OUYA! It's released any time now!" exit else # While the current date is less than the release date, check the time left once every 0.5 seconds. while [[ $now -lt $release ]]; do clear tleft sleep 0.5 done echo "OUYA! It's released any time now!" exit fi