Magellan Linux

Contents of /branches/mage-next/src/mage.in

Parent Directory Parent Directory | Revision Log Revision Log


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