-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
39 lines (28 loc) · 1.06 KB
/
setup.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
import sys
import os
from pathlib import Path
import shutil
install_dir = Path(sys.argv[0]).resolve().parent
user = os.getlogin()
out_lines = []
with open('sssort.sh', 'r') as fH:
for line in fH.readlines():
if line.startswith('INSTALL_DIR'):
out_lines.append('INSTALL_DIR=%s\n' % install_dir)
else:
out_lines.append(line)
bin_dir = Path("/home/%s/.local/bin" % user)
os.makedirs(bin_dir, exist_ok=True)
with open('/home/%s/.bashrc' % user,'r') as fH:
bashrc = fH.readlines()
if not 'export PATH=$PATH:/home/%s/.local/bin\n' % user in bashrc:
bashrc.append("# added by SSSort installer #\n")
bashrc.append('export PATH=$PATH:/home/%s/.local/bin\n' % user)
# make a backup of .bashrc
shutil.copy2("/home/%s/.bashrc" % user, "/home/%s/.bashrc.bak" % user)
with open('/home/%s/.bashrc' % user,'w') as fH:
fH.writelines(bashrc)
with open(bin_dir / 'sssort', 'w') as fH:
fH.writelines(out_lines)
os.system('chmod u+x %s' % (bin_dir / 'sssort'))
# os.system('source /home/%s/.bashrc' % user)