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