Annotation of /trunk/mage/usr/lib/mage/mage4.sh
Parent Directory | Revision Log
Revision 1541 -
(hide annotations)
(download)
(as text)
Tue Dec 20 12:58:32 2011 UTC (12 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 13300 byte(s)
Tue Dec 20 12:58:32 2011 UTC (12 years, 9 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 | niro | 1269 | #!/bin/bash |
2 | niro | 226 | # Magellan Linux Installer (mage.sh) |
3 | niro | 739 | # $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 | niro | 226 | |
5 | # default die function | ||
6 | die() | ||
7 | { | ||
8 | niro | 413 | echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
9 | niro | 226 | echo -e ${COLRED}"$@"${COLDEFAULT} |
10 | exit 1 | ||
11 | } | ||
12 | |||
13 | # include all needed files | ||
14 | niro | 236 | [ -f /etc/mage.rc.global ] && \ |
15 | source /etc/mage.rc.global || \ | ||
16 | die "/etc/mage.rc.global missing" | ||
17 | niro | 226 | |
18 | niro | 418 | [ -f ${MAGERC} ] && source ${MAGERC} || \ |
19 | die "Your ${MAGERC} is missing. Aborting." | ||
20 | niro | 232 | |
21 | niro | 236 | [ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
22 | source ${MLIBDIR}/mage4.functions.sh || \ | ||
23 | niro | 232 | die "mage functions missing" |
24 | |||
25 | niro | 226 | ## 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 | niro | 236 | COLYELLOW="\033[1;6m\033[33m" |
29 | niro | 226 | COLBLUE="\033[1;6m\033[34m" |
30 | niro | 236 | COLMAGENTA="\033[1;6m\033[35m" |
31 | COLWHITE="\033[1;6m\033[37m" | ||
32 | COLGRAY="\033[0;6m\033[37m" | ||
33 | niro | 239 | COLBOLD="\033[1m" |
34 | niro | 226 | COLDEFAULT="\033[0m" |
35 | |||
36 | if [[ ${NOCOLORS} = true ]] | ||
37 | then | ||
38 | COLRED="" | ||
39 | COLGREEN="" | ||
40 | COLYELLOW="" | ||
41 | COLBLUE="" | ||
42 | COLMAGENTA="" | ||
43 | COLWHITE="" | ||
44 | niro | 236 | COLGRAY="" |
45 | niro | 239 | COLBOLD="" |
46 | niro | 226 | 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 | niro | 1080 | if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]] |
59 | niro | 226 | 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 | niro | 295 | showversion() |
68 | { | ||
69 | niro | 226 | 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 | niro | 295 | print_usage() |
76 | { | ||
77 | niro | 299 | #showversion |
78 | #echo | ||
79 | niro | 226 | echo "Usage: $(basename $0) [option] pkgname ..." |
80 | echo "Options:" | ||
81 | niro | 287 | 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 | niro | 739 | echo " update - updates the mage-tree via rsync" |
87 | echo " update-tarball - updates the mage-tree via a tarball" | ||
88 | niro | 287 | 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 | niro | 226 | 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 | niro | 295 | echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE" |
104 | niro | 226 | echo "Overrides stable packages; you can install packages that are marked unstable." |
105 | echo | ||
106 | niro | 295 | echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE" |
107 | niro | 226 | 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 | niro | 230 | if [[ ${METHOD} != upgrade ]] && \ |
125 | [[ ${METHOD} != srcupgrade ]] && \ | ||
126 | [[ ${METHOD} != uppretend ]] && \ | ||
127 | niro | 233 | [[ ${METHOD} != srcuppretend ]] && \ |
128 | [[ ${METHOD} != update ]] && \ | ||
129 | niro | 739 | [[ ${METHOD} != update-tarball ]] && \ |
130 | niro | 233 | [[ ${METHOD} != clean ]] && \ |
131 | [[ ${METHOD} != version ]] && \ | ||
132 | [[ ${METHOD} != search ]] && \ | ||
133 | [[ ${METHOD} != regen-mage-tree ]] | ||
134 | niro | 230 | then |
135 | [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 | ||
136 | fi | ||
137 | niro | 226 | |
138 | niro | 287 | # set PKGDIR and BUILDDIR to MROOT |
139 | if [[ -n ${MROOT} ]] | ||
140 | then | ||
141 | PKGDIR=${MROOT}/${PKGDIR} | ||
142 | BUILDDIR=${MROOT}/${BUILDDIR} | ||
143 | fi | ||
144 | niro | 226 | |
145 | niro | 305 | # before anything run mage_setup |
146 | mage_setup || die "error in mage_setup()" | ||
147 | |||
148 | niro | 226 | 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 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
158 | niro | 226 | |
159 | niro | 372 | # package is masked |
160 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
161 | niro | 370 | |
162 | niro | 226 | # 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 | niro | 230 | md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
177 | niro | 226 | ;; |
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 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
188 | niro | 226 | |
189 | niro | 372 | # package is masked |
190 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
191 | niro | 370 | |
192 | niro | 226 | # 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 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
217 | niro | 226 | |
218 | niro | 372 | # package is masked |
219 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
220 | niro | 370 | |
221 | niro | 226 | # 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 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
246 | |||
247 | niro | 226 | # 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 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
255 | niro | 226 | |
256 | niro | 372 | # package is masked |
257 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
258 | niro | 370 | |
259 | niro | 226 | # 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 | niro | 247 | echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
269 | niro | 226 | 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 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
290 | |||
291 | niro | 226 | # 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 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
299 | niro | 226 | |
300 | niro | 372 | # package is masked |
301 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
302 | niro | 370 | |
303 | niro | 226 | # 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 | niro | 247 | echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
313 | niro | 226 | 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 | niro | 1541 | 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 | niro | 226 | ;; |
338 | |||
339 | niro | 230 | uppretend|srcuppretend) |
340 | ${MLIBDIR}/depwalker.sh \ | ||
341 | --method ${METHOD} \ | ||
342 | --pcat ${METHOD} \ | ||
343 | --pname ${METHOD} \ | ||
344 | --pver ${METHOD} \ | ||
345 | --pbuild ${METHOD} | ||
346 | ;; | ||
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 | ALLDEPS="$(${MLIBDIR}/depwalker.sh \ | ||
354 | --method ${METHOD} \ | ||
355 | --pcat ${METHOD} \ | ||
356 | --pname ${METHOD} \ | ||
357 | --pver ${METHOD} \ | ||
358 | --pbuild ${METHOD})" | ||
359 | |||
360 | niro | 247 | # 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 | 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 | 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 | niro | 226 | search) |
383 | niro | 236 | pkgsearch "${MAGENAME}" |
384 | niro | 226 | ;; |
385 | |||
386 | niro | 230 | unpack) |
387 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
388 | |||
389 | niro | 230 | # first of all get the right pkg which going to be installed |
390 | PCAT="$(pname2pcat ${MAGENAME})" | ||
391 | niro | 226 | |
392 | niro | 230 | # package does not exists |
393 | [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." | ||
394 | |||
395 | # source the highest magefile of this pkg | ||
396 | niro | 254 | PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
397 | niro | 230 | |
398 | niro | 372 | # package is masked |
399 | [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." | ||
400 | niro | 370 | |
401 | niro | 230 | # 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 | niro | 226 | update) |
420 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
421 | niro | 226 | syncmage |
422 | ;; | ||
423 | |||
424 | niro | 739 | update-tarball) |
425 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
426 | niro | 739 | syncmage_tarball |
427 | ;; | ||
428 | |||
429 | niro | 226 | clean) |
430 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
431 | niro | 226 | cleanpkg |
432 | ;; | ||
433 | |||
434 | version) | ||
435 | niro | 295 | # showversion |
436 | exit 0 | ||
437 | niro | 226 | ;; |
438 | |||
439 | regen-mage-tree) | ||
440 | niro | 1541 | have_root_privileges || die "You must be root to run this operation." |
441 | |||
442 | niro | 226 | 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 | * |