This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_to_bash.py
74 lines (60 loc) · 1.71 KB
/
add_to_bash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys
import getpass
user = getpass.getuser()
newdir = homedir
getfiles = newdir + "aliases"
badfix = newdir + "bad_aliases"
try:
with open (badfix, "r") as file:
removeme = file.readlines()
file.close()
except Exception:
cmd = "wget -O \"" + badfix + "\" \"https://raw.githubusercontent.com/MoeFwacky/Python-Plex-Controller/master/bad_aliases\""
os.system(cmd)
print ("Bad Aliases File Acquired.")
with open (badfix, "r") as file:
removeme = file.readlines()
file.close()
with open(getfiles, "r") as file:
thelines = file.readlines()
file.close
workingdir = "/home/" + user + "/.bashrc"
print ("Checking for bad entries.")
with open(workingdir, "r") as file:
oldfile = file.readlines()
file.close()
for line in oldfile:
if line in removeme:
print ("Bad Entry Found: " + line + " -- Removing.\n")
pass
else:
try:
newfile = newfile + line
except Exception:
newfile = line
try:
newfile
command = "sudo cp " + workingdir + " /home/" + user + "/backup_bashrc"
os.system(command)
print("Successfully backed up bash file... just in case..")
with open (workingdir, "w") as file:
file.write(newfile)
file.close()
print ("Bad Entries have been purged. Moving on.")
except Exception:
print ("No Bad Entries Found. No fix actions taken. Moving on.")
with open (workingdir, "r" )as file:
checkme = file.read()
file.close()
for tline in thelines:
tline = tline.replace('/home/pi/hasystem/', newdir)
tcheck = tline.split("=")
tcheck = tcheck[0]
#print (tcheck)
if tcheck not in checkme:
with open(workingdir, "a") as file:
file.write(tline)
file.close()
print ("added: " + tline)
print ("Aliases successfully added. Adding play status files now.\n")