|
1 | | -disp(matlabRelease()) |
| 1 | +%% Finds the program "MathWorksUpdateInstaller" used to check for Matlab updates. |
| 2 | +% |
| 3 | +% The usual MathWorksUpdateInstaller program was removed in R2025a. |
| 4 | +% There is another program under the Mathworks ServiceHost, but folks have |
| 5 | +% observed that program results in network error code 1804. Nonetheless, we |
| 6 | +% give the location of that program, hoping that the Mathworks will make a |
| 7 | +% solution, perhaps via "mpm upgrade" in the future. |
| 8 | +% |
| 9 | +% future: programmatic update is planned for the "mpm" program: |
| 10 | +% https://github.com/mathworks-ref-arch/matlab-dockerfile/issues/129#issuecomment-2783047083 |
| 11 | +% |
| 12 | +% Ref: https://www.mathworks.com/matlabcentral/answers/1815365-how-do-i-uninstall-and-reinstall-the-mathworks-service-host |
2 | 13 |
|
3 | | -r = fullfile(matlabroot, "bin", computer("arch")); |
4 | | -mustBeFolder(r) |
| 14 | +function MatlabReleaseUpgrade() |
| 15 | + |
| 16 | +cmd = getUpgradePath(); |
| 17 | + |
| 18 | +fprintf("Matlab upgrade program found:\n\n%s\n\n", cmd) |
| 19 | + |
| 20 | +end |
| 21 | + |
| 22 | + |
| 23 | +function cmd = getUpgradePath() |
5 | 24 |
|
6 | | -cmd = fullfile(r, "MathWorksUpdateInstaller"); |
| 25 | +name = "MathWorksUpdateInstaller"; |
7 | 26 | if ispc() |
8 | | - cmd = cmd + ".exe"; |
| 27 | + name = name + ".exe"; |
| 28 | +elseif isunix() && ~ismac() |
| 29 | + name = name + ".sh"; |
| 30 | +end |
| 31 | + |
| 32 | +if isMATLABReleaseOlderThan('R2025a') |
| 33 | + cmd = legacy_update_path(name); |
| 34 | +else |
| 35 | + cmd = new_update_path(name); |
9 | 36 | end |
10 | 37 |
|
11 | 38 | 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.") |
| 39 | + error("Did not find upgrade program at %s", cmd) |
| 40 | +end |
| 41 | + |
| 42 | +end |
| 43 | + |
| 44 | + |
| 45 | +function cmd = legacy_update_path(name) |
| 46 | + |
| 47 | +r = fullfile(matlabroot, "bin", computer("arch")); |
| 48 | +mustBeFolder(r) |
| 49 | +cmd = fullfile(r, name); |
| 50 | + |
| 51 | +end |
| 52 | + |
| 53 | + |
| 54 | +function cmd = new_update_path(name) |
| 55 | + |
| 56 | +arch = computer("arch"); |
| 57 | + |
| 58 | +if ismac() |
| 59 | + head = fullfile(getenv("HOME"), 'Library/Application Support/MathWorks'); |
| 60 | + if ~isfolder(head) |
| 61 | + head = '/Library/Application Support/MathWorks'; |
16 | 62 | end |
| 63 | + head = fullfile(head, 'ServiceHost'); |
| 64 | +elseif ispc() |
| 65 | + head = fullfile(getenv("LOCALAPPDATA"), 'MathWorks/ServiceHost'); |
| 66 | +else |
| 67 | + head = fullfile(getenv("HOME"), '.MathWorks/ServiceHost', getenv("HOSTNAME")); |
17 | 68 | end |
| 69 | +mustBeFolder(head) |
| 70 | + |
| 71 | +bin_tail = fullfile("bin", arch); |
18 | 72 |
|
19 | | -fprintf("Run this command in system Terminal to check for Matlab upgrade:\n\n%s\n\n", cmd) |
| 73 | +infoFile = fullfile(head, "LatestInstall.info"); |
| 74 | +fid = fopen(infoFile); |
| 75 | +while ~feof(fid) |
| 76 | + svcRoot = extractAfter(fgetl(fid), "Latest" + optionalPattern("DS") + "InstallRoot"); |
| 77 | + if ~isempty(svcRoot) |
| 78 | + svcRoot = strip(strip(svcRoot), '"'); |
| 79 | + break |
| 80 | + end |
| 81 | +end |
| 82 | +fclose(fid); |
| 83 | +mustBeNonempty(svcRoot) |
| 84 | + |
| 85 | +cmd = fullfile(svcRoot, bin_tail, name); |
| 86 | + |
| 87 | +end |
0 commit comments