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