#!/bin/sh
#
# cook-clean - SliTaz cook: clean wok artefacts. Removes per-package
# build/install/source directories. Source directories alone (heavier
# disk-wise) can be cleaned via the 'src' subcommand.
#
# Usage:
#   cook-clean wok          # rm taz/, install/, source/ for all wok pkgs
#   cook-clean src          # rm source/ only for all wok pkgs
#
# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
#

. /usr/lib/slitaz/libcook.sh


usage() {
	cat <<EOT

$(boldify "$(_ 'Usage:')") cook-clean <command>

$(boldify "$(_ 'Commands:')")
  usage|help|--help|-h $(_ 'Display this short usage.')
  wok                  $(_ 'Remove taz/, install/, source/ for all packages.')
  src                  $(_ 'Remove source/ only for all packages.')

$(boldify "$(_ 'Examples:')")
  cook-clean wok               $(_ 'full wipe of build artefacts')
  cook-clean src               $(_ 'reclaim disk by dropping sources')

EOT
	exit 0
}


case "$1" in
	usage|help|--help|-h|'')
		usage
		;;

	wok)
		check_root
		newline; action 'Cleaning all packages files...'
		rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
		status; newline
		;;

	src)
		check_root
		newline; action 'Cleaning all packages sources...'
		rm -rf $WOK/*/source
		status; newline
		;;

	*)
		_ 'Unknown command: %s' "$1" >&2
		usage
		;;
esac
