

function get_key_response ()
	local event = nil

	repeat
		event = { os.peek_event ("key") }
		os.sleep (0.3)
	until #event > 0

	os.get_event ("key")

	if not event[3] and not event[4] then
		if os.peek_event ("char") then
			os.get_event ("char")
		end

		return event[2] == keys.KEY_Y
	end

	return false
end


local system_found = fs.file_exists ("/boot")


term.set_colors (term.colors.white, term.colors.black)
print ("Installing server\n\n")

if system_found then
term.set_colors (term.colors.yellow, term.colors.black)
print ("System found: /boot will be renamed to /boot_os\n\n")
end

term.set_colors (term.colors.orange, term.colors.black)
print ("Existing files will be overritten\n")
term.set_colors (term.colors.silver, term.colors.black)
print ("Continue? (y to continue)")


if not get_key_response () then
	print ("\r                          \rcancelled\n")

	os.sleep (0.5)

	os.shutdown ()
end
print ("\r                          \r")


if system_found then
	fs.rename ("/boot", "/boot_os")
	fs.copy_file ("/SERVER/boot_system", "/boot")
	fs.copy_file ("/SERVER/server", "/server")
	fs.copy_file ("/SERVER/server.cfg", "/server.cfg")
	fs.copy_file ("/SERVER/license.txt", "license.txt")
else
	fs.copy_file ("/SERVER/boot_alone", "/boot")
	fs.copy_file ("/SERVER/server", "/server")
	fs.copy_file ("/SERVER/server.cfg", "/server.cfg")
	fs.copy_file ("/SERVER/license.txt", "license.txt")
end

term.set_colors (term.colors.silver, term.colors.black)
print ("Server installed")
