-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.m
88 lines (76 loc) · 2.59 KB
/
install.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
function success = install(path)
%INSTALL installs MatCUTEst at fullfile(path, 'matcutest'), using the compiled CUTEst in the
% directory containing this M file or at zipurl.
if ispc || ismac
error('MatCUTEst:InvalidOS', 'This package supports only GNU/Linux.');
end
% 7z is needed. For Ubuntu, try `type 7z || sudo apt install p7zip-full`.
[status, zpath] = system('command -v 7z');
if status ~= 0 || isempty(zpath)
error('MatCUTEst:SevenzNotFound', 'Command ''7z'' not found. Make sure that p7zip-full is installed.');
end
% pkg is the package containing the compiled version of MatCUTEst.
pkg = 'full.matcutest.7z.001';
gitaccount = 'matcutest';
gitrepo = 'matcutest_compiled';
zipurl = ['https://github.com/', gitaccount, '/', gitrepo, '/archive/refs/heads/main.zip'];
% mdir is the directory containing this script.
mdir = fileparts(mfilename('fullpath'));
% cpwd is the current directory.
cpwd = pwd();
if nargin > 0
if ~exist(path, 'dir')
mkdir(path);
end
else
% Decide `path` if it is not provided.
homedir = getenv('HOME');
if exist(fullfile(homedir, 'local'), 'dir')
path = fullfile(homedir, 'local');
elseif exist(fullfile(homedir, '.local'), 'dir')
path = fullfile(homedir, '.local');
else
path = mdir;
end
end
% matcutest is the root directory of MatCUTEst.
matcutest = fullfile(path, 'matcutest');
if exist(matcutest, 'dir') || exist(matcutest, 'file')
fprintf('\nThe package path\n\n %s\n\nalready exists. Remove it to (re-)install the package.\n\n', matcutest);
success = false;
return
end
fprintf('\nMatCUTEst will be installed at\n\n %s\n', matcutest);
if exist(fullfile(mdir, pkg), 'file')
pkg = fullfile(mdir, pkg);
else
[~, name, ext] = fileparts(zipurl);
zipname = [gitrepo, '-', name, ext];
zipname = fullfile(tempdir, zipname);
fprintf('\nDownloading the compiled package from\n\n %s\n', zipurl);
websave(zipname, zipurl);
unzip(zipname, tempdir);
zipdir = fullfile(tempdir, [gitrepo, '-', name]);
pkg = fullfile(zipdir, pkg);
fprintf('\nDone.\n');
end
fprintf('\nInstalling the compiled package\n\n %s\n', pkg);
exception = [];
try
cd(path);
% Run `7z x pkg`. Use `evalc` to make is quiet.
evalc('system([''7z x '', pkg])');
cd(fullfile(matcutest, 'mtools'));
setup();
catch exception
% Do nothing for the moment.
end
cd(cpwd);
if isempty(exception)
fprintf('MatCUTEst is successfully installed at\n\n %s\n', matcutest);
fprintf('\nTry "help matcutest" for more information.\n\n');
success = true;
else
rethrow(exception);
end
return