Contents of /trunk/mage/usr/lib/mage/mage4.functions.sh
Parent Directory | Revision Log
Revision 1209 -
(show annotations)
(download)
(as text)
Fri Jan 28 20:37:27 2011 UTC (13 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 70985 byte(s)
Fri Jan 28 20:37:27 2011 UTC (13 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 70985 byte(s)
- added support for fifos - fifos, character devices and blockdevices should set the owner right - some cosmetic changes and spelling typos
1 | #!/bin/bash |
2 | # Magellan Linux Installer Functions (mage.functions.sh) |
3 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $ |
4 | |
5 | mage_setup() |
6 | { |
7 | [ ! -d ${MROOT}${INSTALLDB} ] && \ |
8 | install -d ${MROOT}${INSTALLDB} |
9 | [ ! -f ${MROOT}${VIRTUALDB_FILE} ] && \ |
10 | touch ${MROOT}${VIRTUALDB_FILE} |
11 | [ ! -d ${PKGDIR} ] && install -d ${PKGDIR} |
12 | [ ! -d ${BUILDDIR} ] && install -d ${BUILDDIR} |
13 | [ ! -d ${MAGEDIR} ] && install -d ${MAGEDIR} |
14 | |
15 | return 0 |
16 | } |
17 | |
18 | unpack_packages() |
19 | { |
20 | local list="$@" |
21 | local magefile |
22 | local pkg |
23 | local pkgtype |
24 | local count_current |
25 | local count_total |
26 | |
27 | # get count of total packages |
28 | declare -i count_current=0 |
29 | declare -i count_total=0 |
30 | |
31 | for i in ${list}; do (( count_total++ )); done |
32 | |
33 | for magefile in ${list} |
34 | do |
35 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
36 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
37 | |
38 | (( count_current++ )) |
39 | xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" |
40 | |
41 | # abort on virtual pkg |
42 | if [[ ${pkgtype} = virtual ]] |
43 | then |
44 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
45 | echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
46 | continue |
47 | fi |
48 | |
49 | # abort on sources pkg |
50 | if [[ ${pkgtype} = sources ]] |
51 | then |
52 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
53 | echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
54 | continue |
55 | fi |
56 | |
57 | echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " |
58 | tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" |
59 | done |
60 | |
61 | # add a crlf for a better view |
62 | if [ ${count_total} -gt 1 ]; then echo; fi |
63 | } |
64 | |
65 | |
66 | # fix_mtime path/to/$mtime/reffile $pathto/file |
67 | # creates a given reference file and fixes given file |
68 | # returns new mtime |
69 | fix_mtime() |
70 | { |
71 | local reference="$1" |
72 | local pathto="$2" |
73 | local mtime |
74 | |
75 | mtime=$(stat -c %Y "${reference}") |
76 | touch \ |
77 | --no-create \ |
78 | --time=mtime \ |
79 | --reference "${reference}" \ |
80 | "${pathto}" |
81 | |
82 | echo "${mtime}" |
83 | } |
84 | |
85 | # fix_descriptor pkgname/.dir "foo1" "foo2" |
86 | fix_descriptor() |
87 | { |
88 | local descriptor="$1" |
89 | local output |
90 | local i |
91 | shift |
92 | |
93 | for i in $@ |
94 | do |
95 | if [[ -z ${output} ]] |
96 | then |
97 | output="${i}" |
98 | else |
99 | output="${output}§${i}" |
100 | fi |
101 | done |
102 | |
103 | echo "${output}" >> ${BUILDDIR}/${descriptor}_fixed |
104 | } |
105 | |
106 | ################################################### |
107 | # function install_direcories # |
108 | # install_direcories $PKGNAME # |
109 | ################################################### |
110 | install_directories() |
111 | { |
112 | local pkgname="$1" |
113 | local pathto |
114 | local posix |
115 | local user |
116 | local group |
117 | local IFS |
118 | |
119 | # sanity checks; abort if not given |
120 | [ -z "${pkgname}" ] && die "install_directories() \$pkgname not given." |
121 | |
122 | # check needed global vars |
123 | [ -z "${BUILDDIR}" ] && die "install_directories() \$BUILDDIR not set." |
124 | |
125 | [ ! -f ${BUILDDIR}/${pkgname}/.dirs ] && die "install_directories() .dirs not found" |
126 | |
127 | # sets fieldseperator to "§" instead of " " |
128 | IFS=§ |
129 | |
130 | while read pathto posix user group |
131 | do |
132 | [ -z "${pathto}" ] && continue |
133 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
134 | |
135 | |
136 | # monitors /etc/env.d -> env-rebuild |
137 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
138 | |
139 | # monitors /usr/share/info -> info-rebuild |
140 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true |
141 | |
142 | install -m "${posix}" -o "${user}" -g "${group}" -d "${MROOT}${pathto}" |
143 | done < ${BUILDDIR}/${pkgname}/.dirs |
144 | |
145 | # very important: unsetting the '§' fieldseperator |
146 | IFS=$'\n' |
147 | } |
148 | |
149 | |
150 | ################################################### |
151 | # function install_files # |
152 | # install_files $PKGNAME # |
153 | ################################################### |
154 | install_files() |
155 | { |
156 | |
157 | local pkgname="$1" |
158 | local pathto |
159 | local posix |
160 | local user |
161 | local group |
162 | local mtime |
163 | local md5sum |
164 | |
165 | local retval |
166 | local counter |
167 | local filename |
168 | local dest_dirname |
169 | local dest_protected |
170 | local IFS |
171 | |
172 | # sanity checks; abort if not given |
173 | [ -z "${pkgname}" ] && die "install_files() \$pkgname not given." |
174 | |
175 | # check needed global vars |
176 | [ -z "${BUILDDIR}" ] && die "install_files() \$BUILDDIR not set." |
177 | |
178 | [ ! -f ${BUILDDIR}/${pkgname}/.files ] && die "install_files() .files not found" |
179 | |
180 | # delete old files |
181 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && rm ${BUILDDIR}/${pkgname}/.files_fixed |
182 | |
183 | # sets fieldseperator to "§" instead of " " |
184 | IFS=§ |
185 | |
186 | while read pathto posix user group mtime md5sum |
187 | do |
188 | [ -z "${pathto}" ] && continue |
189 | |
190 | # final destination dir of file ${pathto} |
191 | dest_dirname="$(dirname "${MROOT}${pathto}")" |
192 | |
193 | ### small hotfix fix ### |
194 | [ ! -d "${dest_dirname}" ] && install -d "${dest_dirname}" |
195 | |
196 | # check if the file is config_protected |
197 | # ${MROOT} will automatically added if set !! |
198 | is_config_protected "${pathto}" |
199 | retval="$?" |
200 | |
201 | # 0 - not protected # |
202 | # 1 - error # |
203 | # 2 - protected # |
204 | # 3 - protected but masked # |
205 | # 4 - protected but ignored # |
206 | |
207 | case ${retval} in |
208 | # file is not protected - (over)write it |
209 | 0|3) |
210 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" |
211 | install -m "${posix}" -o "${user}" -g "${group}" \ |
212 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
213 | "${MROOT}${pathto}" |
214 | |
215 | # fix mtime and db |
216 | fix_descriptor ${pkgname}/.files \ |
217 | "${pathto}" \ |
218 | "${posix}" \ |
219 | "${user}" \ |
220 | "${group}" \ |
221 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
222 | "${MROOT}${pathto}")" \ |
223 | "${md5sum}" |
224 | ;; |
225 | |
226 | # file is protected, write backup file |
227 | 2) |
228 | if [[ ${VERBOSE} = on ]] |
229 | then |
230 | echo -en "${COLRED}" |
231 | echo -n "! prot " |
232 | echo -en "${COLDEFAULT}" |
233 | echo " === FILE: ${MROOT}${pathto}" |
234 | fi |
235 | filename="$(basename "${pathto}")" |
236 | counter=$(count_protected_files "${pathto}") |
237 | dest_protected="${dest_dirname}/._cfg${counter}_${filename}" |
238 | install -m "${posix}" -o "${user}" -g "${group}" \ |
239 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
240 | "${dest_protected}" |
241 | |
242 | # fix mtime and db |
243 | fix_descriptor ${pkgname}/.files \ |
244 | "${pathto}" \ |
245 | "${posix}" \ |
246 | "${user}" \ |
247 | "${group}" \ |
248 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
249 | "${dest_protected}")" \ |
250 | "${md5sum}" |
251 | |
252 | # update global MAGE_PROTECT_COUNTER |
253 | (( MAGE_PROTECT_COUNTER++ )) |
254 | export MAGE_PROTECT_COUNTER |
255 | ;; |
256 | |
257 | # file is protected but ignored, delete the update/do nothing |
258 | 4) |
259 | if [[ ${VERBOSE} = on ]] |
260 | then |
261 | echo -en "${COLRED}" |
262 | echo -n "! ignr " |
263 | echo -en "${COLDEFAULT}" |
264 | echo " === FILE: ${MROOT}${pathto}" |
265 | fi |
266 | # simply do nothing here |
267 | ;; |
268 | esac |
269 | done < ${BUILDDIR}/${pkgname}/.files |
270 | |
271 | # now copy the fixed file over the old one |
272 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && \ |
273 | cp ${BUILDDIR}/${pkgname}/.files{_fixed,} |
274 | |
275 | # very important: unsetting the '§' fieldseperator |
276 | IFS=$'\n' |
277 | } |
278 | |
279 | |
280 | ################################################### |
281 | # function install_symlinks # |
282 | # install_symlinks $PKGNAME # |
283 | ################################################### |
284 | install_symlinks() |
285 | { |
286 | local pkgname="$1" |
287 | local pathto |
288 | local posix |
289 | local link |
290 | local mtime |
291 | local IFS |
292 | |
293 | # sanity checks; abort if not given |
294 | [ -z "${pkgname}" ] && die "install_symlinks() \$pkgname not given." |
295 | |
296 | # check needed global vars |
297 | [ -z "${BUILDDIR}" ] && die "install_symlinks() \$BUILDDIR not set." |
298 | |
299 | [ ! -f ${BUILDDIR}/${pkgname}/.symlinks ] && die "install_symlinks() .symlinks not found" |
300 | |
301 | # delete old files |
302 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && rm ${BUILDDIR}/${pkgname}/.symlinks_fixed |
303 | |
304 | # sets fieldseperator to "§" instead of " " |
305 | IFS=§ |
306 | |
307 | while read pathto posix link mtime |
308 | do |
309 | [ -z "${pathto}" ] && continue |
310 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" |
311 | |
312 | ln -snf "${link}" "${MROOT}${pathto}" |
313 | |
314 | # # fix mtime and db |
315 | # fix_descriptor ${pkgname}/.symlinks \ |
316 | # "${pathto}" \ |
317 | # "${posix}" \ |
318 | # "${link}" \ |
319 | # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
320 | # "${MROOT}${pathto}")" |
321 | |
322 | done < ${BUILDDIR}/${pkgname}/.symlinks |
323 | |
324 | # # now copy the fixed file over the old one |
325 | # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ |
326 | # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} |
327 | |
328 | # very important: unsetting the '§' fieldseperator |
329 | IFS=$'\n' |
330 | } |
331 | |
332 | |
333 | ################################################### |
334 | # function install_blockdevices # |
335 | # install_blockdevices $PKGNAME # |
336 | ################################################### |
337 | install_blockdevices() |
338 | { |
339 | local pkgname="$1" |
340 | local pathto |
341 | local posix |
342 | local user |
343 | local group |
344 | local IFS |
345 | |
346 | # sanity checks; abort if not given |
347 | [ -z "${pkgname}" ] && die "install_blockdevices() \$pkgname not given." |
348 | |
349 | # check needed global vars |
350 | [ -z "${BUILDDIR}" ] && die "install_blockdevices() \$BUILDDIR not set." |
351 | |
352 | [ ! -f ${BUILDDIR}/${pkgname}/.pipes ] && die "install_blockdevices() .pipes not found" |
353 | |
354 | # sets fieldseperator to "§" instead of " " |
355 | IFS=§ |
356 | |
357 | while read pathto posix user group |
358 | do |
359 | [ -z "${pathto}" ] && continue |
360 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" |
361 | |
362 | mkfifo -m "${posix}" "${MROOT}${pathto}" |
363 | chown "${user}:${group}" "${MROOT}${pathto}" |
364 | done < ${BUILDDIR}/${pkgname}/.pipes |
365 | |
366 | # very important: unsetting the '§' fieldseperator |
367 | IFS=$'\n' |
368 | } |
369 | |
370 | |
371 | ################################################### |
372 | # function install_characterdevices # |
373 | # install_characterdevices $PKGNAME # |
374 | ################################################### |
375 | install_characterdevices() |
376 | { |
377 | local pkgname="$1" |
378 | local pathto |
379 | local posix |
380 | local major |
381 | local minor |
382 | local user |
383 | local group |
384 | local IFS |
385 | |
386 | # sanity checks; abort if not given |
387 | [ -z "${pkgname}" ] && die "install_characterdevices() \$pkgname not given." |
388 | |
389 | # check needed global vars |
390 | [ -z "${BUILDDIR}" ] && die "install_characterdevices() \$BUILDDIR not set." |
391 | |
392 | [ ! -f ${BUILDDIR}/${pkgname}/.char ] && die "install_characterdevices() .char not found" |
393 | |
394 | # sets fieldseperator to "§" instead of " " |
395 | IFS=§ |
396 | |
397 | while read pathto posix major minor user group |
398 | do |
399 | [ -z "${pathto}" ] && continue |
400 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" |
401 | |
402 | mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} |
403 | chown "${user}:${group}" "${MROOT}${pathto}" |
404 | done < ${BUILDDIR}/${pkgname}/.char |
405 | |
406 | # very important: unsetting the '§' fieldseperator |
407 | IFS=$'\n' |
408 | } |
409 | |
410 | ################################################### |
411 | # function install_fifos # |
412 | # install_fifos $PKGNAME # |
413 | ################################################### |
414 | install_fifos() |
415 | { |
416 | local pkgname="$1" |
417 | local pathto |
418 | local posix |
419 | local user |
420 | local group |
421 | local IFS |
422 | |
423 | # sanity checks; abort if not given |
424 | [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given." |
425 | |
426 | # check needed global vars |
427 | [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set." |
428 | |
429 | [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found" |
430 | |
431 | # sets fieldseperator to "§" instead of " " |
432 | IFS=§ |
433 | |
434 | while read pathto posix user group |
435 | do |
436 | [ -z "${pathto}" ] && continue |
437 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}" |
438 | |
439 | mkfifo -m "${posix}" "${MROOT}${pathto}" |
440 | chown "${user}:${group}" "${MROOT}${pathto}" |
441 | done < ${BUILDDIR}/${pkgname}/.fifo |
442 | |
443 | # very important: unsetting the '§' fieldseperator |
444 | IFS=$'\n' |
445 | } |
446 | |
447 | |
448 | ################################################### |
449 | # function build_doinstall # |
450 | # build_doinstall $PKGNAME # |
451 | # NOTE: this is an wrapper to install packages # |
452 | ################################################### |
453 | build_doinstall() |
454 | { |
455 | local pkgname="$1" |
456 | |
457 | # sanity checks; abort if not given |
458 | [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." |
459 | |
460 | # this is only a wrapper |
461 | |
462 | # NOTE: |
463 | # !! we use § as field seperator !! |
464 | # doing so prevent us to get errors by filenames with spaces |
465 | |
466 | # create a new mtime reference file |
467 | touch ${BUILDDIR}/${pkgname}/.mtime |
468 | |
469 | install_directories ${pkgname} || die "install directories ${pkgname}" |
470 | install_files ${pkgname} || die "install files ${pkgname}" |
471 | install_symlinks ${pkgname} || die "install symlinks ${pkgname}" |
472 | install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" |
473 | install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" |
474 | install_fifos ${pkgname} || die "install fifos ${pkgname}" |
475 | } |
476 | |
477 | |
478 | ################################################### |
479 | # function install_database_entry # |
480 | # install_database_entry $PKGNAME $PKGTYPE # |
481 | # PKGTYPE can be "virtual", "sources" or nothing # |
482 | ################################################### |
483 | install_database_entry() |
484 | { |
485 | local pcat |
486 | local pname |
487 | local pver |
488 | local pbuild |
489 | local pkgtype |
490 | local pkgname |
491 | local magefile |
492 | local dbrecorddir |
493 | local provide |
494 | local i |
495 | |
496 | # very basic getops |
497 | for i in $* |
498 | do |
499 | case $1 in |
500 | --pcat|-c) shift; pcat="$1" ;; |
501 | --pname|-n) shift; pname="$1" ;; |
502 | --pver|-v) shift; pver="$1" ;; |
503 | --pbuild|-b) shift; pbuild="$1" ;; |
504 | --pkgname|-a) shift; pkgname="$1" ;; |
505 | --pkgtype|-t) shift; pkgtype="$1" ;; |
506 | esac |
507 | shift |
508 | done |
509 | |
510 | # sanity checks; abort if not given |
511 | [ -z "${pcat}" ] && die "install_database_entry() \$pcat not given." |
512 | [ -z "${pname}" ] && die "install_database_entry() \$pname not given." |
513 | [ -z "${pver}" ] && die "install_database_entry() \$pver not given." |
514 | [ -z "${pbuild}" ] && die "install_database_entry() \$pbuild not given." |
515 | [ -z "${pkgname}" ] && die "install_database_entry() \$pkgname not given." |
516 | |
517 | # check needed global vars |
518 | [ -z "${MAGEDIR}" ] && die "install_database_entry() \$MAGEDIR not set." |
519 | [ -z "${INSTALLDB}" ] && die "install_database_entry() \$INSTALLDB not set." |
520 | |
521 | # set needed vars |
522 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" |
523 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" |
524 | |
525 | # abort if mage file not exists |
526 | [ ! -f ${magefile} ] && die "install_database_entry() ${magefile} not exist." |
527 | |
528 | # add package to database |
529 | install -d ${dbrecorddir} |
530 | |
531 | # install mage-file to database |
532 | install -m 0644 -o root -g root ${magefile} ${dbrecorddir} |
533 | |
534 | # create fake file descriptors |
535 | # used by virtual and source packages |
536 | for i in .dirs .symlinks .files .pipes .char .fifo |
537 | do |
538 | touch ${dbrecorddir}/${i} |
539 | done |
540 | |
541 | # put the category to database |
542 | echo ${pcat} > ${dbrecorddir}/.categorie |
543 | |
544 | # now install PKGTYPE specific files |
545 | case ${pkgtype} in |
546 | virtual) touch ${dbrecorddir}/.virtual ;; |
547 | sources) touch ${dbrecorddir}/.sources ;; |
548 | *) |
549 | # !move! .mtime to database (only mv modifies not the mtime!!) |
550 | mv ${BUILDDIR}/${pkgname}/.mtime ${dbrecorddir}/.mtime |
551 | |
552 | # normal packages needs these files |
553 | local i |
554 | for i in .char .dirs .files .pipes .symlinks .fifo |
555 | do |
556 | install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ |
557 | ${dbrecorddir}/${i} |
558 | done |
559 | ;; |
560 | esac |
561 | |
562 | # last but not least register virtuals |
563 | provide="$(get_value_from_magefile PROVIDE ${magefile})" |
564 | if [ -n "${provide}" ] |
565 | then |
566 | for i in ${provide} |
567 | do |
568 | virtuals_add "${i}" "${pcat}/${pname}" |
569 | done |
570 | fi |
571 | } |
572 | |
573 | |
574 | ################################################### |
575 | # function remove_database_entry # |
576 | # remove_database_entry $PKGNAME $PKGTYPE # |
577 | # PKGTYPE can be "virtual", "sources" or nothing # |
578 | ################################################### |
579 | remove_database_entry() |
580 | { |
581 | local pcat |
582 | local pname |
583 | local pver |
584 | local pbuild |
585 | local magefile |
586 | local dbrecorddir |
587 | local provide |
588 | local i |
589 | |
590 | # very basic getops |
591 | for i in $* |
592 | do |
593 | case $1 in |
594 | --pcat|-c) shift; pcat="$1" ;; |
595 | --pname|-n) shift; pname="$1" ;; |
596 | --pver|-v) shift; pver="$1" ;; |
597 | --pbuild|-b) shift; pbuild="$1" ;; |
598 | esac |
599 | shift |
600 | done |
601 | |
602 | # sanity checks; abort if not given |
603 | [ -z "${pcat}" ] && die "remove_database_entry() \$pcat not given." |
604 | [ -z "${pname}" ] && die "remove_database_entry() \$pname not given." |
605 | [ -z "${pver}" ] && die "remove_database_entry() \$pver not given." |
606 | [ -z "${pbuild}" ] && die "remove_database_entry() \$pbuild not given." |
607 | |
608 | # check needed global vars |
609 | [ -z "${INSTALLDB}" ] && die "remove_database_entry() \$INSTALLDB not set." |
610 | |
611 | # set needed vars |
612 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
613 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" |
614 | |
615 | # abort if mage file not exists |
616 | [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
617 | |
618 | # remove virtuals only if no other exist |
619 | if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] |
620 | then |
621 | # first unregister virtuals |
622 | provide="$(get_value_from_magefile PROVIDE ${magefile})" |
623 | if [ -n "${provide}" ] |
624 | then |
625 | for i in ${provide} |
626 | do |
627 | virtuals_del "${i}" "${pcat}/${pname}" |
628 | done |
629 | fi |
630 | fi |
631 | |
632 | # removes database entry |
633 | if [ -d ${dbrecorddir} ] |
634 | then |
635 | rm -rf ${dbrecorddir} |
636 | fi |
637 | } |
638 | |
639 | # get the number of installed packages |
640 | count_installed_pkgs() |
641 | { |
642 | local pcat |
643 | local pname |
644 | local pkg |
645 | local i |
646 | |
647 | # very basic getops |
648 | for i in $* |
649 | do |
650 | case $1 in |
651 | --pcat|-c) shift; pcat="$1" ;; |
652 | --pname|-n) shift; pname="$1" ;; |
653 | esac |
654 | shift |
655 | done |
656 | |
657 | # sanity checks; abort if not given |
658 | [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." |
659 | [ -z "${pname}" ] && die "pkg_count() \$pname not given." |
660 | |
661 | declare -i i=0 |
662 | for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) |
663 | do |
664 | (( i++ )) |
665 | #echo "$i ${pkg}" |
666 | done |
667 | |
668 | # return the value |
669 | echo "${i}" |
670 | } |
671 | |
672 | |
673 | ################################################### |
674 | # function compare_mtime # |
675 | # compare_mtime $pcat/$PKGNAME /path/to/file # |
676 | # # |
677 | # returns: # |
678 | # 0=delete me # |
679 | # 1=keep me # |
680 | # # |
681 | # compares mtime of given files in packages # |
682 | ################################################### |
683 | compare_mtime() |
684 | { |
685 | local pfull="$1" |
686 | local pathto="$2" |
687 | local mtime |
688 | local pcat |
689 | local x |
690 | |
691 | mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
692 | |
693 | # if $pathto is a symlink than compare linked binary |
694 | if [ -L "${MROOT}${pathto}" ] |
695 | then |
696 | # readlink -f resolves full path of linked file |
697 | x="$(readlink -f "${MROOT}${pathto}")" |
698 | |
699 | # abort if target does not exists |
700 | # we keep safe here, theoretically the link can removed |
701 | [ ! -e "${x}" ] && return 1 |
702 | |
703 | x=$(stat -c %Y "${x}") |
704 | else |
705 | x=$(stat -c %Y "${MROOT}${pathto}") |
706 | fi |
707 | |
708 | [[ ${mtime} = ${x} ]] && return 0 |
709 | |
710 | # echo "keep me : ${pathto}" |
711 | return 1 |
712 | } |
713 | |
714 | |
715 | ################################################### |
716 | # function remove_symlinks # |
717 | # remove_symlinks $PKGNAME # |
718 | ################################################### |
719 | remove_symlinks() |
720 | { |
721 | local pathto |
722 | local posix |
723 | local link |
724 | local mtime |
725 | local IFS |
726 | local retval |
727 | local pcat |
728 | local pname |
729 | local pver |
730 | local pbuild |
731 | local i |
732 | local pfull |
733 | |
734 | IFS=$'\n' |
735 | |
736 | # very basic getops |
737 | for i in $* |
738 | do |
739 | case $1 in |
740 | --pcat|-c) shift; pcat="$1" ;; |
741 | --pname|-n) shift; pname="$1" ;; |
742 | --pver|-v) shift; pver="$1" ;; |
743 | --pbuild|-b) shift; pbuild="$1" ;; |
744 | esac |
745 | shift |
746 | done |
747 | |
748 | # sanity checks; abort if not given |
749 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
750 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
751 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
752 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
753 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
754 | |
755 | # check needed global vars |
756 | [ -z "${BUILDDIR}" ] && die "remove_symlinks() \$BUILDDIR not set." |
757 | |
758 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.symlinks ] && die "remove_symlinks() .symlinks not found" |
759 | |
760 | # sets fieldseperator to "§" instead of " " |
761 | IFS=§ |
762 | |
763 | while read pathto posix link mtime |
764 | do |
765 | [ -z "${pathto}" ] && continue |
766 | if [ ! -L "${MROOT}${pathto}" ] |
767 | then |
768 | [[ ${VERBOSE} = on ]] && \ |
769 | echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
770 | continue |
771 | fi |
772 | |
773 | # *no* ${MROOT}, will be set internal |
774 | compare_mtime "${pfull}" "${pathto}" |
775 | retval=$? |
776 | # 0=delete me # |
777 | # 1=keep me # |
778 | case ${retval} in |
779 | 0) |
780 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" |
781 | rm "${MROOT}${pathto}" |
782 | ;; |
783 | |
784 | 1) |
785 | [[ ${VERBOSE} = on ]] && \ |
786 | echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
787 | ;; |
788 | esac |
789 | done < ${MROOT}${INSTALLDB}/${pfull}/.symlinks |
790 | |
791 | # very important: unsetting the '§' fieldseperator |
792 | IFS=$'\n' |
793 | } |
794 | |
795 | |
796 | ################################################### |
797 | # function remove_files # |
798 | # remove_files $PKGNAME # |
799 | ################################################### |
800 | remove_files() |
801 | { |
802 | local pathto |
803 | local posix |
804 | local user |
805 | local group |
806 | local mtime |
807 | local md5sum |
808 | local IFS |
809 | local retval |
810 | local pcat |
811 | local pname |
812 | local pver |
813 | local pbuild |
814 | local i |
815 | local pfull |
816 | |
817 | IFS=$'\n' |
818 | |
819 | # very basic getops |
820 | for i in $* |
821 | do |
822 | case $1 in |
823 | --pcat|-c) shift; pcat="$1" ;; |
824 | --pname|-n) shift; pname="$1" ;; |
825 | --pver|-v) shift; pver="$1" ;; |
826 | --pbuild|-b) shift; pbuild="$1" ;; |
827 | esac |
828 | shift |
829 | done |
830 | |
831 | # sanity checks; abort if not given |
832 | [ -z "${pcat}" ] && die "remove_files() \$pcat not given." |
833 | [ -z "${pname}" ] && die "remove_files() \$pname not given." |
834 | [ -z "${pver}" ] && die "remove_files() \$pver not given." |
835 | [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given." |
836 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
837 | |
838 | # check needed global vars |
839 | [ -z "${BUILDDIR}" ] && die "remove_files() \$BUILDDIR not set." |
840 | |
841 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.files ] && die "remove_files() .files not found" |
842 | |
843 | # sets fieldseperator to "§" instead of " " |
844 | IFS=§ |
845 | |
846 | while read pathto posix user group mtime md5sum |
847 | do |
848 | [ -z "${pathto}" ] && continue |
849 | |
850 | if [ ! -e "${MROOT}${pathto}" ] |
851 | then |
852 | [[ ${VERBOSE} = on ]] && \ |
853 | echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
854 | continue |
855 | fi |
856 | |
857 | # *no* ${MROOT}, will be set internal |
858 | compare_mtime "${pfull}" "${pathto}" |
859 | retval=$? |
860 | # 0=delete me # |
861 | # 1=keep me # |
862 | case ${retval} in |
863 | 0) |
864 | # check if the file is config_protected |
865 | # ${MROOT} will automatically added if set !! |
866 | is_config_protected "${pathto}" |
867 | retval="$?" |
868 | |
869 | # 0 - not protected # |
870 | # 1 - error # |
871 | # 2 - protected # |
872 | # 3 - protected but masked # |
873 | # 4 - protected but ignored # |
874 | |
875 | case ${retval} in |
876 | # file is not protected - delete it |
877 | 0|3) |
878 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" |
879 | rm "${MROOT}${pathto}" |
880 | ;; |
881 | |
882 | # file is protected, do not delete |
883 | 2) |
884 | if [[ ${VERBOSE} = on ]] |
885 | then |
886 | echo -en "${COLRED}" |
887 | echo -n "! prot " |
888 | echo -en "${COLDEFAULT}" |
889 | echo " === FILE: ${MROOT}${pathto}" |
890 | fi |
891 | ;; |
892 | |
893 | # file is protected but ignored, delete the update/do nothing |
894 | 4) |
895 | if [[ ${VERBOSE} = on ]] |
896 | then |
897 | echo -en "${COLRED}" |
898 | echo -n "! ignr " |
899 | echo -en "${COLDEFAULT}" |
900 | echo " === FILE: ${MROOT}${pathto}" |
901 | fi |
902 | # simply do nothing here |
903 | ;; |
904 | esac |
905 | ;; |
906 | 1) |
907 | [[ ${VERBOSE} = on ]] && \ |
908 | echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
909 | ;; |
910 | esac |
911 | done < ${MROOT}${INSTALLDB}/${pfull}/.files |
912 | |
913 | # very important: unsetting the '§' fieldseperator |
914 | IFS=$'\n' |
915 | } |
916 | |
917 | |
918 | ################################################### |
919 | # function remove_blockdevices # |
920 | # remove_blockdevices $PKGNAME # |
921 | ################################################### |
922 | remove_blockdevices() |
923 | { |
924 | local pathto |
925 | local posix |
926 | local user |
927 | local group |
928 | local IFS |
929 | local pcat |
930 | local pname |
931 | local pver |
932 | local pbuild |
933 | local i |
934 | local pfull |
935 | |
936 | IFS=$'\n' |
937 | |
938 | # very basic getops |
939 | for i in $* |
940 | do |
941 | case $1 in |
942 | --pcat|-c) shift; pcat="$1" ;; |
943 | --pname|-n) shift; pname="$1" ;; |
944 | --pver|-v) shift; pver="$1" ;; |
945 | --pbuild|-b) shift; pbuild="$1" ;; |
946 | esac |
947 | shift |
948 | done |
949 | |
950 | # sanity checks; abort if not given |
951 | [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given." |
952 | [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given." |
953 | [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given." |
954 | [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given." |
955 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
956 | |
957 | # check needed global vars |
958 | [ -z "${BUILDDIR}" ] && die "remove_blockdevices() \$BUILDDIR not set." |
959 | |
960 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.pipes ] && die "remove_blockdevices() .pipes not found" |
961 | |
962 | # sets fieldseperator to "§" instead of " " |
963 | IFS=§ |
964 | |
965 | while read pathto posix user group |
966 | do |
967 | [ -z "${pathto}" ] && continue |
968 | |
969 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" |
970 | rm "${MROOT}${pathto}" |
971 | done < ${MROOT}${INSTALLDB}/${pfull}/.pipes |
972 | |
973 | # very important: unsetting the '§' fieldseperator |
974 | IFS=$'\n' |
975 | } |
976 | |
977 | |
978 | ################################################### |
979 | # function remove_characterdevices # |
980 | # remove_characterdevices $PKGNAME # |
981 | ################################################### |
982 | remove_characterdevices() |
983 | { |
984 | local pathto |
985 | local posix |
986 | local user |
987 | local group |
988 | local IFS |
989 | local pcat |
990 | local pname |
991 | local pver |
992 | local pbuild |
993 | local i |
994 | local pfull |
995 | |
996 | IFS=$'\n' |
997 | |
998 | # very basic getops |
999 | for i in $* |
1000 | do |
1001 | case $1 in |
1002 | --pcat|-c) shift; pcat="$1" ;; |
1003 | --pname|-n) shift; pname="$1" ;; |
1004 | --pver|-v) shift; pver="$1" ;; |
1005 | --pbuild|-b) shift; pbuild="$1" ;; |
1006 | esac |
1007 | shift |
1008 | done |
1009 | |
1010 | # sanity checks; abort if not given |
1011 | [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given." |
1012 | [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given." |
1013 | [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given." |
1014 | [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given." |
1015 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1016 | |
1017 | # check needed global vars |
1018 | [ -z "${BUILDDIR}" ] && die "remove_characterdevices() \$BUILDDIR not set." |
1019 | |
1020 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_characterdevices() .char not found" |
1021 | |
1022 | # sets fieldseperator to "§" instead of " " |
1023 | IFS=§ |
1024 | |
1025 | while read pathto posix user group |
1026 | do |
1027 | [ -z "${pathto}" ] && continue |
1028 | |
1029 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" |
1030 | rm "${MROOT}${pathto}" |
1031 | done < ${MROOT}${INSTALLDB}/${pfull}/.char |
1032 | |
1033 | # very important: unsetting the '§' fieldseperator |
1034 | IFS=$'\n' |
1035 | } |
1036 | |
1037 | |
1038 | ################################################### |
1039 | # function remove_fifos # |
1040 | # remove_fifos $PKGNAME # |
1041 | ################################################### |
1042 | remove_fifos() |
1043 | { |
1044 | local pathto |
1045 | local posix |
1046 | local user |
1047 | local group |
1048 | local IFS |
1049 | local pcat |
1050 | local pname |
1051 | local pver |
1052 | local pbuild |
1053 | local i |
1054 | local pfull |
1055 | |
1056 | IFS=$'\n' |
1057 | |
1058 | # very basic getops |
1059 | for i in $* |
1060 | do |
1061 | case $1 in |
1062 | --pcat|-c) shift; pcat="$1" ;; |
1063 | --pname|-n) shift; pname="$1" ;; |
1064 | --pver|-v) shift; pver="$1" ;; |
1065 | --pbuild|-b) shift; pbuild="$1" ;; |
1066 | esac |
1067 | shift |
1068 | done |
1069 | |
1070 | # sanity checks; abort if not given |
1071 | [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given." |
1072 | [ -z "${pname}" ] && die "remove_fifos() \$pname not given." |
1073 | [ -z "${pver}" ] && die "remove_fifos() \$pver not given." |
1074 | [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given." |
1075 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1076 | |
1077 | # check needed global vars |
1078 | [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set." |
1079 | |
1080 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found" |
1081 | |
1082 | # sets fieldseperator to "§" instead of " " |
1083 | IFS=§ |
1084 | |
1085 | while read pathto posix user group |
1086 | do |
1087 | [ -z "${pathto}" ] && continue |
1088 | |
1089 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}" |
1090 | rm "${MROOT}${pathto}" |
1091 | done < ${MROOT}${INSTALLDB}/${pfull}/.fifo |
1092 | |
1093 | # very important: unsetting the '§' fieldseperator |
1094 | IFS=$'\n' |
1095 | } |
1096 | |
1097 | |
1098 | ################################################### |
1099 | # function remove_direcories # |
1100 | # remove_direcories $PKGNAME # |
1101 | ################################################### |
1102 | remove_directories() |
1103 | { |
1104 | local pathto |
1105 | local posix |
1106 | local IFS |
1107 | local pcat |
1108 | local pname |
1109 | local pver |
1110 | local pbuild |
1111 | local i |
1112 | local pfull |
1113 | |
1114 | IFS=$'\n' |
1115 | |
1116 | # very basic getops |
1117 | for i in $* |
1118 | do |
1119 | case $1 in |
1120 | --pcat|-c) shift; pcat="$1" ;; |
1121 | --pname|-n) shift; pname="$1" ;; |
1122 | --pver|-v) shift; pver="$1" ;; |
1123 | --pbuild|-b) shift; pbuild="$1" ;; |
1124 | esac |
1125 | shift |
1126 | done |
1127 | |
1128 | # sanity checks; abort if not given |
1129 | [ -z "${pcat}" ] && die "remove_directories() \$pcat not given." |
1130 | [ -z "${pname}" ] && die "remove_directories() \$pname not given." |
1131 | [ -z "${pver}" ] && die "remove_directories() \$pver not given." |
1132 | [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given." |
1133 | pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1134 | |
1135 | # check needed global vars |
1136 | [ -z "${BUILDDIR}" ] && die "remove_directories() \$BUILDDIR not set." |
1137 | |
1138 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" |
1139 | |
1140 | # sets fieldseperator to "§" instead of " " |
1141 | IFS=§ |
1142 | |
1143 | # reversed order is mandatory ! |
1144 | tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix |
1145 | do |
1146 | [ -z "${pathto}" ] && continue |
1147 | |
1148 | if [ ! -d "${MROOT}${pathto}" ] |
1149 | then |
1150 | [[ ${VERBOSE} = on ]] && \ |
1151 | echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1152 | continue |
1153 | fi |
1154 | |
1155 | # exclude .keep directories |
1156 | if [ -f "${MROOT}${pathto}/.keep" ] |
1157 | then |
1158 | [[ ${VERBOSE} = on ]] && \ |
1159 | echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1160 | continue |
1161 | fi |
1162 | |
1163 | # monitors /etc/env.d -> env-rebuild |
1164 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
1165 | |
1166 | # monitors /usr/share/info -> info-rebuild |
1167 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true |
1168 | |
1169 | if rmdir "${MROOT}${pathto}" &> /dev/null |
1170 | then |
1171 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" |
1172 | else |
1173 | [[ ${VERBOSE} = on ]] && \ |
1174 | echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1175 | fi |
1176 | done |
1177 | |
1178 | # very important: unsetting the '§' fieldseperator |
1179 | IFS=$'\n' |
1180 | } |
1181 | |
1182 | |
1183 | ################################################### |
1184 | # function build_douninstall # |
1185 | # build_douninstall $PKGNAME # |
1186 | # NOTE: this is an wrapper to remove packages # |
1187 | ################################################### |
1188 | build_douninstall() |
1189 | { |
1190 | local pcat |
1191 | local pname |
1192 | local pver |
1193 | local pbuild |
1194 | local i |
1195 | |
1196 | # very basic getops |
1197 | for i in $* |
1198 | do |
1199 | case $1 in |
1200 | --pcat|-c) shift; pcat="$1" ;; |
1201 | --pname|-n) shift; pname="$1" ;; |
1202 | --pver|-v) shift; pver="$1" ;; |
1203 | --pbuild|-b) shift; pbuild="$1" ;; |
1204 | esac |
1205 | shift |
1206 | done |
1207 | |
1208 | # sanity checks; abort if not given |
1209 | [ -z "${pcat}" ] && die "build_douninstall() \$pcat not given." |
1210 | [ -z "${pname}" ] && die "build_douninstall() \$pname not given." |
1211 | [ -z "${pver}" ] && die "build_douninstall() \$pver not given." |
1212 | [ -z "${pbuild}" ] && die "build_douninstall() \$pbuild not given." |
1213 | |
1214 | # this is only a wrapper |
1215 | |
1216 | # NOTE: |
1217 | # !! we use § as field seperator !! |
1218 | # doing so prevent us to get errors by filenames with spaces |
1219 | |
1220 | for i in symlinks files blockdevices characterdevices directories fifos |
1221 | do |
1222 | remove_${i} \ |
1223 | --pcat "${pcat}" \ |
1224 | --pname "${pname}" \ |
1225 | --pver "${pver}" \ |
1226 | --pbuild "${pbuild}" \ |
1227 | || die "remove ${i} ${pcat}/${pname}-${pver}-${pbuild}" |
1228 | done |
1229 | } |
1230 | |
1231 | # fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
1232 | fetch_packages() |
1233 | { |
1234 | local list="$@" |
1235 | local pkg |
1236 | local mirr |
1237 | local magefile |
1238 | local md5file |
1239 | local opt |
1240 | local count_current |
1241 | local count_total |
1242 | |
1243 | [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
1244 | |
1245 | # get count of total packages |
1246 | declare -i count_current=0 |
1247 | declare -i count_total=0 |
1248 | |
1249 | for i in ${list}; do (( count_total++ )); done |
1250 | |
1251 | for magefile in ${list} |
1252 | do |
1253 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
1254 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
1255 | |
1256 | (( count_current++ )) |
1257 | xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" |
1258 | |
1259 | # abort on virtual pkg |
1260 | if [[ ${pkgtype} = virtual ]] |
1261 | then |
1262 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1263 | echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
1264 | continue |
1265 | fi |
1266 | |
1267 | # abort on sources pkg |
1268 | if [[ ${pkgtype} = sources ]] |
1269 | then |
1270 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1271 | echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
1272 | continue |
1273 | fi |
1274 | |
1275 | # abort if already exist |
1276 | if [ -f ${PKGDIR}/${pkg} ] |
1277 | then |
1278 | echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1279 | echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " |
1280 | continue |
1281 | fi |
1282 | |
1283 | for mirr in ${MIRRORS} |
1284 | do |
1285 | echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1286 | #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " |
1287 | echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
1288 | [[ ${VERBOSE} = off ]] && opt="--quiet" |
1289 | wget \ |
1290 | ${WGET_FETCH_OPTIONS} \ |
1291 | --directory-prefix=${PKGDIR} \ |
1292 | ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} |
1293 | if [[ $? = 0 ]] |
1294 | then |
1295 | break |
1296 | else |
1297 | continue |
1298 | fi |
1299 | done |
1300 | |
1301 | if [ ! -f ${PKGDIR}/${pkg} ] |
1302 | then |
1303 | die "Could not download ${pkg}" |
1304 | fi |
1305 | done |
1306 | |
1307 | # add a crlf for a better view |
1308 | if [ ${count_total} -gt 1 ]; then echo; fi |
1309 | } |
1310 | |
1311 | syncmage() |
1312 | { |
1313 | if [ -z "${RSYNC}" ] |
1314 | then |
1315 | die "You have no rsync-mirrors defined. Please edit your ${MAGERC}." |
1316 | fi |
1317 | |
1318 | local i |
1319 | for i in ${RSYNC} |
1320 | do |
1321 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} |
1322 | if [[ $? = 0 ]] |
1323 | then |
1324 | break |
1325 | else |
1326 | continue |
1327 | fi |
1328 | done |
1329 | |
1330 | # clean up backup files (foo~) |
1331 | find ${MAGEDIR} -name *~ -exec rm '{}' ';' |
1332 | |
1333 | # check if a newer mage version is available |
1334 | is_newer_mage_version_available |
1335 | } |
1336 | |
1337 | syncmage_tarball() |
1338 | { |
1339 | local latest_tarball |
1340 | local latest_md5 |
1341 | local temp="$(mktemp -d)" |
1342 | local mirr mymirr |
1343 | local opt |
1344 | |
1345 | # try to get the md5 marked as latest on the server |
1346 | latest_md5="mage-latest.md5" |
1347 | |
1348 | # try to get the tarball marked as latest on the server |
1349 | latest_tarball="mage-latest.tar.bz2" |
1350 | |
1351 | for mirr in ${MIRRORS} |
1352 | do |
1353 | # path without distribution |
1354 | mymirr="${mirr%/*}" |
1355 | |
1356 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1357 | echo "fetching latest md5 from ${mymirr} ..." |
1358 | [[ ${VERBOSE} = off ]] && opt="--quiet" |
1359 | wget \ |
1360 | ${WGET_FETCH_OPTIONS} \ |
1361 | --directory-prefix=${temp} \ |
1362 | ${opt} ${mymirr}/rsync/tarballs/${latest_md5} |
1363 | |
1364 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1365 | echo "fetching latest tarball from ${mymirr} ..." |
1366 | wget \ |
1367 | ${WGET_FETCH_OPTIONS} \ |
1368 | --directory-prefix=${temp} \ |
1369 | ${opt} ${mymirr}/rsync/tarballs/${latest_tarball} |
1370 | if [[ $? = 0 ]] |
1371 | then |
1372 | break |
1373 | else |
1374 | continue |
1375 | fi |
1376 | done |
1377 | |
1378 | if [[ -f ${temp}/${latest_tarball} ]] |
1379 | then |
1380 | # check md5 |
1381 | if [[ ! -f ${temp}/${latest_md5} ]] |
1382 | then |
1383 | die "md5 is missing ... aborting" |
1384 | else |
1385 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1386 | echo -n "checking md5sum... " |
1387 | ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed" |
1388 | fi |
1389 | |
1390 | if [[ -d ${MAGEDIR} ]] |
1391 | then |
1392 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1393 | echo "cleaning old mage-tree ${MAGEDIR}..." |
1394 | rm -rf ${MAGEDIR} |
1395 | fi |
1396 | |
1397 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1398 | echo "updating mage-tree from tarball ..." |
1399 | # unpack in dirname of MAGEDIR, as the tarball has already the mage |
1400 | tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" |
1401 | |
1402 | if [[ -d ${temp} ]] |
1403 | then |
1404 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1405 | echo "cleaning temp-files ..." |
1406 | rm -rf ${temp} |
1407 | fi |
1408 | |
1409 | # check if a newer mage version is available |
1410 | is_newer_mage_version_available |
1411 | else |
1412 | die "Could not fetch the latest tarball ... aborting" |
1413 | fi |
1414 | } |
1415 | |
1416 | cleanpkg() |
1417 | { |
1418 | if [ -d "${PKGDIR}" ] |
1419 | then |
1420 | echo -n "Removing downloaded packages... " |
1421 | rm -rf ${PKGDIR}/* |
1422 | echo "done." |
1423 | fi |
1424 | } |
1425 | |
1426 | xtitle() |
1427 | { |
1428 | if [[ ${TERM} = xterm ]] |
1429 | then |
1430 | echo -ne "\033]0;Mage: $1\007" |
1431 | fi |
1432 | return 0 |
1433 | } |
1434 | |
1435 | |
1436 | xtitleclean() |
1437 | { |
1438 | if [[ ${TERM} = xterm ]] |
1439 | then |
1440 | echo -ne "\033]0;\007" |
1441 | fi |
1442 | return 0 |
1443 | } |
1444 | |
1445 | |
1446 | # cuts full pathnames or versioniezed names down to basename |
1447 | choppkgname() |
1448 | { |
1449 | #we want this only if full name was used |
1450 | if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
1451 | then |
1452 | #cuts ARCH and PBUILD |
1453 | #ARCH comes from ${MAGERC} |
1454 | MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") |
1455 | |
1456 | #cuts version number |
1457 | MAGENAME=$(basename ${MAGENAME%-*} .mage) |
1458 | fi |
1459 | } |
1460 | |
1461 | # get_categorie $PNAME, returns CATEGORIE |
1462 | # $1=pname |
1463 | # ret 0=ok, 1=not_found |
1464 | pname2pcat() |
1465 | { |
1466 | local pname="$1" |
1467 | local repo="$2" |
1468 | local pcat |
1469 | local categorie |
1470 | |
1471 | for pcat in ${MAGEDIR}/* |
1472 | do |
1473 | if [ -d ${pcat}/${pname} ] |
1474 | then |
1475 | categorie=$(basename ${pcat}) |
1476 | fi |
1477 | done |
1478 | |
1479 | echo "${categorie}" |
1480 | } |
1481 | |
1482 | # check_stable_package /path/to/foo.mage |
1483 | # returns 0=stable 1=unstable |
1484 | check_stable_package() |
1485 | { |
1486 | # first check if this magefile is not blacklisted |
1487 | blacklisted "$1" || return 1 |
1488 | |
1489 | local STATE |
1490 | STATE="$(get_value_from_magefile STATE "$1")" |
1491 | |
1492 | # state testing |
1493 | if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] |
1494 | then |
1495 | case ${STATE} in |
1496 | testing|stable) return 0 ;; |
1497 | *) return 1 ;; |
1498 | esac |
1499 | fi |
1500 | |
1501 | # state unstable |
1502 | if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] |
1503 | then |
1504 | case ${STATE} in |
1505 | unstable|testing|stable) return 0 ;; |
1506 | *) return 1 ;; |
1507 | esac |
1508 | fi |
1509 | |
1510 | # no use_state given = stable |
1511 | case ${STATE} in |
1512 | stable) return 0 ;; |
1513 | *) return 1 ;; |
1514 | esac |
1515 | } |
1516 | |
1517 | |
1518 | # get_highest_magefile ${PCAT} ${PNAME} |
1519 | # fake at moment returns only stable pkgs (must set to be one) |
1520 | # return $HIGHEST_MAGEFILE |
1521 | get_highest_magefile() |
1522 | { |
1523 | local HIGHEST_MAGEFILE |
1524 | local PCAT="$1" |
1525 | local PNAME="$2" |
1526 | local magefile |
1527 | |
1528 | # do not list the content of a directory, only the name (-d) |
1529 | for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*) |
1530 | do |
1531 | [[ -z ${magefile} ]] && continue |
1532 | # we exclude subdirs (for stuff like a md5sum dir) |
1533 | [[ -d ${magefile} ]] && continue |
1534 | if check_stable_package ${magefile} |
1535 | then |
1536 | HIGHEST_MAGEFILE=${magefile} |
1537 | #for debug only |
1538 | [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" |
1539 | fi |
1540 | done |
1541 | |
1542 | # do not so anything |
1543 | # # stop here if HIGHEST_MAGEFILE is zero |
1544 | # # this package must be unstable or old |
1545 | # if [ -z "${HIGHEST_MAGEFILE}" ] |
1546 | # then |
1547 | # echo |
1548 | # echo -n "All packages named " |
1549 | # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} |
1550 | # echo -n " are marked " |
1551 | # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} |
1552 | # echo "." |
1553 | # echo "You need to declare USE_UNSTABLE=true to install this." |
1554 | # echo |
1555 | # echo "Example:" |
1556 | # echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" |
1557 | # echo |
1558 | # echo "Be warned that these packages are not stable and may cause serious problems." |
1559 | # echo "You should know what you are doing, so don't complain about any damage." |
1560 | # echo |
1561 | # return 1 |
1562 | # fi |
1563 | |
1564 | echo "${HIGHEST_MAGEFILE}" |
1565 | return 0 |
1566 | } |
1567 | |
1568 | |
1569 | ################################################### |
1570 | # function is_config_protected # |
1571 | # is_config_protected /path/to/file # |
1572 | # # |
1573 | # returns: # |
1574 | # 0 - not protected # |
1575 | # 1 - error # |
1576 | # 2 - protected # |
1577 | # 3 - protected but masked # |
1578 | # 4 - protected but ignored # |
1579 | # # |
1580 | ################################################### |
1581 | is_config_protected() |
1582 | { |
1583 | local EXPFILE |
1584 | local TEST |
1585 | local PROTECTED |
1586 | local IFS |
1587 | local i |
1588 | local x |
1589 | |
1590 | EXPFILE="${MROOT}$1" |
1591 | |
1592 | # file does not exist; it can be written |
1593 | [[ ! -e ${EXPFILE} ]] && return 0 |
1594 | |
1595 | # to be safe; it may be '§' |
1596 | IFS=' ' |
1597 | |
1598 | # check if config protected |
1599 | for i in ${CONFIG_PROTECT} |
1600 | do |
1601 | # only replace $i in the beginning of the variable |
1602 | TEST="${EXPFILE/#${MROOT}${i}/Protected}" |
1603 | if [[ ${TEST} != ${EXPFILE} ]] |
1604 | then |
1605 | # file is config proteced |
1606 | PROTECTED=TRUE |
1607 | |
1608 | # check if not masked |
1609 | for x in ${CONFIG_PROTECT_MASK} |
1610 | do |
1611 | TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" |
1612 | if [[ ${TEST} != ${EXPFILE} ]] |
1613 | then |
1614 | PROTECTED=MASKED |
1615 | fi |
1616 | done |
1617 | |
1618 | # check if not ignored |
1619 | for x in ${CONFIG_PROTECT_IGNORE} |
1620 | do |
1621 | TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}" |
1622 | if [[ ${TEST} != ${EXPFILE} ]] |
1623 | then |
1624 | PROTECTED=IGNORED |
1625 | fi |
1626 | done |
1627 | fi |
1628 | done |
1629 | |
1630 | unset IFS |
1631 | |
1632 | case ${PROTECTED} in |
1633 | TRUE) |
1634 | #echo "I'm protected" |
1635 | return 2 |
1636 | ;; |
1637 | MASKED) |
1638 | #echo "I'm protected, but masked - delete me" |
1639 | return 3 |
1640 | ;; |
1641 | IGNORED) |
1642 | #echo "I'm protected, but ignored - keep me, del update" |
1643 | return 4 |
1644 | ;; |
1645 | *) |
1646 | #echo "delete me" |
1647 | return 0 |
1648 | ;; |
1649 | esac |
1650 | } |
1651 | |
1652 | |
1653 | ################################################### |
1654 | # function count_protected_files # |
1655 | # count_protected_files /path/to/file # |
1656 | # # |
1657 | # note: prints number of protected files # |
1658 | # exp: 0012 # |
1659 | ################################################### |
1660 | count_protected_files() |
1661 | { |
1662 | local file="$1" |
1663 | local dirname="${file%/*}" |
1664 | local filename="${file##*/}" |
1665 | local count |
1666 | local output |
1667 | local i |
1668 | |
1669 | declare -i count=0 |
1670 | |
1671 | # check if there are already protected files |
1672 | for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | |
1673 | sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | |
1674 | sort -t'%' -k3 -k2 | cut -f1 -d'%') |
1675 | do |
1676 | count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") |
1677 | done |
1678 | (( count ++ )) |
1679 | |
1680 | # fill output up with zeros |
1681 | for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done |
1682 | output="${output}${count}" |
1683 | |
1684 | echo "${output}" |
1685 | } |
1686 | |
1687 | # call with |
1688 | # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME' |
1689 | # returns /path/to/magefile(s) |
1690 | get_uninstall_candidates() |
1691 | { |
1692 | local search_pname |
1693 | local pkg |
1694 | local pcat |
1695 | local pname |
1696 | local pver |
1697 | local pbuild |
1698 | local list |
1699 | local pcatdir |
1700 | local protected |
1701 | local i |
1702 | |
1703 | # very basic getops |
1704 | for i in $* |
1705 | do |
1706 | case $1 in |
1707 | --pcat|-c) shift; pcatdir="$1" ;; |
1708 | --pname|-n) shift; search_pname="$1" ;; |
1709 | --protected|-p) shift; protected="$1" ;; |
1710 | esac |
1711 | shift |
1712 | done |
1713 | |
1714 | # it's not good to complain here about empty pnames; better to continue later anyway |
1715 | # # sanity checks; abort if not given |
1716 | # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." |
1717 | |
1718 | |
1719 | # check needed global vars |
1720 | [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." |
1721 | |
1722 | # set pcatdir to '*' if empty |
1723 | [ -z "${pcatdir}" ] && pcatdir='*' |
1724 | |
1725 | for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* |
1726 | do |
1727 | # abort if not a dir |
1728 | [ ! -d ${pkg} ] && continue |
1729 | |
1730 | pname="$(magename2pname ${pkg})" |
1731 | |
1732 | if [[ ${search_pname} = ${pname} ]] |
1733 | then |
1734 | pcat="$(magename2pcat ${pkg} installdb)" |
1735 | pver="$(magename2pver ${pkg})" |
1736 | pbuild="$(magename2pbuild ${pkg})" |
1737 | |
1738 | # exclude proteced |
1739 | [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue |
1740 | |
1741 | list="${list} ${pcat}/${pname}-${pver}-${pbuild}" |
1742 | fi |
1743 | done |
1744 | |
1745 | echo "${list}" |
1746 | } |
1747 | |
1748 | # reads virtualdb file |
1749 | #$1 = virtualname; $2 commands: showpkgs, showline |
1750 | #return 0 == installed -> shows installed pkg as well |
1751 | #return 1 == not installed |
1752 | virtuals_read() |
1753 | { |
1754 | local virtualname="$1" |
1755 | local command="$2" |
1756 | local virtline |
1757 | local line x i |
1758 | |
1759 | # parse file to get virtual_name line |
1760 | IFS=$'\n' |
1761 | for line in $(< ${MROOT}${VIRTUALDB_FILE}) |
1762 | do |
1763 | IFS=$' ' |
1764 | for x in ${line} |
1765 | do |
1766 | if [[ ${x} = ${virtualname} ]] |
1767 | then |
1768 | virtline="${line}" |
1769 | [[ ${command} = showline ]] && echo "${line}" |
1770 | fi |
1771 | done |
1772 | IFS=$'\n' |
1773 | done |
1774 | |
1775 | unset IFS |
1776 | |
1777 | # now read the packages linked to VIRTUAL_NAME and output them |
1778 | if [ -n "${virtline}" ] |
1779 | then |
1780 | if [[ ${command} = showpkgs ]] |
1781 | then |
1782 | declare -i x=0 |
1783 | for i in ${virtline} |
1784 | do |
1785 | if [ ${x} -ge 1 ] |
1786 | then |
1787 | echo "${i}" |
1788 | fi |
1789 | ((x++)) |
1790 | done |
1791 | fi |
1792 | return 0 |
1793 | fi |
1794 | return 1 |
1795 | } |
1796 | |
1797 | |
1798 | #add pkg to virtualdb |
1799 | # $1 == virtualname $2= pkgname |
1800 | # retvals: 0=ok,added; 1=error; 3=pkg already in virtual |
1801 | virtuals_add() |
1802 | { |
1803 | local virtualname="$1" |
1804 | local pkgname="$2" |
1805 | local oldline |
1806 | local line i |
1807 | local installed_file |
1808 | local OLDIFS |
1809 | |
1810 | if virtuals_read ${virtualname} |
1811 | then |
1812 | # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already |
1813 | for i in $(virtuals_read ${virtualname} showpkgs) |
1814 | do |
1815 | if [[ ${i} = ${pkgname} ]] |
1816 | then |
1817 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1818 | echo "${pkgname} already linked as ${virtualname} ..." |
1819 | #return 3 |
1820 | return 0 |
1821 | fi |
1822 | done |
1823 | |
1824 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1825 | echo "updating ${virtualname} entry with ${pkgname} ..." |
1826 | oldline="$(virtuals_read ${virtualname} showline)" |
1827 | |
1828 | # make a backup |
1829 | mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old |
1830 | |
1831 | OLDIFS="${IFS}" |
1832 | IFS=$'\n' |
1833 | for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) |
1834 | do |
1835 | # if the right line, append ${pkgname}, else do nothing |
1836 | if [[ ${line} = ${oldline} ]] |
1837 | then |
1838 | echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
1839 | else |
1840 | echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} |
1841 | fi |
1842 | done |
1843 | # unset IFS |
1844 | IFS="${OLDIFS}" |
1845 | else |
1846 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
1847 | echo "register ${pkgname} as ${virtualname} ..." |
1848 | echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
1849 | fi |
1850 | |
1851 | return 0 |
1852 | } |
1853 | |
1854 | #deletes pakages from virtual database |
1855 | #$1 virtualname; $2 pkgname |
1856 | virtuals_del() |
1857 | { |
1858 | |
1859 | local virtualname="$1" |
1860 | local pkgname="$2" |
1861 | local oldline |
1862 | local method |
1863 | local line i x |
1864 | local pkg_installed |
1865 | local OLDIFS |
1866 | |
1867 | # first check if exists |
1868 | if virtuals_read ${virtualname} |
1869 | then |
1870 | # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
1871 | declare -i x=0 |
1872 | for i in $(virtuals_read ${virtualname} showpkgs) |
1873 | do |
1874 | if [[ ${i} = ${pkgname} ]] |
1875 | then |
1876 | pkg_installed=true |
1877 | fi |
1878 | ((x++)) |
1879 | done |
1880 | |
1881 | # abort if not installed |
1882 | if [[ ${pkg_installed} != true ]] |
1883 | then |
1884 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1885 | echo "${pkgname} does not exists in ${virtualname}." |
1886 | return 0 |
1887 | fi |
1888 | |
1889 | if [ ${x} -ge 2 ] |
1890 | then |
1891 | method=update |
1892 | else |
1893 | method=delall |
1894 | fi |
1895 | |
1896 | # get the complete line |
1897 | oldline="$(virtuals_read ${virtualname} showline)" |
1898 | |
1899 | # make a backup of the db |
1900 | mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
1901 | |
1902 | # parse virtualdb |
1903 | OLDIFS="${IFS}" |
1904 | IFS=$'\n' |
1905 | for line in $(< ${VIRTUALDB_FILE}.old) |
1906 | do |
1907 | if [[ ${line} = ${oldline} ]] |
1908 | then |
1909 | #delall or update? |
1910 | case ${method} in |
1911 | update) |
1912 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1913 | echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." |
1914 | # del PKG_NAME from line |
1915 | echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} |
1916 | ;; |
1917 | delall) |
1918 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
1919 | echo "Deleting ${virtualname} in virtual database ..." |
1920 | # continue; do not write anything |
1921 | continue |
1922 | ;; |
1923 | esac |
1924 | else |
1925 | echo "${line}" >> ${VIRTUALDB_FILE} |
1926 | fi |
1927 | done |
1928 | # unset IFS |
1929 | IFS="${OLDIFS}" |
1930 | else |
1931 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1932 | echo "${virtualname} does not exists in virtual database." |
1933 | fi |
1934 | } |
1935 | |
1936 | # gets real pkgname from virtuals.default |
1937 | #$1=VIRTUAL_NAME; returns PKG_NAME |
1938 | default_virtualname_to_pkgname() |
1939 | { |
1940 | local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname |
1941 | |
1942 | VIRTUAL_NAME=$1 |
1943 | |
1944 | while read db_virtualname db_pkgname |
1945 | do |
1946 | if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ] |
1947 | then |
1948 | PKG_NAME="${db_pkgname}" |
1949 | fi |
1950 | done << EOF |
1951 | $(< ${VIRTUALDB_DEFAULTS}) |
1952 | EOF |
1953 | |
1954 | if [ -n "${PKG_NAME}" ] |
1955 | then |
1956 | echo "${PKG_NAME}" |
1957 | fi |
1958 | } |
1959 | |
1960 | minclude() |
1961 | { |
1962 | local i |
1963 | |
1964 | if [[ -n $* ]] |
1965 | then |
1966 | for i in $* |
1967 | do |
1968 | [[ ${MAGEDEBUG} = on ]] && \ |
1969 | echo "--- Including ${MAGEDIR}/include/${i}.minc" |
1970 | source ${MAGEDIR}/include/${i}.minc |
1971 | done |
1972 | [[ ${MAGEDEBUG} = on ]] && echo |
1973 | fi |
1974 | } |
1975 | |
1976 | sminclude() |
1977 | { |
1978 | local i |
1979 | |
1980 | if [[ -n $* ]] |
1981 | then |
1982 | for i in $* |
1983 | do |
1984 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
1985 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
1986 | done |
1987 | echo |
1988 | fi |
1989 | } |
1990 | |
1991 | # checks if an newer mage version is available |
1992 | is_newer_mage_version_available() |
1993 | { |
1994 | local newest_mage |
1995 | local installed_mage |
1996 | |
1997 | newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" |
1998 | installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
1999 | |
2000 | if [[ ${newest_mage} > ${installed_mage} ]] |
2001 | then |
2002 | echo |
2003 | echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} |
2004 | echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} |
2005 | echo "It is recommened to install this newer version" |
2006 | echo "or your current system installation may break." |
2007 | echo |
2008 | echo -en "Please update mage by running " |
2009 | echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} |
2010 | echo |
2011 | fi |
2012 | } |
2013 | |
2014 | |
2015 | # returns pname from pkgname |
2016 | # pkgname2pname $PKGNAME |
2017 | pkgname2pname() |
2018 | { |
2019 | local pname |
2020 | |
2021 | pname="${1%-*-*-*}" |
2022 | echo "${pname}" |
2023 | } |
2024 | |
2025 | # returns pver from pkgname |
2026 | # pkgname2pver $PKGNAME |
2027 | pkgname2pver() |
2028 | { |
2029 | local i pver |
2030 | |
2031 | i="${1/$(pkgname2pname $1)-/}" |
2032 | pver="${i%-*-*}" |
2033 | echo "${pver}" |
2034 | } |
2035 | |
2036 | # returns pbuild from pkgname |
2037 | # pkgname2pbuild $PKGNAME |
2038 | pkgname2pbuild() |
2039 | { |
2040 | local pbuild |
2041 | |
2042 | pbuild="${1##*-}" |
2043 | echo "${pbuild}" |
2044 | } |
2045 | |
2046 | # returns parch from pkgname |
2047 | # pkgname2parch $PKGNAME |
2048 | pkgname2parch() |
2049 | { |
2050 | local i x parch |
2051 | |
2052 | i="${1%-*-*}-" |
2053 | x="${1%-*}" |
2054 | parch="${x/${i}/}" |
2055 | echo "${parch}" |
2056 | } |
2057 | |
2058 | # returns pname from magename |
2059 | # magename2pname /PATH/TO/MAGE/FILE |
2060 | magename2pname() |
2061 | { |
2062 | local i pname |
2063 | |
2064 | i="$(basename $1 .mage)" |
2065 | pname="${i%-*-*}" |
2066 | echo "${pname}" |
2067 | } |
2068 | |
2069 | # returns pver from magename |
2070 | # magename2pver /PATH/TO/MAGE/FILE |
2071 | magename2pver() |
2072 | { |
2073 | local i pver |
2074 | |
2075 | i="$(basename $1 .mage)" |
2076 | i="${i/$(magename2pname $1)-/}" |
2077 | pver="${i%-*}" |
2078 | echo "${pver}" |
2079 | } |
2080 | |
2081 | # returns pbuild from magename |
2082 | # magename2pbuild /PATH/TO/MAGE/FILE |
2083 | magename2pbuild() |
2084 | { |
2085 | local i pbuild |
2086 | |
2087 | i="$(basename $1 .mage)" |
2088 | pbuild="${i##*-}" |
2089 | echo "${pbuild}" |
2090 | } |
2091 | |
2092 | # returns pcat from magename |
2093 | # magename2pcat /PATH/TO/MAGE/FILE |
2094 | magename2pcat() |
2095 | { |
2096 | local i pcat |
2097 | |
2098 | if [[ ${2} = installdb ]] |
2099 | then |
2100 | # go 1 dir back |
2101 | i="${1%/*}" |
2102 | else |
2103 | # go 2 dirs back |
2104 | i="${1%/*/*}" |
2105 | fi |
2106 | |
2107 | # get basename |
2108 | pcat="${i##*/}" |
2109 | echo "${pcat}" |
2110 | } |
2111 | |
2112 | # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION) |
2113 | # dep2pcat DEPEND |
2114 | dep2pcat() |
2115 | { |
2116 | local pcat |
2117 | |
2118 | pcat="${1%/*}" |
2119 | echo "${pcat}" |
2120 | } |
2121 | |
2122 | # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION) |
2123 | # $2=virtual is used to resolv VDEPEND from virtual packages |
2124 | # dep2pcat DEPEND (virtual) |
2125 | dep2pname() |
2126 | { |
2127 | local pname |
2128 | |
2129 | pname="${1##*/}" |
2130 | |
2131 | # cut version only if not virtual or it will cut the name |
2132 | if [[ $(dep2pcat $1) != virtual ]] && \ |
2133 | [[ $2 != virtual ]] |
2134 | then |
2135 | pname="${pname%-*}" |
2136 | fi |
2137 | |
2138 | echo "${pname}" |
2139 | } |
2140 | |
2141 | dep2highest_magefile() |
2142 | { |
2143 | local pcat |
2144 | local pname |
2145 | local magefile |
2146 | local installed_virtuals |
2147 | |
2148 | pcat="$(dep2pcat $1)" |
2149 | pname="$(dep2pname $1)" |
2150 | |
2151 | if [[ ${pcat} = virtual ]] |
2152 | then |
2153 | # first check if virtual is already installed |
2154 | installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)" |
2155 | if [ -n "${installed_virtuals}" ] |
2156 | then |
2157 | for vpkg in ${installed_virtuals} |
2158 | do |
2159 | realpkgname="${vpkg}" |
2160 | virtualpkgname="${pcat}/${pname}" |
2161 | pcat="$(dep2pcat ${realpkgname})" |
2162 | pname="$(dep2pname ${realpkgname} virtual)" |
2163 | done |
2164 | else |
2165 | # choose one from virtualdb defaults (virtuals.defaults) |
2166 | realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})" |
2167 | virtualpkgname="${pcat}/${pname}" |
2168 | pcat="$(dep2pcat ${realpkgname})" |
2169 | pname="$(dep2pname ${realpkgname} virtual)" |
2170 | fi |
2171 | fi |
2172 | |
2173 | magefile="$(get_highest_magefile ${pcat} ${pname})" |
2174 | echo "${magefile}" |
2175 | } |
2176 | |
2177 | # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
2178 | is_installed() |
2179 | { |
2180 | local fullpkgname="$1" |
2181 | |
2182 | # return 0 if installed |
2183 | [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0 |
2184 | |
2185 | return 1 |
2186 | } |
2187 | |
2188 | install_packages() |
2189 | { |
2190 | local list="$@" |
2191 | local pkg |
2192 | local pcat |
2193 | local pname |
2194 | local pver |
2195 | local pbuild |
2196 | local total_pkgs |
2197 | local current_pkg |
2198 | local src_install |
2199 | local uninstall_list |
2200 | |
2201 | # check for --src-install |
2202 | if [[ $1 = --src-install ]] |
2203 | then |
2204 | # remove --src-install from list |
2205 | list=${list/--src-install/} |
2206 | # enable src-install |
2207 | src_install="--src-install" |
2208 | fi |
2209 | |
2210 | # reset MAGE_PROTECT_COUNTER |
2211 | declare -i MAGE_PROTECT_COUNTER=0 |
2212 | export MAGE_PROTECT_COUNTER |
2213 | |
2214 | # get count of total packages |
2215 | declare -i total_pkgs=0 |
2216 | declare -i current_pkg=0 |
2217 | for i in ${list}; do (( total_pkgs++ )); done |
2218 | |
2219 | echo |
2220 | |
2221 | if [[ -n ${MROOT} ]] |
2222 | then |
2223 | echo -ne ${COLRED} |
2224 | echo "!! installing in MROOT=${MROOT}" |
2225 | echo -ne ${COLDEFAULT} |
2226 | echo |
2227 | fi |
2228 | |
2229 | for pkg in ${list} |
2230 | do |
2231 | (( current_pkg++ )) |
2232 | pcat=$(magename2pcat ${pkg}) |
2233 | pname=$(magename2pname ${pkg}) |
2234 | pver=$(magename2pver ${pkg}) |
2235 | pbuild=$(magename2pbuild ${pkg}) |
2236 | |
2237 | mage_install \ |
2238 | --pcat ${pcat} \ |
2239 | --pname ${pname} \ |
2240 | --pver ${pver} \ |
2241 | --pbuild ${pbuild} \ |
2242 | --count-total ${total_pkgs} \ |
2243 | --count-current ${current_pkg} \ |
2244 | ${src_install} |
2245 | |
2246 | # check for allready installed packages and remove them |
2247 | # except the package we have installed |
2248 | uninstall_list="$(get_uninstall_candidates \ |
2249 | --pcat "${pcat}" \ |
2250 | --pname "${pname}" \ |
2251 | --protected ${pcat}/${pname}-${pver}-${pbuild})" |
2252 | |
2253 | # uninstall all packges in uninstall_list if not empty |
2254 | if [ -n "${uninstall_list}" ] |
2255 | then |
2256 | echo |
2257 | uninstall_packages ${uninstall_list} \ |
2258 | || die "install_packges() uninstalling not-needed." |
2259 | fi |
2260 | |
2261 | # crlf for better view in VERBOSE mode |
2262 | #if [[ ${VERBOSE} = on ]]; then echo; fi |
2263 | echo |
2264 | done |
2265 | |
2266 | #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}" |
2267 | show_etc_update_mesg |
2268 | } |
2269 | |
2270 | # get_value_from_magefile VARIABLE |
2271 | # returns the content of this VAR |
2272 | get_value_from_magefile() |
2273 | { |
2274 | local var="$1" |
2275 | local magefile="$2" |
2276 | local value |
2277 | |
2278 | [[ -z ${var} ]] && return 1 |
2279 | [[ -z ${magefile} ]] && return 1 |
2280 | |
2281 | # local all possible vars of a mage file |
2282 | # to prevent bad issues |
2283 | local PKGNAME |
2284 | local STATE |
2285 | local DESCRIPTION |
2286 | local HOMEPAGE |
2287 | local DEPEND |
2288 | local SDEPEND |
2289 | local PROVIDE |
2290 | local PKGTYPE |
2291 | local MAGE_TARGETS |
2292 | local SPLIT_PACKAGE_BASE |
2293 | local preinstall |
2294 | local postinstall |
2295 | local preremove |
2296 | local postremove |
2297 | |
2298 | # sanity checks |
2299 | [ -f ${magefile} ] && source ${magefile} || \ |
2300 | die "get_value_from_magefile: ${magefile} not found." |
2301 | [ -z "${var}" ] && die "get_value_from_magefile: \$var not given." |
2302 | |
2303 | source ${magefile} |
2304 | eval value=\$$(echo ${var}) |
2305 | echo "${value}" |
2306 | |
2307 | # unset these functions |
2308 | unset -f preinstall |
2309 | unset -f postinstall |
2310 | unset -f preremove |
2311 | unset -f postremove |
2312 | } |
2313 | |
2314 | mage_install() |
2315 | { |
2316 | # local all possible vars of a mage file |
2317 | # to prevent bad issues |
2318 | local PKGNAME |
2319 | local STATE |
2320 | local DESCRIPTION |
2321 | local HOMEPAGE |
2322 | local DEPEND |
2323 | local SDEPEND |
2324 | local PROVIDE |
2325 | local PKGTYPE |
2326 | local preinstall |
2327 | local postinstall |
2328 | local preremove |
2329 | local postremove |
2330 | |
2331 | local pcat |
2332 | local pname |
2333 | local pver |
2334 | local pbuild |
2335 | local count_total |
2336 | local count_current |
2337 | local magefile |
2338 | local src_install |
2339 | local i |
2340 | |
2341 | # very basic getops |
2342 | for i in $* |
2343 | do |
2344 | case $1 in |
2345 | --pcat|-c) shift; pcat="$1" ;; |
2346 | --pname|-n) shift; pname="$1" ;; |
2347 | --pver|-v) shift; pver="$1" ;; |
2348 | --pbuild|-b) shift; pbuild="$1" ;; |
2349 | --count-total) shift; count_total="$1" ;; |
2350 | --count-current) shift; count_current="$1" ;; |
2351 | --src-install|-s) shift; src_install=true ;; |
2352 | esac |
2353 | shift |
2354 | done |
2355 | |
2356 | # sanity checks; abort if not given |
2357 | [ -z "${pcat}" ] && die "mage_install() \$pcat not given." |
2358 | [ -z "${pname}" ] && die "mage_install() \$pname not given." |
2359 | [ -z "${pver}" ] && die "mage_install() \$pver not given." |
2360 | [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given." |
2361 | |
2362 | # check needed global vars |
2363 | [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set." |
2364 | [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set." |
2365 | [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set." |
2366 | |
2367 | xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]" |
2368 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
2369 | echo -n "installing (${count_current}/${count_total}): " |
2370 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2371 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2372 | |
2373 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" |
2374 | source ${magefile} |
2375 | |
2376 | # abort on sources if no srcinstall |
2377 | if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]] |
2378 | then |
2379 | echo |
2380 | echo -e "This Package is a Source Package." |
2381 | echo |
2382 | echo -e "Only 'srcinstall' works with this type of packages" |
2383 | echo -en "If you have done a srcinstall before, " |
2384 | echo -e "you will find the files in /usr/src." |
2385 | echo |
2386 | exit 1 |
2387 | fi |
2388 | |
2389 | ## preinstall scripts |
2390 | if [ -n "$(typeset -f preinstall)" ] |
2391 | then |
2392 | echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... " |
2393 | preinstall |
2394 | unset preinstall |
2395 | fi |
2396 | |
2397 | if [[ ${src_install} = true ]] |
2398 | then |
2399 | local smage2file |
2400 | # check needed global vars |
2401 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." |
2402 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." |
2403 | [ -z "${BINDIR}" ] && die "\$BINDIR not set." |
2404 | |
2405 | # build the package first |
2406 | if [[ ${MAGEDEBUG} = on ]] |
2407 | then |
2408 | echo M:${pname} |
2409 | echo V:${pver} |
2410 | echo B:${pbuild} |
2411 | fi |
2412 | |
2413 | if [[ -n ${MAGE_TARGETS} ]] |
2414 | then |
2415 | # basic svn compat |
2416 | if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
2417 | then |
2418 | for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
2419 | do |
2420 | smage2file="${i}" |
2421 | done |
2422 | else |
2423 | smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
2424 | fi |
2425 | |
2426 | elif [[ -n ${SPLIT_PACKAGE_BASE} ]] |
2427 | then |
2428 | # basic svn compat |
2429 | if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
2430 | then |
2431 | for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
2432 | do |
2433 | smage2file="${i}" |
2434 | done |
2435 | else |
2436 | smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
2437 | fi |
2438 | |
2439 | else |
2440 | # basic svn compat |
2441 | if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
2442 | then |
2443 | for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2444 | do |
2445 | smage2file="${i}" |
2446 | done |
2447 | else |
2448 | smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2449 | fi |
2450 | fi |
2451 | |
2452 | if [ -f "${smage2file}" ] |
2453 | then |
2454 | echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " |
2455 | smage2 ${smage2file} || die "compile failed" |
2456 | else |
2457 | echo |
2458 | echo "$(basename ${SMAGEFILE}) not found." |
2459 | echo "update your smage-tree and try it again." |
2460 | echo |
2461 | die |
2462 | fi |
2463 | fi |
2464 | |
2465 | if [[ ${PKGTYPE} != virtual ]] && \ |
2466 | [[ ${PKGTYPE} != sources ]] |
2467 | then |
2468 | echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
2469 | build_doinstall ${PKGNAME} |
2470 | fi |
2471 | |
2472 | ## postinstall scripts |
2473 | if [ -n "$(typeset -f postinstall)" ] |
2474 | then |
2475 | echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... " |
2476 | postinstall |
2477 | unset postinstall |
2478 | fi |
2479 | |
2480 | # install a database entry |
2481 | install_database_entry \ |
2482 | --pcat "${pcat}" \ |
2483 | --pname "${pname}" \ |
2484 | --pver "${pver}" \ |
2485 | --pbuild "${pbuild}" \ |
2486 | --pkgname "${PKGNAME}" \ |
2487 | --pkgtype "${PKGTYPE}" \ |
2488 | || die "error in mage_install() running install_database_entry()." |
2489 | |
2490 | # remove the package dir now |
2491 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
2492 | then |
2493 | rm -rf ${BUILDDIR}/${PKGNAME} |
2494 | fi |
2495 | |
2496 | # rebuilds toplevel info node |
2497 | if [[ ${MAGE_INFO_REBUILD} = true ]] |
2498 | then |
2499 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2500 | echo -n "rebuilding top-level info node ... " |
2501 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ |
2502 | > ${MROOT}/usr/share/info/dir && \ |
2503 | echo "done." || echo "failure." |
2504 | unset MAGE_INFO_REBUILD |
2505 | fi |
2506 | |
2507 | # rebuilds the enviroment with the content of /etc/env.d |
2508 | if [[ ${MAGE_ENV_REBUILD} = true ]] |
2509 | then |
2510 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2511 | echo -n "rebuilding environment ... " |
2512 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
2513 | echo "done." || echo "failure." |
2514 | unset MAGE_ENV_REBUILD |
2515 | fi |
2516 | |
2517 | xtitleclean |
2518 | |
2519 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2520 | echo -n "package " |
2521 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2522 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
2523 | echo "successfully installed." |
2524 | |
2525 | # unset these functions |
2526 | unset -f preinstall |
2527 | unset -f postinstall |
2528 | unset -f preremove |
2529 | unset -f postremove |
2530 | } |
2531 | |
2532 | md5sum_packages() |
2533 | { |
2534 | local list="$@" |
2535 | local magefile |
2536 | local pcat |
2537 | local pname |
2538 | local pkgname |
2539 | local pkgfile |
2540 | local pkgtype |
2541 | local count_current |
2542 | local count_total |
2543 | |
2544 | # get count of total packages |
2545 | declare -i count_current=0 |
2546 | declare -i count_total=0 |
2547 | |
2548 | for i in ${list}; do (( count_total++ )); done |
2549 | |
2550 | for magefile in ${list} |
2551 | do |
2552 | pcat=$(magename2pcat ${magefile}) |
2553 | pname=$(magename2pname ${magefile}) |
2554 | pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
2555 | md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
2556 | pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
2557 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
2558 | |
2559 | (( count_current++ )) |
2560 | xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]" |
2561 | |
2562 | # abort on virtual pkg |
2563 | if [[ ${pkgtype} = virtual ]] |
2564 | then |
2565 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2566 | echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
2567 | continue |
2568 | fi |
2569 | |
2570 | # abort on sources pkg |
2571 | if [[ ${pkgtype} = sources ]] |
2572 | then |
2573 | echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2574 | echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
2575 | continue |
2576 | fi |
2577 | |
2578 | if [ -f "${md5file}" ] |
2579 | then |
2580 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2581 | echo -ne "checking md5sum (${count_current}/${count_total}): " |
2582 | ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" |
2583 | else |
2584 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2585 | echo -e "!! no md5sum file found for ${pkgfile} :(" |
2586 | fi |
2587 | done |
2588 | |
2589 | # add a crlf for a better view |
2590 | if [ ${count_total} -gt 1 ]; then echo; fi |
2591 | } |
2592 | |
2593 | ## uninstall_packages ulist |
2594 | uninstall_packages() |
2595 | { |
2596 | local list="$@" |
2597 | local pcat |
2598 | local pname |
2599 | local pver |
2600 | local pbuild |
2601 | local can_pcat |
2602 | local can_pname |
2603 | local can_ver_list |
2604 | |
2605 | if [[ -n ${MROOT} ]] |
2606 | then |
2607 | echo -ne ${COLRED} |
2608 | echo "!! uninstalling from MROOT=${MROOT}" |
2609 | echo -ne ${COLDEFAULT} |
2610 | echo |
2611 | fi |
2612 | |
2613 | # generate a candidates list |
2614 | for pkg in ${list} |
2615 | do |
2616 | pcat=$(dep2pcat ${pkg}) |
2617 | pname=$(magename2pname ${pkg}) |
2618 | pver=$(magename2pver ${pkg}) |
2619 | pbuild=$(magename2pbuild ${pkg}) |
2620 | can_pcat="${pcat}" |
2621 | can_pname="${pname}" |
2622 | |
2623 | if [ -z "${can_ver_list}" ] |
2624 | then |
2625 | can_ver_list=" ${pver}-${pbuild}" |
2626 | else |
2627 | can_ver_list="${can_ver_list}, ${pver}-${pbuild}" |
2628 | fi |
2629 | done |
2630 | |
2631 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2632 | echo "following candidate(s) will be removed:" |
2633 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2634 | echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" |
2635 | echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
2636 | echo |
2637 | if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] |
2638 | then |
2639 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2640 | echo "( Press [CTRL+C] to abort )" |
2641 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2642 | echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." |
2643 | for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) |
2644 | do |
2645 | echo -ne "${COLRED} ${i}${COLDEFAULT}" |
2646 | sleep 1 |
2647 | done |
2648 | echo |
2649 | echo |
2650 | fi |
2651 | |
2652 | for pkg in ${list} |
2653 | do |
2654 | pcat=$(dep2pcat ${pkg}) |
2655 | pname=$(magename2pname ${pkg}) |
2656 | pver=$(magename2pver ${pkg}) |
2657 | pbuild=$(magename2pbuild ${pkg}) |
2658 | |
2659 | mage_uninstall \ |
2660 | --pcat ${pcat} \ |
2661 | --pname ${pname} \ |
2662 | --pver ${pver} \ |
2663 | --pbuild ${pbuild} \ |
2664 | --count-total ${total_pkgs} \ |
2665 | --count-current ${current_pkg} \ |
2666 | ${src_install} |
2667 | |
2668 | # crlf for better view in VERBOSE mode |
2669 | #if [[ ${VERBOSE} = on ]]; then echo; fi |
2670 | echo |
2671 | done |
2672 | } |
2673 | |
2674 | mage_uninstall() |
2675 | { |
2676 | # local all possible vars of a mage file |
2677 | # to prevent bad issues |
2678 | local PKGNAME |
2679 | local STATE |
2680 | local DESCRIPTION |
2681 | local HOMEPAGE |
2682 | local DEPEND |
2683 | local SDEPEND |
2684 | local PROVIDE |
2685 | local PKGTYPE |
2686 | local preinstall |
2687 | local postinstall |
2688 | local preremove |
2689 | local postremove |
2690 | |
2691 | local pcat |
2692 | local pname |
2693 | local pver |
2694 | local pbuild |
2695 | local magefile |
2696 | local i |
2697 | |
2698 | # very basic getops |
2699 | for i in $* |
2700 | do |
2701 | case $1 in |
2702 | --pcat|-c) shift; pcat="$1" ;; |
2703 | --pname|-n) shift; pname="$1" ;; |
2704 | --pver|-v) shift; pver="$1" ;; |
2705 | --pbuild|-b) shift; pbuild="$1" ;; |
2706 | esac |
2707 | shift |
2708 | done |
2709 | |
2710 | # sanity checks; abort if not given |
2711 | [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given." |
2712 | [ -z "${pname}" ] && die "mage_uninstall() \$pname not given." |
2713 | [ -z "${pver}" ] && die "mage_uninstall() \$pver not given." |
2714 | [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given." |
2715 | |
2716 | # check needed global vars |
2717 | [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set." |
2718 | [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set." |
2719 | [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set." |
2720 | |
2721 | xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]" |
2722 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
2723 | echo -n "removing: " |
2724 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2725 | echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2726 | |
2727 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
2728 | source ${magefile} |
2729 | |
2730 | ## preremove scripts |
2731 | if [ -n "$(typeset -f preremove)" ] |
2732 | then |
2733 | echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... " |
2734 | preremove |
2735 | unset preremove |
2736 | fi |
2737 | |
2738 | # runs uninstall |
2739 | build_douninstall \ |
2740 | --pcat "${pcat}" \ |
2741 | --pname "${pname}" \ |
2742 | --pver "${pver}" \ |
2743 | --pbuild "${pbuild}" |
2744 | |
2745 | ## postremove scripts |
2746 | if [ -n "$(typeset -f postremove)" ] |
2747 | then |
2748 | echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... " |
2749 | postremove |
2750 | unset postremove |
2751 | fi |
2752 | |
2753 | # removes the database entry |
2754 | remove_database_entry \ |
2755 | --pcat "${pcat}" \ |
2756 | --pname "${pname}" \ |
2757 | --pver "${pver}" \ |
2758 | --pbuild "${pbuild}" \ |
2759 | || die "error in mage_uninstall() running remove_database_entry()." |
2760 | |
2761 | # rebuilds toplevel info node |
2762 | if [[ ${MAGE_INFO_REBUILD} = true ]] |
2763 | then |
2764 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2765 | echo -n "rebuilding top-level info node ... " |
2766 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ |
2767 | > ${MROOT}/usr/share/info/dir && \ |
2768 | echo "done." || echo "failure." |
2769 | unset MAGE_INFO_REBUILD |
2770 | fi |
2771 | |
2772 | # rebuilds the enviroment with the content of /etc/env.d |
2773 | if [[ ${MAGE_ENV_REBUILD} = true ]] |
2774 | then |
2775 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2776 | echo -n "rebuilding environment ... " |
2777 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
2778 | echo "done." || echo "failure." |
2779 | unset MAGE_ENV_REBUILD |
2780 | fi |
2781 | |
2782 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2783 | echo -n "package " |
2784 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2785 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
2786 | echo "successfully removed." |
2787 | |
2788 | # unset these functions |
2789 | unset -f preinstall |
2790 | unset -f postinstall |
2791 | unset -f preremove |
2792 | unset -f postremove |
2793 | } |
2794 | |
2795 | show_etc_update_mesg() |
2796 | { |
2797 | [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
2798 | |
2799 | echo |
2800 | echo -ne "${COLRED}" |
2801 | echo "Important:" |
2802 | echo -ne ${COLDEFAULT} |
2803 | echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed." |
2804 | echo |
2805 | echo "Please run 'etc-update' to update your configuration files." |
2806 | echo |
2807 | } |
2808 | |
2809 | pkgsearch() |
2810 | { |
2811 | local string="$1" |
2812 | local result |
2813 | local pkg |
2814 | local pcat |
2815 | local pname |
2816 | local magefile |
2817 | local pver |
2818 | local pbuild |
2819 | local state |
2820 | local descriptiom |
2821 | local homepage |
2822 | local i |
2823 | local all_installed |
2824 | local ipver |
2825 | local ipbuild |
2826 | local latest_available |
2827 | local depsfull |
2828 | local sdepsfull |
2829 | local deps |
2830 | local sdeps |
2831 | local dep |
2832 | local sign |
2833 | |
2834 | # only names no versions |
2835 | result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" |
2836 | #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)" |
2837 | |
2838 | # nothing found |
2839 | [[ -z ${result} ]] && die "No package found containing '${string}' in the name." |
2840 | |
2841 | for pkg in ${result} |
2842 | do |
2843 | # dirty, but does the job |
2844 | pcat="$(magename2pcat ${pkg}/foo)" |
2845 | pname="$(magename2pname ${pkg}-foo-foo)" |
2846 | |
2847 | # get highest version available |
2848 | magefile=$(get_highest_magefile ${pcat} ${pname}) |
2849 | |
2850 | if [[ ! -z ${magefile} ]] |
2851 | then |
2852 | # now get all needed infos to print a nice output |
2853 | pver="$(magename2pver ${magefile})" |
2854 | pbuild="$(magename2pbuild ${magefile})" |
2855 | state="$(get_value_from_magefile STATE ${magefile})" |
2856 | description="$(get_value_from_magefile DESCRIPTION ${magefile})" |
2857 | homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" |
2858 | |
2859 | # all installed |
2860 | for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) |
2861 | do |
2862 | ipver="$(magename2pver ${i})" |
2863 | ipbuild="$(magename2pbuild ${i})" |
2864 | |
2865 | if [[ -z ${all_installed} ]] |
2866 | then |
2867 | all_installed="${ipver}-${ipbuild}" |
2868 | else |
2869 | all_installed="${all_installed} ${ipver}-${ipbuild}" |
2870 | fi |
2871 | done |
2872 | [[ -z ${all_installed} ]] && all_installed="none" |
2873 | |
2874 | case ${state} in |
2875 | stable) state=${COLGREEN}"[s] ";; |
2876 | testing) state=${COLYELLOW}"[t] ";; |
2877 | unstable) state=${COLRED}"[u] ";; |
2878 | old) state=${COLGRAY}"[o] ";; |
2879 | esac |
2880 | |
2881 | latest_available="${pver}-${pbuild}" |
2882 | else |
2883 | # package is masked |
2884 | state="${COLRED}[m] " |
2885 | latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" |
2886 | fi |
2887 | |
2888 | depsfull="$(get_value_from_magefile DEPEND ${magefile})" |
2889 | sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" |
2890 | |
2891 | while read sign dep |
2892 | do |
2893 | case ${dep} in |
2894 | "") continue;; |
2895 | esac |
2896 | |
2897 | deps="${deps} $(basename ${dep%-*})" |
2898 | done << EOF |
2899 | ${depsfull} |
2900 | EOF |
2901 | |
2902 | while read sign dep |
2903 | do |
2904 | case ${dep} in |
2905 | "") continue;; |
2906 | esac |
2907 | |
2908 | sdeps="${sdeps} $(basename ${dep%-*})" |
2909 | done << EOF |
2910 | ${sdepsfull} |
2911 | EOF |
2912 | |
2913 | echo -e "${state}${pcat}/${pname}"${COLDEFAULT} |
2914 | echo -e " Latest available: ${latest_available}" |
2915 | echo " Installed versions: ${all_installed}" |
2916 | echo " Description: ${description}" |
2917 | echo " Homepage: ${homepage}" |
2918 | echo " Depends: ${deps}" |
2919 | echo " SDepends: ${sdeps}" |
2920 | echo |
2921 | |
2922 | unset pcat |
2923 | unset pname |
2924 | unset magefile |
2925 | unset pver |
2926 | unset pbuild |
2927 | unset state |
2928 | unset descriptiom |
2929 | unset homepage |
2930 | unset all_installed |
2931 | unset ipver |
2932 | unset ipbuild |
2933 | unset depsfull |
2934 | unset sdepsfull |
2935 | unset deps |
2936 | unset sdeps |
2937 | unset dep |
2938 | unset sign |
2939 | done |
2940 | } |
2941 | |
2942 | export_inherits() |
2943 | { |
2944 | local include="$1" |
2945 | shift |
2946 | |
2947 | while [ "$1" ] |
2948 | do |
2949 | local functions="$1" |
2950 | |
2951 | # sanity checks |
2952 | [ -z "${include}" ] && die "export_inherits(): \$include not given." |
2953 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." |
2954 | |
2955 | eval "${functions}() { ${include}_${functions} ; }" |
2956 | |
2957 | # debug |
2958 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" |
2959 | |
2960 | shift |
2961 | done |
2962 | } |
2963 | |
2964 | mlibdir() |
2965 | { |
2966 | local libdir=lib |
2967 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 |
2968 | |
2969 | echo "${libdir}" |
2970 | } |
2971 | |
2972 | ## blacklisted ${magefile} |
2973 | blacklisted() |
2974 | { |
2975 | [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable |
2976 | |
2977 | # compat |
2978 | [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable |
2979 | [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing |
2980 | |
2981 | # support both types for the moment |
2982 | if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]] |
2983 | then |
2984 | local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" |
2985 | else |
2986 | local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}" |
2987 | fi |
2988 | |
2989 | # return 0 if the list not exist; nothin is masked |
2990 | [[ ! -f ${EXCLUDED} ]] && return 0 |
2991 | |
2992 | local MAGEFILE="$1" |
2993 | |
2994 | local PCAT="$(magename2pcat ${MAGEFILE})" |
2995 | local PNAME="$(magename2pname ${MAGEFILE})" |
2996 | local PVER="$(magename2pver ${MAGEFILE})" |
2997 | local PBUILD="$(magename2pbuild ${MAGEFILE})" |
2998 | |
2999 | local EXPCAT EXPNAME EXPVER EXPBUILD |
3000 | while read EXPCAT EXPNAME EXPVER EXPBUILD |
3001 | do |
3002 | # ignore spaces and comments |
3003 | case "${EXPCAT}" in |
3004 | \#*|"") continue ;; |
3005 | esac |
3006 | |
3007 | # exclude full pver |
3008 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
3009 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
3010 | [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && |
3011 | [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] |
3012 | then |
3013 | [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 |
3014 | fi |
3015 | |
3016 | # exclude pcat/pname only |
3017 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
3018 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
3019 | [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] |
3020 | then |
3021 | [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 |
3022 | fi |
3023 | done << EOF |
3024 | $( cat ${EXCLUDED}; echo) |
3025 | EOF |
3026 | |
3027 | return 0 |
3028 | } |
3029 |