#!/bin/bash
####################################################################
# Prey System Module Core Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################

scan_system_hardware(){

	get_system_ids 2> /dev/null
	[ "$os" != "mac" ] && get_mb_info 2> /dev/null
	get_cpu_info 2> /dev/null
	get_memory_info 2> /dev/null
	get_bios_info 2> /dev/null

	get_storage_devices 2> /dev/null
	get_network_interfaces 2> /dev/null

}

store_system_value(){
	[ -n "$2" ] && store_key_value 'system' "hardware_attributes__${1}" "$(urlencode "$2")"
}

store_network_interface_value(){
	[ -n "$3" ] && store_key_value 'network_interfaces' "${1}__${2}" "$(urlencode "$3")"
}

store_storage_device_value(){
	[ -n "$3" ] && store_key_value 'storage_devices' "${1}__${2}" "$(urlencode "$3")"
}

store_system_params(){

	for key in $(echo $system__vars); do
		local value=$(eval echo "\$system__${key}")
		[ -n "$value" ] && store_system_value "$key" "$value"
	done

}

full_hardware_params(){
	store_system_params

	local system_params=$(generate_query_string 'system' '&device')
	# log "$system_params"

	local network_params=$(generate_query_string 'network_interfaces' '&device[hardware_attributes][network]')
	# log "$network_params"

	local storage_params=$(generate_query_string 'storage_devices' '&device[hardware_attributes][storage]')
	# log "$storage_params"

	echo "${system_params}${network_params}${storage_params}"
}

send_updated_hardware_data(){
	update_device_info_with "$(full_hardware_params)"
}
