Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2721 - (hide annotations) (download)
Tue Jul 22 14:18:57 2014 UTC (9 years, 9 months ago) by niro
File size: 14125 byte(s)
-speak of environment vars in help msg
1 niro 1269 #!/bin/bash
2 niro 226 # Magellan Linux Installer (mage.sh)
3 niro 2268 # $Id$
4 niro 226
5 niro 2618 # set default variables
6     : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
7     : ${MLIBDIR="@@MAGELIBDIR@@"}
8 niro 226
9 niro 2618 # first of all include common functions
10 niro 2621 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 niro 232
15 niro 226 # 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 niro 2273 if [ ! -e ${VIRTUALDB_DEFAULTS} ] &&
25     [[ $1 != update ]] &&
26     [[ $1 != update-rsync ]] &&
27     [[ $1 != update-tarball ]]
28 niro 226 then
29     echo
30     echo "Please choose an profile from the mage tree."
31 niro 2620 echo "ln -snf ${MAGEDIR}/profiles/profilename @@SYSCONFDIR@@/mage-profile"
32 niro 226 exit 1
33     fi
34    
35     # default messages
36 niro 295 print_usage()
37     {
38 niro 299 #showversion
39     #echo
40 niro 226 echo "Usage: $(basename $0) [option] pkgname ..."
41     echo "Options:"
42 niro 287 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 niro 2273 echo " update - updates the mage-tree via default sync method"
48     echo " update-rsync - updates the mage-tree via rsync"
49 niro 739 echo " update-tarball - updates the mage-tree via a tarball"
50 niro 287 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 niro 2358 echo " pretend-build-prerequisites - prints build prerequisites"
55     echo " install-build-prerequisites - install build prerequisites"
56 niro 2371 echo " run-preinstall - runs preinstall part of an installed package"
57     echo " run-postinstall - runs postinstall part of an installed package"
58 niro 287 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 niro 1780 echo " print-features - prints all enabled mage-features"
63 niro 287 echo " version - prints version info"
64     echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
65 niro 226 echo
66 niro 2721 echo "Environment variables::"
67 niro 226 # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"
68     # echo "Builds a Package with its dependencies, but won't install anything."
69     # echo
70 niro 295 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
71 niro 226 echo "Overrides stable packages; you can install packages that are marked unstable."
72     echo
73 niro 295 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
74 niro 226 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 niro 1551 # initial unversionized packagename, gets overridden later on
89 niro 226 MAGENAME="$2"
90    
91 niro 1780 if [[ ${METHOD} != upgrade ]] &&
92     [[ ${METHOD} != srcupgrade ]] &&
93     [[ ${METHOD} != uppretend ]] &&
94     [[ ${METHOD} != srcuppretend ]] &&
95     [[ ${METHOD} != update ]] &&
96 niro 2273 [[ ${METHOD} != update-rsync ]] &&
97 niro 1780 [[ ${METHOD} != update-tarball ]] &&
98     [[ ${METHOD} != clean ]] &&
99     [[ ${METHOD} != version ]] &&
100     [[ ${METHOD} != search ]] &&
101     [[ ${METHOD} != regen-mage-tree ]] &&
102     [[ ${METHOD} != print-features ]]
103 niro 230 then
104     [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
105     fi
106 niro 226
107 niro 287 # set PKGDIR and BUILDDIR to MROOT
108     if [[ -n ${MROOT} ]]
109     then
110     PKGDIR=${MROOT}/${PKGDIR}
111     BUILDDIR=${MROOT}/${BUILDDIR}
112     fi
113 niro 226
114 niro 305 # before anything run mage_setup
115     mage_setup || die "error in mage_setup()"
116    
117 niro 1584 # load supported mage features
118     load_mage_features
119    
120 niro 2221 # query debug mode
121     if mqueryfeature "debug"
122     then
123     depwalker_debug="--debug"
124     else
125     depwalker_debug=""
126     fi
127    
128 niro 226 case ${METHOD} in
129     download)
130 niro 2233 have_root_privileges || die "You must be root to run this operation."
131    
132 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
140 niro 226
141 niro 372 # package is masked
142     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
143 niro 370
144 niro 226 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
152 niro 226 --method install \
153     --pcat ${PCAT} \
154     --pname ${PNAME} \
155     --pver ${PVER} \
156 niro 2221 --pbuild ${PBUILD} \
157     ${depwalker_debug})"
158 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
159 niro 230 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
160 niro 226 ;;
161    
162     srcdownload)
163 niro 2233 have_root_privileges || die "You must be root to run this operation."
164    
165 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
173 niro 226
174 niro 372 # package is masked
175     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
176 niro 370
177 niro 226 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
185 niro 226 --method srcinstall \
186     --pcat ${PCAT} \
187     --pname ${PNAME} \
188     --pver ${PVER} \
189 niro 2221 --pbuild ${PBUILD} \
190     ${depwalker_debug})"
191 niro 226 fetch_packages ${ALLDEPS} || die "fetching packages"
192     ;;
193    
194 niro 2210 pretend|srcpretend|pretend-build-prerequisites)
195 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
203 niro 226
204 niro 372 # package is masked
205     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
206 niro 370
207 niro 226 # 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 niro 2605 ${MLIBDIR}/depwalker \
223 niro 226 --method ${METHOD} \
224     --pcat ${PCAT} \
225     --pname ${PNAME} \
226     --pver ${PVER} \
227 niro 2221 --pbuild ${PBUILD} \
228     ${depwalker_debug}
229 niro 226 ;;
230    
231 niro 2210 install|install-build-prerequisites)
232 niro 1541 have_root_privileges || die "You must be root to run this operation."
233    
234 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
242 niro 226
243 niro 372 # package is masked
244     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
245 niro 370
246 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
256 niro 226 echo -e " already installed."
257     exit 3
258     fi
259    
260     # get all dependencies of this package
261 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
262 niro 226 --method ${METHOD} \
263     --pcat ${PCAT} \
264     --pname ${PNAME} \
265     --pver ${PVER} \
266 niro 2221 --pbuild ${PBUILD} \
267     ${depwalker_debug})"
268 niro 226
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 niro 1541 have_root_privileges || die "You must be root to run this operation."
277    
278 niro 226 # 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 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
286 niro 226
287 niro 372 # package is masked
288     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
289 niro 370
290 niro 226 # 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 niro 247 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
300 niro 226 echo -e " already installed."
301     exit 3
302     fi
303    
304     # get all dependencies of this package
305 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
306 niro 226 --method ${METHOD} \
307     --pcat ${PCAT} \
308     --pname ${PNAME} \
309     --pver ${PVER} \
310 niro 2221 --pbuild ${PBUILD} \
311     ${depwalker_debug})"
312 niro 226
313     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
314     ;;
315    
316     uninstall)
317 niro 1541 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 niro 226 ;;
326    
327 niro 2371 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 niro 230 uppretend|srcuppretend)
339 niro 2605 ${MLIBDIR}/depwalker \
340 niro 230 --method ${METHOD} \
341     --pcat ${METHOD} \
342     --pname ${METHOD} \
343     --pver ${METHOD} \
344 niro 2221 --pbuild ${METHOD} \
345     ${depwalker_debug}
346 niro 230 ;;
347    
348 niro 247 upgrade)
349 niro 1541 have_root_privileges || die "You must be root to run this operation."
350    
351 niro 230 # get all dependencies of *all* installed packages
352     # fake pcat,pname,pver,pbuild ...
353 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
354 niro 230 --method ${METHOD} \
355     --pcat ${METHOD} \
356     --pname ${METHOD} \
357     --pver ${METHOD} \
358 niro 2221 --pbuild ${METHOD} \
359     ${depwalker_debug})"
360 niro 230
361 niro 247 # 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 niro 230 ;;
366 niro 236
367 niro 247 srcupgrade)
368 niro 1541 have_root_privileges || die "You must be root to run this operation."
369    
370 niro 247 # get all dependencies of *all* installed packages
371     # fake pcat,pname,pver,pbuild ...
372 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
373 niro 247 --method ${METHOD} \
374     --pcat ${METHOD} \
375     --pname ${METHOD} \
376     --pver ${METHOD} \
377 niro 2221 --pbuild ${METHOD} \
378     ${depwalker_debug})"
379 niro 247
380     install_packages --src-install ${ALLDEPS} || die "src-installing packages"
381     ;;
382    
383 niro 226 search)
384 niro 236 pkgsearch "${MAGENAME}"
385 niro 226 ;;
386    
387 niro 230 unpack)
388 niro 1541 have_root_privileges || die "You must be root to run this operation."
389    
390 niro 230 # first of all get the right pkg which going to be installed
391     PCAT="$(pname2pcat ${MAGENAME})"
392 niro 226
393 niro 230 # package does not exists
394     [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
395    
396     # source the highest magefile of this pkg
397 niro 254 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
398 niro 230
399 niro 372 # package is masked
400     [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
401 niro 370
402 niro 230 # 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 niro 2605 ALLDEPS="$(${MLIBDIR}/depwalker \
410 niro 230 --method install \
411     --pcat ${PCAT} \
412     --pname ${PNAME} \
413     --pver ${PVER} \
414 niro 2221 --pbuild ${PBUILD} \
415     ${depwalker_debug})"
416    
417 niro 230 fetch_packages ${ALLDEPS} || die "fetching packages"
418     md5sum_packages ${ALLDEPS} || die "md5 sum packages"
419     unpack_packages ${ALLDEPS} || die "unpacking packages"
420     ;;
421    
422 niro 226 update)
423 niro 1541 have_root_privileges || die "You must be root to run this operation."
424 niro 2273 # 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 niro 226 syncmage
436     ;;
437    
438 niro 739 update-tarball)
439 niro 1541 have_root_privileges || die "You must be root to run this operation."
440 niro 739 syncmage_tarball
441     ;;
442    
443 niro 226 clean)
444 niro 1541 have_root_privileges || die "You must be root to run this operation."
445 niro 226 cleanpkg
446     ;;
447    
448     version)
449 niro 295 # showversion
450     exit 0
451 niro 226 ;;
452    
453     regen-mage-tree)
454 niro 1541 have_root_privileges || die "You must be root to run this operation."
455    
456 niro 226 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 niro 1780 print-features)
468     mprintfeatures
469     ;;
470    
471 niro 226 *)
472     print_usage
473     ;;
474     esac