#!/usr/bin/python

import os
import argparse
import sys
import subprocess

GTERM = "/usr/bin/gterm"
MINISH = "/usr/bin/minish"


if __name__ == '__main__':

    if not os.path.exists(GTERM):
        os.system('sudo ln -s /usr/bin/xfce4-terminal %s' % GTERM)

    if not os.path.exists(MINISH):
        os.system('minish --install')
    
    returned_output=''
    try:
        returned_output = subprocess.check_output('cat $HOME/.bashrc | grep MININET_DIFFERENT_PROBES_PER_NODES', shell=True) 
    except Exception:
        pass # does nothing 
    
    if (not 'MININET' in returned_output):
        to_be_appended = """
#MININET_DIFFERENT_PROBES_PER_NODES
myline=`lsns -t net -p $$ | grep 'is mininet'`
for word in $myline; do : ; done
if [[ !  -z  $word  ]] ; then
  IFS=':' read -ra ARRAY <<< "$word"
  #echo ${ARRAY[1]}
  PS1='< \[\033[01;32m\]${ARRAY[1]}\[\033[00m\] >:\[\033[01;34m\]\w\[\033[00m\] \$ '
fi
"""
        with open (os.getenv('HOME')+'/.bashrc','a') as fbashrc :
            fbashrc.write(to_be_appended) 

    

