-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·206 lines (176 loc) · 6.13 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python
'''
Alias Manager - Installer
...installs Alias Manager
Created on Jan 21, 2013
@author: cj
'''
from __future__ import print_function
import sys
import os
import os.path
try:
import aliasmgr_settings
except:
print("Alias Manager Import Error: missing local imports!")
print("Can't find aliasmgr_settings.py or aliasmgr_integrator.py")
exit(1)
bdebug = False
sinstall_dir = '/usr/share/aliasmgr'
def main(largs):
global bdebug, sinstall_dir
# root check
if os.environ.has_key("USER"):
suser = os.environ["USER"]
if suser != 'root':
print("Please run this installer as root.")
print("You might try 'sudo ./install'")
exit(1)
for sarg in largs:
if "-h" in sarg or "--h" in sarg:
print("Alias Manager Installer Help:")
print(" This installer needs root, you might try running:")
print(" sudo ./install")
print("\n To uninstall Alias Manager please run the uninstall")
print(" script. Like this:")
print(" sudo ./uninstall\n")
exit(0)
if '-d' in sarg or '--d' in sarg:
bdebug = True
if os.path.isdir(sinstall_dir):
sinstall_dir = sarg
do_install()
def do_install():
lst_status = []
settings = aliasmgr_settings.am_settings()
print("Installing Alias Manager v." + settings.version + "...")
if bdebug:
print("[Debug Mode - Dry Run]")
lst_exts = ['.py', '.xpm', '.glade',
'install', 'uninstall', '.desktop',
'examples.sh']
if not os.path.isdir(sinstall_dir):
print("Creating Alias Manager directory... [" + sinstall_dir + "]")
if not bdebug:
lst_status.append(make_dir(sinstall_dir))
print("Copying files...")
lst_files = os.listdir(sys.path[0])
for sfile in lst_files:
for sext in lst_exts:
if sfile.endswith(sext):
sfilepath = os.path.join(sys.path[0], sfile)
print(" " + sfile + (' ' * (25 - len(sfile))) + \
' > ' + sinstall_dir)
lst_status.append(copy_file(sfilepath, sinstall_dir))
print("Making read/write and executables...")
try:
if not bdebug:
os.system('chmod a+rw ' + sinstall_dir)
print(" +rw " + sinstall_dir)
lst_installed = os.listdir(sinstall_dir)
except:
# for debug purposes
lst_installed = []
for sfile in lst_installed:
sfilepath = os.path.join(sinstall_dir, sfile)
if (sfile.endswith('.pyc') or
sfile.endswith('.py') or
sfile.endswith('.sh')):
print(" +x " + sfile)
lst_status.append(make_exec(sfilepath))
print(" +rw " +sfile)
lst_status.append(make_rw(sfilepath))
print("Creating menu item...")
lst_status.append(make_menuitem())
print("Creating symlink...")
lst_status.append(make_symlink())
if all(lst_status):
print('\nAlias Manager was installed.')
exit(0)
else:
print('\nAlias Manager encountered errors during install!')
exit(1)
def make_symlink():
smainfile = os.path.join(sinstall_dir, 'aliasmgr.py')
if os.path.isfile(smainfile):
try:
if not bdebug:
os.system('ln -s ' + smainfile + ' ' + '/usr/bin/aliasmgr')
print(' /usr/bin/aliasmgr')
except:
print("Unable to create symlink!: /usr/bin/aliasmgr")
return False
return True
def make_menuitem():
print(" copying icon file > /usr/share/pixmaps/")
sicon_file = os.path.join(sinstall_dir, 'alias-manager.xpm')
if not bdebug:
make_dir('/usr/share/pixmaps')
if os.path.isfile(sicon_file) and os.path.isdir('/usr/share/pixmaps'):
if not bdebug:
copy_file(sicon_file, '/usr/share/pixmaps/alias-manager.xpm')
else:
print("Unable to copy icon file! Make menu item aborted!")
return False
sdesktop_file = os.path.join(sinstall_dir, 'aliasmanager.desktop')
sdestdir = '/usr/share/applications'
print(" copying desktop file > " + sdestdir)
if not bdebug:
make_dir(sdestdir)
if os.path.isfile(sdesktop_file) and os.path.isdir(sdestdir):
sdestpath = os.path.join(sdestdir, 'aliasmanager.desktop')
if not bdebug:
copy_file(sdesktop_file, sdestpath)
else:
print("Unable to copy desktop file! Make menu item aborted!")
return False
return True
def make_exec(sfile):
""" makes a file executable """
if not bdebug:
try:
os.system('chmod a+x ' + sfile)
except:
print("Unable to chmod +x file!: " + sfile)
return False
return True
def make_rw(sfile):
""" makes a file read/write """
if not bdebug:
try:
os.system('chmod a+rw ' + sfile)
except:
print("Unable to chmod +rw file!: " + sfile)
return False
return True
def copy_file(ssrc, sdest):
""" copies file to install dir """
if not bdebug:
try:
os.system('cp ' + ssrc + ' ' + sdest)
except:
print("Unable to copy file!: " + ssrc)
return False
return True
def make_dir(sdir):
""" makes dir, starting at root dir and makes sure all sub-dirs exist
or are created """
if not bdebug:
spath = ''
for sbuilddir in sdir.split('/'):
if sbuilddir != '':
spath += '/' + sbuilddir
if not os.path.isdir(spath):
try:
os.mkdir(spath)
print(' made dir ' + spath)
except OSError:
print("Unable to create directory: " + spath)
return False
return True
if __name__ == "__main__":
if len(sys.argv) < 2:
largs = []
else:
largs = sys.argv[1:]
main(largs)