Magellan Linux

Annotation of /trunk/mage/usr/lib/mage/mage4.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2840 - (hide annotations) (download) (as text)
Fri Oct 24 08:23:22 2014 UTC (9 years, 6 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 niro 1269 #!/bin/bash
2 niro 226 # Magellan Linux Installer (mage.sh)
3 niro 2268 # $Id$
4 niro 226
5     # default die function
6     die()
7     {
8 niro 2222 xtitleclean
9     mqueryfeature "debug" && echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
10 niro 226 echo -e ${COLRED}"$@"${COLDEFAULT}
11     exit 1
12     }
13    
14     # include all needed files
15 niro 236 [ -f /etc/mage.rc.global ] && \
16     source /etc/mage.rc.global || \
17     die "/etc/mage.rc.global missing"
18 niro 226
19 niro 418 [ -f ${MAGERC} ] && source ${MAGERC} || \
20     die "Your ${MAGERC} is missing. Aborting."
21 niro 232
22 niro 236 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
23     source ${MLIBDIR}/mage4.functions.sh || \
24 niro 232 die "mage functions missing"
25    
26 niro 226 # 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 niro 2273 if [ ! -e ${VIRTUALDB_DEFAULTS} ] &&
36     [[ $1 != update ]] &&
37     [[ $1 != update-rsync ]] &&
38     [[ $1 != update-tarball ]]
39 niro 226 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 niro 295 showversion()
48     {
49 niro 226 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 niro 295 print_usage()
56     {
57 niro 299 #showversion
58     #echo
59 niro 226 echo "Usage: $(basename $0) [option] pkgname ..."
60     echo "Options:"
61 niro 287 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 niro 2273 echo " update - updates the mage-tree via default sync method"
67     echo " update-rsync - updates the mage-tree via rsync"
68 niro 739 echo " update-tarball - updates the mage-tree via a tarball"
69 niro 287 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 niro 2358 echo " pretend-build-prerequisites - prints build prerequisites"
74     echo " install-build-prerequisites - install build prerequisites"
75 niro 2840 echo " pretend-deep-build-prerequisites - prints deep build prerequisites"
76     echo " install-deep-build-prerequisites - install deep build prerequisites"
77 niro 2371 echo " run-preinstall - runs preinstall part of an installed package"
78     echo " run-postinstall - runs postinstall part of an installed package"
79 niro 287 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 niro 1780 echo " print-features - prints all enabled mage-features"
84 niro 287 echo " version - prints version info"
85     echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
86 niro 226 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 niro 295 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
92 niro 226 echo "Overrides stable packages; you can install packages that are marked unstable."
93     echo
94 niro 295 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
95 niro 226 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 niro 1551 # initial unversionized packagename, gets overridden later on
110 niro 226 MAGENAME="$2"
111    
112 niro 1780 if [[ ${METHOD} != upgrade ]] &&
113     [[ ${METHOD} != srcupgrade ]] &&
114     [[ ${METHOD} != uppretend ]] &&
115     [[ ${METHOD} != srcuppretend ]] &&
116     [[ ${METHOD} != update ]] &&
117 niro 2273 [[ ${METHOD} != update-rsync ]] &&
118 niro 1780 [[ ${METHOD} != update-tarball ]] &&
119     [[ ${METHOD} != clean ]] &&
120     [[ ${METHOD} != version ]] &&
121     [[ ${METHOD} != search ]] &&
122     [[ ${METHOD} != regen-mage-tree ]] &&
123     [[ ${METHOD} != print-features ]]
124 niro 230 then
125     [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
126     fi
127 niro 226
128 niro 287 # set PKGDIR and BUILDDIR to MROOT
129     if [[ -n ${MROOT} ]]
130     then
131     PKGDIR=${MROOT}/${PKGDIR}
132     BUILDDIR=${MROOT}/${BUILDDIR}
133     fi
134 niro 226
135 niro 305 # before anything run mage_setup
136     mage_setup || die "error in mage_setup()"
137    
138 niro 1584 # load supported mage features
139     load_mage_features
140    
141 niro 2221 # query debug mode
142     if mqueryfeature "debug"
143     then
144     depwalker_debug="--debug"
145     else
146     depwalker_debug=""
147     fi
148    
149 niro 226 case ${METHOD} in
150     download)
151 niro 2233 have_root_privileges || die "You must be root to run this operation."
152    
153 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
161 niro 226
162 niro 372 # package is masked
163     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
164 niro 370
165 niro 226 # 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 niro 2221 --pbuild ${PBUILD} \
178     ${depwalker_debug})"
179 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
180 niro 230 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
181 niro 226 ;;
182    
183     srcdownload)
184 niro 2233 have_root_privileges || die "You must be root to run this operation."
185    
186 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
194 niro 226
195 niro 372 # package is masked
196     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
197 niro 370
198 niro 226 # 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 niro 2221 --pbuild ${PBUILD} \
211     ${depwalker_debug})"
212 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
213     ;;
214    
215 niro 2840 pretend|srcpretend|pretend-build-prerequisites|pretend-deep-build-prerequisites)
216 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
224 niro 226
225 niro 372 # package is masked
226     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
227 niro 370
228 niro 226 # 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 niro 2221 --pbuild ${PBUILD} \
249     ${depwalker_debug}
250 niro 226 ;;
251    
252 niro 2840 install|install-build-prerequisites|install-deep-build-prerequisites)
253 niro 1541 have_root_privileges || die "You must be root to run this operation."
254    
255 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
263 niro 226
264 niro 372 # package is masked
265     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
266 niro 370
267 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
277 niro 226 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 niro 2221 --pbuild ${PBUILD} \
288     ${depwalker_debug})"
289 niro 226
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 niro 1541 have_root_privileges || die "You must be root to run this operation."
298    
299 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
307 niro 226
308 niro 372 # package is masked
309     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
310 niro 370
311 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
321 niro 226 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 niro 2221 --pbuild ${PBUILD} \
332     ${depwalker_debug})"
333 niro 226
334     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
335     ;;
336    
337     uninstall)
338 niro 1541 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 niro 226 ;;
347    
348 niro 2371 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 niro 230 uppretend|srcuppretend)
360     ${MLIBDIR}/depwalker.sh \
361     --method ${METHOD} \
362     --pcat ${METHOD} \
363     --pname ${METHOD} \
364     --pver ${METHOD} \
365 niro 2221 --pbuild ${METHOD} \
366     ${depwalker_debug}
367 niro 230 ;;
368    
369 niro 247 upgrade)
370 niro 1541 have_root_privileges || die "You must be root to run this operation."
371    
372 niro 230 # 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 niro 2221 --pbuild ${METHOD} \
380     ${depwalker_debug})"
381 niro 230
382 niro 247 # 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 niro 230 ;;
387 niro 236
388 niro 247 srcupgrade)
389 niro 1541 have_root_privileges || die "You must be root to run this operation."
390    
391 niro 247 # 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 niro 2221 --pbuild ${METHOD} \
399     ${depwalker_debug})"
400 niro 247
401     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
402     ;;
403    
404 niro 226 search)
405 niro 236 pkgsearch "${MAGENAME}"
406 niro 226 ;;
407    
408 niro 230 unpack)
409 niro 1541 have_root_privileges || die "You must be root to run this operation."
410    
411 niro 230 # first of all get the right pkg which going to be installed
412     PCAT="$(pname2pcat ${MAGENAME})"
413 niro 226
414 niro 230 # package does not exists
415     [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
416    
417     # source the highest magefile of this pkg
418 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
419 niro 230
420 niro 372 # package is masked
421     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
422 niro 370
423 niro 230 # 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 niro 2221 --pbuild ${PBUILD} \
436     ${depwalker_debug})"
437    
438 niro 230 fetch_packages ${ALLDEPS} || die "fetching packages"
439     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
440     unpack_packages ${ALLDEPS} || die "unpacking packages"
441     ;;
442    
443 niro 226 update)
444 niro 1541 have_root_privileges || die "You must be root to run this operation."
445 niro 2273 # 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 niro 226 syncmage
457     ;;
458    
459 niro 739 update-tarball)
460 niro 1541 have_root_privileges || die "You must be root to run this operation."
461 niro 739 syncmage_tarball
462     ;;
463    
464 niro 226 clean)
465 niro 1541 have_root_privileges || die "You must be root to run this operation."
466 niro 226 cleanpkg
467     ;;
468    
469     version)
470 niro 295 # showversion
471     exit 0
472 niro 226 ;;
473    
474     regen-mage-tree)
475 niro 1541 have_root_privileges || die "You must be root to run this operation."
476    
477 niro 226 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 niro 1780 print-features)
489     mprintfeatures
490     ;;
491    
492 niro 226 *)
493     print_usage
494     ;;
495     esac

Properties

Name Value
svn:executable *