forked from Unisens/unisens4matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_unisens_toolbox.m
150 lines (122 loc) · 4.72 KB
/
install_unisens_toolbox.m
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
function unisens_install()
% UNISENS_INSTALL installs Unisens toolbox permanently
%
% Example:
%
% unisens_install
% Copyright 2010 FZI Forschungszentrum Informatik Karlsruhe,
% Embedded Systems and Sensors Engineering
% Malte Kirst ([email protected])
% Joerg Ottenbacher ([email protected])
% Copyright 2014 Karlsruhe Institute of Technology
% Malte Kirst ([email protected])
% Change Log
% 2010-04-23 file established
% 2010-04-28 toolboxdir-bug fixed
% 2010-05-21 better handling of classpath.txt
% 2014-10-09 added support for Java 1.7
TOOLBOX = 'ANT_TOOLBOX';
URL = 'ANT_URL';
disp(' ');
disp('***********************************************************************');
disp(' ');
disp('This is the Unisens installation tool for Matlab. This tool will');
disp(['download the file ', TOOLBOX, ' from']);
disp([URL, ' and install it permanently.']);
disp(' ');
disp('When you have already installed the Unisens toolbox, it will be replaced');
disp('without request.');
disp(' ');
a = input('Do you want to continue? (y/n)\n', 's');
disp(' ');
if (~strcmpi(a, 'y'))
disp('Installation aborted');
disp(' ');
return;
end
% Check Java version
disp('Checking Java version...');
javaVersion = version('-java');
if (isempty(strfind(javaVersion, 'Java 1.6')) && isempty(strfind(javaVersion, 'Java 1.7')))
error([javaVersion, ' is installed. Unisens needs Java version 1.6 or 1.7.']);
else
disp([javaVersion, ' is installed.']);
disp(' ');
end
% Check installed Unisens version
disp('Checking previous installed Unisens toolbox...');
try
% If the toolbox is installed, remove toolbox directory.
rmdir(toolboxdir('unisens'), 's');
catch
% The toolbox is not installed. Check older unisens installations.
try
tmp = which('unisens_version');
tmp = strrep(tmp, 'unisens_version.m', '');
error(['Unisens is already installed (version ', unisensVersion, '). Remove this version before continue. Remove ', tmp, ' from PATH before continue.']);
catch
end
end
disp(' ');
% Check permissions
disp('Checking file permissions...');
s = mkdir([matlabroot, filesep, 'toolbox', filesep, 'unisens']);
if (~s)
error('Cannot write to toolbox folder.');
end
disp(' ');
% Download toolbox and extract to Matlab toolbox folder.
disp('Downloading data...');
unzip([URL, TOOLBOX], [matlabroot, filesep, 'toolbox', filesep]);
disp(' ');
% Check classpath for unisens library
disp('Editing Java classpath...');
clear java;
classPathList = javaclasspath('-static');
nClassPathList = length(classPathList);
unisensPath = [matlabroot, filesep, 'toolbox', filesep, 'unisens', filesep, 'lib', filesep];
% Remove eventually existing Unisens jar files from classpath list
newClassPathList = {};
for (i = 1:nClassPathList)
if (isempty(strfind(classPathList{i}, 'org.unisens.jar')) && ...
isempty(strfind(classPathList{i}, 'org.unisens.ri.jar')))
newClassPathList = [newClassPathList; classPathList(i)];
end
end
% Add new Unisens jar files to classpath list
newClassPathList = [newClassPathList; [unisensPath, 'org.unisens.jar']];
newClassPathList = [newClassPathList; [unisensPath, 'org.unisens.ri.jar']];
% Edit classpath.txt and add library to static path
classPathFile = which('classpath.txt');
copyfile(classPathFile, [classPathFile '.bak.unisens']);
try
h = fopen(classPathFile, 'w');
fprintf(h, '%s\n', newClassPathList{:});
fclose(h);
catch
fprintf(['\nInstaller cannot edit classpath.txt. You have to edit classpath.txt \n'...
'manually. Type "edit classpath.txt" in your Matlab command window and\n'...
'insert the following lines at the end of the file:\n\n'...
unisensPath, 'org.unisens.jar', '\n', unisensPath, 'org.unisens.ri.jar', '\n\n']);
end
% Add library to dynamic path (optional).
javaaddpath([unisensPath, 'org.unisens.jar']);
javaaddpath([unisensPath, 'org.unisens.ri.jar']);
disp(' ');
% Add toolbox to Matlab path and save this
disp('Editing Matlab path...');
addpath([matlabroot, filesep, 'toolbox', filesep, 'unisens']);
if (savepath())
error('Matlab path cannot be saved permanently.');
end
disp(' ');
disp('Installation successful. More information on http://unisens.org');
disp(' ');
disp('***********************************************************************');
disp(' ');
% disp('You have to configure the toolbox manually. Please click the Matlab START');
% disp('button -> DESKTOP TOOLS -> VIEW START BUTTON CONFIGURATION FILES. Press the');
% disp('REFRESH START BUTTON and close the window. Now you can find the toolbox in');
% disp('in the toolbox menu.');
disp('You have to restart Matlab now!');
disp(' ');