#!/bin/bash
#
# 	DESCRIPTION:	generate system issue file
#
#	SCRIPT NAME:	generate_issue.sh
#
#	Input:	argument
#			[--help]		show this message
#			[-v|--version]	version of OS
#			[-a|--arch]	architecture of OS
#			[-r|--release]	release of OS
#			[-d|--date]	date of generate OS
#
#	Output:	
# 			1 argument error
#
#	AUTHOR:		Qin Bo
#
#	EMAIL:		bqin@linx-info.com
#
#	DATE:		2010-08-13
#
#	HISTORY:
#	REVISOR		DATE			MODIFICATION
#	Qin Bo		2010-08-13		create
#
#
#

source ./functions

usage ()
{
	if [ "$1" == "-n" ];then
		cmd="info"
		ret=0
	else
		cmd="err"
		ret=1
	fi
	$cmd "
This script will generate issue

Usage: $0 options

options:
   [--help]		show this message
   [-v|--version]	version of OS
   [-a|--arch]	architecture of OS
   [-r|--release]	release of OS
   [-d|--date]	date of generate OS
   
   "
   return $ret
}

generate_issue () {

	local version="$1"
	local arch="$2"
	local release="$3"
	local date="$4"

	echo -e "\033[H\033[J"
	echo "Welcome to Rocky OS ${version} ${arch} ${release} ($date) (\n) (\l)"
	echo
	echo

}

main()
{
	local tmp

	if [ $# -eq 0 ];then
		usage;erv
	fi
	
	tmp=$(getopt -o v:a:r:d: --long version:,arch:,release:,date:,help -- "$@" 2>>$DEV_LOG)
	if [ "$?" -ne 0 ];then
		usage
		erv
	fi

	# set all argument to arg variable
	eval set -- "$tmp"

	while true ;do
		case "$1" in
			-v|--version) local version="$2"; shift 2 ;;
			-a|--arch) local arch="$2"; shift 2 ;;
			-r|--release) local release="$2"; shift 2 ;;
			-d|--date) local date="$2"; shift 2 ;;
			--help) usage -n; exit 0 ;;
			# shift the last "--", this dash is define by getopt (more information see man getopt)
			--) shift; break;;
			*) usage; erv ;;
		esac
	done

	info "generate issue"
	generate_issue "$version" "$arch" "$release" "$date" >"$TARGET/etc/issue"
	erv
	info "generate issue sucess"

}

main "$@"


