forked from ChariteExpMri/antx2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallfromgithub.m
1679 lines (1438 loc) · 61.6 KB
/
installfromgithub.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% this installs/updates ANTx2-TBX
% #m THE UPDATE-MODE IS SELECTED VIA GUI
% #r _______NOTE______________________________________________________________________
% #r Instead of using "installfromgithub.m" use one the following two options for
% #r faster and more convenient update procedure:
% #r (1) type: updateantx(2) ..or
% #r (2) hit [download latest updates from Github]-Button right to the [antver]-button
% #r _________________________________________________________________________________
% #lk ____BUTTONS_______
% #b [check for update]
% - check for updates...if updates where found click...
% #b [yes, update now] #n ..to update the toolbox
% #b [no] #n ..to cancel
% #b [update without check]
% - just update toolbox.. don't ask questions
% - this works only if no files of the toolbox where modified ore deleted
% #b [rebuild]
% -use "rebuild" in case of locally modified or deleted files
% -use "rebuild" if [update without check] failed!
% #b [fresh installation]
% - make a fresh installation
% - you have to specify a target-directory to download/save the toolbox
% hit #b [close] #n when finished..
%% ===================================
%% [INSTALLATION WITHOUT GUI]
%% ===================================
% where "path2install" is the path to install ANTx2 (i.e. upper folder!)
% installfromgithub('install','path',path2install) ;
%
% example: install antx without GUI
% installfromgithub('install','path','X:\ressources\bla')
%-------------------------
function installfromgithub(varargin)
% if nargin==1
% if strcmp(varargin{1},'install')
% installer
% return
% end
if nargin==0
clear global antupd
else
if ischar(varargin{1}) && strcmp(varargin{1},'install')
if nargin==1
installer();
else
s=cell2struct(varargin(3:2:end),varargin(2:2:end),2);
if isfield(s,'isgui')==0
s.isgui=0;
end
installer(s);
try; delete(findobj(0,'tag','fupd')); end
end
return
end
end
if strcmp(mfilename,'installfromgithub')
%--------------------------------------------------------------------
%% first try to download the m-file from github
if 1
try
fiout=fullfile(fileparts(which('installfromgithub.m')), 'installfromgithub0.m') ;
url = 'https://raw.githubusercontent.com/ChariteExpMri/antx2/master/installfromgithub.m';
try
websave(fiout,url);
catch
urlwrite(url,fiout);
end
if exist(fiout) %replace file with downloaded version
pause(.2);
k=dir(fiout);
if k.bytes>1000
disp('get "installfromgithub.m" from github...');
movefile(which('installfromgithub0.m'),which('installfromgithub.m'),'f');
pause(.1);
end
end
end
end
% ------------------------------------------------------------------------
try
copyfile(which('installfromgithub.m'), fullfile(fileparts(which('installfromgithub.m')),'temp_installfromgithub.m'),'f');
% global antupd;
% antupd.tempfile=fullfile(fileparts(which('installfromgithub.m')),'temp_installfromgithub.m');
%try; delete(which('installfromgithub.m')); end
end
temp_installfromgithub;
return
end
initialize();
mkgui();
end
%% installer
function installer(arg)
% keyboard
if exist('arg')==1
s=arg;
if isfield(s,'path')
global antupd
v.pwd = pwd ; %'X:\ressources'
v.updatepath= fileparts(s.path);%'X:\ressources'
v.antxpath = '';
v.tempfile = '';
v.patempup = s.path; %'X:\ressources\bla'
antupd=v;
end
end
atime=tic;
if exist('s') && isfield(s,'isgui') && s.isgui==0
%without gui
% installfromgithub('install','path',pwd)
else
mkgui();
end
fprintf(['installation..please wait..\n']);
setstatus(1,'fresh installation..'); drawnow;
global antupd;
if isempty(antupd.patempup); error('global "antupd" is empty');end
%% ========== [1] [antx2]-folder exists ==================
% disp(which('installfromgithub.m'));
isPrevANTXdir=0; % previous ANTX dir exist
if exist(fullfile(antupd.patempup,'antx2'))==7
isPrevANTXdir=1;
% keyboard
disp('..[antx2]-folder exist ..folder will be renamed & removed');
cd(antupd.patempup); drawnow;
pause(1);
%disp(fullfile(antupd.patempup,'antx2'));
%disp(fullfile(antupd.patempup,'_antx2'));
if isunix && ~ismac
try
rmdir(fullfile(antupd.patempup,'antx2'),'s');
catch
pa2=fullfile(antupd.patempup, 'antx2');
system(['sudo rm -r "' pa2 '"']);
end
else
try; rmdir(fullfile(antupd.patempup,'antx2'),'s'); end
end
%try; disp(pwd); end
drawnow;
end
% if 1
% % try
% % Editor = com.mathworks.mlservices.MLEditorServices;
% % Editor.getEditorApplication.closeNoPrompt;
% % end
%
% disp(fullfile(antupd.patempup,'antx2'));
% disp(fullfile(antupd.patempup,'_antx2'));
% if isunix && ~ismac
% pa2=fullfile(antupd.patempup, 'antx2');
% system(['sudo rm -r ' pa2]);
% else
% try; rmdir(fullfile(antupd.patempup,'antx2'),'s'); end
% end
% try; disp(pwd); end
% drawnow;
% disp('..cloning repository from GITHUB..please wait..');
% %git clone https://github.com/pstkoch/antx2
% %git(['clone ' gitrepository]);
% git(['clone --depth=1 ' gitrepository]);
%
% %fprintf(['installation..done t=%2.3f min\n'],toc(atime)/60);
% cd(fullfile(antupd.patempup,'antx2'));
% end
%
% if isfield(antupd, 'patempup')
% if exist(fullfile(antupd.patempup,'installfromgithub.m'))
% %disp('..deleting "installfromgithub.m" from upper directory ');
% try; delete(fullfile(antupd.patempup,'installfromgithub.m')); end
% try; delete(fullfile(antupd.patempup,'temp_installfromgithub.m')); end
% end
% end
% try; fprintf(['installation..done t=%2.3f min\n'],toc(atime)/60);end
%===============================================================
%% ========== [2] clone REPO ==================
if 1
if 1
disp('..cloning repository from GITHUB..please wait...');
%git clone https://github.com/pstkoch/antx2
%git(['clone ' gitrepository]);
%[msg]=git(['clone --depth=1 ' gitrepository]); % %CLONE-WITHOUT-PROGRESS
msg=git(['ls-remote --exit-code ' gitrepository]); %CHECK ACCESS
clonefun=['!git clone --depth=1 --progress ' gitrepository]; %CLONE-WITH-PROGRESS
eval(clonefun);
msg=git(['ls-remote --exit-code ' gitrepository]); %CHECK ACCESS
%if contains(msg,'unable to access') || (exist(fullfile(antupd.patempup,'antx2','.git'))~=7)
if ~isempty(regexp(msg,'unable to access')) || (exist(fullfile(antupd.patempup,'antx2','.git'))~=7)
installLinux(antupd,gitrepository);
if isunix && ~ismac
%system(['sudo git clone --depth=1 ' gitrepository])
installLinux(antupd,gitrepository);
elseif ismac
error('mac issue -cloning (check newtork/firewall/proxy settings)');
elseif ispc
error('PC issue -cloning (check newtork/firewall/proxy settings)');
end
end
%fprintf(['installation..done t=%2.3f min\n'],toc(atime)/60);
end
if 0 % not needed..git creates the antx2-folder
mkdir(fullfile(antupd.patempup,'antx2'))
copyfile(fullfile(antupd.patempup,'installfromgithub.m'),fullfile(antupd.patempup,'antx2','installfromgithub.m'),'f')
end
try
cd(fullfile(antupd.patempup,'antx2'));
end
warning off;
success=0;
try; delete(fullfile(antupd.patempup,'temp_installfromgithub.m'));
catch; disp(['failed to delete: ' fullfile(antupd.patempup,'temp_installfromgithub.m')]);
end
try; delete(antupd.tempfile); end
success=0;
if exist(fullfile(antupd.patempup,'antx2'))==7
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
try
success=1;
end
end
end
end
if success==1 %% SUCCESS
ELA=sprintf(['(t=%2.3f min)'],toc(atime)/60);
cprintf([0 .5 0],['Package installation done' ELA '.\n']);
else
%% PROBLEM
cprintf([1 0 0],['.. installation failure.. check network connection/proxy settings/firewall.\n']);
cprintf([1 0 0],['.. TESTING a possible solution...\n']);
% ---POTENTIAL SOLUTION------------------
git fetch origin
git add -A
git reset --hard;
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
try; git(['remote add origin ' gitrepository]); end
git pull origin master
% ---------------------
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
success=1;
else
cprintf([1 0 0],['.. persisting installation failure.. check network connection/proxy settings/firewall.\n']);
end
end
if ~isempty(findobj(0,'tag','ant'))
disp('..linking paths');
thispa=pwd;
cd(antupd.updatepath);
antlink(1);
cd(thispa);
antcb('update');
end
if success==1 %% SUCCESS
setstatus(2,'Instalation completed. Up-to-data.');
else
setstatus(3,'Installation failed..check network connection/proxy settings/firewall');
end
installfromgithub;
if exist('s') && isfield(s,'isgui') && s.isgui==0
try; cd(s.path); end
end
end
%% ________________________________________________________________________________________________
function https=gitrepository
https='https://github.com/ChariteExpMri/antx2.git';
end
%% ________________________________________________________________________________________________
function initialize
p.pwd = pwd;
p.updatepath = fileparts(which(mfilename));
p.antxpath = which('ant.m');
global antupd;
antupd=p;
cd(p.updatepath);
if ~isempty(p.antxpath); antlink(0);end
end
function pbclose(e,e2)
% keyboard
global antupd;
cd(antupd.updatepath);
tmpfile=fullfile(antupd.updatepath,'temp_installfromgithub.m');
try; delete(tmpfile);
disp('.."temp_installfromgithub.m" removed');
catch
disp('..could not delete "temp_installfromgithub.m", please do it manually later');
end
if ~isempty(antupd.antxpath); antlink(1);
disp('..set antx2-path again');
if ~isempty(findobj(0,'tag','ant'))
global an
try
antcb('load',[regexprep(an.configfile,'.m$','') '.m']);
catch
antcb('reload');
end
disp('..reopen antgui..reloading project');
end
end
rehash path;
disp('..rehashing paths');
cd(antupd.pwd);
disp([' current working directory: ' antupd.pwd]);
delete(findobj(gcf,'tag','fupd')); %close WINDOW
if isfield(antupd,'patempup')
% keyboard
if exist(fullfile(antupd.patempup,'installfromgithub.m'))==2
if 1 %show QUESTION and ask
try
%% [QUESTION] DELETE "installfromgithub" -
warning off;
answer = questdlg(...
['\bf Delete used installtion file "installfromgithub.m" ? \rm' char(10) ...
' \diamondsuit If download/installation was successfull you don''t need ' char (10) ...
' the file anymore. Note that the folder "antx2" contains the file' char (10) ...
' "installfromgithub.m (used for updates and new installation)" ' char(10)...
' \diamondsuit If download/installation failed..you may keep that file. ' ...
], ...
'Delete installtion file' ,...
'Yes,delete','No, keep file',struct('Interpreter','tex','Default',''));
%% QUESTION off
if ~isempty(strfind(answer,'Yes'))
try;
delete(fullfile(antupd.patempup,'installfromgithub.m'));
disp('..removed temporary "installfromgithub"-file from upper dir');
catch; disp(['failed to delete: ' fullfile(antupd.patempup,'installfromgithub.m')]) ;
end
end
end
end%
% delete temp-files
try; delete(fullfile(antupd.patempup,'temp_installfromgithub.m')); end
end
end
try; delete(fullfile(antupd.tempfile)); end
disp('DONE');
end
function pbinstallfromgithubcall(e,e2,updatecode)
pbinstallfromgithub(updatecode);
end
% --------- MESSAGE what is modified
function [msg st]=antx_gitstatus(message)
% [msg st]=git('diff --name-only');
% [msg st]=git('diff --name-only origin');
[msg st]=git('diff --name-only -G. origin'); %cont' check permission rights
msg=strsplit(msg,char(10));
msg=msg(cellfun('isempty',strfind(msg,'prevprojects.mat'))); % without 'prevprojects.mat' in list
if ~isempty(msg)
msg=strjoin(msg,char(10));
end
if ~isempty(msg)
if strcmp(message,'check')
cprintf([ 1 0 1],'-----------------------------\n');
cprintf([ 1 0 1],' MODIFIED GITHUB FILES \n');
cprintf([ 1 0 1],'-----------------------------\n');
cprintf([ 0 0 0],'The following files have been created or modified in GITHUB.\n');
cprintf([ 0 0 0],'Note that the list might contain also locally modified or deleted files.\n');
cprintf([ .5 .5 .5],msg);
cprintf([ .5 .5 .5],'\n');
elseif strcmp(message,'recheck')
cprintf([0.9294 0.6902 0.1294],'-----------------------------\n');
cprintf([0.9294 0.6902 0.1294],' ERRONEOUS UPDATE \n');
cprintf([0.9294 0.6902 0.1294],'-----------------------------\n');
cprintf([ 0 0 0],'The following files were not updated successfully.\n');
cprintf([ 0 0 0],'..REASONS: local files have been modified/deleted.\n');
cprintf([ 0 0 0],'Please hit ');
cprintf([ 1 0 1],'[rebuild] ');
cprintf([ 0 0 0],'button to update those files.\n');
cprintf([ .5 .5 .5],msg);
cprintf([ .5 .5 .5],'\n');
end
else
cprintf([ 0.4667 0.6745 0.1882],'------------------------------------------------\n');
cprintf([ 0.4667 0.6745 0.1882],' ::.STATUS: UP-TO-DATE. NO NEWER UPDATES FOUND \n');
cprintf([ 0.4667 0.6745 0.1882],'------------------------------------------------\n');
end
end
function pbinstallfromgithub(updatecode)
global antupd;
atime=tic;
% prevdir =p.pwd;
% updatepath =p.updatepath;
% antxpath =p.antxpath;
if exist('.git','dir')~=7
disp('version control (".git") folder has been removed previously');
disp('set [keepVersionControl] to true and re-clone repository');
end
%% ==================== jeck UPDATES ..SHOW Y/N-update-POP ========================================
if updatecode==1 %check before
setstatus(1,'checking updates');
git fetch
%git diff master origin/master
% git diff --compact-summary master origin/master
%[msg st]=git('diff --compact-summary master origin/master');
% [msg st]=git('diff --stat master origin/master');
% [msg st]=git(' diff --name-only master origin/master');
% git diff --name-only
[msg st]=antx_gitstatus('check');
if isempty(msg);
%disp('no changes/no updates found');
setstatus(2,'Up-to-date. No updates found.');
return
else
%disp(['####### CHANGES #######']);
%disp(msg);
button = questdlg(['updates where found' char(10) 'Update toolbox now? '],'',...
'YES, update now','Cancel','canel');
if ~isempty(regexpi(button,'yes'))
updatecode=2;
else
%disp('nothing updated');
cprintf([ 1 0 1],' local package was not updated \n');
return
end
end
end
%% ==================== JUST UPDATE ========================================
if updatecode==2
setstatus(1,'updating..');
fprintf(['updating using version control (".git")..please wait..\n']);
if exist(fullfile(pwd,'.git'))~=7
button = questdlg(['".git-dir" not found, but mandatory for update' char(10)...
'Create/Recreate ".git"-dir? ' char(10) ...
' ..this might take a while..'],'',...
'YES, do it','Cancel','canel');
git reset --hard HEAD;
if ~isempty(regexpi(button,'yes'))
updatecode=4;
else
disp('..".git"-not found, .git not restored');
return
end
else
git pull;
end
[msg st]=antx_gitstatus('recheck');
try; antcb('versionupdate'); end
if isempty(msg)
fprintf(['updating..done t=%2.3f min\n'],toc(atime)/60);
setstatus(2,'Up-to-date. Updating finished');
else
setstatus(3,'updaiting failed..press [rebuild] button');
end
if updatecode==2
return
end
end
%% ==================== .GIT IS MISSING..UPDATE ========================================
if updatecode==3
setstatus(1,'create ".git" & updating..');
% need to initialize a new Git repository in your machine:
fprintf(['creating/restore ".git"..please wait..\n']);
git init
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
git(['remote add origin ' gitrepository]);
git pull origin master
%Or you can simply clone the existing remote repository as suggested in the above comments:
%git clone https://your_repot_url
try; antcb('versionupdate'); end
fprintf(['..done t=%2.3f min\n'],toc(atime)/60);
end
%% ==================== HARD RESET ========================================
if updatecode==5 %hard reset
setstatus(1,'hard reset..');
fprintf(['hard reset,updating..please wait..\n']);
%if exist(fullfile(pwd,'.git'))~=7
%git clean -df
%PREV VERSION
% git reset --hard HEAD;
% git init
%% save temp_installfromgithub
orig_tempfile =which('temp_installfromgithub.m');
[patt tempfi]=fileparts(orig_tempfile);
moved_tempfile=fullfile(fileparts(patt),[tempfi '.m']);
copyfile(orig_tempfile,moved_tempfile,'f');
% ---------------------
git fetch origin
git add -A
git reset --hard;
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
try; git(['remote add origin ' gitrepository]); end
git pull origin master
% ---------------------
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
fprintf(['updating..done t=%2.3f min\n'],toc(atime)/60);
setstatus(2,'Up-to-date. Updating finished');
else
setstatus(3,'updaiting failed..try again or make fresh installation');
end
if ~isempty(findobj(0,'tag','ant'))
disp('..linking paths');
thispa=pwd;
cd(antupd.updatepath);
antlink(1);
cd(thispa);
antcb('update');
try; antcb('versionupdate'); end
end
% put temp_installfromgithub back to folder,
copyfile(moved_tempfile,orig_tempfile,'f'); % allows to use pbclose and GIT-www-button
%fprintf(['updating..done t=%2.3f min\n'],toc(atime)/60);
return
end
%% FRESH INSTALLATION
if updatecode==4
global antupd;
antupd.tempfile=which('temp_installfromgithub.m');%fullfile(fileparts(which('installfromgithub.m')),'temp_installfromgithub.m');
disp('====== FRESH INSTALLATION =====================================================');
msg_uigetdir=['# Please select the local destination path for "antx2"'];
disp([msg_uigetdir ]);
pa=uigetdir(pwd,msg_uigetdir );
if isnumeric(pa); return ; end
[pa2 pa1]=fileparts(pa);
if strcmp(pa1,'antx2');%antx2-path selected
patempup=pa2; %..than use upper folder of antx2
% elseif exist(fullfile(pa,'antx2'))==7
% patempup=pa2; %..than use upper folder of antx2
else
patempup=pa;
end
antupd.patempup=patempup;
% disp(patempup);
cd(patempup);
try
copyfile(fullfile(antupd.updatepath,'installfromgithub.m'), fullfile(antupd.patempup,'installfromgithub.m'),'f');
end
msgpafinal=[' DESTINATION PATH: ' fullfile(antupd.patempup,'antx2') ] ;
if ispc==1
msgpafinal=strrep(msgpafinal,filesep,[filesep filesep]);
end
cprintf([0 .5 0], [msgpafinal '\n']);
%disp(['..selected path: "' fullfile(antupd.patempup,'antx2') '"']);
disp([' Click hyperlink to install from GITHUB": <a href="matlab: cd(''' antupd.patempup ''');installfromgithub(''install'');">install</a>']);
end
setstatus(0);
end
function posthoc
global antupd;
if ~isempty(p.antxpath);
antlink(1);
rehash path;
end
cd(p.prevdir);
disp('..updated');
% edit(fullfile(paantx,'README.txt'));
end
function mkgui()
% ==============================================
%%
% ===============================================
butwid=.75;
butx =.1;
% global antpd
% figpos=[0.3750 0.3544 0.2896 0.2289];
figpos=[0.5111 0.3567 0.1271 0.2289];
try; delete(findobj(0,'tag','fupd')); end
figure; set(gcf,'color','w','units','normalized','menubar','none',...
'position',figpos,'tag','fupd',...
'name', [mfilename],'NumberTitle','off');
set(gcf,'CloseRequestFcn',{@pbclose});
% HEAD
hp=uicontrol('style','text','units','norm','string','Update from GITHUB repository',...
'fontsize',9,'fontweight','bold');
set(hp,'position',[.01 0.8 .99 .17],'tag','txinfo','foregroundcolor',[0 0 1],'backgroundcolor',[1 1 1]);
% STATUS-WARNING SIGN
hp=uicontrol('style','text','units','norm','string','!','fontsize',9);
set(hp,'position',[.01 0.6 .05 .2],'tag','msgwarn','foregroundcolor',[.4 .4 .4],'backgroundcolor',[1 1 1]);
set(hp,'horizontalalignment','left');
set(hp,'backgroundcolor','w','foregroundcolor',[0.9294 0.6941 0.1255],'fontweight','bold','fontsize',20)
% STATUS
hp=uicontrol('style','text','units','norm','string','status: -unknown-','fontsize',9);
set(hp,'position',[butx 0.6 1.0-butx-0.05 .2],'tag','msg','foregroundcolor',[.4 .4 .4],'backgroundcolor',[1 1 1]);
set(hp,'horizontalalignment','left');
setstatus(0);
% UPDATE/UPDATE WITHOUT CHECK
hp=uicontrol('style','pushbutton','units','norm','string','check for updates','fontsize',9);
set(hp,'position',[butx .5 butwid .1],'callback',{@pbinstallfromgithubcall,1});
set(hp,'tooltipstring',['..checks for updates from repository only']);
hp=uicontrol('style','pushbutton','units','norm','string','update without check','fontsize',9);
set(hp,'position',[butx .4 butwid .1],'callback',{@pbinstallfromgithubcall,2});
set(hp,'tooltipstring',['..updates from repository without checking ' char(10) ...
' [duration]: fast (secs) ']);
%REBUILD
hp=uicontrol('style','pushbutton','units','norm','string','rebuild','fontsize',9);
set(hp,'position',[butx .3 butwid .1],'callback',{@pbinstallfromgithubcall,5});
set(hp,'tooltipstring',['..rebuild toolbox' char(10) ...
' * USED WHEN: ' char(10) ...
' - files are missing / not updated' char(10)' ...
' - ".git"-folder is lost ' char(10)' ...
' [duration]: fast (secs) ']);
%FRESH INSTALL
hp=uicontrol('style','pushbutton','units','norm','string','fresh installation','fontsize',9);
set(hp,'position',[butx .2 butwid .1],'callback',{@pbinstallfromgithubcall,4},'foregroundcolor','r');
set(hp,'tooltipstring',['..make FRESH INSTALLATION' char(10) ...
' * USED WHEN: ' char(10) ...
' - toolbox was never installed before' char(10)' ...
' - files are missing / not updated' char(10)' ...
' - ".git"-folder is lost ' char(10)' ...
' [duration]: slow (mins) ']);
hp=uicontrol('style','pushbutton','units','norm','string','Close','fontsize',9);
set(hp,'position',[.01 .01 .3 .1],'callback',{@pbclose},'foregroundcolor','k');
set(hp,'tooltipstring',['..close window']);
% WEB
% hp=uicontrol('style','text','units','norm','string','visit Github','fontsize',7);
% set(hp,'position',[.5 .01 .3 .1],'callback',{@pbvisitGithub},'backgroundcolor','w','foregroundcolor','b');
% set(hp,'tooltipstring',['..visit GitHub repositiory online']);
% set(hp,'string','<html><a href="">visit Github</a></html>','fontsize',5)
%
%
%
url = 'https://github.com/ChariteExpMri/antx2';
labelStr = ['<html>visit <a href="">' 'GitHUB' '</a></html>'];
jLabel = javaObjectEDT('javax.swing.JLabel', labelStr);
[hjLabel,hContainer] = javacomponent(jLabel, [10,10,250,20], gcf);
set(hContainer,'units','norm','position',[.5 .02 6 .1]);%,'backgroundcolor',[0 1 1])
% http://undocumentedmatlab.com/articles/javacomponent-background-color
% Modify the mouse cursor when hovering on the label
hjLabel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
hjLabel.setBackground(java.awt.Color(1,1,1));
jFont = java.awt.Font('Tahoma', java.awt.Font.PLAIN, 12);
hjLabel.setFont(jFont);
drawnow;
% Set the label's tooltip
hjLabel.setToolTipText(['Visit Github repository ' url ' ']);
% Set the mouse-click callback
set(hjLabel, 'MouseClickedCallback', @(h,e)web([url], '-browser'));
% ==============================================
%%
% ===============================================
end
function pbvisitGithub(e,e2)
web('https://github.com/ChariteExpMri/antx2','-browser');
end
function setstatus(arg,msg)
if arg==0
set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[.4 .4 .4],'string','[idle] ');
elseif arg==1
set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[1 0 1],'string',['[busy] ' msg]);
elseif arg==2
set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[ 0.4667 0.6745 0.1882],'string',['[idle] ' msg]);
elseif arg==3
set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[ 1 0 0],'string',['[idle] ' msg]);
end
drawnow
end
function installLinux(antupd,gitrepository)
%% proxy+port problem: Connection timed out while accessing
% source:
% https://stackoverflow.com/questions/12117957/global-git-file-location-linux/23134785
% find out the IP of our proxy server
% declare the proxy corporate to git. Depending on whether you need to authenticate or not you should add this information to the global configuration of git :
% git config --global http.proxy http://proxyuser:[email protected]:8080
% or
% git config --global http.proxy http://proxy.server.com:8080
if ispc || ismac==1; return; end
% clc
dowhile=1;
% disp(['..']);
% disp('=============================================');
%disp('LINUX USER - get ANTX repository from GITHUB');
cprintf(-[1,0,1], ' \n');
cprintf(-[1,0,1], 'LINUX USER - get ANTX repository from GITHUB\n');
disp('..PROBLEMS with GIT proxy/port settings and/or SUDO PERMISSION ..');
disp(' step-1: modify proxy/port settings () ');
disp(' step-2: clone repository with sudo permission');
disp(' Do step-2 if you think that proxy/port settings is ok');
disp(' Otherwise do step-1 followed by step-2');
cprintf( [ 0.8294 0.4902 0.1294], '..sudo passwort is needed (password request via command window)\n');
while dowhile==1
if 1
%disp('====== USERINPUT ==============================================');
cprintf(-[1,0,1], '====== USERINPUT =========================\n');
disp(' select [1] to modify the proxy/port settings. than..select [2]');
disp(' select [2] to (try to) clone the repository');
disp(' select [0] to proceed (at this point it is assumed that cloning of repository was succesfull (see message above)');
%answer=input('## What do you want to do select [1],[2], or [0]: ','s');
cprintf( [0 0 1], '## What do you want to do select [1],[2], or [0]: ');
answer=input(' ','s');
end
if strcmp(char(answer),'0')
dowhile=0;
end
if strcmp(char(answer),'1')
%disp('step[1]===================================================');
cprintf(-[1,0,1], 'step[1]===================================================\n');
disp(['please provide your/department''s proxy address and port' ]);
disp(['..see "gitconfig"-document in Matlab editor']);
disp([' Please enter a new line with your proxy and port below the "[http]"-tag' ]);
disp([' If necessary, remove all other proxies/ports from this file.' ]);
disp(' ..or from shell: git config --global --edit');
disp('');
disp('------------------------------------------------------------');
disp([' Here is an example how the file might look like.']);
disp('------------------------------------------------------------');
disp(['[http]']);
disp([' proxy = http://proxy.YOURPROXYSERVER:8080/']);
disp('------------------------------------------------------------');
disp(['[http]']);
disp([' proxy = http://proxy.charite.de:8080/']);
disp('------------------------------------------------------------');
disp(['..where "http://proxy.YOURPROXYSERVER" is an examplatory proxy server' ]);
disp(['..where "8080" is the PORT for HTTP protocol (http)' ]);
disp([' ..CLICK SAVE BUTTON TO SAVE THIS FILE..' ]);
disp([' ..ENTER [2] in COMMAND WINDOW TO CHECK WHETHER GIT CLONING WORKS' ]);
disp('===============================================================');
% disp(['proxy = http://proxy.charite.de:8080/ ' ]);
% msg
%%if exist('~/.gitconfig')==2
!touch ~/.gitconfig
%system('sudo xdg-open ~/.gitconfig');
system('sudo chmod 777 ~/.gitconfig'); %compare with 755
edit('~/.gitconfig');
end
% [~,gitconfig ]=system('readlink -f ~/.gitconfig')
% gitconfig=regexprep(gitconfig,char(10),'')
% ef = matlab.desktop.editor.openDocument(gitconfig); % opens the file in the editor
% waitfor(ef,'Opened',0); % this line waits for the editor property 'Opened' to change from a 1 to a 0 when the file is closed
%
%===================================
% now clone it
if strcmp(char(answer),'2')
% git clone <repo> <directory>
pa2=fullfile(antupd.patempup, 'antx2');
system(['sudo rm -r ' pa2]);
mkdir(pa2);
%gitrepository='https://github.com/ChariteExpMri/antx2.git'; %temp
disp('..please wait');
[r1 r2]=system(['sudo git clone --depth=1 -v ' gitrepository ' ' pa2 ]);
cprintf(-[1,0,1], 'step[2]===================================================\n');
%disp('step[2]===================================================');
if isempty(strfind(r2,'done'))
cprintf([1.0000 0.4118 0.1608], ['..git clone PROPLEM:\n']);
cprintf([1.0000 0.4118 0.1608], r2);
cprintf([1.0000 0.4118 0.1608], ' ');
%disp('### ..git clone PROPLEM: ###');
%disp(r2);
else
cprintf([0 .5 0], '### ..git clone SUCCESSFULL..select [0] to proceed.. ###\n');
%disp('### ..git clone SUCCESSFULL..select [0] to proceed.. ###');
end
% proxy = http://proxy.charite.de:8080/
end
end %while
disp('..');
end
function [cmdout, statout] = git(varargin)
% A thin MATLAB wrapper for Git.
%
% Short instructions:
% Use this exactly as you would use the OS command-line verison of Git.
%
% Long instructions are:
% This is not meant to be a comprehensive guide to the near-omnipotent
% Git SCM:
% http://git-scm.com/documentation
%
% Common MATLAB workflow:
%
% % Creates initial repository tracking all files under some root
% % folder
% >> cd ~/
% >> git init
%
% % Shows changes made to all files in repo (none so far)
% >> git status
%
% % Create a new file and add some code
% >> edit foo.m
%
% % Check repo status, after new file created
% >> git status
%