Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *