
# Log to /var/log/ufa.log unless defined by the sourcer.
# TODO mcarifio: Take this out or use logrotate to clean up the logs.
# TODO mcarifio: Log to /dev/console w/o being root?

UFA_LOG=${UFA_LOG:-/var/log/ufa.log}

function log {
	message=$1
	level=${2:-I}
	echo "$level:$(date):$(basename $0): $message" | tee -a $UFA_LOG > /dev/console
}


# ck_dir /some/directory0 /some/directory1 #=> and so forth
# return 0 iff all directories exist
# Useful to debug, only log missing ones
function ck_dir {
	status=0
	for d in $*
	do
		if ! [[ -e $d ]]
		then
			log "Missing directory '$d'" 
			status=1
		fi
	done
	return $status
}

# configuration abstractions

# https://help.ubuntu.com/community/UbuntuTime
function change_timezone {
	timezone=$1
	echo $timezone > /etc/timezone
	dpkg-reconfigure --frontend noninteractive tzdata
}

# We receive $UFA_DOMAIN_NAME_SERVERS, and expect it to contain:
# "x.x.x.x y.y.y.y", namely the IP address of two servers, separated
# by a space.
function change_dns {
	dns=$1
	for ns in $dns
	do
		echo "nameserver $ns" >> /etc/resolv.conf
	done
}

# locale_gen "en_US.UTF-8" calls locale-gen
function locale_gen {
	locale=$1
	locale-gen $1
}

function set_fb {
	/bin/fbset -fb /dev/graphics/fb2 -g 1920 1080 1920 1080 16
}
