Mercurial > hg > octave-nkf
comparison scripts/pkg/pkg.m @ 6925:1401a79af68c
[project @ 2007-09-26 18:58:52 by dbateman]
author | dbateman |
---|---|
date | Wed, 26 Sep 2007 18:58:53 +0000 |
parents | 65d0fa83261a |
children | ee12d56c4200 |
comparison
equal
deleted
inserted
replaced
6924:be176b7e110a | 6925:1401a79af68c |
---|---|
114 ## It is possible to get the current installation prefix by requesting an | 114 ## It is possible to get the current installation prefix by requesting an |
115 ## output argument. For example, | 115 ## output argument. For example, |
116 ## @example | 116 ## @example |
117 ## p = pkg prefix | 117 ## p = pkg prefix |
118 ## @end example | 118 ## @end example |
119 ## | |
120 ## The location in which to install the architecture dependent files can be | |
121 ## independent specified with an addition argument. For example | |
122 ## | |
123 ## @example | |
124 ## pkg prefix ~/my_octave_packages ~/my_octave_packages_for_my_pc | |
125 ## @end example | |
119 ## @item local_list | 126 ## @item local_list |
120 ## Set the file in which to look for information on the locally | 127 ## Set the file in which to look for information on the locally |
121 ## installed packages. Locally installed packages are those that are | 128 ## installed packages. Locally installed packages are those that are |
122 ## typically available only to the current user. For example | 129 ## typically available only to the current user. For example |
123 ## @example | 130 ## @example |
171 | 178 |
172 function [local_packages, global_packages] = pkg (varargin) | 179 function [local_packages, global_packages] = pkg (varargin) |
173 ## Installation prefix (XXX: what should these be on windows?) | 180 ## Installation prefix (XXX: what should these be on windows?) |
174 persistent user_prefix = false; | 181 persistent user_prefix = false; |
175 persistent prefix = -1; | 182 persistent prefix = -1; |
183 persistent archprefix = -1; | |
176 persistent local_list = tilde_expand (fullfile("~", ".octave_packages")); | 184 persistent local_list = tilde_expand (fullfile("~", ".octave_packages")); |
177 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", | 185 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", |
178 "octave_packages"); | 186 "octave_packages"); |
179 mlock (); | 187 mlock (); |
180 | 188 |
181 if (ispc () && ! isunix ()) | 189 global_install = issuperuser (); |
182 global_install = 1; | |
183 else | |
184 global_install = (geteuid() == 0); | |
185 endif | |
186 | 190 |
187 if (prefix == -1) | 191 if (prefix == -1) |
188 if (global_install) | 192 if (global_install) |
189 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); | 193 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
194 archprefix = fullfile (OCTAVE_HOME (), "libexec", "octave", "packages"); | |
190 else | 195 else |
191 prefix = fullfile ("~", "octave"); | 196 prefix = fullfile ("~", "octave"); |
197 archprefix = prefix; | |
192 endif | 198 endif |
193 prefix = tilde_expand (prefix); | 199 prefix = tilde_expand (prefix); |
200 archprefix = tilde_expand (archprefix); | |
194 endif | 201 endif |
195 | 202 |
196 ## Handle input | 203 ## Handle input |
197 if (length (varargin) == 0 || ! iscellstr (varargin)) | 204 if (length (varargin) == 0 || ! iscellstr (varargin)) |
198 print_usage (); | 205 print_usage (); |
220 case "-global" | 227 case "-global" |
221 global_install = true; | 228 global_install = true; |
222 if (! user_prefix) | 229 if (! user_prefix) |
223 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); | 230 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
224 endif | 231 endif |
225 case {"list", "install", "uninstall", "load", "unload", ... | 232 case {"list", "install", "uninstall", "load", "unload", "prefix", ... |
226 "prefix", "local_list", "global_list", "rebuild", "build"} | 233 "local_list", "global_list", "rebuild", "build"} |
227 if (strcmp (action,"none")) | 234 if (strcmp (action, "none")) |
228 action = varargin{i}; | 235 action = varargin{i}; |
229 else | 236 else |
230 error ("more than one action specified"); | 237 error ("more than one action specified"); |
231 endif | 238 endif |
232 otherwise | 239 otherwise |
250 | 257 |
251 case "install" | 258 case "install" |
252 if (length (files) == 0) | 259 if (length (files) == 0) |
253 error ("you must specify at least one filename when calling 'pkg install'"); | 260 error ("you must specify at least one filename when calling 'pkg install'"); |
254 endif | 261 endif |
255 install (files, deps, auto, prefix, verbose, local_list, | 262 install (files, deps, auto, prefix, archprefix, verbose, local_list, |
256 global_list, global_install); | 263 global_list, global_install); |
257 | 264 |
258 case "uninstall" | 265 case "uninstall" |
259 if (length (files) == 0) | 266 if (length (files) == 0) |
260 error ("you must specify at least one package when calling 'pkg uninstall'"); | 267 error ("you must specify at least one package when calling 'pkg uninstall'"); |
274 endif | 281 endif |
275 unload_packages (files, deps, local_list, global_list); | 282 unload_packages (files, deps, local_list, global_list); |
276 | 283 |
277 case "prefix" | 284 case "prefix" |
278 if (length (files) == 0 && nargout == 0) | 285 if (length (files) == 0 && nargout == 0) |
279 disp (prefix); | 286 printf ("Installation prefix: %s\n", prefix); |
280 elseif (length (files) == 0 && nargout == 1) | 287 printf ("Architecture dependent prefix: %s\n", archprefix); |
288 elseif (length (files) == 0 && nargout >= 1) | |
281 local_packages = prefix; | 289 local_packages = prefix; |
282 elseif (length (files) == 1 && nargout <= 1 && ischar (files{1})) | 290 global_packages = archprefix; |
291 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1})) | |
283 prefix = files{1}; | 292 prefix = files{1}; |
284 ## if (!strcmp(prefix(end), filesep)) | |
285 ## prefix(end+1) = filesep; | |
286 ## endif | |
287 prefix = absolute_pathname (prefix); | 293 prefix = absolute_pathname (prefix); |
288 local_packages = prefix; | 294 local_packages = prefix; |
289 user_prefix = true; | 295 user_prefix = true; |
296 if (length (files) >= 2 && ischar (files{2})) | |
297 archprefix = files{2}; | |
298 try | |
299 archprefix = absolute_pathname (archprefix); | |
300 catch | |
301 mkdir (archprefix); | |
302 warning ("creating the directory %s\n", archprefix); | |
303 archprefix = absolute_pathname (archprefix); | |
304 end_try_catch | |
305 global_packages = archprefix; | |
306 endif | |
290 else | 307 else |
291 error ("you must specify a prefix directory, or request an output argument"); | 308 error ("you must specify a prefix directory, or request an output argument"); |
292 endif | 309 endif |
293 | 310 |
294 case "local_list" | 311 case "local_list" |
325 error ("you must specify a global_list file, or request an output argument"); | 342 error ("you must specify a global_list file, or request an output argument"); |
326 endif | 343 endif |
327 | 344 |
328 case "rebuild" | 345 case "rebuild" |
329 if (global_install) | 346 if (global_install) |
330 global_packages = rebuild (prefix, global_list, files, auto, verbose); | 347 global_packages = rebuild (prefix, archprefix, global_list, files, |
348 auto, verbose); | |
331 global_packages = save_order (global_packages); | 349 global_packages = save_order (global_packages); |
332 save (global_list, "global_packages"); | 350 save (global_list, "global_packages"); |
333 if (nargout > 0) | 351 if (nargout > 0) |
334 local_packages = global_packages; | 352 local_packages = global_packages; |
335 endif | 353 endif |
336 else | 354 else |
337 local_packages = rebuild (prefix, local_list, files, auto, verbose); | 355 local_packages = rebuild (prefix, archprefix, local_list, files, auto, |
356 verbose); | |
338 local_packages = save_order (local_packages); | 357 local_packages = save_order (local_packages); |
339 save (local_list, "local_packages"); | 358 save (local_list, "local_packages"); |
340 if (nargout == 0) | 359 if (nargout == 0) |
341 clear ("local_packages"); | 360 clear ("local_packages"); |
342 endif | 361 endif |
351 otherwise | 370 otherwise |
352 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); | 371 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); |
353 endswitch | 372 endswitch |
354 endfunction | 373 endfunction |
355 | 374 |
356 function descriptions = rebuild (prefix, list, files, auto, verbose) | 375 function descriptions = rebuild (prefix, archprefix, list, files, auto, verbose) |
357 if (isempty (files)) | 376 if (isempty (files)) |
358 [dirlist, err, msg] = readdir (prefix); | 377 [dirlist, err, msg] = readdir (prefix); |
359 if (err) | 378 if (err) |
360 error ("couldn't read directory %s: %s", prefix, msg); | 379 error ("couldn't read directory %s: %s", prefix, msg); |
361 endif | 380 endif |
378 printf ("recreating package description from %s\n", dirlist{k}); | 397 printf ("recreating package description from %s\n", dirlist{k}); |
379 endif | 398 endif |
380 if (exist (descfile, "file")) | 399 if (exist (descfile, "file")) |
381 desc = get_description (descfile); | 400 desc = get_description (descfile); |
382 desc.dir = fullfile (prefix, dirlist{k}); | 401 desc.dir = fullfile (prefix, dirlist{k}); |
402 desc.archprefix = fullfile (archprefix, strcat (desc.name, "-", | |
403 desc.version)); | |
383 if (auto != 0) | 404 if (auto != 0) |
384 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) | 405 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
385 unlink (fullfile (desc.dir, "packinfo", ".autoload")); | 406 unlink (fullfile (desc.dir, "packinfo", ".autoload")); |
386 endif | 407 endif |
387 if (auto < 0) | 408 if (auto < 0) |
448 error ("could not create installation directory: %s", msg); | 469 error ("could not create installation directory: %s", msg); |
449 endif | 470 endif |
450 endif | 471 endif |
451 files(1) = []; | 472 files(1) = []; |
452 buildlist = fullfile (builddir, "octave_packages"); | 473 buildlist = fullfile (builddir, "octave_packages"); |
453 install (files, handle_deps, autoload, installdir, verbose, | 474 install (files, handle_deps, autoload, installdir, installdir, verbose, |
454 buildlist, "", false); | 475 buildlist, "", false); |
455 unwind_protect | 476 unwind_protect |
456 repackage (builddir, buildlist); | 477 repackage (builddir, buildlist); |
457 unwind_protect_cleanup | 478 unwind_protect_cleanup |
458 unload_packages ({"all"}, handle_deps, buildlist, ""); | 479 unload_packages ({"all"}, handle_deps, buildlist, ""); |
463 unlink (buildlist); | 484 unlink (buildlist); |
464 endif | 485 endif |
465 end_unwind_protect | 486 end_unwind_protect |
466 endfunction | 487 endfunction |
467 | 488 |
468 function install (files, handle_deps, autoload, prefix, verbose, local_list, global_list, global_install) | 489 function install (files, handle_deps, autoload, prefix, archprefix, verbose, |
490 local_list, global_list, global_install) | |
469 | 491 |
470 # Check that the directory in prefix exist. If it doesn't: create it! | 492 # Check that the directory in prefix exist. If it doesn't: create it! |
471 if (! exist (prefix, "dir")) | 493 if (! exist (prefix, "dir")) |
472 warning ("creating installation directory %s", prefix); | 494 warning ("creating installation directory %s", prefix); |
473 [status, msg] = mkdir (prefix); | 495 [status, msg] = mkdir (prefix); |
489 endif | 511 endif |
490 | 512 |
491 ## Uncompress the packages and read the DESCRIPTION files | 513 ## Uncompress the packages and read the DESCRIPTION files |
492 tmpdirs = packdirs = descriptions = {}; | 514 tmpdirs = packdirs = descriptions = {}; |
493 try | 515 try |
494 | |
495 ## Warn about non existent files | 516 ## Warn about non existent files |
496 for i = 1:length (files) | 517 for i = 1:length (files) |
497 if (isempty (glob(files{i}))) | 518 if (isempty (glob(files{i}))) |
498 warning ("file %s does not exist", files{i}); | 519 warning ("file %s does not exist", files{i}); |
499 endif | 520 endif |
547 | 568 |
548 ## Verify that package name corresponds with filename | 569 ## Verify that package name corresponds with filename |
549 [dummy, nm] = fileparts (tgz); | 570 [dummy, nm] = fileparts (tgz); |
550 if ((length (nm) >= length (desc.name)) | 571 if ((length (nm) >= length (desc.name)) |
551 && ! strcmp (desc.name, nm(1:length(desc.name)))) | 572 && ! strcmp (desc.name, nm(1:length(desc.name)))) |
552 error ("package name '%s' doesn't correspond to its filename '%s'", desc.name, nm); | 573 error ("package name '%s' doesn't correspond to its filename '%s'", |
574 desc.name, nm); | |
553 endif | 575 endif |
554 | 576 |
555 ## Set default installation directory | 577 ## Set default installation directory |
556 desc.dir = fullfile (prefix, strcat (desc.name, "-", desc.version)); | 578 desc.dir = fullfile (prefix, strcat (desc.name, "-", desc.version)); |
579 | |
580 ## Set default architectire dependent installation directory | |
581 desc.archprefix = fullfile (archprefix, strcat (desc.name, "-", | |
582 desc.version)); | |
557 | 583 |
558 ## Save desc | 584 ## Save desc |
559 descriptions{end+1} = desc; | 585 descriptions{end+1} = desc; |
560 | 586 |
561 ## Are any of the new packages already installed? | 587 ## Are any of the new packages already installed? |
654 ## Install each package | 680 ## Install each package |
655 try | 681 try |
656 for i = 1:length (descriptions) | 682 for i = 1:length (descriptions) |
657 desc = descriptions{i}; | 683 desc = descriptions{i}; |
658 pdir = packdirs{i}; | 684 pdir = packdirs{i}; |
659 copy_files (desc, pdir); | 685 copy_files (desc, pdir, global_install); |
660 create_pkgadddel (desc, pdir, "PKG_ADD"); | 686 create_pkgadddel (desc, pdir, "PKG_ADD", global_install); |
661 create_pkgadddel (desc, pdir, "PKG_DEL"); | 687 create_pkgadddel (desc, pdir, "PKG_DEL", global_install); |
662 finish_installation (desc, pdir) | 688 finish_installation (desc, pdir, global_install) |
663 endfor | 689 endfor |
664 catch | 690 catch |
665 ## Something went wrong, delete tmpdirs | 691 ## Something went wrong, delete tmpdirs |
666 for i = 1:length (tmpdirs) | 692 for i = 1:length (tmpdirs) |
667 rm_rf (tmpdirs{i}); | 693 rm_rf (tmpdirs{i}); |
668 endfor | 694 endfor |
669 for i = 1:length (descriptions) | 695 for i = 1:length (descriptions) |
670 rm_rf (descriptions{i}.dir); | 696 rm_rf (descriptions{i}.dir); |
697 rm_rf (getarchdir (descriptions{i})); | |
671 endfor | 698 endfor |
672 rethrow (lasterror ()); | 699 rethrow (lasterror ()); |
673 end_try_catch | 700 end_try_catch |
674 | 701 |
675 ## Check if the installed directory is empty. If it is remove it | 702 ## Check if the installed directory is empty. If it is remove it |
676 ## from the list | 703 ## from the list |
677 for i = length (descriptions):-1:1 | 704 for i = length (descriptions):-1:1 |
678 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"})) | 705 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && |
706 dirempty (getarchdir (descriptions{i}))) | |
679 warning ("package %s is empty\n", descriptions{i}.name); | 707 warning ("package %s is empty\n", descriptions{i}.name); |
680 rm_rf (descriptions{i}.dir); | 708 rm_rf (descriptions{i}.dir); |
709 rm_rf (getarchdir (descriptions{i})); | |
681 descriptions(i) = []; | 710 descriptions(i) = []; |
682 endif | 711 endif |
683 endfor | 712 endfor |
684 | 713 |
685 ## If the package requested that it is autoloaded, or the installer | 714 ## If the package requested that it is autoloaded, or the installer |
736 for i = 1:length (descriptions) | 765 for i = 1:length (descriptions) |
737 if (isautoload (descriptions(i))) | 766 if (isautoload (descriptions(i))) |
738 idx (end + 1) = i; | 767 idx (end + 1) = i; |
739 endif | 768 endif |
740 endfor | 769 endfor |
741 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst); | 770 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
771 global_install); | |
742 endif | 772 endif |
743 endfunction | 773 endfunction |
744 | 774 |
745 function uninstall (pkgnames, handle_deps, verbose, local_list, | 775 function uninstall (pkgnames, handle_deps, verbose, local_list, |
746 global_list, global_install) | 776 global_list, global_install) |
824 cd (wd); | 854 cd (wd); |
825 endif | 855 endif |
826 ## Do the actual deletion | 856 ## Do the actual deletion |
827 if (desc.loaded) | 857 if (desc.loaded) |
828 rmpath (desc.dir); | 858 rmpath (desc.dir); |
829 if (exist (fullfile (desc.dir, getarch()), "dir")) | 859 if (exist (getarchdir (desc))) |
830 rmpath (fullfile (desc.dir, getarch ())); | 860 rmpath (getarchdir (desc)); |
831 endif | 861 endif |
832 endif | 862 endif |
833 if (exist (desc.dir, "dir")) | 863 if (exist (desc.dir, "dir")) |
834 [status, msg] = rm_rf (desc.dir); | 864 [status, msg] = rm_rf (desc.dir); |
835 if (status != 1) | 865 if (status != 1) |
836 error ("couldn't delete directory %s: %s", desc.dir, msg); | 866 error ("couldn't delete directory %s: %s", desc.dir, msg); |
867 endif | |
868 [status, msg] = rm_rf (getarchdir (desc)); | |
869 if (status != 1) | |
870 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); | |
871 endif | |
872 if (dirempty (desc.archprefix)) | |
873 rm_rf (desc.archprefix); | |
837 endif | 874 endif |
838 else | 875 else |
839 warning ("directory %s previously lost", desc.dir); | 876 warning ("directory %s previously lost", desc.dir); |
840 endif | 877 endif |
841 endfor | 878 endfor |
892 movefile (fullfile (pack.name, "inst", "doc"), pack.name); | 929 movefile (fullfile (pack.name, "inst", "doc"), pack.name); |
893 endif | 930 endif |
894 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) | 931 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) |
895 movefile (fullfile (pack.name, "inst", "bin"), pack.name); | 932 movefile (fullfile (pack.name, "inst", "bin"), pack.name); |
896 endif | 933 endif |
897 archdir = fullfile (pack.name, "inst", getarch ()); | 934 archdir = fullfile (pack.archprefix, strcat (pack.name, "-", |
935 pack.version), getarch ()); | |
898 if (exist (archdir, "dir")) | 936 if (exist (archdir, "dir")) |
899 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) | 937 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
900 unlink (fullfile (pack.name, "inst", "PKG_ADD")); | 938 unlink (fullfile (pack.name, "inst", "PKG_ADD")); |
901 endif | 939 endif |
902 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) | 940 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) |
920 fullfile (pack.name, "PKG_DEL")); | 958 fullfile (pack.name, "PKG_DEL")); |
921 endif | 959 endif |
922 endif | 960 endif |
923 tfile = strcat (pack.name, "-", pack.version, ".tar"); | 961 tfile = strcat (pack.name, "-", pack.version, ".tar"); |
924 tar (tfile, pack.name); | 962 tar (tfile, pack.name); |
925 | 963 try |
964 gzip (tfile); | |
965 unlink (tfile); | |
966 catch | |
967 warning ("failed to compress %s", tfile); | |
968 end_try_catch | |
926 unwind_protect_cleanup | 969 unwind_protect_cleanup |
927 if (exist (pack.name, "dir")) | 970 if (exist (pack.name, "dir")) |
928 rm_rf (pack.name); | 971 rm_rf (pack.name); |
929 endif | 972 endif |
930 cd (wd); | 973 cd (wd); |
1121 endif | 1164 endif |
1122 fclose (fid); | 1165 fclose (fid); |
1123 endif | 1166 endif |
1124 endfunction | 1167 endfunction |
1125 | 1168 |
1126 function create_pkgadddel (desc, packdir, nm) | 1169 function create_pkgadddel (desc, packdir, nm, global_install) |
1127 instpkg = fullfile (desc.dir, nm); | 1170 instpkg = fullfile (desc.dir, nm); |
1128 instfid = fopen (instpkg, "wt"); | 1171 instfid = fopen (instpkg, "wt"); |
1129 ## If it is exists, most of the PKG_* file should go into the | 1172 ## If it is exists, most of the PKG_* file should go into the |
1130 ## architecture dependent directory so that the autoload/mfilename | 1173 ## architecture dependent directory so that the autoload/mfilename |
1131 ## commands work as expected. The only part that doesn't is the | 1174 ## commands work as expected. The only part that doesn't is the |
1132 ## part in the main directory. | 1175 ## part in the main directory. |
1133 if (exist (fullfile (desc.dir, getarch ()), "dir")) | 1176 archdir = fullfile (getarchprefix (desc), strcat (desc.name, "-", |
1134 archpkg = fullfile (desc.dir, getarch (), nm); | 1177 desc.version), getarch ()); |
1135 archfid = fopen (archpkg, "wt"); | 1178 if (exist (getarchdir (desc, global_install), "dir")) |
1179 archpkg = fullfile (getarchdir (desc, global_install), nm); | |
1180 archfid = fopen (archpkg, "at"); | |
1136 else | 1181 else |
1137 archpkg = instpkg; | 1182 archpkg = instpkg; |
1138 archfid = instfid; | 1183 archfid = instfid; |
1139 endif | 1184 endif |
1140 | 1185 |
1184 endif | 1229 endif |
1185 endif | 1230 endif |
1186 endif | 1231 endif |
1187 endfunction | 1232 endfunction |
1188 | 1233 |
1189 function copy_files (desc, packdir, bindir) | 1234 function copy_files (desc, packdir, global_install) |
1190 ## Create the installation directory | 1235 ## Create the installation directory |
1191 if (! exist (desc.dir, "dir")) | 1236 if (! exist (desc.dir, "dir")) |
1192 [status, output] = mkdir (desc.dir); | 1237 [status, output] = mkdir (desc.dir); |
1193 if (status != 1) | 1238 if (status != 1) |
1194 error ("couldn't create installation directory %s : %s", | 1239 error ("couldn't create installation directory %s : %s", |
1195 desc.dir, output); | 1240 desc.dir, output); |
1196 endif | 1241 endif |
1197 endif | 1242 endif |
1243 | |
1244 octfiledir = getarchdir (desc); | |
1198 | 1245 |
1199 ## Copy the files from "inst" to installdir | 1246 ## Copy the files from "inst" to installdir |
1200 instdir = fullfile (packdir, "inst"); | 1247 instdir = fullfile (packdir, "inst"); |
1201 if (! dirempty (instdir)) | 1248 if (! dirempty (instdir)) |
1202 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); | 1249 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); |
1203 if (status != 1) | 1250 if (status != 1) |
1204 rm_rf (desc.dir); | 1251 rm_rf (desc.dir); |
1205 error ("couldn't copy files to the installation directory"); | 1252 error ("couldn't copy files to the installation directory"); |
1206 endif | 1253 endif |
1254 if (exist (fullfile (desc.dir, getarch ()), "dir") && | |
1255 ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) | |
1256 if (! exist (octfiledir, "dir")) | |
1257 ## Can be required to create upto three levels of dirs | |
1258 octm1 = fileparts (octfiledir); | |
1259 if (! exist (octm1, "dir")) | |
1260 octm2 = fileparts (octm1); | |
1261 if (! exist (octm2, "dir")) | |
1262 octm3 = fileparts (octm2); | |
1263 if (! exist (octm3, "dir")) | |
1264 [status, output] = mkdir (octm3); | |
1265 if (status != 1) | |
1266 rm_rf (desc.dir); | |
1267 error ("couldn't create installation directory %s : %s", | |
1268 octm3, output); | |
1269 endif | |
1270 endif | |
1271 [status, output] = mkdir (octm2); | |
1272 if (status != 1) | |
1273 rm_rf (desc.dir); | |
1274 error ("couldn't create installation directory %s : %s", | |
1275 octm2, output); | |
1276 endif | |
1277 endif | |
1278 [status, output] = mkdir (octm1); | |
1279 if (status != 1) | |
1280 rm_rf (desc.dir); | |
1281 error ("couldn't create installation directory %s : %s", | |
1282 octm1, output); | |
1283 endif | |
1284 endif | |
1285 [status, output] = mkdir (octfiledir); | |
1286 if (status != 1) | |
1287 rm_rf (desc.dir); | |
1288 error ("couldn't create installation directory %s : %s", | |
1289 octfiledir, output); | |
1290 endif | |
1291 endif | |
1292 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), | |
1293 octfiledir); | |
1294 rm_rf (fullfile (desc.dir, getarch ())); | |
1295 | |
1296 if (status != 1) | |
1297 rm_rf (desc.dir); | |
1298 rm_rf (octfiledir); | |
1299 error ("couldn't copy files to the installation directory"); | |
1300 endif | |
1301 endif | |
1302 | |
1207 endif | 1303 endif |
1208 | 1304 |
1209 ## Create the "packinfo" directory | 1305 ## Create the "packinfo" directory |
1210 packinfo = fullfile (desc.dir, "packinfo"); | 1306 packinfo = fullfile (desc.dir, "packinfo"); |
1211 [status, msg] = mkdir (packinfo); | 1307 [status, msg] = mkdir (packinfo); |
1212 if (status != 1) | 1308 if (status != 1) |
1213 rm_rf (desc.dir); | 1309 rm_rf (desc.dir); |
1310 rm_rf (octfiledir); | |
1214 error ("couldn't create packinfo directory: %s", msg); | 1311 error ("couldn't create packinfo directory: %s", msg); |
1215 endif | 1312 endif |
1216 | 1313 |
1217 ## Copy DESCRIPTION | 1314 ## Copy DESCRIPTION |
1218 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); | 1315 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); |
1219 if (status != 1) | 1316 if (status != 1) |
1220 rm_rf (desc.dir); | 1317 rm_rf (desc.dir); |
1221 error ("couldn't copy DESCRIPTION: %s", output); | 1318 rm_rf (octfiledir); |
1319 error ("couldn't copy DESCRIPTION: %s", output); | |
1222 endif | 1320 endif |
1223 | 1321 |
1224 ## Copy COPYING | 1322 ## Copy COPYING |
1225 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); | 1323 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); |
1226 if (status != 1) | 1324 if (status != 1) |
1227 rm_rf (desc.dir); | 1325 rm_rf (desc.dir); |
1228 error ("couldn't copy COPYING: %s", output); | 1326 rm_rf (octfiledir); |
1327 error ("couldn't copy COPYING: %s", output); | |
1229 endif | 1328 endif |
1230 | 1329 |
1231 ## If the file ChangeLog exists, copy it | 1330 ## If the file ChangeLog exists, copy it |
1232 fChangeLog = fullfile(packdir, "ChangeLog"); | 1331 fChangeLog = fullfile(packdir, "ChangeLog"); |
1233 if (exist (fChangeLog, "file")) | 1332 if (exist (fChangeLog, "file")) |
1234 [status, output] = copyfile (fChangeLog, packinfo); | 1333 [status, output] = copyfile (fChangeLog, packinfo); |
1235 if (status != 1) | 1334 if (status != 1) |
1236 rm_rf (desc.dir); | 1335 rm_rf (desc.dir); |
1336 rm_rf (octfiledir); | |
1237 error ("couldn't copy ChangeLog file: %s", output); | 1337 error ("couldn't copy ChangeLog file: %s", output); |
1238 endif | 1338 endif |
1239 endif | 1339 endif |
1240 | 1340 |
1241 ## Is there an INDEX file to copy or should we generate one? | 1341 ## Is there an INDEX file to copy or should we generate one? |
1242 fINDEX = fullfile (packdir, "INDEX"); | 1342 fINDEX = fullfile (packdir, "INDEX"); |
1243 if (exist(fINDEX, "file")) | 1343 if (exist(fINDEX, "file")) |
1244 [status, output] = copyfile (fINDEX, packinfo); | 1344 [status, output] = copyfile (fINDEX, packinfo); |
1245 if (status != 1) | 1345 if (status != 1) |
1246 rm_rf (desc.dir); | 1346 rm_rf (desc.dir); |
1347 rm_rf (octfiledir); | |
1247 error ("couldn't copy INDEX file: %s", output); | 1348 error ("couldn't copy INDEX file: %s", output); |
1248 endif | 1349 endif |
1249 else | 1350 else |
1250 try | 1351 try |
1251 write_INDEX (desc, fullfile (packdir, "inst"), | 1352 write_INDEX (desc, fullfile (packdir, "inst"), |
1252 fullfile (packinfo, "INDEX")); | 1353 fullfile (packinfo, "INDEX"), global_install); |
1253 catch | 1354 catch |
1254 rm_rf (desc.dir); | 1355 rm_rf (desc.dir); |
1356 rm_rf (octfiledir); | |
1255 rethrow (lasterror ()); | 1357 rethrow (lasterror ()); |
1256 end_try_catch | 1358 end_try_catch |
1257 endif | 1359 endif |
1258 | 1360 |
1259 ## Is there an 'on_uninstall.m' to install? | 1361 ## Is there an 'on_uninstall.m' to install? |
1260 fon_uninstall = fullfile(packdir, "on_uninstall.m"); | 1362 fon_uninstall = fullfile(packdir, "on_uninstall.m"); |
1261 if (exist (fon_uninstall, "file")) | 1363 if (exist (fon_uninstall, "file")) |
1262 [status, output] = copyfile (fon_uninstall, packinfo); | 1364 [status, output] = copyfile (fon_uninstall, packinfo); |
1263 if (status != 1) | 1365 if (status != 1) |
1264 rm_rf (desc.dir); | 1366 rm_rf (desc.dir); |
1367 rm_rf (octfiledir); | |
1265 error ("couldn't copy on_uninstall.m: %s", output); | 1368 error ("couldn't copy on_uninstall.m: %s", output); |
1266 endif | 1369 endif |
1267 endif | 1370 endif |
1268 | 1371 |
1269 ## Is there a doc/ directory that needs to be installed | 1372 ## Is there a doc/ directory that needs to be installed |
1270 docdir = fullfile (packdir, "doc"); | 1373 docdir = fullfile (packdir, "doc"); |
1271 if (exist (docdir, "dir") && ! dirempty (docdir)) | 1374 if (exist (docdir, "dir") && ! dirempty (docdir)) |
1272 [status, output] = copyfile (docdir, desc.dir); | 1375 [status, output] = copyfile (docdir, desc.dir); |
1273 endif | 1376 endif |
1274 | 1377 |
1275 ## Is there a bin/ directory that needs to be installed | 1378 ## Is there a bin/ directory that needs to be installed |
1276 bindir = fullfile (packdir, "bin"); | 1379 bindir = fullfile (packdir, "bin"); |
1277 if (exist (bindir, "dir") && ! dirempty (bindir)) | 1380 if (exist (bindir, "dir") && ! dirempty (bindir)) |
1278 [status, output] = copyfile (bindir, desc.dir); | 1381 [status, output] = copyfile (bindir, desc.dir); |
1279 endif | 1382 endif |
1280 endfunction | 1383 endfunction |
1281 | 1384 |
1282 function finish_installation (desc, packdir) | 1385 function finish_installation (desc, packdir, global_install) |
1283 ## Is there a post-install to call? | 1386 ## Is there a post-install to call? |
1284 if (exist (fullfile (packdir, "post_install.m"), "file")) | 1387 if (exist (fullfile (packdir, "post_install.m"), "file")) |
1285 wd = pwd (); | 1388 wd = pwd (); |
1286 try | 1389 try |
1287 cd (packdir); | 1390 cd (packdir); |
1288 post_install (desc); | 1391 post_install (desc); |
1289 cd (wd); | 1392 cd (wd); |
1290 catch | 1393 catch |
1291 cd (wd); | 1394 cd (wd); |
1292 rm_rf (desc.dir); | 1395 rm_rf (desc.dir); |
1396 rm_rf (getarchdir (desc), global_install); | |
1293 rethrow (lasterror ()); | 1397 rethrow (lasterror ()); |
1294 end_try_catch | 1398 end_try_catch |
1295 endif | 1399 endif |
1296 endfunction | 1400 endfunction |
1297 | 1401 |
1468 | 1572 |
1469 ## Creates an INDEX file for a package that doesn't provide one. | 1573 ## Creates an INDEX file for a package that doesn't provide one. |
1470 ## 'desc' describes the package. | 1574 ## 'desc' describes the package. |
1471 ## 'dir' is the 'inst' direcotyr in temporary directory. | 1575 ## 'dir' is the 'inst' direcotyr in temporary directory. |
1472 ## 'INDEX' is the name (including path) of resulting INDEX file. | 1576 ## 'INDEX' is the name (including path) of resulting INDEX file. |
1473 function write_INDEX (desc, dir, INDEX) | 1577 function write_INDEX (desc, dir, INDEX, global_install) |
1474 ## Get names of functions in dir | 1578 ## Get names of functions in dir |
1475 [files, err, msg] = readdir (dir); | 1579 [files, err, msg] = readdir (dir); |
1476 if (err) | 1580 if (err) |
1477 error ("couldn't read directory %s: %s", dir, msg); | 1581 error ("couldn't read directory %s: %s", dir, msg); |
1478 endif | 1582 endif |
1479 | 1583 |
1480 ## Check for architecture dependent files | 1584 ## Check for architecture dependent files |
1481 arch = getarch(); | 1585 tmpdir = getarchdir (desc); |
1482 tmpdir = fullfile (dir, arch); | |
1483 if (exist (tmpdir, "dir")) | 1586 if (exist (tmpdir, "dir")) |
1484 [files2, err, msg] = readdir (tmpdir); | 1587 [files2, err, msg] = readdir (tmpdir); |
1485 if (err) | 1588 if (err) |
1486 error ("couldn't read directory %s: %s", tmpdir, msg); | 1589 error ("couldn't read directory %s: %s", tmpdir, msg); |
1487 endif | 1590 endif |
1716 idx (end + 1) = idx2; | 1819 idx (end + 1) = idx2; |
1717 endfor | 1820 endfor |
1718 endif | 1821 endif |
1719 | 1822 |
1720 ## Load the packages, but take care of the ordering of dependencies | 1823 ## Load the packages, but take care of the ordering of dependencies |
1721 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst); | 1824 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); |
1722 endfunction | 1825 endfunction |
1723 | 1826 |
1724 function unload_packages (files, handle_deps, local_list, global_list) | 1827 function unload_packages (files, handle_deps, local_list, global_list) |
1725 installed_pkgs_lst = installed_packages (local_list, global_list); | 1828 installed_pkgs_lst = installed_packages (local_list, global_list); |
1726 num_packages = length (installed_pkgs_lst); | 1829 num_packages = length (installed_pkgs_lst); |
1737 p = split_by (path(), pathsep ()); | 1840 p = split_by (path(), pathsep ()); |
1738 | 1841 |
1739 ## unload all | 1842 ## unload all |
1740 if (length (files) == 1 && strcmp (files{1}, "all")) | 1843 if (length (files) == 1 && strcmp (files{1}, "all")) |
1741 dirs = pdirs; | 1844 dirs = pdirs; |
1845 desc = installed_pkgs_lst; | |
1742 ## unload package_name1 ... | 1846 ## unload package_name1 ... |
1743 else | 1847 else |
1744 dirs = {}; | 1848 dirs = {}; |
1849 desc = {}; | |
1745 for i = 1:length (files) | 1850 for i = 1:length (files) |
1746 idx = strcmp (pnames, files{i}); | 1851 idx = strcmp (pnames, files {i}); |
1747 if (! any (idx)) | 1852 if (! any (idx)) |
1748 error ("package %s is not installed", files{i}); | 1853 error ("package %s is not installed", files{i}); |
1749 endif | 1854 endif |
1750 dirs{end+1} = pdirs{idx}; | 1855 dirs {end + 1} = pdirs {idx}; |
1856 desc {end + 1} = installed_pkgs_lst {idx}; | |
1751 endfor | 1857 endfor |
1752 endif | 1858 endif |
1753 | 1859 |
1754 ## Check for architecture dependent directories | 1860 ## Check for architecture dependent directories |
1755 arch = getarch(); | |
1756 archdirs = {}; | 1861 archdirs = {}; |
1757 for i = 1:length (dirs) | 1862 for i = 1:length (dirs) |
1758 tmpdir = fullfile (dirs{i}, arch); | 1863 tmpdir = getarchdir (desc {i}); |
1759 if (exist (tmpdir, "dir")) | 1864 if (exist (tmpdir, "dir")) |
1760 archdirs{end + 1} = dirs{i}; | 1865 archdirs{end + 1} = dirs{i}; |
1761 archdirs{end + 1} = tmpdir; | 1866 archdirs{end + 1} = tmpdir; |
1762 endif | 1867 else |
1763 endfor | 1868 archdirs{end+ 1} = dirs {i}; |
1764 if (length (archdirs) > 0) | 1869 endif |
1765 dirs = archdirs; | 1870 endfor |
1766 endif | |
1767 | 1871 |
1768 ## Unload the packages | 1872 ## Unload the packages |
1769 for i = 1:length (dirs) | 1873 for i = 1:length (archdirs) |
1770 d = dirs{i}; | 1874 d = archdirs{i}; |
1771 idx = strcmp (p, d); | 1875 idx = strcmp (p, d); |
1772 if (any (idx)) | 1876 if (any (idx)) |
1773 rmpath (d); | 1877 rmpath (d); |
1774 ## XXX: We should also check if we need to remove items from EXEC_PATH | 1878 ## XXX: We should also check if we need to remove items from EXEC_PATH |
1775 endif | 1879 endif |
1776 endfor | 1880 endfor |
1777 endfunction | 1881 endfunction |
1778 | 1882 |
1779 function [status_out, msg_out] = rm_rf (dir) | 1883 function [status_out, msg_out] = rm_rf (dir) |
1780 crr = confirm_recursive_rmdir (); | 1884 if (exist (dir)) |
1781 unwind_protect | 1885 crr = confirm_recursive_rmdir (); |
1782 confirm_recursive_rmdir (false); | 1886 unwind_protect |
1783 [status, msg] = rmdir (dir, "s"); | 1887 confirm_recursive_rmdir (false); |
1784 unwind_protect_cleanup | 1888 [status, msg] = rmdir (dir, "s"); |
1785 confirm_recursive_rmdir (crr); | 1889 unwind_protect_cleanup |
1786 end_unwind_protect | 1890 confirm_recursive_rmdir (crr); |
1891 end_unwind_protect | |
1892 else | |
1893 status = 1; | |
1894 msg = ""; | |
1895 endif | |
1787 if (nargout > 0) | 1896 if (nargout > 0) |
1788 status_out = status; | 1897 status_out = status; |
1789 endif | 1898 endif |
1790 if (nargout > 1) | 1899 if (nargout > 1) |
1791 msg_out = msg; | 1900 msg_out = msg; |
1792 endif | 1901 endif |
1793 endfunction | 1902 endfunction |
1794 | 1903 |
1795 function emp = dirempty (nm, ign) | 1904 function emp = dirempty (nm, ign) |
1796 if (nargin < 2) | 1905 if (exist (nm, "dir")) |
1797 ign = {".", ".."}; | 1906 if (nargin < 2) |
1907 ign = {".", ".."}; | |
1908 else | |
1909 ign = [{".", ".."}, ign]; | |
1910 endif | |
1911 l = dir (nm); | |
1912 for i = 1:length (l) | |
1913 found = false; | |
1914 for j = 1:length (ign) | |
1915 if (strcmp (l(i).name, ign{j})) | |
1916 found = true; | |
1917 break; | |
1918 endif | |
1919 endfor | |
1920 if (! found) | |
1921 emp = false; | |
1922 return | |
1923 endif | |
1924 endfor | |
1925 emp = true; | |
1798 else | 1926 else |
1799 ign = [{".", ".."}, ign]; | 1927 emp = true; |
1800 endif | 1928 endif |
1801 l = dir (nm); | |
1802 for i = 1:length (l) | |
1803 found = false; | |
1804 for j = 1:length (ign) | |
1805 if (strcmp (l(i).name, ign{j})) | |
1806 found = true; | |
1807 break; | |
1808 endif | |
1809 endfor | |
1810 if (! found) | |
1811 emp = false; | |
1812 return | |
1813 endif | |
1814 endfor | |
1815 emp = true; | |
1816 endfunction | 1929 endfunction |
1817 | 1930 |
1818 function arch = getarch () | 1931 function arch = getarch () |
1819 persistent _arch = strcat (octave_config_info("canonical_host_type"), ... | 1932 persistent _arch = strcat (octave_config_info("canonical_host_type"), ... |
1820 "-", octave_config_info("api_version")); | 1933 "-", octave_config_info("api_version")); |
1821 arch = _arch; | 1934 arch = _arch; |
1935 endfunction | |
1936 | |
1937 function archprefix = getarchprefix (desc, global_install) | |
1938 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) | |
1939 archprefix = fullfile (octave_config_info ("libexecdir"), "octave", | |
1940 "packages", strcat(desc.name, "-", desc.version)); | |
1941 else | |
1942 archprefix = desc.dir; | |
1943 endif | |
1944 endfunction | |
1945 | |
1946 function archdir = getarchdir (desc) | |
1947 archdir = fullfile (desc.archprefix, getarch()); | |
1948 endfunction | |
1949 | |
1950 function s = issuperuser () | |
1951 if ((ispc () && ! isunix ()) || (geteuid() == 0)) | |
1952 s = true; | |
1953 else | |
1954 s = false; | |
1955 endif | |
1822 endfunction | 1956 endfunction |
1823 | 1957 |
1824 function [status, output] = shell (cmd) | 1958 function [status, output] = shell (cmd) |
1825 persistent have_sh; | 1959 persistent have_sh; |
1826 | 1960 |
1877 endfor | 2011 endfor |
1878 endfor | 2012 endfor |
1879 newdesc(idx) = []; | 2013 newdesc(idx) = []; |
1880 endfunction | 2014 endfunction |
1881 | 2015 |
1882 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst) | 2016 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
2017 global_install) | |
1883 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); | 2018 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); |
1884 arch = getarch (); | |
1885 dirs = {}; | 2019 dirs = {}; |
1886 execpath = EXEC_PATH (); | 2020 execpath = EXEC_PATH (); |
1887 for i = idx; | 2021 for i = idx; |
1888 ndir = installed_pkgs_lst{i}.dir; | 2022 ndir = installed_pkgs_lst{i}.dir; |
1889 dirs {end + 1} = ndir; | 2023 dirs {end + 1} = ndir; |
1890 if (exist (fullfile (dirs{end}, "bin"), "dir")) | 2024 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
1891 execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath); | 2025 execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath); |
1892 endif | 2026 endif |
1893 tmpdir = fullfile (ndir, arch); | 2027 tmpdir = getarchdir (installed_pkgs_lst {i}); |
1894 if (exist (tmpdir, "dir")) | 2028 if (exist (tmpdir, "dir")) |
1895 dirs{end + 1} = tmpdir; | 2029 dirs{end + 1} = tmpdir; |
1896 endif | 2030 endif |
1897 endfor | 2031 endfor |
1898 | 2032 |