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