#! /usr/bin/env python

# On Linux systems, read /proc/config.gz and check for the
# needed kernel options.

from __future__ import print_function

import gzip
import sys

config_file_name = '/proc/config.gz'

try:
    with gzip.open(config_file_name, 'rb') as f:
        file_content = f.read()
except:
    print("ERROR: can not read your %s" % (config_file_name))
    sys.exit(1)

tests = (
    ('CONFIG_CPU_FREQ_GOV_PERFORMANCE', 'For best performance'),
    ('CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE', 'For best performance'),
    ('CONFIG_SECCOMP', 'For extra security'),
    ('CONFIG_THERMAL', 'For thermal monitoring'),
    ('CONFIG_PPS', 'Needed for PPS support'),
    ('CONFIG_PPS_CLIENT_LDISC', 'For PPS support on serial lines'),
    ('CONFIG_PPS_CLIENT_GPIO', 'For PPS support on GPIO lines'),
    ('CONFIG_USB_SERIAL_GARMIN', 'For Garmin USB GPS support'),
    ('CONFIG_USB_SERIAL_PL2303', 'For PL2303 USB GPS support'),
)

# when this figures out how to test for platform, add these
# for Pi:
# CONFIG_THERMAL_BCM2835

for test in tests:
    print("Checking: %s, %s: " % (test[0], test[1]), end='')
    index = file_content.find("\n%s" % (test[0]))
    if 0 <= index:
        print("OK")
    else:
        print("Missing")

sys.exit(0)
