Magellan Linux

Annotation of /branches/mage-next/usr/lib/mage/mage4.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2371 - (hide annotations) (download) (as text)
Mon Jan 6 14:09:10 2014 UTC (10 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/mage4.sh
File MIME type: application/x-sh
File size: 14440 byte(s)
-introduce rerun_pkgfunctions() and let the user re-run preinstall|postinstall parts of an installed package
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 2371 echo " run-preinstall - runs preinstall part of an installed package"
76     echo " run-postinstall - runs postinstall part of an installed package"
77 niro 287 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 niro 1780 echo " print-features - prints all enabled mage-features"
82 niro 287 echo " version - prints version info"
83     echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
84 niro 226 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 niro 295 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
90 niro 226 echo "Overrides stable packages; you can install packages that are marked unstable."
91     echo
92 niro 295 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
93 niro 226 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 niro 1551 # initial unversionized packagename, gets overridden later on
108 niro 226 MAGENAME="$2"
109    
110 niro 1780 if [[ ${METHOD} != upgrade ]] &&
111     [[ ${METHOD} != srcupgrade ]] &&
112     [[ ${METHOD} != uppretend ]] &&
113     [[ ${METHOD} != srcuppretend ]] &&
114     [[ ${METHOD} != update ]] &&
115 niro 2273 [[ ${METHOD} != update-rsync ]] &&
116 niro 1780 [[ ${METHOD} != update-tarball ]] &&
117     [[ ${METHOD} != clean ]] &&
118     [[ ${METHOD} != version ]] &&
119     [[ ${METHOD} != search ]] &&
120     [[ ${METHOD} != regen-mage-tree ]] &&
121     [[ ${METHOD} != print-features ]]
122 niro 230 then
123     [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
124     fi
125 niro 226
126 niro 287 # set PKGDIR and BUILDDIR to MROOT
127     if [[ -n ${MROOT} ]]
128     then
129     PKGDIR=${MROOT}/${PKGDIR}
130     BUILDDIR=${MROOT}/${BUILDDIR}
131     fi
132 niro 226
133 niro 305 # before anything run mage_setup
134     mage_setup || die "error in mage_setup()"
135    
136 niro 1584 # load supported mage features
137     load_mage_features
138    
139 niro 2221 # query debug mode
140     if mqueryfeature "debug"
141     then
142     depwalker_debug="--debug"
143     else
144     depwalker_debug=""
145     fi
146    
147 niro 226 case ${METHOD} in
148     download)
149 niro 2233 have_root_privileges || die "You must be root to run this operation."
150    
151 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
159 niro 226
160 niro 372 # package is masked
161     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
162 niro 370
163 niro 226 # 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 niro 2221 --pbuild ${PBUILD} \
176     ${depwalker_debug})"
177 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
178 niro 230 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
179 niro 226 ;;
180    
181     srcdownload)
182 niro 2233 have_root_privileges || die "You must be root to run this operation."
183    
184 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
192 niro 226
193 niro 372 # package is masked
194     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
195 niro 370
196 niro 226 # 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 niro 2221 --pbuild ${PBUILD} \
209     ${depwalker_debug})"
210 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
211     ;;
212    
213 niro 2210 pretend|srcpretend|pretend-build-prerequisites)
214 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
222 niro 226
223 niro 372 # package is masked
224     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
225 niro 370
226 niro 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 niro 2221 --pbuild ${PBUILD} \
247     ${depwalker_debug}
248 niro 226 ;;
249    
250 niro 2210 install|install-build-prerequisites)
251 niro 1541 have_root_privileges || die "You must be root to run this operation."
252    
253 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
261 niro 226
262 niro 372 # package is masked
263     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
264 niro 370
265 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
275 niro 226 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 niro 2221 --pbuild ${PBUILD} \
286     ${depwalker_debug})"
287 niro 226
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 niro 1541 have_root_privileges || die "You must be root to run this operation."
296    
297 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
305 niro 226
306 niro 372 # package is masked
307     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
308 niro 370
309 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
319 niro 226 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 niro 2221 --pbuild ${PBUILD} \
330     ${depwalker_debug})"
331 niro 226
332     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
333     ;;
334    
335     uninstall)
336 niro 1541 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 niro 226 ;;
345    
346 niro 2371 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 niro 230 uppretend|srcuppretend)
358     ${MLIBDIR}/depwalker.sh \
359     --method ${METHOD} \
360     --pcat ${METHOD} \
361     --pname ${METHOD} \
362     --pver ${METHOD} \
363 niro 2221 --pbuild ${METHOD} \
364     ${depwalker_debug}
365 niro 230 ;;
366    
367 niro 247 upgrade)
368 niro 1541 have_root_privileges || die "You must be root to run this operation."
369    
370 niro 230 # 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 niro 2221 --pbuild ${METHOD} \
378     ${depwalker_debug})"
379 niro 230
380 niro 247 # 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 niro 230 ;;
385 niro 236
386 niro 247 srcupgrade)
387 niro 1541 have_root_privileges || die "You must be root to run this operation."
388    
389 niro 247 # 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 niro 2221 --pbuild ${METHOD} \
397     ${depwalker_debug})"
398 niro 247
399     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
400     ;;
401    
402 niro 226 search)
403 niro 236 pkgsearch "${MAGENAME}"
404 niro 226 ;;
405    
406 niro 230 unpack)
407 niro 1541 have_root_privileges || die "You must be root to run this operation."
408    
409 niro 230 # first of all get the right pkg which going to be installed
410     PCAT="$(pname2pcat ${MAGENAME})"
411 niro 226
412 niro 230 # package does not exists
413     [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
414    
415     # source the highest magefile of this pkg
416 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
417 niro 230
418 niro 372 # package is masked
419     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
420 niro 370
421 niro 230 # 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 niro 2221 --pbuild ${PBUILD} \
434     ${depwalker_debug})"
435    
436 niro 230 fetch_packages ${ALLDEPS} || die "fetching packages"
437     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
438     unpack_packages ${ALLDEPS} || die "unpacking packages"
439     ;;
440    
441 niro 226 update)
442 niro 1541 have_root_privileges || die "You must be root to run this operation."
443 niro 2273 # 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 niro 226 syncmage
455     ;;
456    
457 niro 739 update-tarball)
458 niro 1541 have_root_privileges || die "You must be root to run this operation."
459 niro 739 syncmage_tarball
460     ;;
461    
462 niro 226 clean)
463 niro 1541 have_root_privileges || die "You must be root to run this operation."
464 niro 226 cleanpkg
465     ;;
466    
467     version)
468 niro 295 # showversion
469     exit 0
470 niro 226 ;;
471    
472     regen-mage-tree)
473 niro 1541 have_root_privileges || die "You must be root to run this operation."
474    
475 niro 226 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 niro 1780 print-features)
487     mprintfeatures
488     ;;
489    
490 niro 226 *)
491     print_usage
492     ;;
493     esac

Properties

Name Value
svn:executable *