#!/bin/bash
#  Called from ./idle in the X console window

cd

### Email reminders to myself, if there are any
# This will have to wait for a new calendar app.

### See whether we can use ssh

sshOK=false
[ -z $SSH_AUTH_SOCK ] || sshOK=true

### See where things are:

if [ -d /vv/users ]; then
    VV=/vv
elif [ -d $HOME/vv ]; then
    VV=$HOME/vv
else
    echo Nothing to back up.
    exit 1
fi


### Backups
#   This is obsolete; backups are now done with cron on nova only.
#   We could, however, use it to keep a secondary mirror up to date.
backups() {
    # Do the backups if there's a mirror mountpoint on this machine
    # It's done in idle because we need ssh for nova's root partition
    #
    if [ -d /mirror ] && [ -x /usr/local/sbin/daily-mirror ] && $sshOK; then
	ssh -x root@localhost /usr/local/sbin/daily-mirror -v < /dev/null
    fi	
}

pushIfPresent() {
    if [ -d $1/.git ] && [ ! -z "`git -C $1 status --porcelain`" ]; then
	    echo -n in $1: " "
	    (cd $1 && make push) 2>&1
    fi
}

uploads() {
    # Sync using make push.
    #
    if $sshOK; then
	for u in lgf starport steve tg; do
	    pushIfPresent $VV/users/$u
	    pushIfPresent $VV/users/$u/Lyrics
	done
	for d in MakeStuff Config Private; do 
	    pushIfPresent $VV/users/steve/$d
	done
    fi
}

# Email a status ping:  uptime, disk, users, and backup report
(uptime; df | grep -v tmpfs; w; uploads)
# FIXME: backups not called, and we're not emailing results.
#    | mail -s "STATUS: `hostname` `date +%Y-%m-%d`" \
#      steve@theStarport.org steve@savitzky.net


