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