Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *