Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *