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