Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2222 - (show annotations) (download) (as text)
Wed Oct 16 07:41:04 2013 UTC (10 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 13403 byte(s)
die(): only print debug infos on request and always clean the xtitles
1 #!/bin/bash
2 # Magellan Linux Installer (mage.sh)
3 # $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
5 # default die function
6 die()
7 {
8 xtitleclean
9 mqueryfeature "debug" && echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
10 echo -e ${COLRED}"$@"${COLDEFAULT}
11 exit 1
12 }
13
14 # include all needed files
15 [ -f /etc/mage.rc.global ] && \
16 source /etc/mage.rc.global || \
17 die "/etc/mage.rc.global missing"
18
19 [ -f ${MAGERC} ] && source ${MAGERC} || \
20 die "Your ${MAGERC} is missing. Aborting."
21
22 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
23 source ${MLIBDIR}/mage4.functions.sh || \
24 die "mage functions missing"
25
26 # 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 if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]]
36 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 showversion()
45 {
46 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 print_usage()
53 {
54 #showversion
55 #echo
56 echo "Usage: $(basename $0) [option] pkgname ..."
57 echo "Options:"
58 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 echo " update - updates the mage-tree via rsync"
64 echo " update-tarball - updates the mage-tree via a tarball"
65 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 echo " pretend-build-prerequisites"
70 echo " install-build-prerequisites"
71 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 echo " print-features - prints all enabled mage-features"
76 echo " version - prints version info"
77 echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
78 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 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
84 echo "Overrides stable packages; you can install packages that are marked unstable."
85 echo
86 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
87 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 # initial unversionized packagename, gets overridden later on
102 MAGENAME="$2"
103
104 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 then
116 [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
117 fi
118
119 # set PKGDIR and BUILDDIR to MROOT
120 if [[ -n ${MROOT} ]]
121 then
122 PKGDIR=${MROOT}/${PKGDIR}
123 BUILDDIR=${MROOT}/${BUILDDIR}
124 fi
125
126 # before anything run mage_setup
127 mage_setup || die "error in mage_setup()"
128
129 # load supported mage features
130 load_mage_features
131
132 # query debug mode
133 if mqueryfeature "debug"
134 then
135 depwalker_debug="--debug"
136 else
137 depwalker_debug=""
138 fi
139
140 case ${METHOD} in
141 download)
142 # first of all get the right pkg which going to be installed
143 PCAT="$(pname2pcat ${MAGENAME})"
144
145 # package does not exists
146 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
147
148 # source the highest magefile of this pkg
149 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
150
151 # package is masked
152 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
153
154 # convert PKGNAME to PNAME/PVER/PBUILD
155 # we're working *only* with these three vars from here on
156 PNAME="$(pkgname2pname ${PKGNAME})"
157 PVER="$(pkgname2pver ${PKGNAME})"
158 PBUILD="$(pkgname2pbuild ${PKGNAME})"
159
160 # get all dependencies of this package
161 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
162 --method install \
163 --pcat ${PCAT} \
164 --pname ${PNAME} \
165 --pver ${PVER} \
166 --pbuild ${PBUILD} \
167 ${depwalker_debug})"
168 fetch_packages ${ALLDEPS} || die "fetching packages"
169 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
170 ;;
171
172 srcdownload)
173 # first of all get the right pkg which going to be installed
174 PCAT="$(pname2pcat ${MAGENAME})"
175
176 # package does not exists
177 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
178
179 # source the highest magefile of this pkg
180 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
181
182 # package is masked
183 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
184
185 # convert PKGNAME to PNAME/PVER/PBUILD
186 # we're working *only* with these three vars from here on
187 PNAME="$(pkgname2pname ${PKGNAME})"
188 PVER="$(pkgname2pver ${PKGNAME})"
189 PBUILD="$(pkgname2pbuild ${PKGNAME})"
190
191 # get all dependencies of this package
192 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
193 --method srcinstall \
194 --pcat ${PCAT} \
195 --pname ${PNAME} \
196 --pver ${PVER} \
197 --pbuild ${PBUILD} \
198 ${depwalker_debug})"
199 fetch_packages ${ALLDEPS} || die "fetching packages"
200 ;;
201
202 pretend|srcpretend|pretend-build-prerequisites)
203 # first of all get the right pkg which going to be installed
204 PCAT="$(pname2pcat ${MAGENAME})"
205
206 # package does not exists
207 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
208
209 # source the highest magefile of this pkg
210 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
211
212 # package is masked
213 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
214
215 # convert PKGNAME to PNAME/PVER/PBUILD
216 # we're working *only* with these three vars from here on
217 PNAME="$(pkgname2pname ${PKGNAME})"
218 PVER="$(pkgname2pver ${PKGNAME})"
219 PBUILD="$(pkgname2pbuild ${PKGNAME})"
220
221 # abort if already installed
222 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
223 then
224 echo -en "Package "
225 echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
226 echo -e " already installed."
227 exit 3
228 fi
229 # get all dependencies of this package
230 ${MLIBDIR}/depwalker.sh \
231 --method ${METHOD} \
232 --pcat ${PCAT} \
233 --pname ${PNAME} \
234 --pver ${PVER} \
235 --pbuild ${PBUILD} \
236 ${depwalker_debug}
237 ;;
238
239 install|install-build-prerequisites)
240 have_root_privileges || die "You must be root to run this operation."
241
242 # first of all get the right pkg which going to be installed
243 PCAT="$(pname2pcat ${MAGENAME})"
244
245 # package does not exists
246 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
247
248 # source the highest magefile of this pkg
249 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
250
251 # package is masked
252 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
253
254 # convert PKGNAME to PNAME/PVER/PBUILD
255 # we're working *only* with these three vars from here on
256 PNAME="$(pkgname2pname ${PKGNAME})"
257 PVER="$(pkgname2pver ${PKGNAME})"
258 PBUILD="$(pkgname2pbuild ${PKGNAME})"
259
260 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
261 then
262 echo -en "Package "
263 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
264 echo -e " already installed."
265 exit 3
266 fi
267
268 # get all dependencies of this package
269 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
270 --method ${METHOD} \
271 --pcat ${PCAT} \
272 --pname ${PNAME} \
273 --pver ${PVER} \
274 --pbuild ${PBUILD} \
275 ${depwalker_debug})"
276
277 # first fetch all packages
278 fetch_packages ${ALLDEPS} || die "fetching packages"
279 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
280 install_packages ${ALLDEPS} || die "installing packages"
281 ;;
282
283 srcinstall)
284 have_root_privileges || die "You must be root to run this operation."
285
286 # first of all get the right pkg which going to be installed
287 PCAT="$(pname2pcat ${MAGENAME})"
288
289 # package does not exists
290 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
291
292 # source the highest magefile of this pkg
293 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
294
295 # package is masked
296 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
297
298 # convert PKGNAME to PNAME/PVER/PBUILD
299 # we're working *only* with these three vars from here on
300 PNAME="$(pkgname2pname ${PKGNAME})"
301 PVER="$(pkgname2pver ${PKGNAME})"
302 PBUILD="$(pkgname2pbuild ${PKGNAME})"
303
304 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
305 then
306 echo -en "Package "
307 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
308 echo -e " already installed."
309 exit 3
310 fi
311
312 # get all dependencies of this package
313 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
314 --method ${METHOD} \
315 --pcat ${PCAT} \
316 --pname ${PNAME} \
317 --pver ${PVER} \
318 --pbuild ${PBUILD} \
319 ${depwalker_debug})"
320
321 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
322 ;;
323
324 uninstall)
325 have_root_privileges || die "You must be root to run this operation."
326
327 ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"
328 if [ -z "${ALLDEPS}" ]
329 then
330 die "No package installed named '${MAGENAME}'."
331 fi
332 uninstall_packages ${ALLDEPS}
333 ;;
334
335 uppretend|srcuppretend)
336 ${MLIBDIR}/depwalker.sh \
337 --method ${METHOD} \
338 --pcat ${METHOD} \
339 --pname ${METHOD} \
340 --pver ${METHOD} \
341 --pbuild ${METHOD} \
342 ${depwalker_debug}
343 ;;
344
345 upgrade)
346 have_root_privileges || die "You must be root to run this operation."
347
348 # get all dependencies of *all* installed packages
349 # fake pcat,pname,pver,pbuild ...
350 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
351 --method ${METHOD} \
352 --pcat ${METHOD} \
353 --pname ${METHOD} \
354 --pver ${METHOD} \
355 --pbuild ${METHOD} \
356 ${depwalker_debug})"
357
358 # first fetch all packages
359 fetch_packages ${ALLDEPS} || die "fetching packages"
360 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
361 install_packages ${ALLDEPS} || die "installing packages"
362 ;;
363
364 srcupgrade)
365 have_root_privileges || die "You must be root to run this operation."
366
367 # get all dependencies of *all* installed packages
368 # fake pcat,pname,pver,pbuild ...
369 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
370 --method ${METHOD} \
371 --pcat ${METHOD} \
372 --pname ${METHOD} \
373 --pver ${METHOD} \
374 --pbuild ${METHOD} \
375 ${depwalker_debug})"
376
377 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
378 ;;
379
380 search)
381 pkgsearch "${MAGENAME}"
382 ;;
383
384 unpack)
385 have_root_privileges || die "You must be root to run this operation."
386
387 # first of all get the right pkg which going to be installed
388 PCAT="$(pname2pcat ${MAGENAME})"
389
390 # package does not exists
391 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
392
393 # source the highest magefile of this pkg
394 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
395
396 # package is masked
397 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
398
399 # convert PKGNAME to PNAME/PVER/PBUILD
400 # we're working *only* with these three vars from here on
401 PNAME="$(pkgname2pname ${PKGNAME})"
402 PVER="$(pkgname2pver ${PKGNAME})"
403 PBUILD="$(pkgname2pbuild ${PKGNAME})"
404
405 # get all dependencies of this package
406 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
407 --method install \
408 --pcat ${PCAT} \
409 --pname ${PNAME} \
410 --pver ${PVER} \
411 --pbuild ${PBUILD} \
412 ${depwalker_debug})"
413
414 fetch_packages ${ALLDEPS} || die "fetching packages"
415 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
416 unpack_packages ${ALLDEPS} || die "unpacking packages"
417 ;;
418
419 update)
420 have_root_privileges || die "You must be root to run this operation."
421 syncmage
422 ;;
423
424 update-tarball)
425 have_root_privileges || die "You must be root to run this operation."
426 syncmage_tarball
427 ;;
428
429 clean)
430 have_root_privileges || die "You must be root to run this operation."
431 cleanpkg
432 ;;
433
434 version)
435 # showversion
436 exit 0
437 ;;
438
439 regen-mage-tree)
440 have_root_privileges || die "You must be root to run this operation."
441
442 if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]
443 then
444 echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos."
445 exit 1
446 fi
447 for i in $(find ${SMAGESCRIPTSDIR} -type f -name "*.smage2")
448 do
449 smage2 only-regen-tree "${i}"
450 done
451 ;;
452
453 print-features)
454 mprintfeatures
455 ;;
456
457 *)
458 print_usage
459 ;;
460 esac

Properties

Name Value
svn:executable *