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