39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os, shutil, sys
|
|
|
|
from crontab import CronTab
|
|
|
|
def search_str(file_path, word):
|
|
with open(file_path, 'r') as file:
|
|
# read all content of a file
|
|
content = file.read()
|
|
# check if string present in a file
|
|
if word in content:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
user_bin = os.environ["HOME"] + os.sep + "bin"
|
|
user_zshrc = os.environ["HOME"] + "/.zshrc"
|
|
|
|
if not os.path.exists(user_bin):
|
|
os.mkdir(user_bin)
|
|
|
|
if not search_str(user_zshrc, 'PATH=$PATH:'):
|
|
with open(user_zshrc, 'a') as zshrc:
|
|
print('PATH=$PATH:' + user_bin, file=zshrc)
|
|
else:
|
|
print('PATH=$PATH:', "exist in", user_zshrc, sep=' ')
|
|
|
|
try:
|
|
copy_file = shutil.copyfile(os.path.dirname(os.path.realpath(sys.argv[0])) + os.sep + "pull_and_push.py", user_bin + os.sep + "pull_and_push")
|
|
os.chmod(user_bin + os.sep + "pull_and_push",0o775)
|
|
except FileExistsError:
|
|
print("File konnte nicht kopiert werden")
|
|
|
|
cron = CronTab(user=os.environ["USER"])
|
|
cron_job = cron.new(command='pull_and_push >> /var/log/pull_and_push.log')
|
|
cron_job.hours.every(17)
|
|
cron.write() |