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