-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.sd.setup
executable file
·124 lines (111 loc) · 4.27 KB
/
.sd.setup
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
import os, subprocess, shutil, sys
opj = os.path.join
ope = os.path.exists
MAIN = os.path.split(os.path.abspath(__file__))[0]
try:
os.mkdir(opj(MAIN,'Src'))
except OSError:
pass
def call(cmd_list, err_msg, **kwds):
err = subprocess.call(cmd_list,**kwds)
if err:
print err_msg
print "Please address the issue and rerun .sd.setup"
sys.exit(err)
def rewrite(filename, contents):
tmpfile = opj(MAIN,'.tmp')
if ope(tmpfile):
print "Temp file %s already exists: aborting"%tmpfile
sys.exit(1)
with open(tmpfile,'w') as F:
F.write("".join(contents))
shutil.move(tmpfile, filename)
def set_sagedays_number():
sdnum = opj(MAIN,'.sd.num')
if not ope(sdnum):
SDNUM = raw_input('Which Sage Days is this (e.g. "88")? ')
with open(sdnum,'w') as F:
F.write(SDNUM)
def modify_bashrc():
bashrc = opj(MAIN, '.bashrc')
with open(bashrc) as F:
contents = F.readlines()
if not contents[0].startswith("export"):
print "Changing PATH for non-interactive prompts...."
contents.insert(0,"LANG=en_US.UTF-8\n")
contents.insert(0,"export PATH=$HOME/bin:$HOME/.local/bin:$PATH\n")
rewrite(bashrc, contents)
def create_authorized_keys_link():
try:
os.mkdir(opj(MAIN,'.ssh'))
except OSError:
pass
authkeys = opj(MAIN,'.ssh','authorized_keys')
open(authkeys, 'a').close()
try:
os.symlink(opj(MAIN,'authorized_keys'),authkeys)
except OSError:
pass
def lock_gitconfig():
config = opj(MAIN,'.gitconfig')
if not ope(config):
print "Creating unreadable .gitconfig to prevent global git settings...."
subprocess.call(["touch",config])
subprocess.call(["chmod",'000',config])
def setup_git_trac():
git_trac_link = opj(MAIN,'bin','git-trac')
git_trac_exec = opj(MAIN,'Src','git-trac-command','bin','git-trac')
if not ope(git_trac_exec):
print "Downloading git-trac-command...."
os.chdir(opj(MAIN,'Src'))
call(['git','clone','https://github.com/sagemath/git-trac-command.git'],
"Cloning the git trac command failed.")
if not ope(git_trac_link):
os.symlink(git_trac_exec,git_trac_link)
def setup_git_tab_completion():
if not ope(opj(MAIN, '.git-completion.bash')):
print "Setting up tab completion for git branches...."
os.chdir(MAIN)
call(['wget','https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash'],
"Downloading git completion bash script failed.")
shutil.move('git-completion.bash','.git-completion.bash')
def setup_binary_pkg():
sageyaml = opj(MAIN,'Src','binary-pkg','sage.yaml')
if not ope(sageyaml):
print "Downloading binary-pkg...."
os.chdir(opj(MAIN,'Src'))
call(['git','clone','https://github.com/sagemath/binary-pkg.git'],
"Downloading binary-pkg failed.")
contents = []
with open(sageyaml) as F:
for line in F:
contents.append(line.replace("SAGE_FAT_BINARY=yes",
"SAGE_FAT_BINARY=no").replace(
"tar cjf {dist}/sage-{version}-{osname}-{arch}.tar.bz2 {path}",
"tar cf {dist}/sage-latest.tar {path}"))
rewrite(sageyaml, contents)
def create_sage_tarball():
Src_latest = opj(MAIN,'Src','sage-latest.tar')
dist_latest = opj('dist','sage-latest.tar')
if not ope(Src_latest):
print "Creating Sage tarball. This process will take some time."
print "You can track progress by running\n 'tail -f %s/Src/binary-pkg/make.out'\nin another terminal"%MAIN
os.chdir(opj(MAIN,'Src','binary-pkg'))
with open('make.out','w') as F:
call(['make','package-sage'],
"Making Sage binary failed.",
stdout=F, stderr=subprocess.STDOUT)
shutil.move(dist_latest,Src_latest)
def setup():
print "Setting up Sage Days environment...."
set_sagedays_number()
modify_bashrc()
create_authorized_keys_link()
#lock_gitconfig() # not necessary since no top level .git
setup_git_trac()
setup_git_tab_completion()
setup_binary_pkg()
create_sage_tarball()
print "Sage Days environment setup complete!"
setup()