Skip to content

Commit e209ad4

Browse files
committed
MathworksUpgrade with R2025a too [skip ci]
1 parent 07cec52 commit e209ad4

File tree

1 file changed

+72
-10
lines changed

1 file changed

+72
-10
lines changed

scripts/MatlabReleaseUpgrade.m

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,81 @@
1-
disp(matlabRelease())
1+
%% Finds the program "MathWorksUpdateInstaller" used to check for Matlab updates.
2+
%
3+
% future: programmatic update is planned for the "mpm" program:
4+
% https://github.com/mathworks-ref-arch/matlab-dockerfile/issues/129#issuecomment-2783047083
25

3-
r = fullfile(matlabroot, "bin", computer("arch"));
4-
mustBeFolder(r)
6+
function MatlabReleaseUpgrade()
7+
8+
cmd = getUpgradePath();
9+
10+
fprintf("Matlab upgrade program found:\n\n%s\n\n", cmd)
11+
12+
end
13+
14+
15+
function cmd = getUpgradePath()
516

6-
cmd = fullfile(r, "MathWorksUpdateInstaller");
17+
name = "MathWorksUpdateInstaller";
718
if ispc()
8-
cmd = cmd + ".exe";
19+
name = name + ".exe";
20+
end
21+
22+
if isMATLABReleaseOlderThan('R2025a')
23+
cmd = legacy_update_path(name);
24+
else
25+
cmd = new_update_path(name);
926
end
1027

1128
if ~isfile(cmd)
12-
if isMATLABReleaseOlderThan('R2025a')
13-
error("Did not find upgrade program at %s", cmd)
14-
else
15-
error("Matlab R2025a changed the upgrade process, use the GUI.")
29+
error("Did not find upgrade program at %s", cmd)
30+
end
31+
32+
end
33+
34+
35+
function cmd = legacy_update_path(name)
36+
37+
r = fullfile(matlabroot, "bin", computer("arch"));
38+
mustBeFolder(r)
39+
cmd = fullfile(r, name);
40+
41+
end
42+
43+
44+
function cmd = new_update_path(name)
45+
46+
arch = computer("arch");
47+
48+
if ismac()
49+
bin_head = fullfile(getenv("HOME"), "Library/Application Support/MathWorks");
50+
if ~isfolder(bin_head)
51+
bin_head = "/Library/Application Support/MathWorks";
1652
end
53+
bin_tail = fullfile("bin", "MathWorksServiceHost.app/Contents/Frameworks/bin", arch);
54+
elseif ispc()
55+
bin_head = fullfile(getenv("LOCALAPPDATA"), "MathWorks");
56+
bin_tail = fullfile("bin", arch);
57+
else
58+
bin_head = " ~/.MathWorks";
59+
bin_tail = fullfile("bin", arch);
1760
end
1861

19-
fprintf("Run this command in system Terminal to check for Matlab upgrade:\n\n%s\n\n", cmd)
62+
mustBeFolder(bin_head)
63+
64+
glob = fullfile(bin_head, "ServiceHost/v*", bin_tail, name);
65+
match = dir(glob);
66+
if isempty(match)
67+
error('could not find program with %s', glob)
68+
end
69+
folders = string(match.folder);
70+
% extract version number from string array of folders
71+
pattern = lookBehindBoundary("\v") + digitsPattern(4) + lookAheadBoundary(".");
72+
pv = extract(folders, pattern);
73+
rel = matlabRelease().Release;
74+
i = contains(rel, pv);
75+
if ~any(i)
76+
error('could not find program %s corresponding to %s', glob, rel)
77+
end
78+
79+
cmd = fullfile(folders(i), name);
80+
81+
end

0 commit comments

Comments
 (0)