Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2617 - (hide annotations) (download)
Tue Mar 4 15:31:43 2014 UTC (10 years, 2 months ago) by niro
File size: 14042 byte(s)
-removed functions provided by common.functions.sh
1 niro 1269 #!/bin/bash
2 niro 226 # Magellan Linux Installer (mage.sh)
3 niro 2268 # $Id$
4 niro 226
5     # include all needed files
6 niro 236 [ -f /etc/mage.rc.global ] && \
7     source /etc/mage.rc.global || \
8     die "/etc/mage.rc.global missing"
9 niro 226
10 niro 418 [ -f ${MAGERC} ] && source ${MAGERC} || \
11     die "Your ${MAGERC} is missing. Aborting."
12 niro 232
13 niro 236 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
14     source ${MLIBDIR}/mage4.functions.sh || \
15 niro 232 die "mage functions missing"
16    
17 niro 226 # export default path
18     export PATH="${PATH}:${MLIBDIR}"
19    
20     # export the default C locale
21     export LC_ALL=C
22    
23     # sanity checks
24     [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}
25    
26 niro 2273 if [ ! -e ${VIRTUALDB_DEFAULTS} ] &&
27     [[ $1 != update ]] &&
28     [[ $1 != update-rsync ]] &&
29     [[ $1 != update-tarball ]]
30 niro 226 then
31     echo
32     echo "Please choose an profile from the mage tree."
33     echo "ln -snf ${MAGEDIR}/profiles/profilename /etc/mage-profile"
34     exit 1
35     fi
36    
37     # default messages
38 niro 295 print_usage()
39     {
40 niro 299 #showversion
41     #echo
42 niro 226 echo "Usage: $(basename $0) [option] pkgname ..."
43     echo "Options:"
44 niro 287 echo " pretend - pretends dependencies of a package"
45     echo " srcpretend - pretends dependencies of a package (build from source)"
46     echo " install - installs a package"
47     echo " srcinstall - installs a package from source"
48     echo " uninstall - removes a package"
49 niro 2273 echo " update - updates the mage-tree via default sync method"
50     echo " update-rsync - updates the mage-tree via rsync"
51 niro 739 echo " update-tarball - updates the mage-tree via a tarball"
52 niro 287 echo " uppretend - pretend dependencies for a system upgrade"
53     echo " upgrade - runs a complete system upgrade"
54     echo " srcuppretend - pretend dependencies for a system upgrade from source"
55     echo " srcupgrade - runs a complete system upgrade from source"
56 niro 2358 echo " pretend-build-prerequisites - prints build prerequisites"
57     echo " install-build-prerequisites - install build prerequisites"
58 niro 2371 echo " run-preinstall - runs preinstall part of an installed package"
59     echo " run-postinstall - runs postinstall part of an installed package"
60 niro 287 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 niro 1780 echo " print-features - prints all enabled mage-features"
65 niro 287 echo " version - prints version info"
66     echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
67 niro 226 echo
68     echo "Other options:"
69     # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"
70     # echo "Builds a Package with its dependencies, but won't install anything."
71     # echo
72 niro 295 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
73 niro 226 echo "Overrides stable packages; you can install packages that are marked unstable."
74     echo
75 niro 295 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
76 niro 226 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 niro 1551 # initial unversionized packagename, gets overridden later on
91 niro 226 MAGENAME="$2"
92    
93 niro 1780 if [[ ${METHOD} != upgrade ]] &&
94     [[ ${METHOD} != srcupgrade ]] &&
95     [[ ${METHOD} != uppretend ]] &&
96     [[ ${METHOD} != srcuppretend ]] &&
97     [[ ${METHOD} != update ]] &&
98 niro 2273 [[ ${METHOD} != update-rsync ]] &&
99 niro 1780 [[ ${METHOD} != update-tarball ]] &&
100     [[ ${METHOD} != clean ]] &&
101     [[ ${METHOD} != version ]] &&
102     [[ ${METHOD} != search ]] &&
103     [[ ${METHOD} != regen-mage-tree ]] &&
104     [[ ${METHOD} != print-features ]]
105 niro 230 then
106     [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
107     fi
108 niro 226
109 niro 287 # set PKGDIR and BUILDDIR to MROOT
110     if [[ -n ${MROOT} ]]
111     then
112     PKGDIR=${MROOT}/${PKGDIR}
113     BUILDDIR=${MROOT}/${BUILDDIR}
114     fi
115 niro 226
116 niro 305 # before anything run mage_setup
117     mage_setup || die "error in mage_setup()"
118    
119 niro 1584 # load supported mage features
120     load_mage_features
121    
122 niro 2221 # query debug mode
123     if mqueryfeature "debug"
124     then
125     depwalker_debug="--debug"
126     else
127     depwalker_debug=""
128     fi
129    
130 niro 226 case ${METHOD} in
131     download)
132 niro 2233 have_root_privileges || die "You must be root to run this operation."
133    
134 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
142 niro 226
143 niro 372 # package is masked
144     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
145 niro 370
146 niro 226 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
154 niro 226 --method install \
155     --pcat ${PCAT} \
156     --pname ${PNAME} \
157     --pver ${PVER} \
158 niro 2221 --pbuild ${PBUILD} \
159     ${depwalker_debug})"
160 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
161 niro 230 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
162 niro 226 ;;
163    
164     srcdownload)
165 niro 2233 have_root_privileges || die "You must be root to run this operation."
166    
167 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
175 niro 226
176 niro 372 # package is masked
177     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
178 niro 370
179 niro 226 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
187 niro 226 --method srcinstall \
188     --pcat ${PCAT} \
189     --pname ${PNAME} \
190     --pver ${PVER} \
191 niro 2221 --pbuild ${PBUILD} \
192     ${depwalker_debug})"
193 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
194     ;;
195    
196 niro 2210 pretend|srcpretend|pretend-build-prerequisites)
197 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
205 niro 226
206 niro 372 # package is masked
207     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
208 niro 370
209 niro 226 # 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 niro 2605 ${MLIBDIR}/depwalker \
225 niro 226 --method ${METHOD} \
226     --pcat ${PCAT} \
227     --pname ${PNAME} \
228     --pver ${PVER} \
229 niro 2221 --pbuild ${PBUILD} \
230     ${depwalker_debug}
231 niro 226 ;;
232    
233 niro 2210 install|install-build-prerequisites)
234 niro 1541 have_root_privileges || die "You must be root to run this operation."
235    
236 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
244 niro 226
245 niro 372 # package is masked
246     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
247 niro 370
248 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
258 niro 226 echo -e " already installed."
259     exit 3
260     fi
261    
262     # get all dependencies of this package
263 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
264 niro 226 --method ${METHOD} \
265     --pcat ${PCAT} \
266     --pname ${PNAME} \
267     --pver ${PVER} \
268 niro 2221 --pbuild ${PBUILD} \
269     ${depwalker_debug})"
270 niro 226
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 niro 1541 have_root_privileges || die "You must be root to run this operation."
279    
280 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
288 niro 226
289 niro 372 # package is masked
290     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
291 niro 370
292 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
302 niro 226 echo -e " already installed."
303     exit 3
304     fi
305    
306     # get all dependencies of this package
307 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
308 niro 226 --method ${METHOD} \
309     --pcat ${PCAT} \
310     --pname ${PNAME} \
311     --pver ${PVER} \
312 niro 2221 --pbuild ${PBUILD} \
313     ${depwalker_debug})"
314 niro 226
315     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
316     ;;
317    
318     uninstall)
319 niro 1541 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 niro 226 ;;
328    
329 niro 2371 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 niro 230 uppretend|srcuppretend)
341 niro 2605 ${MLIBDIR}/depwalker \
342 niro 230 --method ${METHOD} \
343     --pcat ${METHOD} \
344     --pname ${METHOD} \
345     --pver ${METHOD} \
346 niro 2221 --pbuild ${METHOD} \
347     ${depwalker_debug}
348 niro 230 ;;
349    
350 niro 247 upgrade)
351 niro 1541 have_root_privileges || die "You must be root to run this operation."
352    
353 niro 230 # get all dependencies of *all* installed packages
354     # fake pcat,pname,pver,pbuild ...
355 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
356 niro 230 --method ${METHOD} \
357     --pcat ${METHOD} \
358     --pname ${METHOD} \
359     --pver ${METHOD} \
360 niro 2221 --pbuild ${METHOD} \
361     ${depwalker_debug})"
362 niro 230
363 niro 247 # 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 niro 230 ;;
368 niro 236
369 niro 247 srcupgrade)
370 niro 1541 have_root_privileges || die "You must be root to run this operation."
371    
372 niro 247 # get all dependencies of *all* installed packages
373     # fake pcat,pname,pver,pbuild ...
374 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
375 niro 247 --method ${METHOD} \
376     --pcat ${METHOD} \
377     --pname ${METHOD} \
378     --pver ${METHOD} \
379 niro 2221 --pbuild ${METHOD} \
380     ${depwalker_debug})"
381 niro 247
382     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
383     ;;
384    
385 niro 226 search)
386 niro 236 pkgsearch "${MAGENAME}"
387 niro 226 ;;
388    
389 niro 230 unpack)
390 niro 1541 have_root_privileges || die "You must be root to run this operation."
391    
392 niro 230 # first of all get the right pkg which going to be installed
393     PCAT="$(pname2pcat ${MAGENAME})"
394 niro 226
395 niro 230 # package does not exists
396     [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
397    
398     # source the highest magefile of this pkg
399 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
400 niro 230
401 niro 372 # package is masked
402     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
403 niro 370
404 niro 230 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
412 niro 230 --method install \
413     --pcat ${PCAT} \
414     --pname ${PNAME} \
415     --pver ${PVER} \
416 niro 2221 --pbuild ${PBUILD} \
417     ${depwalker_debug})"
418    
419 niro 230 fetch_packages ${ALLDEPS} || die "fetching packages"
420     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
421     unpack_packages ${ALLDEPS} || die "unpacking packages"
422     ;;
423    
424 niro 226 update)
425 niro 1541 have_root_privileges || die "You must be root to run this operation."
426 niro 2273 # 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 niro 226 syncmage
438     ;;
439    
440 niro 739 update-tarball)
441 niro 1541 have_root_privileges || die "You must be root to run this operation."
442 niro 739 syncmage_tarball
443     ;;
444    
445 niro 226 clean)
446 niro 1541 have_root_privileges || die "You must be root to run this operation."
447 niro 226 cleanpkg
448     ;;
449    
450     version)
451 niro 295 # showversion
452     exit 0
453 niro 226 ;;
454    
455     regen-mage-tree)
456 niro 1541 have_root_privileges || die "You must be root to run this operation."
457    
458 niro 226 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 niro 1780 print-features)
470     mprintfeatures
471     ;;
472    
473 niro 226 *)
474     print_usage
475     ;;
476     esac