Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2268 - (show annotations) (download) (as text)
Fri Oct 25 06:48:57 2013 UTC (10 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 13443 byte(s)
-fixed header
1 #!/bin/bash
2 # Magellan Linux Installer (mage.sh)
3 # $Id$
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 have_root_privileges || die "You must be root to run this operation."
143
144 # 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 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
152
153 # package is masked
154 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
155
156 # 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 --pbuild ${PBUILD} \
169 ${depwalker_debug})"
170 fetch_packages ${ALLDEPS} || die "fetching packages"
171 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
172 ;;
173
174 srcdownload)
175 have_root_privileges || die "You must be root to run this operation."
176
177 # 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 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
185
186 # package is masked
187 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
188
189 # 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 --pbuild ${PBUILD} \
202 ${depwalker_debug})"
203 fetch_packages ${ALLDEPS} || die "fetching packages"
204 ;;
205
206 pretend|srcpretend|pretend-build-prerequisites)
207 # 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 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
215
216 # package is masked
217 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
218
219 # 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 --pbuild ${PBUILD} \
240 ${depwalker_debug}
241 ;;
242
243 install|install-build-prerequisites)
244 have_root_privileges || die "You must be root to run this operation."
245
246 # 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 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
254
255 # package is masked
256 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
257
258 # 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 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
268 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 --pbuild ${PBUILD} \
279 ${depwalker_debug})"
280
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 have_root_privileges || die "You must be root to run this operation."
289
290 # 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 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
298
299 # package is masked
300 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
301
302 # 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 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
312 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 --pbuild ${PBUILD} \
323 ${depwalker_debug})"
324
325 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
326 ;;
327
328 uninstall)
329 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 ;;
338
339 uppretend|srcuppretend)
340 ${MLIBDIR}/depwalker.sh \
341 --method ${METHOD} \
342 --pcat ${METHOD} \
343 --pname ${METHOD} \
344 --pver ${METHOD} \
345 --pbuild ${METHOD} \
346 ${depwalker_debug}
347 ;;
348
349 upgrade)
350 have_root_privileges || die "You must be root to run this operation."
351
352 # 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 --pbuild ${METHOD} \
360 ${depwalker_debug})"
361
362 # 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 ;;
367
368 srcupgrade)
369 have_root_privileges || die "You must be root to run this operation."
370
371 # 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 --pbuild ${METHOD} \
379 ${depwalker_debug})"
380
381 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
382 ;;
383
384 search)
385 pkgsearch "${MAGENAME}"
386 ;;
387
388 unpack)
389 have_root_privileges || die "You must be root to run this operation."
390
391 # first of all get the right pkg which going to be installed
392 PCAT="$(pname2pcat ${MAGENAME})"
393
394 # package does not exists
395 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
396
397 # source the highest magefile of this pkg
398 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
399
400 # package is masked
401 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
402
403 # 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 --pbuild ${PBUILD} \
416 ${depwalker_debug})"
417
418 fetch_packages ${ALLDEPS} || die "fetching packages"
419 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
420 unpack_packages ${ALLDEPS} || die "unpacking packages"
421 ;;
422
423 update)
424 have_root_privileges || die "You must be root to run this operation."
425 syncmage
426 ;;
427
428 update-tarball)
429 have_root_privileges || die "You must be root to run this operation."
430 syncmage_tarball
431 ;;
432
433 clean)
434 have_root_privileges || die "You must be root to run this operation."
435 cleanpkg
436 ;;
437
438 version)
439 # showversion
440 exit 0
441 ;;
442
443 regen-mage-tree)
444 have_root_privileges || die "You must be root to run this operation."
445
446 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 print-features)
458 mprintfeatures
459 ;;
460
461 *)
462 print_usage
463 ;;
464 esac

Properties

Name Value
svn:executable *