#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from BootLib import ogBoot

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogBoot', 'ogBoot int_ndisk int_nfilesys [ NVRAMPERM ] [str_kernel str_initrd str_kernelparams]', ['ogBoot 1 2 "/boot/vmlinuz /boot/initrd.img root=/dev/sda2 ro"', 'ogBoot 1 2 NVRAMPERM'])
    sys.exit (0)

parser = argparse.ArgumentParser (add_help=False)
if 3 == len (sys.argv):
    parser.add_argument ('disk')
    parser.add_argument ('par')
elif 4 == len (sys.argv):
    parser.add_argument ('disk')
    parser.add_argument ('par')
    parser.add_argument ('nvramperm_or_params')
elif 5 == len (sys.argv):
    parser.add_argument ('disk')
    parser.add_argument ('par')
    parser.add_argument ('nvramperm')
    parser.add_argument ('params')

args = parser.parse_args()

if 3 == len (sys.argv):
    ret = ogBoot (args.disk, args.par)
elif 4 == len (sys.argv):
    if 'NVRAMPERM' == args.nvramperm_or_params.upper():
        nvramperm = True
        params = ''
    else:
        nvramperm = False
        params = args.nvramperm_or_params
    ret = ogBoot (args.disk, args.par, nvramperm, params)
elif 5 == len (sys.argv):
    ret = ogBoot (args.disk, args.par, not not args.nvramperm, args.params)

if ret is not None:
    if   ret == True: sys.exit (0)
    elif ret == False: sys.exit (1)
    else: print (ret)
