import os, sys

if int(os.popen('id -u').readline().strip()) != 0:
  print "Legyel rut"
  sys.exit()

devices = []
disks = []

def get_model(devname):
  for line in os.popen('hdparm -i /dev/' + devname).readlines():
    if line.find('Model') == -1:
      continue
    
    return line.split('=')[1].split(',')[0].strip()

for line in os.popen('LC_ALL=C /sbin/fdisk -l').readlines():
  if line.find('Disk /') == 0:
    
    name = line.split()[1][5:-1]
    size = line.split(':')[1].split(',')[0].strip()
    tmp = [name, size, get_model(name)]
    disks.append(tmp)
    
  if line.find('/dev/') == -1 or line.find('Linux') == -1:
    continue
    
  columns = line.split()
  
  devname = columns[0].split('/')[-1]
  hasboot = columns[1] == '*'
  hasbootdir = False
  tmp = [devname, hasboot, hasbootdir]
  devices.append(tmp)

for dev in devices:
  rcode = os.popen('mount /dev/'+ dev[0] +' /mnt 2> /dev/null').close()
  
  if rcode != None and int(rcode) == 8192:
    continue
  
  if os.path.exists('/mnt/boot'):
    dev[2] = True

  os.popen('umount /mnt')

def grub_install(to):
  os.popen('mount /dev/'+ to +' /mnt')
  os.popen('grub-install --root-directory=/mnt /dev/'+ to[0:3])

"""
    Listazasa az osszegyujtott adatoknak.
"""

print "Lemezek: "
for i in disks:
  print "\tTipus: %s,\tMerete: %s,\tEszkoznev: %s" % (i[2], i[1], i[0])

print "\nParticiok: "
for i in devices:
  if i[1]:
    hasboot = "van"
  else:
    hasboot = "nincs"
    
  if i[2]:
    hasbootdir = "igen"
  else:
    hasbootdir = "nem"
    
  print "\tParticionev: %s,\tBootflag: %s,  \tKaphat-e bootflaget: %s" % (i[0], hasboot, hasbootdir)

