Contents of /trunk/mage/usr/lib/mage/mage4.sh
Parent Directory | Revision Log
Revision 2840 -
(show annotations)
(download)
(as text)
Fri Oct 24 08:23:22 2014 UTC (9 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 14665 byte(s)
Fri Oct 24 08:23:22 2014 UTC (9 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 14665 byte(s)
-support deep and simple build-prerequisites, which reduces the overhead as they only respect the sdepend of the target mage/smagefile and not from all deps
1 | #!/bin/bash |
2 | # Magellan Linux Installer (mage.sh) |
3 | # $Id$ |
4 | |
5 | # default die function |
6 | die() |
7 | { |
8 | xtitleclean |
9 | mqueryfeature "debug" && echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
10 | echo -e ${COLRED}"$@"${COLDEFAULT} |
11 | exit 1 |
12 | } |
13 | |
14 | # include all needed files |
15 | [ -f /etc/mage.rc.global ] && \ |
16 | source /etc/mage.rc.global || \ |
17 | die "/etc/mage.rc.global missing" |
18 | |
19 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
20 | die "Your ${MAGERC} is missing. Aborting." |
21 | |
22 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
23 | source ${MLIBDIR}/mage4.functions.sh || \ |
24 | die "mage functions missing" |
25 | |
26 | # export default path |
27 | export PATH="${PATH}:${MLIBDIR}" |
28 | |
29 | # export the default C locale |
30 | export LC_ALL=C |
31 | |
32 | # sanity checks |
33 | [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} |
34 | |
35 | if [ ! -e ${VIRTUALDB_DEFAULTS} ] && |
36 | [[ $1 != update ]] && |
37 | [[ $1 != update-rsync ]] && |
38 | [[ $1 != update-tarball ]] |
39 | then |
40 | echo |
41 | echo "Please choose an profile from the mage tree." |
42 | echo "ln -snf ${MAGEDIR}/profiles/profilename /etc/mage-profile" |
43 | exit 1 |
44 | fi |
45 | |
46 | # default messages |
47 | showversion() |
48 | { |
49 | local MAGEVERSION="$(< ${MLIBDIR}/version)" |
50 | |
51 | echo -en "Magellan Package Manager v${MAGEVERSION} " |
52 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
53 | } |
54 | |
55 | print_usage() |
56 | { |
57 | #showversion |
58 | #echo |
59 | echo "Usage: $(basename $0) [option] pkgname ..." |
60 | echo "Options:" |
61 | echo " pretend - pretends dependencies of a package" |
62 | echo " srcpretend - pretends dependencies of a package (build from source)" |
63 | echo " install - installs a package" |
64 | echo " srcinstall - installs a package from source" |
65 | echo " uninstall - removes a package" |
66 | echo " update - updates the mage-tree via default sync method" |
67 | echo " update-rsync - updates the mage-tree via rsync" |
68 | echo " update-tarball - updates the mage-tree via a tarball" |
69 | echo " uppretend - pretend dependencies for a system upgrade" |
70 | echo " upgrade - runs a complete system upgrade" |
71 | echo " srcuppretend - pretend dependencies for a system upgrade from source" |
72 | echo " srcupgrade - runs a complete system upgrade from source" |
73 | echo " pretend-build-prerequisites - prints build prerequisites" |
74 | echo " install-build-prerequisites - install build prerequisites" |
75 | echo " pretend-deep-build-prerequisites - prints deep build prerequisites" |
76 | echo " install-deep-build-prerequisites - install deep build prerequisites" |
77 | echo " run-preinstall - runs preinstall part of an installed package" |
78 | echo " run-postinstall - runs postinstall part of an installed package" |
79 | echo " search - searches mage-tree for a package" |
80 | echo " clean - removes *all* downloaded packages" |
81 | echo " unpack - unpacks *all* needed package for 'foo'" |
82 | echo " download - downloads *all* needed packages for 'foo'" |
83 | echo " print-features - prints all enabled mage-features" |
84 | echo " version - prints version info" |
85 | echo " regen-mage-tree - regenerates the whole mage database (for devs only)" |
86 | echo |
87 | echo "Other options:" |
88 | # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE" |
89 | # echo "Builds a Package with its dependencies, but won't install anything." |
90 | # echo |
91 | echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE" |
92 | echo "Overrides stable packages; you can install packages that are marked unstable." |
93 | echo |
94 | echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE" |
95 | echo "Overrides stable packages; you can install packages that are marked testing." |
96 | echo |
97 | echo "NOCOLORS=true $(basename $0) [src]install PACKAGE" |
98 | echo "Disables all colors in the messages." |
99 | echo |
100 | } |
101 | |
102 | |
103 | showversion |
104 | echo |
105 | |
106 | # install method |
107 | METHOD="$1" |
108 | |
109 | # initial unversionized packagename, gets overridden later on |
110 | MAGENAME="$2" |
111 | |
112 | if [[ ${METHOD} != upgrade ]] && |
113 | [[ ${METHOD} != srcupgrade ]] && |
114 | [[ ${METHOD} != uppretend ]] && |
115 | [[ ${METHOD} != srcuppretend ]] && |
116 | [[ ${METHOD} != update ]] && |
117 | [[ ${METHOD} != update-rsync ]] && |
118 | [[ ${METHOD} != update-tarball ]] && |
119 | [[ ${METHOD} != clean ]] && |
120 | [[ ${METHOD} != version ]] && |
121 | [[ ${METHOD} != search ]] && |
122 | [[ ${METHOD} != regen-mage-tree ]] && |
123 | [[ ${METHOD} != print-features ]] |
124 | then |
125 | [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 |
126 | fi |
127 | |
128 | # set PKGDIR and BUILDDIR to MROOT |
129 | if [[ -n ${MROOT} ]] |
130 | then |
131 | PKGDIR=${MROOT}/${PKGDIR} |
132 | BUILDDIR=${MROOT}/${BUILDDIR} |
133 | fi |
134 | |
135 | # before anything run mage_setup |
136 | mage_setup || die "error in mage_setup()" |
137 | |
138 | # load supported mage features |
139 | load_mage_features |
140 | |
141 | # query debug mode |
142 | if mqueryfeature "debug" |
143 | then |
144 | depwalker_debug="--debug" |
145 | else |
146 | depwalker_debug="" |
147 | fi |
148 | |
149 | case ${METHOD} in |
150 | download) |
151 | have_root_privileges || die "You must be root to run this operation." |
152 | |
153 | # first of all get the right pkg which going to be installed |
154 | PCAT="$(pname2pcat ${MAGENAME})" |
155 | |
156 | # package does not exists |
157 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
158 | |
159 | # source the highest magefile of this pkg |
160 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
161 | |
162 | # package is masked |
163 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
164 | |
165 | # convert PKGNAME to PNAME/PVER/PBUILD |
166 | # we're working *only* with these three vars from here on |
167 | PNAME="$(pkgname2pname ${PKGNAME})" |
168 | PVER="$(pkgname2pver ${PKGNAME})" |
169 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
170 | |
171 | # get all dependencies of this package |
172 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
173 | --method install \ |
174 | --pcat ${PCAT} \ |
175 | --pname ${PNAME} \ |
176 | --pver ${PVER} \ |
177 | --pbuild ${PBUILD} \ |
178 | ${depwalker_debug})" |
179 | fetch_packages ${ALLDEPS} || die "fetching packages" |
180 | md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
181 | ;; |
182 | |
183 | srcdownload) |
184 | have_root_privileges || die "You must be root to run this operation." |
185 | |
186 | # first of all get the right pkg which going to be installed |
187 | PCAT="$(pname2pcat ${MAGENAME})" |
188 | |
189 | # package does not exists |
190 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
191 | |
192 | # source the highest magefile of this pkg |
193 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
194 | |
195 | # package is masked |
196 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
197 | |
198 | # convert PKGNAME to PNAME/PVER/PBUILD |
199 | # we're working *only* with these three vars from here on |
200 | PNAME="$(pkgname2pname ${PKGNAME})" |
201 | PVER="$(pkgname2pver ${PKGNAME})" |
202 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
203 | |
204 | # get all dependencies of this package |
205 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
206 | --method srcinstall \ |
207 | --pcat ${PCAT} \ |
208 | --pname ${PNAME} \ |
209 | --pver ${PVER} \ |
210 | --pbuild ${PBUILD} \ |
211 | ${depwalker_debug})" |
212 | fetch_packages ${ALLDEPS} || die "fetching packages" |
213 | ;; |
214 | |
215 | pretend|srcpretend|pretend-build-prerequisites|pretend-deep-build-prerequisites) |
216 | # first of all get the right pkg which going to be installed |
217 | PCAT="$(pname2pcat ${MAGENAME})" |
218 | |
219 | # package does not exists |
220 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
221 | |
222 | # source the highest magefile of this pkg |
223 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
224 | |
225 | # package is masked |
226 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
227 | |
228 | # convert PKGNAME to PNAME/PVER/PBUILD |
229 | # we're working *only* with these three vars from here on |
230 | PNAME="$(pkgname2pname ${PKGNAME})" |
231 | PVER="$(pkgname2pver ${PKGNAME})" |
232 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
233 | |
234 | # abort if already installed |
235 | if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
236 | then |
237 | echo -en "Package " |
238 | echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
239 | echo -e " already installed." |
240 | exit 3 |
241 | fi |
242 | # get all dependencies of this package |
243 | ${MLIBDIR}/depwalker.sh \ |
244 | --method ${METHOD} \ |
245 | --pcat ${PCAT} \ |
246 | --pname ${PNAME} \ |
247 | --pver ${PVER} \ |
248 | --pbuild ${PBUILD} \ |
249 | ${depwalker_debug} |
250 | ;; |
251 | |
252 | install|install-build-prerequisites|install-deep-build-prerequisites) |
253 | have_root_privileges || die "You must be root to run this operation." |
254 | |
255 | # first of all get the right pkg which going to be installed |
256 | PCAT="$(pname2pcat ${MAGENAME})" |
257 | |
258 | # package does not exists |
259 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
260 | |
261 | # source the highest magefile of this pkg |
262 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
263 | |
264 | # package is masked |
265 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
266 | |
267 | # convert PKGNAME to PNAME/PVER/PBUILD |
268 | # we're working *only* with these three vars from here on |
269 | PNAME="$(pkgname2pname ${PKGNAME})" |
270 | PVER="$(pkgname2pver ${PKGNAME})" |
271 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
272 | |
273 | if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
274 | then |
275 | echo -en "Package " |
276 | echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
277 | echo -e " already installed." |
278 | exit 3 |
279 | fi |
280 | |
281 | # get all dependencies of this package |
282 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
283 | --method ${METHOD} \ |
284 | --pcat ${PCAT} \ |
285 | --pname ${PNAME} \ |
286 | --pver ${PVER} \ |
287 | --pbuild ${PBUILD} \ |
288 | ${depwalker_debug})" |
289 | |
290 | # first fetch all packages |
291 | fetch_packages ${ALLDEPS} || die "fetching packages" |
292 | md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
293 | install_packages ${ALLDEPS} || die "installing packages" |
294 | ;; |
295 | |
296 | srcinstall) |
297 | have_root_privileges || die "You must be root to run this operation." |
298 | |
299 | # first of all get the right pkg which going to be installed |
300 | PCAT="$(pname2pcat ${MAGENAME})" |
301 | |
302 | # package does not exists |
303 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
304 | |
305 | # source the highest magefile of this pkg |
306 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
307 | |
308 | # package is masked |
309 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
310 | |
311 | # convert PKGNAME to PNAME/PVER/PBUILD |
312 | # we're working *only* with these three vars from here on |
313 | PNAME="$(pkgname2pname ${PKGNAME})" |
314 | PVER="$(pkgname2pver ${PKGNAME})" |
315 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
316 | |
317 | if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
318 | then |
319 | echo -en "Package " |
320 | echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
321 | echo -e " already installed." |
322 | exit 3 |
323 | fi |
324 | |
325 | # get all dependencies of this package |
326 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
327 | --method ${METHOD} \ |
328 | --pcat ${PCAT} \ |
329 | --pname ${PNAME} \ |
330 | --pver ${PVER} \ |
331 | --pbuild ${PBUILD} \ |
332 | ${depwalker_debug})" |
333 | |
334 | install_packages --src-install ${ALLDEPS} || die "src-installing packages" |
335 | ;; |
336 | |
337 | uninstall) |
338 | have_root_privileges || die "You must be root to run this operation." |
339 | |
340 | ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
341 | if [ -z "${ALLDEPS}" ] |
342 | then |
343 | die "No package installed named '${MAGENAME}'." |
344 | fi |
345 | uninstall_packages ${ALLDEPS} |
346 | ;; |
347 | |
348 | run-preinstall|run-postinstall) |
349 | have_root_privileges || die "You must be root to run this operation." |
350 | |
351 | ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
352 | if [ -z "${ALLDEPS}" ] |
353 | then |
354 | die "No package installed named '${MAGENAME}'." |
355 | fi |
356 | rerun_pkgfunctions --method "${METHOD//run-}" ${ALLDEPS} |
357 | ;; |
358 | |
359 | uppretend|srcuppretend) |
360 | ${MLIBDIR}/depwalker.sh \ |
361 | --method ${METHOD} \ |
362 | --pcat ${METHOD} \ |
363 | --pname ${METHOD} \ |
364 | --pver ${METHOD} \ |
365 | --pbuild ${METHOD} \ |
366 | ${depwalker_debug} |
367 | ;; |
368 | |
369 | upgrade) |
370 | have_root_privileges || die "You must be root to run this operation." |
371 | |
372 | # get all dependencies of *all* installed packages |
373 | # fake pcat,pname,pver,pbuild ... |
374 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
375 | --method ${METHOD} \ |
376 | --pcat ${METHOD} \ |
377 | --pname ${METHOD} \ |
378 | --pver ${METHOD} \ |
379 | --pbuild ${METHOD} \ |
380 | ${depwalker_debug})" |
381 | |
382 | # first fetch all packages |
383 | fetch_packages ${ALLDEPS} || die "fetching packages" |
384 | md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
385 | install_packages ${ALLDEPS} || die "installing packages" |
386 | ;; |
387 | |
388 | srcupgrade) |
389 | have_root_privileges || die "You must be root to run this operation." |
390 | |
391 | # get all dependencies of *all* installed packages |
392 | # fake pcat,pname,pver,pbuild ... |
393 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
394 | --method ${METHOD} \ |
395 | --pcat ${METHOD} \ |
396 | --pname ${METHOD} \ |
397 | --pver ${METHOD} \ |
398 | --pbuild ${METHOD} \ |
399 | ${depwalker_debug})" |
400 | |
401 | install_packages --src-install ${ALLDEPS} || die "src-installing packages" |
402 | ;; |
403 | |
404 | search) |
405 | pkgsearch "${MAGENAME}" |
406 | ;; |
407 | |
408 | unpack) |
409 | have_root_privileges || die "You must be root to run this operation." |
410 | |
411 | # first of all get the right pkg which going to be installed |
412 | PCAT="$(pname2pcat ${MAGENAME})" |
413 | |
414 | # package does not exists |
415 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
416 | |
417 | # source the highest magefile of this pkg |
418 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
419 | |
420 | # package is masked |
421 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
422 | |
423 | # convert PKGNAME to PNAME/PVER/PBUILD |
424 | # we're working *only* with these three vars from here on |
425 | PNAME="$(pkgname2pname ${PKGNAME})" |
426 | PVER="$(pkgname2pver ${PKGNAME})" |
427 | PBUILD="$(pkgname2pbuild ${PKGNAME})" |
428 | |
429 | # get all dependencies of this package |
430 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
431 | --method install \ |
432 | --pcat ${PCAT} \ |
433 | --pname ${PNAME} \ |
434 | --pver ${PVER} \ |
435 | --pbuild ${PBUILD} \ |
436 | ${depwalker_debug})" |
437 | |
438 | fetch_packages ${ALLDEPS} || die "fetching packages" |
439 | md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
440 | unpack_packages ${ALLDEPS} || die "unpacking packages" |
441 | ;; |
442 | |
443 | update) |
444 | have_root_privileges || die "You must be root to run this operation." |
445 | # default to tarball |
446 | [[ -z ${MAGE_UPDATE_METHOD} ]] && MAGE_UPDATE_METHOD="tarball" |
447 | case ${MAGE_UPDATE_METHOD} in |
448 | rsync) syncmage ;; |
449 | tarball) syncmage_tarball ;; |
450 | *) die "Unknown MAGE_UPDATE_METHOD defined." ;; |
451 | esac |
452 | ;; |
453 | |
454 | update-rsync) |
455 | have_root_privileges || die "You must be root to run this operation." |
456 | syncmage |
457 | ;; |
458 | |
459 | update-tarball) |
460 | have_root_privileges || die "You must be root to run this operation." |
461 | syncmage_tarball |
462 | ;; |
463 | |
464 | clean) |
465 | have_root_privileges || die "You must be root to run this operation." |
466 | cleanpkg |
467 | ;; |
468 | |
469 | version) |
470 | # showversion |
471 | exit 0 |
472 | ;; |
473 | |
474 | regen-mage-tree) |
475 | have_root_privileges || die "You must be root to run this operation." |
476 | |
477 | if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] |
478 | then |
479 | echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos." |
480 | exit 1 |
481 | fi |
482 | for i in $(find ${SMAGESCRIPTSDIR} -type f -name "*.smage2") |
483 | do |
484 | smage2 only-regen-tree "${i}" |
485 | done |
486 | ;; |
487 | |
488 | print-features) |
489 | mprintfeatures |
490 | ;; |
491 | |
492 | *) |
493 | print_usage |
494 | ;; |
495 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |