Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *