#!/bin/sh
#
# Chub admin utility - SliTaz Community HUB aka Chub is the server hosting
# all end users sites such as the website, doc, forum as well as Hg repos.
# This tiny utility can be run by a cron job or via the command line for 
# maintenance tasks.
#
# Copyright (C) 2012 SliTaz GNU/Linux - BSD License
#
# Authors : Christophe Lincoln <pankso@slitaz.org>
#

[ -f "/etc/slitaz/chub.conf" ] && . /etc/slitaz/chub.conf
[ -f "chub.conf" ] && . ./chub.conf

usage() {
	cat << EOT

Usage: $(basename $0) [command]

Commands:
  stats        Display some server stats
  up-chub      Update Chub web interface chub.slitaz.org
  up-doc       Update doc.slitaz.org Wiki template
  rrd          Update RRD graphs images
  backup       Backup MySQL DB and files"

EOT
}

case "$1" in
	up-chub)
		# Update Chub web interface from repo.
		echo "Updating: chub.slitaz.org..."
		cd $REPOS/slitaz-forge
		hg pull -u
		rm -rf $VHOST/*.* $VHOST/images/*.png
		cp -a chub/web/* $VHOST ;;
	up-doc)
		# Update Wiki doc template from Hg.
		echo "Updating Wiki documentation template..."
		cd $REPOS/slitaz-forge
		hg pull -u
		cp -a doc/lib/tpl/* $DOC_LIB/tpl ;;
	stats)
		# Echo some stats.
		echo "======== Disk usage ============="
		df -h | grep ^/dev
		echo "======== Memory usage ==========="
		free -m | grep ^Mem
		echo "======== Connected users ========"
		who ;;
	rrd)
		echo "Making RRD graphs images..."
		$VHOST/lib/makegraphs >/dev/null ;;
	
	backup)
		echo "TODO: backup MySQL, SCN files, etc" ;;
	*)
		usage ;;
esac
exit 0
