-
Notifications
You must be signed in to change notification settings - Fork 4
/
install
190 lines (134 loc) · 5.83 KB
/
install
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#! /usr/bin/env python2
# This script installs the files for Indexmeister and Imbrowse.in
# locations for a 'typical' (i.e. GNU Debian based) Linux setup. You might
# need to adjust it slightly for your system
#
import sys, os, subprocess, shutil, os.path, string, platform, stat
def p_wrap(pstring):
''' Prints a string with word-wrap to terminal column size '''
try:
a = term_cols
except:
try:
with os.popen("echo $COLUMNS") as b:
term_cols = int(b.read())
except:
term_cols = 40 # there aren`t that many 40-col CRTs around
# these days but terminals on mobile devices
# can be pretty narrow, so this seems like a
# reasonable default
while len(pstring) > term_cols:
print (pstring[:pstring[:term_cols].rfind(" ")])
pstring = pstring[len(pstring[:pstring[:term_cols].rfind(" ")]):]
print pstring
def make_executable(path):
''' This is from StackOverflow user Jonathon Reinhart '''
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X
os.chmod(path, mode)
p_wrap ("Installing the Indexmeister suite.")
p_wrap ("NOTE: If this script fails check to make sure you are Root.")
#Try to figure out what kind of system this is
termux = False
if "termux" in sys.prefix:
p_wrap ("I think this is an Android/Termux system. " +
"People who run console apps on a mobile OS " +
"are awesome." )
termux = True
elif "win32" in sys.platform:
p_wrap ("This seems to be a Windows system. I'll try to " +
"install anyway, but it probably won't work. " +
"Consider upgrading to a modern, POSIX complient OS.")
elif "linux" in sys.platform:
p_wrap ("This seems to be a Linux system " + "(" + string.join(platform.linux_distribution())
+ "). Penguin Power!")
linux = True
else:
p_wrap ("'" + sys.platform +"' system detected. This install script " +
"hasn't really been tested on your system, but let's go " +
"ahead and try anyway.")
# Now see if the dependencies are present
p_wrap ("Checking for some required dependencies.")
abort_flag = False
try:
import curses
except:
p_wrap ("WARNING: The Python 'curses' library doesn't seem to be installed. You " +
"won't be able to run imbrowse until you install it. The other programs " +
"should still work.")
''' #Shouldn't need grep anymore
if subprocess.call("grep hoser < /dev/null", shell=True) != 1:
p_wrap ("WARNING: grep doesn't seem to be installed on this system. You " +
"won't be able to run imbrowse until you install it. The other programs " +
"should still work.")
if termux: p_wrap ('On termux the command "pkg install grep" should do the trick.')
'''
#aspell / hunspell
print "Checking for aspell and/or hunspell..."
if subprocess.call("aspell list < /dev/null",
shell=True) != 0 and subprocess.call(
"hunspell -l < /dev/null", shell=True) != 0:
p_wrap ("I can't find aspell nor hunspell on your machine. " +
"unfortunately, indexmeister needs at least one of these to run.")
if termux: p_wrap ('On termux the command "pkg install hunspell" should do the trick.')
abort_flag = True
#detex / pandoc
print "Checking for pandoc and/or detex..."
if subprocess.call("pandoc < /dev/null",
shell=True) != 0 and subprocess.call("detex < /dev/null",
shell=True) != 0:
p_wrap ("I can't find pandoc nor detex on your machine. " +
"unfortunately, indexmeister needs at least one of these to run. " +
"Detex is included with texlive and many other LaTex distributions. " +
"Pandoc (prefered) is available as a package on most Linux distributions.")
if termux:
p_wrap ('On termux the easiest way to get detex is usually to install the texlive' +
' package: "pkg install texlive*"')
abort_flag = True
if abort_flag:
p_wrap ("Installation aborted because some required dependencies are not present.")
quit()
# OK, now on to the actual installation
# Try to find the important directories
tree = [t for t in os.walk(sys.prefix)]
manpath = ""
#this works on most debian derivatives and some others
with os.popen("manpath") as b:
manpath = b.read().strip()
manpaths = manpath.split(os.path.pathsep)
for m in manpaths:
if os.path.exists(m+"/man1"):
manpath = m
#but if there's no 'manpath' just guess
if manpath == "":
manpath = sys.prefix + "/share/man/"
if termux:
execpath = sys.prefix + '/bin/'
else:
if os.path.exists("/usr/local/bin/"):
execpath = "/usr/local/bin/"
elif os.path.exists("/usr/bin"):
execpath = "/usr/bin/"
else:
execpath = sys.prefix + '/bin/'
#copy the files over
p_wrap("Attempting to copy executable scripts to " + execpath)
try:
shutil.copy("./imbrowse", execpath+"imbrowse")
make_executable(execpath+"imbrowse")
shutil.copy("./indexmeister", execpath+"indexmeister")
make_executable(execpath+"indexmeister")
shutil.copy("./imhier", execpath+"imhier")
make_executable(execpath+"imhier")
p_wrap("Success!")
except:
p_wrap ("It lookes like something went wrong. You will probably need" +
" to install the scripts by hand.")
p_wrap("Attempting to copy man pages to " + manpath + "man1/")
try:
shutil.copy("./indexmeister.1.gz", manpath+ "/man1/")
shutil.copy("./imbrowse.1.gz", manpath+ "/man1/")
p_wrap("Success!")
except:
p_wrap ("It lookes like something went wrong. You will probably need" +
" to install the man pages by hand.")