1 |
#!/bin/bash |
#!/bin/bash |
2 |
# Magellan Linux Installer Functions (mage.functions.sh) |
# Magellan Linux Installer Functions (mage.functions.sh) |
3 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.1 2005-09-09 16:35:38 niro Exp $ |
# $Id$ |
4 |
|
|
5 |
mage_setup() |
mage_setup() |
6 |
{ |
{ |
15 |
return 0 |
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() |
unpack_packages() |
142 |
{ |
{ |
143 |
local list="$@" |
local list="$@" |
144 |
local magefile |
local magefile |
|
local pkg |
|
|
local pkgtype |
|
145 |
local count_current |
local count_current |
146 |
local count_total |
local count_total |
147 |
|
local tar_opts |
148 |
|
|
149 |
# get count of total packages |
# get count of total packages |
150 |
declare -i count_current=0 |
declare -i count_current=0 |
154 |
|
|
155 |
for magefile in ${list} |
for magefile in ${list} |
156 |
do |
do |
157 |
pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
unpack_package "${magefile}" |
|
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
|
|
|
|
158 |
(( count_current++ )) |
(( count_current++ )) |
|
xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" |
|
|
|
|
|
# abort on virtual pkg |
|
|
if [[ ${pkgtype} = virtual ]] |
|
|
then |
|
|
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
|
|
echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
|
|
continue |
|
|
fi |
|
|
|
|
|
# abort on sources pkg |
|
|
if [[ ${pkgtype} = sources ]] |
|
|
then |
|
|
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
|
|
echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
|
|
continue |
|
|
fi |
|
|
|
|
|
echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " |
|
|
tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" |
|
159 |
done |
done |
160 |
|
|
161 |
# add a crlf for a better view |
# add a crlf for a better view |
175 |
mtime=$(stat -c %Y "${reference}") |
mtime=$(stat -c %Y "${reference}") |
176 |
touch \ |
touch \ |
177 |
--no-create \ |
--no-create \ |
178 |
|
--no-dereference \ |
179 |
--time=mtime \ |
--time=mtime \ |
180 |
--reference "${reference}" \ |
--reference="${reference}" \ |
181 |
"${pathto}" |
"${pathto}" |
182 |
|
|
183 |
echo "${mtime}" |
echo "${mtime}" |
231 |
while read pathto posix user group |
while read pathto posix user group |
232 |
do |
do |
233 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
234 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
|
|
|
235 |
|
|
236 |
# monitors /etc/env.d -> env-rebuild |
# monitors /etc/env.d -> env-rebuild |
237 |
[[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
[[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
298 |
is_config_protected "${pathto}" |
is_config_protected "${pathto}" |
299 |
retval="$?" |
retval="$?" |
300 |
|
|
301 |
# 0 - not protected # |
# 0 - not protected # |
302 |
# 1 - error # |
# 1 - error # |
303 |
# 2 - protected # |
# 2 - protected # |
304 |
# 3 - protected but masked # |
# 3 - protected but masked # |
305 |
|
# 4 - protected but ignored # |
306 |
|
|
307 |
case ${retval} in |
case ${retval} in |
308 |
# file is not protected - (over)write it |
# file is not protected - (over)write it |
309 |
0|3) |
0|3) |
310 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}" |
311 |
install -m "${posix}" -o "${user}" -g "${group}" \ |
install -m "${posix}" -o "${user}" -g "${group}" \ |
312 |
${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ |
313 |
"${MROOT}${pathto}" |
"${MROOT}${pathto}" |
319 |
"${user}" \ |
"${user}" \ |
320 |
"${group}" \ |
"${group}" \ |
321 |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
322 |
"${MROOT}${pathto}")" \ |
"${MROOT}${pathto}")" \ |
323 |
"${md5sum}" |
"${md5sum}" |
324 |
;; |
;; |
325 |
|
|
326 |
# file is protected, write backup file |
# file is protected, write backup file |
327 |
2) |
2) |
328 |
if [[ ${VERBOSE} = on ]] |
if mqueryfeature "verbose" |
329 |
then |
then |
330 |
echo -en "${COLRED}" |
echo -en "${COLRED}" |
331 |
echo -n "! prot " |
echo -n "! prot " |
346 |
"${user}" \ |
"${user}" \ |
347 |
"${group}" \ |
"${group}" \ |
348 |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
349 |
"${dest_protected}")" \ |
"${dest_protected}")" \ |
350 |
"${md5sum}" |
"${md5sum}" |
351 |
|
|
352 |
# update global MAGE_PROTECT_COUNTER |
# update global MAGE_PROTECT_COUNTER |
353 |
(( MAGE_PROTECT_COUNTER++ )) |
(( MAGE_PROTECT_COUNTER++ )) |
354 |
export MAGE_PROTECT_COUNTER |
export MAGE_PROTECT_COUNTER |
355 |
;; |
;; |
356 |
|
|
357 |
|
# file is protected but ignored, delete the update/do nothing |
358 |
|
4) |
359 |
|
if mqueryfeature "verbose" |
360 |
|
then |
361 |
|
echo -en "${COLRED}" |
362 |
|
echo -n "! ignr " |
363 |
|
echo -en "${COLDEFAULT}" |
364 |
|
echo " === FILE: ${MROOT}${pathto}" |
365 |
|
fi |
366 |
|
# simply do nothing here - only fix mtime |
367 |
|
fix_descriptor ${pkgname}/.files \ |
368 |
|
"${pathto}" \ |
369 |
|
"${posix}" \ |
370 |
|
"${user}" \ |
371 |
|
"${group}" \ |
372 |
|
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
373 |
|
"${MROOT}${pathto}")" \ |
374 |
|
"${md5sum}" |
375 |
|
;; |
376 |
esac |
esac |
377 |
done < ${BUILDDIR}/${pkgname}/.files |
done < ${BUILDDIR}/${pkgname}/.files |
378 |
|
|
415 |
while read pathto posix link mtime |
while read pathto posix link mtime |
416 |
do |
do |
417 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
418 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}" |
419 |
|
|
420 |
ln -snf "${link}" "${MROOT}${pathto}" |
ln -snf "${link}" "${MROOT}${pathto}" |
421 |
|
|
422 |
# fix mtime and db |
# fix mtime and db |
423 |
fix_descriptor ${pkgname}/.symlinks \ |
fix_descriptor ${pkgname}/.symlinks \ |
424 |
"${pathto}" \ |
"${pathto}" \ |
425 |
"${posix}" \ |
"${posix}" \ |
426 |
"${link}" \ |
"${link}" \ |
427 |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
428 |
"${MROOT}${pathto}")" |
"${MROOT}${pathto}")" |
429 |
|
|
430 |
done < ${BUILDDIR}/${pkgname}/.symlinks |
done < ${BUILDDIR}/${pkgname}/.symlinks |
431 |
|
|
432 |
# now copy the fixed file over the old one |
# # now copy the fixed file over the old one |
433 |
[ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ |
# [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ |
434 |
cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} |
# cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} |
435 |
|
|
436 |
# very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
437 |
IFS=$'\n' |
IFS=$'\n' |
447 |
local pkgname="$1" |
local pkgname="$1" |
448 |
local pathto |
local pathto |
449 |
local posix |
local posix |
450 |
|
local user |
451 |
|
local group |
452 |
local IFS |
local IFS |
453 |
|
|
454 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
462 |
# sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
463 |
IFS=§ |
IFS=§ |
464 |
|
|
465 |
while read pathto posix |
while read pathto posix major minor user group |
466 |
do |
do |
467 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
468 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}" |
469 |
|
|
470 |
mkfifo -m "${posix}" "${MROOT}$pathto" |
mknod -m "${posix}" "${MROOT}${pathto}" |
471 |
|
# make it optional atm !! |
472 |
|
if [[ ! -z ${user} ]] && [[ ! -z ${group} ]] |
473 |
|
then |
474 |
|
chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}" |
475 |
|
fi |
476 |
done < ${BUILDDIR}/${pkgname}/.pipes |
done < ${BUILDDIR}/${pkgname}/.pipes |
477 |
|
|
478 |
# very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
489 |
local pkgname="$1" |
local pkgname="$1" |
490 |
local pathto |
local pathto |
491 |
local posix |
local posix |
492 |
|
local major |
493 |
|
local minor |
494 |
|
local user |
495 |
|
local group |
496 |
local IFS |
local IFS |
497 |
|
|
498 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
506 |
# sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
507 |
IFS=§ |
IFS=§ |
508 |
|
|
509 |
while read pathto posix |
while read pathto posix major minor user group |
510 |
do |
do |
511 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
512 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}" |
513 |
|
|
514 |
mknode -m ${posix} -c "${MROOT}${pathto}" |
mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}" |
515 |
|
|
516 |
|
# make it optional atm !! |
517 |
|
if [[ ! -z ${user} ]] && [[ ! -z ${group} ]] |
518 |
|
then |
519 |
|
chown "${user}:${group}" "${MROOT}${pathto}" |
520 |
|
fi |
521 |
done < ${BUILDDIR}/${pkgname}/.char |
done < ${BUILDDIR}/${pkgname}/.char |
522 |
|
|
523 |
# very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
524 |
IFS=$'\n' |
IFS=$'\n' |
525 |
} |
} |
526 |
|
|
527 |
|
################################################### |
528 |
|
# function install_fifos # |
529 |
|
# install_fifos $PKGNAME # |
530 |
|
################################################### |
531 |
|
install_fifos() |
532 |
|
{ |
533 |
|
local pkgname="$1" |
534 |
|
local pathto |
535 |
|
local posix |
536 |
|
local user |
537 |
|
local group |
538 |
|
local IFS |
539 |
|
|
540 |
|
# sanity checks; abort if not given |
541 |
|
[ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given." |
542 |
|
|
543 |
|
# check needed global vars |
544 |
|
[ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set." |
545 |
|
|
546 |
|
# make it optional atm !! |
547 |
|
#[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found" |
548 |
|
[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return |
549 |
|
|
550 |
|
# sets fieldseperator to "§" instead of " " |
551 |
|
IFS=§ |
552 |
|
|
553 |
|
while read pathto posix user group |
554 |
|
do |
555 |
|
[ -z "${pathto}" ] && continue |
556 |
|
mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}" |
557 |
|
|
558 |
|
mkfifo -m "${posix}" "${MROOT}${pathto}" |
559 |
|
chown "${user}:${group}" "${MROOT}${pathto}" |
560 |
|
done < ${BUILDDIR}/${pkgname}/.fifo |
561 |
|
|
562 |
|
# very important: unsetting the '§' fieldseperator |
563 |
|
IFS=$'\n' |
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
################################################### |
################################################### |
568 |
# function build_doinstall # |
# function build_doinstall # |
569 |
# build_doinstall $PKGNAME # |
# build_doinstall $PKGNAME # |
570 |
# NOTE: this is an wrapper do install packages # |
# NOTE: this is an wrapper to install packages # |
571 |
################################################### |
################################################### |
572 |
build_doinstall() |
build_doinstall() |
573 |
{ |
{ |
575 |
|
|
576 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
577 |
[ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." |
[ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." |
578 |
|
|
579 |
# this is only a wrapper |
# this is only a wrapper |
580 |
|
|
581 |
# NOTE: |
# NOTE: |
590 |
install_symlinks ${pkgname} || die "install symlinks ${pkgname}" |
install_symlinks ${pkgname} || die "install symlinks ${pkgname}" |
591 |
install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" |
install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" |
592 |
install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" |
install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" |
593 |
|
install_fifos ${pkgname} || die "install fifos ${pkgname}" |
594 |
} |
} |
595 |
|
|
596 |
|
|
610 |
local magefile |
local magefile |
611 |
local dbrecorddir |
local dbrecorddir |
612 |
local provide |
local provide |
613 |
|
local i |
614 |
|
|
615 |
# very basic getops |
# very basic getops |
616 |
for i in $* |
for i in $* |
652 |
|
|
653 |
# create fake file descriptors |
# create fake file descriptors |
654 |
# used by virtual and source packages |
# used by virtual and source packages |
655 |
local i |
for i in .dirs .symlinks .files .pipes .char .fifo |
|
for i in .dirs .symlinks .files .pipes .char |
|
656 |
do |
do |
657 |
touch ${dbrecorddir}/${i} |
touch ${dbrecorddir}/${i} |
658 |
done |
done |
670 |
|
|
671 |
# normal packages needs these files |
# normal packages needs these files |
672 |
local i |
local i |
673 |
for i in .char .dirs .files .pipes .symlinks |
for i in .char .dirs .files .pipes .symlinks .fifo |
674 |
do |
do |
675 |
install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ |
# make .fifo optional atm |
676 |
${dbrecorddir}/${i} |
if [[ -f ${BUILDDIR}/${pkgname}/${i} ]] |
677 |
|
then |
678 |
|
install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i} |
679 |
|
fi |
680 |
done |
done |
681 |
;; |
;; |
682 |
esac |
esac |
685 |
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
686 |
if [ -n "${provide}" ] |
if [ -n "${provide}" ] |
687 |
then |
then |
688 |
virtuals_add "${provide}" "${pcat}/${pname}" |
for i in ${provide} |
689 |
|
do |
690 |
|
virtuals_add "${i}" "${pcat}/${pname}" |
691 |
|
done |
692 |
fi |
fi |
693 |
} |
} |
694 |
|
|
707 |
local magefile |
local magefile |
708 |
local dbrecorddir |
local dbrecorddir |
709 |
local provide |
local provide |
710 |
|
local i |
711 |
|
|
712 |
# very basic getops |
# very basic getops |
713 |
for i in $* |
for i in $* |
737 |
# abort if mage file not exists |
# abort if mage file not exists |
738 |
[ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
[ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
739 |
|
|
740 |
# first unregister virtuals |
# remove virtuals only if no other exist |
741 |
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] |
|
if [ -n "${provide}" ] |
|
742 |
then |
then |
743 |
virtuals_del "${provide}" "${pcat}/${pname}" |
# first unregister virtuals |
744 |
|
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
745 |
|
if [ -n "${provide}" ] |
746 |
|
then |
747 |
|
for i in ${provide} |
748 |
|
do |
749 |
|
virtuals_del "${i}" "${pcat}/${pname}" |
750 |
|
done |
751 |
|
fi |
752 |
fi |
fi |
753 |
|
|
754 |
# removes database entry |
# removes database entry |
758 |
fi |
fi |
759 |
} |
} |
760 |
|
|
761 |
|
# get the number of installed packages |
762 |
|
count_installed_pkgs() |
763 |
|
{ |
764 |
|
local pcat |
765 |
|
local pname |
766 |
|
local pkg |
767 |
|
local i |
768 |
|
|
769 |
|
# very basic getops |
770 |
|
for i in $* |
771 |
|
do |
772 |
|
case $1 in |
773 |
|
--pcat|-c) shift; pcat="$1" ;; |
774 |
|
--pname|-n) shift; pname="$1" ;; |
775 |
|
esac |
776 |
|
shift |
777 |
|
done |
778 |
|
|
779 |
|
# sanity checks; abort if not given |
780 |
|
[ -z "${pcat}" ] && die "pkg_count() \$pcat not given." |
781 |
|
[ -z "${pname}" ] && die "pkg_count() \$pname not given." |
782 |
|
|
783 |
|
declare -i i=0 |
784 |
|
for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) |
785 |
|
do |
786 |
|
(( i++ )) |
787 |
|
#echo "$i ${pkg}" |
788 |
|
done |
789 |
|
|
790 |
|
# return the value |
791 |
|
echo "${i}" |
792 |
|
} |
793 |
|
|
794 |
|
|
795 |
################################################### |
################################################### |
796 |
# function compare_mtime # |
# function compare_mtime # |
812 |
|
|
813 |
mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
814 |
|
|
815 |
# if $pathto is a symlink than compare linked binary |
# no extra handlink for symlinks anymore as fix_mtime |
816 |
if [ -L "${MROOT}${pathto}" ] |
# uses --no-dereference, compare directly |
817 |
then |
x=$(stat -c %Y "${MROOT}${pathto}") |
|
# readlink -f resolves full path of linked file |
|
|
x="$(readlink -f "${MROOT}${pathto}")" |
|
|
|
|
|
# abort if target does not exists |
|
|
# we keep safe here, theoretically the link can removed |
|
|
[ ! -e "${x}" ] && return 1 |
|
|
|
|
|
x=$(stat -c %Y "${x}") |
|
|
else |
|
|
x=$(stat -c %Y "${MROOT}${pathto}") |
|
|
fi |
|
818 |
|
|
819 |
[[ ${mtime} = ${x} ]] && return 0 |
[[ ${mtime} = ${x} ]] && return 0 |
820 |
|
|
876 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
877 |
if [ ! -L "${MROOT}${pathto}" ] |
if [ ! -L "${MROOT}${pathto}" ] |
878 |
then |
then |
879 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
880 |
echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
881 |
continue |
continue |
882 |
fi |
fi |
888 |
# 1=keep me # |
# 1=keep me # |
889 |
case ${retval} in |
case ${retval} in |
890 |
0) |
0) |
891 |
[[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}" |
892 |
rm "${MROOT}${pathto}" |
rm "${MROOT}${pathto}" |
893 |
;; |
;; |
894 |
|
|
895 |
1) |
1) |
896 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
897 |
echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" |
898 |
;; |
;; |
899 |
esac |
esac |
940 |
done |
done |
941 |
|
|
942 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
943 |
[ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
[ -z "${pcat}" ] && die "remove_files() \$pcat not given." |
944 |
[ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
[ -z "${pname}" ] && die "remove_files() \$pname not given." |
945 |
[ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
[ -z "${pver}" ] && die "remove_files() \$pver not given." |
946 |
[ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
[ -z "${pbuild}" ] && die "remove_files() \$pbuild not given." |
947 |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
948 |
|
|
949 |
# check needed global vars |
# check needed global vars |
958 |
do |
do |
959 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
960 |
|
|
961 |
if [ -e "${MROOT}${pathto}" ] |
if [ ! -e "${MROOT}${pathto}" ] |
962 |
then |
then |
963 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
964 |
echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
965 |
continue |
continue |
966 |
fi |
fi |
972 |
# 1=keep me # |
# 1=keep me # |
973 |
case ${retval} in |
case ${retval} in |
974 |
0) |
0) |
975 |
[[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" |
# check if the file is config_protected |
976 |
rm "${MROOT}${pathto}" |
# ${MROOT} will automatically added if set !! |
977 |
;; |
is_config_protected "${pathto}" |
978 |
|
retval="$?" |
979 |
|
|
980 |
|
# 0 - not protected # |
981 |
|
# 1 - error # |
982 |
|
# 2 - protected # |
983 |
|
# 3 - protected but masked # |
984 |
|
# 4 - protected but ignored # |
985 |
|
|
986 |
|
case ${retval} in |
987 |
|
# file is not protected - delete it |
988 |
|
0|3) |
989 |
|
mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}" |
990 |
|
rm "${MROOT}${pathto}" |
991 |
|
;; |
992 |
|
|
993 |
|
# file is protected, do not delete |
994 |
|
2) |
995 |
|
if mqueryfeature "verbose" |
996 |
|
then |
997 |
|
echo -en "${COLRED}" |
998 |
|
echo -n "! prot " |
999 |
|
echo -en "${COLDEFAULT}" |
1000 |
|
echo " === FILE: ${MROOT}${pathto}" |
1001 |
|
fi |
1002 |
|
;; |
1003 |
|
|
1004 |
|
# file is protected but ignored, delete the update/do nothing |
1005 |
|
4) |
1006 |
|
if mqueryfeature "verbose" |
1007 |
|
then |
1008 |
|
echo -en "${COLRED}" |
1009 |
|
echo -n "! ignr " |
1010 |
|
echo -en "${COLDEFAULT}" |
1011 |
|
echo " === FILE: ${MROOT}${pathto}" |
1012 |
|
fi |
1013 |
|
# simply do nothing here |
1014 |
|
;; |
1015 |
|
esac |
1016 |
|
;; |
1017 |
1) |
1) |
1018 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
1019 |
echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" |
1020 |
;; |
;; |
1021 |
esac |
esac |
1034 |
{ |
{ |
1035 |
local pathto |
local pathto |
1036 |
local posix |
local posix |
1037 |
|
local user |
1038 |
|
local group |
1039 |
local IFS |
local IFS |
1040 |
local pcat |
local pcat |
1041 |
local pname |
local pname |
1059 |
done |
done |
1060 |
|
|
1061 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
1062 |
[ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
[ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given." |
1063 |
[ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
[ -z "${pname}" ] && die "remove_blockdevices() \$pname not given." |
1064 |
[ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
[ -z "${pver}" ] && die "remove_blockdevices() \$pver not given." |
1065 |
[ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
[ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given." |
1066 |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1067 |
|
|
1068 |
# check needed global vars |
# check needed global vars |
1073 |
# sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
1074 |
IFS=§ |
IFS=§ |
1075 |
|
|
1076 |
while read pathto posix |
while read pathto posix user group |
1077 |
do |
do |
1078 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
1079 |
|
|
1080 |
[[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}" |
1081 |
rm "${MROOT}${pathto}" |
rm "${MROOT}${pathto}" |
1082 |
done < ${MROOT}${INSTALLDB}/${pfull}/.pipes |
done < ${MROOT}${INSTALLDB}/${pfull}/.pipes |
1083 |
|
|
1094 |
{ |
{ |
1095 |
local pathto |
local pathto |
1096 |
local posix |
local posix |
1097 |
|
local user |
1098 |
|
local group |
1099 |
local IFS |
local IFS |
1100 |
local pcat |
local pcat |
1101 |
local pname |
local pname |
1119 |
done |
done |
1120 |
|
|
1121 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
1122 |
[ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
[ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given." |
1123 |
[ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
[ -z "${pname}" ] && die "remove_characterdevices() \$pname not given." |
1124 |
[ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
[ -z "${pver}" ] && die "remove_characterdevices() \$pver not given." |
1125 |
[ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
[ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given." |
1126 |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1127 |
|
|
1128 |
# check needed global vars |
# check needed global vars |
1133 |
# sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
1134 |
IFS=§ |
IFS=§ |
1135 |
|
|
1136 |
while read pathto posix |
while read pathto posix user group |
1137 |
do |
do |
1138 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
1139 |
|
|
1140 |
[[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}" |
1141 |
rm "${MROOT}${pathto}" |
rm "${MROOT}${pathto}" |
1142 |
done < ${MROOT}${INSTALLDB}/${pfull}/.char |
done < ${MROOT}${INSTALLDB}/${pfull}/.char |
1143 |
|
|
1147 |
|
|
1148 |
|
|
1149 |
################################################### |
################################################### |
1150 |
|
# function remove_fifos # |
1151 |
|
# remove_fifos $PKGNAME # |
1152 |
|
################################################### |
1153 |
|
remove_fifos() |
1154 |
|
{ |
1155 |
|
local pathto |
1156 |
|
local posix |
1157 |
|
local user |
1158 |
|
local group |
1159 |
|
local IFS |
1160 |
|
local pcat |
1161 |
|
local pname |
1162 |
|
local pver |
1163 |
|
local pbuild |
1164 |
|
local i |
1165 |
|
local pfull |
1166 |
|
|
1167 |
|
IFS=$'\n' |
1168 |
|
|
1169 |
|
# very basic getops |
1170 |
|
for i in $* |
1171 |
|
do |
1172 |
|
case $1 in |
1173 |
|
--pcat|-c) shift; pcat="$1" ;; |
1174 |
|
--pname|-n) shift; pname="$1" ;; |
1175 |
|
--pver|-v) shift; pver="$1" ;; |
1176 |
|
--pbuild|-b) shift; pbuild="$1" ;; |
1177 |
|
esac |
1178 |
|
shift |
1179 |
|
done |
1180 |
|
|
1181 |
|
# sanity checks; abort if not given |
1182 |
|
[ -z "${pcat}" ] && die "remove_fifos() \$pcat not given." |
1183 |
|
[ -z "${pname}" ] && die "remove_fifos() \$pname not given." |
1184 |
|
[ -z "${pver}" ] && die "remove_fifos() \$pver not given." |
1185 |
|
[ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given." |
1186 |
|
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1187 |
|
|
1188 |
|
# check needed global vars |
1189 |
|
[ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set." |
1190 |
|
|
1191 |
|
# make it optional atm !! |
1192 |
|
#[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found" |
1193 |
|
[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return |
1194 |
|
|
1195 |
|
# sets fieldseperator to "§" instead of " " |
1196 |
|
IFS=§ |
1197 |
|
|
1198 |
|
while read pathto posix user group |
1199 |
|
do |
1200 |
|
[ -z "${pathto}" ] && continue |
1201 |
|
|
1202 |
|
mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}" |
1203 |
|
rm "${MROOT}${pathto}" |
1204 |
|
done < ${MROOT}${INSTALLDB}/${pfull}/.fifo |
1205 |
|
|
1206 |
|
# very important: unsetting the '§' fieldseperator |
1207 |
|
IFS=$'\n' |
1208 |
|
} |
1209 |
|
|
1210 |
|
|
1211 |
|
################################################### |
1212 |
# function remove_direcories # |
# function remove_direcories # |
1213 |
# remove_direcories $PKGNAME # |
# remove_direcories $PKGNAME # |
1214 |
################################################### |
################################################### |
1239 |
done |
done |
1240 |
|
|
1241 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
1242 |
[ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." |
[ -z "${pcat}" ] && die "remove_directories() \$pcat not given." |
1243 |
[ -z "${pname}" ] && die "remove_symlinks() \$pname not given." |
[ -z "${pname}" ] && die "remove_directories() \$pname not given." |
1244 |
[ -z "${pver}" ] && die "remove_symlinks() \$pver not given." |
[ -z "${pver}" ] && die "remove_directories() \$pver not given." |
1245 |
[ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." |
[ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given." |
1246 |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
pfull="${pcat}/${pname}-${pver}-${pbuild}" |
1247 |
|
|
1248 |
# check needed global vars |
# check needed global vars |
1250 |
|
|
1251 |
[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" |
[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" |
1252 |
|
|
|
# uninstall of dirs ## added small hack to fix dirs |
|
|
# must be reverse -> smage2 doesn't sort them |
|
|
# -> using tac |
|
|
|
|
1253 |
# sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
1254 |
IFS=§ |
IFS=§ |
1255 |
|
|
1256 |
while read pathto posix |
# reversed order is mandatory ! |
1257 |
|
tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix |
1258 |
do |
do |
1259 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
1260 |
|
|
1261 |
if [ ! -d "${MROOT}${pathto}" ] |
if [ ! -d "${MROOT}${pathto}" ] |
1262 |
then |
then |
1263 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
1264 |
echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1265 |
continue |
continue |
1266 |
fi |
fi |
1268 |
# exclude .keep directories |
# exclude .keep directories |
1269 |
if [ -f "${MROOT}${pathto}/.keep" ] |
if [ -f "${MROOT}${pathto}/.keep" ] |
1270 |
then |
then |
1271 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
1272 |
echo -e "${COLRED} .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1273 |
continue |
continue |
1274 |
fi |
fi |
1275 |
|
|
1281 |
|
|
1282 |
if rmdir "${MROOT}${pathto}" &> /dev/null |
if rmdir "${MROOT}${pathto}" &> /dev/null |
1283 |
then |
then |
1284 |
[[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" |
mqueryfeature "verbose" && echo -e "\t<<< DIR: ${MROOT}${pathto}" |
1285 |
else |
else |
1286 |
[[ ${VERBOSE} = on ]] && \ |
mqueryfeature "verbose" && \ |
1287 |
echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1288 |
fi |
fi |
1289 |
done < ${MROOT}${INSTALLDB}/${pfull}/.dirs |
done |
1290 |
|
|
1291 |
# very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
1292 |
IFS=$'\n' |
IFS=$'\n' |
1296 |
################################################### |
################################################### |
1297 |
# function build_douninstall # |
# function build_douninstall # |
1298 |
# build_douninstall $PKGNAME # |
# build_douninstall $PKGNAME # |
1299 |
# NOTE: this is an wrapper do remove packages # |
# NOTE: this is an wrapper to remove packages # |
1300 |
################################################### |
################################################### |
1301 |
build_douninstall() |
build_douninstall() |
1302 |
{ |
{ |
1330 |
# !! we use § as field seperator !! |
# !! we use § as field seperator !! |
1331 |
# doing so prevent us to get errors by filenames with spaces |
# doing so prevent us to get errors by filenames with spaces |
1332 |
|
|
1333 |
for i in symlinks files blockdevices characterdevices directories |
for i in symlinks files blockdevices characterdevices directories fifos |
1334 |
do |
do |
1335 |
remove_${i} \ |
remove_${i} \ |
1336 |
--pcat "${pcat}" \ |
--pcat "${pcat}" \ |
1341 |
done |
done |
1342 |
} |
} |
1343 |
|
|
1344 |
# fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
# convertmirrors [uri] |
1345 |
fetch_packages() |
convertmirrors() |
1346 |
{ |
{ |
1347 |
local list="$@" |
local uri="$1" |
1348 |
local pkg |
local scheme |
1349 |
|
local mirror |
1350 |
|
local mirrors |
1351 |
|
local addon |
1352 |
|
local real_uri |
1353 |
|
local output |
1354 |
|
|
1355 |
|
# needs |
1356 |
|
[[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!" |
1357 |
|
[[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!" |
1358 |
|
[[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!" |
1359 |
|
[[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!" |
1360 |
|
[[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!" |
1361 |
|
|
1362 |
|
# check known uri schemes |
1363 |
|
case ${uri} in |
1364 |
|
http://*|https://*|ftp://*|ftps://*) mirrors="" ;; |
1365 |
|
mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; |
1366 |
|
package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; |
1367 |
|
gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; |
1368 |
|
sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;; |
1369 |
|
gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;; |
1370 |
|
kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;; |
1371 |
|
*) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;; |
1372 |
|
esac |
1373 |
|
|
1374 |
|
if [[ ! -z ${mirrors} ]] |
1375 |
|
then |
1376 |
|
for mirror in ${mirrors} |
1377 |
|
do |
1378 |
|
# add a whitespace to the output |
1379 |
|
[[ -z ${output} ]] || output+=" " |
1380 |
|
output+="${mirror}${addon}/${uri/${scheme}/}" |
1381 |
|
done |
1382 |
|
else |
1383 |
|
output="${uri}" |
1384 |
|
fi |
1385 |
|
|
1386 |
|
echo "${output}" |
1387 |
|
} |
1388 |
|
|
1389 |
|
mdownload() |
1390 |
|
{ |
1391 |
|
local i |
1392 |
|
local uri |
1393 |
|
local real_uris |
1394 |
|
local mirror |
1395 |
|
local outputfile |
1396 |
|
local outputdir |
1397 |
|
local retval |
1398 |
|
local wget_opts |
1399 |
|
|
1400 |
|
# very basic getops |
1401 |
|
for i in $* |
1402 |
|
do |
1403 |
|
case $1 in |
1404 |
|
--uri|-u) shift; uri="$1" ;; |
1405 |
|
--dir|-d) shift; outputdir="$1" ;; |
1406 |
|
esac |
1407 |
|
shift |
1408 |
|
done |
1409 |
|
|
1410 |
|
# sanity checks; abort if not given |
1411 |
|
[[ -z ${uri} ]] && die "mdownload(): no uri given!" |
1412 |
|
[[ -z ${outputdir} ]] && die "mdownload(): no dir given!" |
1413 |
|
|
1414 |
|
# convert mirrored uris to the real ones |
1415 |
|
real_uris="$(convertmirrors ${uri})" |
1416 |
|
|
1417 |
|
# verbose or not |
1418 |
|
mqueryfeature "!verbose" && wget_opts+=" --quiet" |
1419 |
|
|
1420 |
|
# filter wget options if busybox was found |
1421 |
|
wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" |
1422 |
|
|
1423 |
|
# create outputdir |
1424 |
|
[[ ! -d ${outputdir} ]] && install -d "${outputdir}" |
1425 |
|
|
1426 |
|
for mirror in ${real_uris} |
1427 |
|
do |
1428 |
|
# get the name of the output file |
1429 |
|
outputfile="${mirror##*/}" |
1430 |
|
|
1431 |
|
wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" |
1432 |
|
retval="$?" |
1433 |
|
if [[ ${retval} = 0 ]] |
1434 |
|
then |
1435 |
|
break |
1436 |
|
else |
1437 |
|
continue |
1438 |
|
fi |
1439 |
|
done |
1440 |
|
|
1441 |
|
# return wget retval |
1442 |
|
return "${retval}" |
1443 |
|
} |
1444 |
|
|
1445 |
|
# fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
1446 |
|
fetch_packages() |
1447 |
|
{ |
1448 |
|
local i |
1449 |
|
local list="$@" |
1450 |
|
local pkgname |
1451 |
|
local pkgfile |
1452 |
|
local pcat |
1453 |
|
local pname |
1454 |
local mirr |
local mirr |
1455 |
local magefile |
local magefile |
1456 |
local md5file |
local md5file |
1457 |
local opt |
local opt |
1458 |
local count_current |
local count_current |
1459 |
local count_total |
local count_total |
1460 |
|
local wget_opts |
1461 |
|
local fetching |
1462 |
|
|
1463 |
|
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
1464 |
|
|
1465 |
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc." |
# filter wget command if busybox was found |
1466 |
|
wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" |
1467 |
|
|
1468 |
# get count of total packages |
# get count of total packages |
1469 |
declare -i count_current=0 |
declare -i count_current=0 |
1473 |
|
|
1474 |
for magefile in ${list} |
for magefile in ${list} |
1475 |
do |
do |
1476 |
pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
1477 |
|
pkgfile="${pkgname}.${PKGSUFFIX}" |
1478 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
1479 |
|
|
1480 |
|
pcat=$(magename2pcat ${magefile}) |
1481 |
|
pname=$(magename2pname ${magefile}) |
1482 |
|
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
1483 |
|
|
1484 |
(( count_current++ )) |
(( count_current++ )) |
1485 |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]" |
1486 |
|
|
1487 |
# abort on virtual pkg |
# abort on virtual pkg |
1488 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
1489 |
then |
then |
1490 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1491 |
echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... " |
1492 |
continue |
continue |
1493 |
fi |
fi |
1494 |
|
|
1496 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
1497 |
then |
then |
1498 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1499 |
echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... " |
1500 |
continue |
continue |
1501 |
fi |
fi |
1502 |
|
|
1503 |
# abort if already exist |
# check if FETCHING is required |
1504 |
if [ -f ${PKGDIR}/${pkg} ] |
if [ ! -f "${md5file}" ] |
1505 |
then |
then |
1506 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
fetching=true |
1507 |
echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " |
else |
1508 |
continue |
if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null |
|
fi |
|
|
|
|
|
for mirr in ${MIRRORS} |
|
|
do |
|
|
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
|
|
#echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " |
|
|
echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
|
|
[[ ${VERBOSE} = off ]] && opt="--quiet" |
|
|
wget \ |
|
|
--passive-ftp \ |
|
|
--tries 3 \ |
|
|
--continue \ |
|
|
--progress bar \ |
|
|
--directory-prefix=${PKGDIR} \ |
|
|
${opt} ${mirr}/packages/${pkg} |
|
|
if [[ $? = 0 ]] |
|
1509 |
then |
then |
1510 |
break |
# md5's ok, no fetching required |
1511 |
|
fetching=false |
1512 |
else |
else |
1513 |
continue |
fetching=true |
1514 |
fi |
fi |
1515 |
done |
fi |
1516 |
|
|
1517 |
if [ ! -f ${PKGDIR}/${pkg} ] |
if [[ ${fetching} = false ]] |
1518 |
then |
then |
1519 |
die "Could not download ${pkg}" |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1520 |
|
echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... " |
1521 |
|
continue |
1522 |
|
else |
1523 |
|
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1524 |
|
echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... " |
1525 |
|
mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}" |
1526 |
|
fi |
1527 |
|
|
1528 |
|
# sanity check, not really needed but to be sure |
1529 |
|
if [ ! -f ${PKGDIR}/${pkgfile} ] |
1530 |
|
then |
1531 |
|
die "Package '${pkgfile}' after download not found in '${PKGDIR}'" |
1532 |
fi |
fi |
1533 |
done |
done |
1534 |
|
|
1540 |
{ |
{ |
1541 |
if [ -z "${RSYNC}" ] |
if [ -z "${RSYNC}" ] |
1542 |
then |
then |
1543 |
die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." |
die "You have no rsync-mirrors defined. Please edit your ${MAGERC}." |
1544 |
fi |
fi |
1545 |
|
|
1546 |
local i |
local i |
1547 |
for i in ${RSYNC} |
for i in ${RSYNC} |
1548 |
do |
do |
1549 |
rsync \ |
rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} |
|
--recursive \ |
|
|
--links \ |
|
|
--perms \ |
|
|
--times \ |
|
|
--devices \ |
|
|
--timeout=600 \ |
|
|
--verbose \ |
|
|
--compress \ |
|
|
--progress \ |
|
|
--stats \ |
|
|
--delete \ |
|
|
--delete-after \ |
|
|
${i} ${MAGEDIR} |
|
1550 |
if [[ $? = 0 ]] |
if [[ $? = 0 ]] |
1551 |
then |
then |
1552 |
break |
break |
1556 |
done |
done |
1557 |
|
|
1558 |
# clean up backup files (foo~) |
# clean up backup files (foo~) |
1559 |
find ${MAGEDIR} -name *~ -exec rm '{}' ';' |
find ${MAGEDIR} -name \*~ -exec rm '{}' ';' |
1560 |
|
|
1561 |
# check if an newer mage version is available |
# check if a newer mage version is available |
1562 |
is_newer_mage_version_available |
is_newer_mage_version_available |
1563 |
} |
} |
1564 |
|
|
1565 |
cleanpkg() |
syncmage_tarball() |
1566 |
{ |
{ |
1567 |
if [ -d "${PKGDIR}" ] |
local latest_tarball |
1568 |
then |
local latest_md5 |
1569 |
echo -n "Removing downloaded packages... " |
local temp="$(mktemp -d)" |
1570 |
rm -rf ${PKGDIR}/* |
local mirr mymirr |
1571 |
echo "done." |
local opt |
1572 |
fi |
local tar_opts |
1573 |
} |
local wget_opts |
1574 |
|
|
1575 |
xtitle() |
# try to get the md5 marked as latest on the server |
1576 |
{ |
latest_md5="mage-latest.md5" |
|
if [[ ${TERM} = xterm ]] |
|
|
then |
|
|
echo -ne "\033]0;Mage: $1\007" |
|
|
fi |
|
|
return 0 |
|
|
} |
|
1577 |
|
|
1578 |
|
# try to get the tarball marked as latest on the server |
1579 |
|
latest_tarball="mage-latest.tar.bz2" |
1580 |
|
|
1581 |
xtitleclean() |
# filter wget command if busybox was found |
1582 |
{ |
wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" |
1583 |
if [[ ${TERM} = xterm ]] |
|
1584 |
|
for mirr in ${MIRRORS} |
1585 |
|
do |
1586 |
|
# path without distribution |
1587 |
|
# (only for stable|testing|unstable and not DISTROTAG) |
1588 |
|
case ${mirr##*/} in |
1589 |
|
stable|testing|unstable) mymirr="${mirr%/*}";; |
1590 |
|
*) mymirr="${mirr}";; |
1591 |
|
esac |
1592 |
|
|
1593 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1594 |
|
echo "fetching latest md5 from ${mymirr} ..." |
1595 |
|
mqueryfeature "!verbose" && opt="--quiet" |
1596 |
|
wget \ |
1597 |
|
${wget_opts} \ |
1598 |
|
--directory-prefix=${temp} \ |
1599 |
|
${opt} ${mymirr}/rsync/tarballs/${latest_md5} |
1600 |
|
|
1601 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1602 |
|
echo "fetching latest tarball from ${mymirr} ..." |
1603 |
|
wget \ |
1604 |
|
${wget_opts} \ |
1605 |
|
--directory-prefix=${temp} \ |
1606 |
|
${opt} ${mymirr}/rsync/tarballs/${latest_tarball} |
1607 |
|
if [[ $? = 0 ]] |
1608 |
|
then |
1609 |
|
break |
1610 |
|
else |
1611 |
|
continue |
1612 |
|
fi |
1613 |
|
done |
1614 |
|
|
1615 |
|
if [[ -f ${temp}/${latest_tarball} ]] |
1616 |
then |
then |
1617 |
echo -ne "\033]0;\007" |
# check md5 |
1618 |
|
if [[ ! -f ${temp}/${latest_md5} ]] |
1619 |
|
then |
1620 |
|
die "md5 is missing ... aborting" |
1621 |
|
else |
1622 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1623 |
|
echo -n "checking md5sum... " |
1624 |
|
mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed" |
1625 |
|
fi |
1626 |
|
|
1627 |
|
if [[ -d ${MAGEDIR} ]] |
1628 |
|
then |
1629 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1630 |
|
echo "cleaning old mage-tree ${MAGEDIR}..." |
1631 |
|
# honor mountpoints and empty dirs |
1632 |
|
if mountpoint -q ${MAGEDIR} |
1633 |
|
then |
1634 |
|
if ! mcheckemptydir ${MAGEDIR} |
1635 |
|
then |
1636 |
|
find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r |
1637 |
|
fi |
1638 |
|
else |
1639 |
|
rm -rf ${MAGEDIR} |
1640 |
|
fi |
1641 |
|
fi |
1642 |
|
|
1643 |
|
if need_busybox_support tar |
1644 |
|
then |
1645 |
|
tar_opts="xjf" |
1646 |
|
else |
1647 |
|
tar_opts="xjmf" |
1648 |
|
fi |
1649 |
|
|
1650 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1651 |
|
echo "updating mage-tree from tarball ..." |
1652 |
|
# unpack in dirname of MAGEDIR, as the tarball has already the mage |
1653 |
|
tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" |
1654 |
|
|
1655 |
|
if [[ -d ${temp} ]] |
1656 |
|
then |
1657 |
|
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1658 |
|
echo "cleaning temp-files ..." |
1659 |
|
rm -rf ${temp} |
1660 |
|
fi |
1661 |
|
|
1662 |
|
# check if a newer mage version is available |
1663 |
|
is_newer_mage_version_available |
1664 |
|
else |
1665 |
|
die "Could not fetch the latest tarball ... aborting" |
1666 |
fi |
fi |
|
return 0 |
|
1667 |
} |
} |
1668 |
|
|
1669 |
|
cleanpkg() |
|
# cuts full pathnames or versioniezed names down to basename |
|
|
choppkgname() |
|
1670 |
{ |
{ |
1671 |
#we want this only if full name was used |
if [ -d "${PKGDIR}" ] |
|
if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
|
1672 |
then |
then |
1673 |
#cuts ARCH and PBUILD |
echo -n "Removing downloaded packages... " |
1674 |
#ARCH comes from /etc/mage.rc |
rm -rf ${PKGDIR}/* |
1675 |
MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") |
echo "done." |
|
|
|
|
#cuts version number |
|
|
MAGENAME=$(basename ${MAGENAME%-*} .mage) |
|
1676 |
fi |
fi |
1677 |
} |
} |
1678 |
|
|
1679 |
|
# unused? |
1680 |
|
# |
1681 |
|
# # cuts full pathnames or versionized names down to basename |
1682 |
|
# choppkgname() |
1683 |
|
# { |
1684 |
|
# #we want this only if full name was used |
1685 |
|
# if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
1686 |
|
# then |
1687 |
|
# #cuts ARCH and PBUILD |
1688 |
|
# #ARCH comes from ${MAGERC} |
1689 |
|
# MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g") |
1690 |
|
# |
1691 |
|
# #cuts version number |
1692 |
|
# MAGENAME=$(basename ${MAGENAME%-*} .mage) |
1693 |
|
# fi |
1694 |
|
# } |
1695 |
|
|
1696 |
|
|
1697 |
# get_categorie $PNAME, returns CATEGORIE |
# get_categorie $PNAME, returns CATEGORIE |
1698 |
# $1=pname |
# $1=pname |
1699 |
# ret 0=ok, 1=not_found |
# ret 0=ok, 1=not_found |
1719 |
# returns 0=stable 1=unstable |
# returns 0=stable 1=unstable |
1720 |
check_stable_package() |
check_stable_package() |
1721 |
{ |
{ |
1722 |
|
# first check if this magefile is not blacklisted |
1723 |
|
blacklisted "$1" || return 1 |
1724 |
|
|
1725 |
local STATE |
local STATE |
1726 |
STATE="$(get_value_from_magefile STATE "$1")" |
STATE="$(get_value_from_magefile STATE "$1")" |
1727 |
|
|
1728 |
# state testing |
# state testing |
1729 |
if [[ ${USE_TESTING} = true ]] |
if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] |
1730 |
then |
then |
1731 |
case ${STATE} in |
case ${STATE} in |
1732 |
testing|stable) return 0 ;; |
testing|stable) return 0 ;; |
1735 |
fi |
fi |
1736 |
|
|
1737 |
# state unstable |
# state unstable |
1738 |
if [[ ${USE_UNSTABLE} = true ]] |
if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] |
1739 |
then |
then |
1740 |
case ${STATE} in |
case ${STATE} in |
1741 |
unstable|testing|stable) return 0 ;; |
unstable|testing|stable) return 0 ;; |
1761 |
local PNAME="$2" |
local PNAME="$2" |
1762 |
local magefile |
local magefile |
1763 |
|
|
1764 |
for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*) |
# do not list the content of a directory, only the name (-d) |
1765 |
|
for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null) |
1766 |
do |
do |
1767 |
|
[[ -z ${magefile} ]] && continue |
1768 |
# we exclude subdirs (for stuff like a md5sum dir) |
# we exclude subdirs (for stuff like a md5sum dir) |
1769 |
[ -d ${magefile} ] && continue |
[[ -d ${magefile} ]] && continue |
1770 |
if check_stable_package ${magefile} |
if check_stable_package ${magefile} |
1771 |
then |
then |
1772 |
HIGHEST_MAGEFILE=${magefile} |
HIGHEST_MAGEFILE=${magefile} |
1773 |
#for debug only |
#for debug only |
1774 |
[[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" |
mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2 |
1775 |
fi |
fi |
1776 |
done |
done |
1777 |
|
|
|
# stop here if HIGHEST_MAGEFILE is zero |
|
|
# this package must be unstable or old |
|
|
if [ -z "${HIGHEST_MAGEFILE}" ] |
|
|
then |
|
|
echo |
|
|
echo -n "All packages named " |
|
|
echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} |
|
|
echo -n " are marked " |
|
|
echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} |
|
|
echo "." |
|
|
echo "You need to declare USE_UNSTABLE=true to install this." |
|
|
echo |
|
|
echo "Example:" |
|
|
echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" |
|
|
echo |
|
|
echo "Be warned that these packages are not stable and may cause serious problems." |
|
|
echo "You should know what you are doing, so don't complain about any damage." |
|
|
echo |
|
|
return 1 |
|
|
fi |
|
|
|
|
1778 |
echo "${HIGHEST_MAGEFILE}" |
echo "${HIGHEST_MAGEFILE}" |
1779 |
return 0 |
return 0 |
1780 |
} |
} |
1789 |
# 1 - error # |
# 1 - error # |
1790 |
# 2 - protected # |
# 2 - protected # |
1791 |
# 3 - protected but masked # |
# 3 - protected but masked # |
1792 |
|
# 4 - protected but ignored # |
1793 |
# # |
# # |
1794 |
################################################### |
################################################### |
1795 |
is_config_protected() |
is_config_protected() |
1798 |
local TEST |
local TEST |
1799 |
local PROTECTED |
local PROTECTED |
1800 |
local IFS |
local IFS |
1801 |
|
local i |
1802 |
|
local x |
1803 |
|
|
1804 |
EXPFILE="${MROOT}$1" |
EXPFILE="${MROOT}$1" |
1805 |
|
|
1806 |
# file does not exist; it can be written |
# file does not exist; it can be written |
1807 |
[ ! -e ${EXPFILE} ] && return 0 |
[[ ! -e ${EXPFILE} ]] && return 0 |
1808 |
|
|
1809 |
# to be safe; it may be '§' |
# to be safe; it may be '§' |
1810 |
IFS=' ' |
IFS=' ' |
1811 |
|
|
1812 |
# check ob in config protect |
# check if config protected |
1813 |
for i in ${CONFIG_PROTECT} |
for i in ${CONFIG_PROTECT} |
1814 |
do |
do |
1815 |
# ersetzen von $i nur wenn am anfang der variable |
# only replace $i in the beginning of the variable |
1816 |
TEST="${EXPFILE/#${MROOT}${i}/Protected}" |
TEST="${EXPFILE/#${MROOT}${i}/Protected}" |
1817 |
if [ "${TEST}" != "${EXPFILE}" ] |
if [[ ${TEST} != ${EXPFILE} ]] |
1818 |
then |
then |
1819 |
# setzen das es protected ist |
# file is config proteced |
1820 |
PROTECTED=TRUE |
PROTECTED=TRUE |
1821 |
|
|
1822 |
# check ob nicht doch maskiert |
# check if not masked |
1823 |
for x in ${CONFIG_PROTECT_MASK} |
for x in ${CONFIG_PROTECT_MASK} |
1824 |
do |
do |
1825 |
TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" |
TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" |
1826 |
if [ "${TEST}" != "${EXPFILE}" ] |
if [[ ${TEST} != ${EXPFILE} ]] |
1827 |
then |
then |
1828 |
PROTECTED=MASKED |
PROTECTED=MASKED |
1829 |
fi |
fi |
1830 |
done |
done |
1831 |
|
|
1832 |
|
# check if not ignored |
1833 |
|
for x in ${CONFIG_PROTECT_IGNORE} |
1834 |
|
do |
1835 |
|
TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}" |
1836 |
|
if [[ ${TEST} != ${EXPFILE} ]] |
1837 |
|
then |
1838 |
|
PROTECTED=IGNORED |
1839 |
|
fi |
1840 |
|
done |
1841 |
fi |
fi |
1842 |
done |
done |
1843 |
|
|
1852 |
#echo "I'm protected, but masked - delete me" |
#echo "I'm protected, but masked - delete me" |
1853 |
return 3 |
return 3 |
1854 |
;; |
;; |
1855 |
|
IGNORED) |
1856 |
|
#echo "I'm protected, but ignored - keep me, del update" |
1857 |
|
return 4 |
1858 |
|
;; |
1859 |
*) |
*) |
1860 |
#echo "delete me" |
#echo "delete me" |
1861 |
return 0 |
return 0 |
1873 |
################################################### |
################################################### |
1874 |
count_protected_files() |
count_protected_files() |
1875 |
{ |
{ |
1876 |
${MLIBDIR}/writeprotected "$1" |
local file="$1" |
1877 |
|
local dirname="${file%/*}" |
1878 |
|
local filename="${file##*/}" |
1879 |
|
local count |
1880 |
|
local output |
1881 |
|
local oldprotected |
1882 |
|
local i |
1883 |
|
local x |
1884 |
|
|
1885 |
|
# hack; do not honor a global set IFS like '§' |
1886 |
|
local IFS |
1887 |
|
|
1888 |
|
count=0 |
1889 |
|
|
1890 |
|
# check if there are already protected files |
1891 |
|
for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" | |
1892 |
|
sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | |
1893 |
|
sort -t'%' -k3 -k2 | cut -f1 -d'%') |
1894 |
|
do |
1895 |
|
count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" |
1896 |
|
done |
1897 |
|
|
1898 |
|
# convert 0001 -> 1; 0120 -> 120 etc |
1899 |
|
# use bash internal base functions to this task |
1900 |
|
x="$((10#${count}))" |
1901 |
|
for (( i=0; i<x; i++ )) |
1902 |
|
do |
1903 |
|
if [[ ${count:${i}:1} != 0 ]] |
1904 |
|
then |
1905 |
|
count="${count:${i}}" |
1906 |
|
break |
1907 |
|
fi |
1908 |
|
done |
1909 |
|
|
1910 |
|
count="$(( ${count}+1 ))" |
1911 |
|
|
1912 |
|
# fill output up with zeros |
1913 |
|
for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done |
1914 |
|
output="${output}${count}" |
1915 |
|
|
1916 |
|
echo "${output}" |
1917 |
} |
} |
1918 |
|
|
1919 |
# call with |
# call with |
1930 |
local list |
local list |
1931 |
local pcatdir |
local pcatdir |
1932 |
local protected |
local protected |
1933 |
|
local i |
1934 |
|
|
1935 |
# very basic getops |
# very basic getops |
1936 |
for i in $* |
for i in $* |
1943 |
shift |
shift |
1944 |
done |
done |
1945 |
|
|
1946 |
# sanity checks; abort if not given |
# it's not good to complain here about empty pnames; better to continue later anyway |
1947 |
[ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." |
# # sanity checks; abort if not given |
1948 |
|
# [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." |
1949 |
|
|
1950 |
|
|
1951 |
# check needed global vars |
# check needed global vars |
1952 |
[ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." |
[ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." |
1953 |
|
|
1954 |
# set pcatdir to '*' if empty |
# set pcatdir to '*' if empty |
1955 |
[ -z "${pcatdir}" ] && pcatdir=* |
[ -z "${pcatdir}" ] && pcatdir='*' |
1956 |
|
|
1957 |
for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* |
for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* |
1958 |
do |
do |
2037 |
local oldline |
local oldline |
2038 |
local line i |
local line i |
2039 |
local installed_file |
local installed_file |
2040 |
|
local OLDIFS |
2041 |
|
|
2042 |
if virtuals_read ${virtualname} |
if virtuals_read ${virtualname} |
2043 |
then |
then |
2044 |
# make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already |
# make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already |
2045 |
for i in $(virtuals_read ${virtualname} showpkgs) |
for i in $(virtuals_read ${virtualname} showpkgs) |
2046 |
do |
do |
2047 |
if [[ ${i} = ${pkgname} ]] |
if [[ ${i} = ${pkgname} ]] |
2060 |
# make a backup |
# make a backup |
2061 |
mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old |
mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old |
2062 |
|
|
2063 |
|
OLDIFS="${IFS}" |
2064 |
IFS=$'\n' |
IFS=$'\n' |
2065 |
for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) |
for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) |
2066 |
do |
do |
2072 |
echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} |
echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} |
2073 |
fi |
fi |
2074 |
done |
done |
2075 |
|
# unset IFS |
2076 |
#unset IFS |
IFS="${OLDIFS}" |
2077 |
else |
else |
2078 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
2079 |
echo "register ${pkgname} as ${virtualname} ..." |
echo "register ${pkgname} as ${virtualname} ..." |
2080 |
echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} |
2081 |
fi |
fi |
2085 |
|
|
2086 |
#deletes pakages from virtual database |
#deletes pakages from virtual database |
2087 |
#$1 virtualname; $2 pkgname |
#$1 virtualname; $2 pkgname |
2088 |
virtuals_del() { |
virtuals_del() |
2089 |
|
{ |
2090 |
|
|
2091 |
local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED |
local virtualname="$1" |
2092 |
|
local pkgname="$2" |
2093 |
VIRTUAL_NAME=$1 |
local oldline |
2094 |
PKG_NAME=$2 |
local method |
2095 |
|
local line i x |
2096 |
#first check if exists |
local pkg_installed |
2097 |
if virtuals_read ${VIRTUAL_NAME} |
local OLDIFS |
2098 |
|
|
2099 |
|
# first check if exists |
2100 |
|
if virtuals_read ${virtualname} |
2101 |
then |
then |
2102 |
#get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
# get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
2103 |
declare -i x=0 |
declare -i x=0 |
2104 |
for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs) |
for i in $(virtuals_read ${virtualname} showpkgs) |
2105 |
do |
do |
2106 |
if [ "${i}" == "${PKG_NAME}" ] |
if [[ ${i} = ${pkgname} ]] |
2107 |
then |
then |
2108 |
PKG_INSTALLED=true |
pkg_installed=true |
2109 |
fi |
fi |
2110 |
((x++)) |
((x++)) |
2111 |
done |
done |
2112 |
|
|
2113 |
#abort if not installed |
# abort if not installed |
2114 |
if [ "${PKG_INSTALLED}" != "true" ] |
if [[ ${pkg_installed} != true ]] |
2115 |
then |
then |
2116 |
echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}." |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2117 |
|
echo "${pkgname} does not exists in ${virtualname}." |
2118 |
return 0 |
return 0 |
2119 |
fi |
fi |
2120 |
|
|
2121 |
if [ ${x} -ge 2 ] |
if [ ${x} -ge 2 ] |
2122 |
then |
then |
2123 |
METHOD=update |
method=update |
2124 |
else |
else |
2125 |
METHOD=delall |
method=delall |
2126 |
fi |
fi |
2127 |
|
|
2128 |
#get the complete line |
# get the complete line |
2129 |
OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)" |
oldline="$(virtuals_read ${virtualname} showline)" |
2130 |
|
|
2131 |
#make a backup |
# make a backup of the db |
2132 |
mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
2133 |
|
|
2134 |
#parse virtualdb |
# parse virtualdb |
2135 |
|
OLDIFS="${IFS}" |
2136 |
IFS=$'\n' |
IFS=$'\n' |
2137 |
for line in $(< ${VIRTUALDB_FILE}.old) |
for line in $(< ${VIRTUALDB_FILE}.old) |
2138 |
do |
do |
2139 |
if [ "${line}" == "${OLD_LINE}" ] |
if [[ ${line} = ${oldline} ]] |
2140 |
then |
then |
2141 |
#delall or update? |
#delall or update? |
2142 |
case ${METHOD} in |
case ${method} in |
2143 |
update) |
update) |
2144 |
echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..." |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2145 |
#del PKG_NAME from line |
echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." |
2146 |
echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE} |
# del PKG_NAME from line |
2147 |
|
echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} |
2148 |
;; |
;; |
2149 |
delall) |
delall) |
2150 |
echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..." |
echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
2151 |
#continue; do not write anything |
echo "Deleting ${virtualname} in virtual database ..." |
2152 |
|
# continue; do not write anything |
2153 |
continue |
continue |
2154 |
;; |
;; |
2155 |
esac |
esac |
2157 |
echo "${line}" >> ${VIRTUALDB_FILE} |
echo "${line}" >> ${VIRTUALDB_FILE} |
2158 |
fi |
fi |
2159 |
done |
done |
2160 |
unset IFS |
# unset IFS |
2161 |
|
IFS="${OLDIFS}" |
2162 |
else |
else |
2163 |
echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database." |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2164 |
|
echo "${virtualname} does not exists in virtual database." |
2165 |
fi |
fi |
2166 |
} |
} |
2167 |
|
|
2193 |
{ |
{ |
2194 |
local i |
local i |
2195 |
|
|
2196 |
if [ -n "$@" ] |
if [[ -n $* ]] |
2197 |
then |
then |
2198 |
for i in $@ |
for i in $* |
2199 |
do |
do |
2200 |
[[ ${MAGEDEBUG} = on ]] && \ |
mqueryfeature "debug" && \ |
2201 |
echo "--- Including ${MAGEDIR}/include/${i}.minc" |
echo "--- Including ${MAGEDIR}/include/${i}.minc" |
2202 |
source ${MAGEDIR}/include/${i}.minc |
source ${MAGEDIR}/include/${i}.minc |
2203 |
done |
done |
2204 |
[[ ${MAGEDEBUG} = on ]] && echo |
mqueryfeature "debug" && echo |
2205 |
fi |
fi |
2206 |
} |
} |
2207 |
|
|
2209 |
{ |
{ |
2210 |
local i |
local i |
2211 |
|
|
2212 |
if [ -n "$@" ] |
if [[ -n $* ]] |
2213 |
then |
then |
2214 |
for i in $@ |
for i in $* |
2215 |
do |
do |
2216 |
echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
[[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
2217 |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
2218 |
done |
done |
2219 |
echo |
[[ ${SILENT} = 1 ]] || echo |
2220 |
fi |
fi |
2221 |
} |
} |
2222 |
|
|
2226 |
local newest_mage |
local newest_mage |
2227 |
local installed_mage |
local installed_mage |
2228 |
|
|
2229 |
newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )" |
newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" |
2230 |
installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
2231 |
|
|
2232 |
if [[ ${newest_mage} > ${installed_mage} ]] |
if [[ ${newest_mage} > ${installed_mage} ]] |
2235 |
echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} |
echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} |
2236 |
echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} |
echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} |
2237 |
echo "It is recommened to install this newer version" |
echo "It is recommened to install this newer version" |
2238 |
echo "or your current system installation may brake." |
echo "or your current system installation may break." |
2239 |
echo |
echo |
2240 |
echo -en "Please update mage by running " |
echo -en "Please update mage by running " |
2241 |
echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} |
echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} |
2243 |
fi |
fi |
2244 |
} |
} |
2245 |
|
|
|
|
|
2246 |
# returns pname from pkgname |
# returns pname from pkgname |
2247 |
# pkgname2pname $PKGNAME |
# pkgname2pname $PKGNAME |
2248 |
pkgname2pname() |
pkgname2pname() |
2506 |
local magefile="$2" |
local magefile="$2" |
2507 |
local value |
local value |
2508 |
|
|
2509 |
|
[[ -z ${var} ]] && return 1 |
2510 |
|
[[ -z ${magefile} ]] && return 1 |
2511 |
|
|
2512 |
# local all possible vars of a mage file |
# local all possible vars of a mage file |
2513 |
# to prevent bad issues |
# to prevent bad issues |
2514 |
local PKGNAME |
local PKGNAME |
2519 |
local SDEPEND |
local SDEPEND |
2520 |
local PROVIDE |
local PROVIDE |
2521 |
local PKGTYPE |
local PKGTYPE |
2522 |
|
local SPLIT_PACKAGE_BASE |
2523 |
local preinstall |
local preinstall |
2524 |
local postinstall |
local postinstall |
2525 |
|
local preremove |
2526 |
|
local postremove |
2527 |
|
|
2528 |
# sanity checks |
# sanity checks |
2529 |
[ -f ${magefile} ] && source ${magefile} || \ |
[ -f ${magefile} ] && source ${magefile} || \ |
2533 |
source ${magefile} |
source ${magefile} |
2534 |
eval value=\$$(echo ${var}) |
eval value=\$$(echo ${var}) |
2535 |
echo "${value}" |
echo "${value}" |
2536 |
|
|
2537 |
|
# unset these functions |
2538 |
|
unset -f preinstall |
2539 |
|
unset -f postinstall |
2540 |
|
unset -f preremove |
2541 |
|
unset -f postremove |
2542 |
} |
} |
2543 |
|
|
2544 |
mage_install() |
mage_install() |
2555 |
local PKGTYPE |
local PKGTYPE |
2556 |
local preinstall |
local preinstall |
2557 |
local postinstall |
local postinstall |
2558 |
|
local preremove |
2559 |
|
local postremove |
2560 |
|
|
2561 |
local pcat |
local pcat |
2562 |
local pname |
local pname |
2566 |
local count_current |
local count_current |
2567 |
local magefile |
local magefile |
2568 |
local src_install |
local src_install |
2569 |
|
local i |
2570 |
|
|
2571 |
# very basic getops |
# very basic getops |
2572 |
for i in $* |
for i in $* |
2640 |
echo B:${pbuild} |
echo B:${pbuild} |
2641 |
fi |
fi |
2642 |
|
|
2643 |
smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 |
if [[ -n ${SPLIT_PACKAGE_BASE} ]] |
2644 |
|
then |
2645 |
|
# basic svn compat |
2646 |
|
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2647 |
|
then |
2648 |
|
for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
2649 |
|
do |
2650 |
|
smage2file="${i}" |
2651 |
|
done |
2652 |
|
else |
2653 |
|
smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
2654 |
|
fi |
2655 |
|
|
2656 |
|
else |
2657 |
|
# basic svn compat |
2658 |
|
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2659 |
|
then |
2660 |
|
for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2661 |
|
do |
2662 |
|
smage2file="${i}" |
2663 |
|
done |
2664 |
|
else |
2665 |
|
smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2666 |
|
fi |
2667 |
|
fi |
2668 |
|
|
2669 |
if [ -f "${smage2file}" ] |
if [ -f "${smage2file}" ] |
2670 |
then |
then |
2671 |
|
echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " |
2672 |
smage2 ${smage2file} || die "compile failed" |
smage2 ${smage2file} || die "compile failed" |
2673 |
else |
else |
2674 |
echo |
echo |
2682 |
if [[ ${PKGTYPE} != virtual ]] && \ |
if [[ ${PKGTYPE} != virtual ]] && \ |
2683 |
[[ ${PKGTYPE} != sources ]] |
[[ ${PKGTYPE} != sources ]] |
2684 |
then |
then |
2685 |
# show a verbose message on src-install |
unpack_package "${magefile}" |
2686 |
if [[ ${src_install} = true ]] |
echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
|
then |
|
|
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
|
|
echo -ne "merging files: " |
|
|
echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
|
|
echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
|
|
fi |
|
2687 |
build_doinstall ${PKGNAME} |
build_doinstall ${PKGNAME} |
2688 |
fi |
fi |
2689 |
|
|
2727 |
then |
then |
2728 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2729 |
echo -n "rebuilding environment ... " |
echo -n "rebuilding environment ... " |
2730 |
${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
${MLIBDIR}/env-rebuild > /dev/null && \ |
2731 |
echo "done." || echo "failure." |
echo "done." || echo "failure." |
2732 |
unset MAGE_ENV_REBUILD |
unset MAGE_ENV_REBUILD |
2733 |
fi |
fi |
2739 |
# echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
# echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2740 |
# echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
# echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
2741 |
echo "successfully installed." |
echo "successfully installed." |
2742 |
|
|
2743 |
|
# unset these functions |
2744 |
|
unset -f preinstall |
2745 |
|
unset -f postinstall |
2746 |
|
unset -f preremove |
2747 |
|
unset -f postremove |
2748 |
} |
} |
2749 |
|
|
2750 |
md5sum_packages() |
md5sum_packages() |
2771 |
pname=$(magename2pname ${magefile}) |
pname=$(magename2pname ${magefile}) |
2772 |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
2773 |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
2774 |
pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgfile="${pkgname}.${PKGSUFFIX}" |
2775 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
2776 |
|
|
2777 |
(( count_current++ )) |
(( count_current++ )) |
2781 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
2782 |
then |
then |
2783 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2784 |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... " |
2785 |
continue |
continue |
2786 |
fi |
fi |
2787 |
|
|
2789 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
2790 |
then |
then |
2791 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2792 |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... " |
2793 |
continue |
continue |
2794 |
fi |
fi |
2795 |
|
|
2797 |
then |
then |
2798 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2799 |
echo -ne "checking md5sum (${count_current}/${count_total}): " |
echo -ne "checking md5sum (${count_current}/${count_total}): " |
2800 |
( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" |
mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed" |
2801 |
else |
else |
2802 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2803 |
echo -e "!! no md5sum file found for ${pkgfile} :(" |
echo -e "!! no md5sum file found for ${pkgfile} :(" |
2837 |
pbuild=$(magename2pbuild ${pkg}) |
pbuild=$(magename2pbuild ${pkg}) |
2838 |
can_pcat="${pcat}" |
can_pcat="${pcat}" |
2839 |
can_pname="${pname}" |
can_pname="${pname}" |
2840 |
|
|
2841 |
if [ -z "${can_ver_list}" ] |
if [ -z "${can_ver_list}" ] |
2842 |
then |
then |
2843 |
can_ver_list=" ${pver}-${pbuild}" |
can_ver_list=" ${pver}-${pbuild}" |
2849 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2850 |
echo "following candidate(s) will be removed:" |
echo "following candidate(s) will be removed:" |
2851 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2852 |
echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}" |
echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" |
2853 |
echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
2854 |
echo |
echo |
2855 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] |
2856 |
echo "( Press [CTRL+C] to abort )" |
then |
2857 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2858 |
echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." |
echo "( Press [CTRL+C] to abort )" |
2859 |
for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2860 |
do |
echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." |
2861 |
echo -ne "${COLRED} ${i}${COLDEFAULT}" |
for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) |
2862 |
sleep 1 |
do |
2863 |
done |
echo -ne "${COLRED} ${i}${COLDEFAULT}" |
2864 |
echo |
sleep 1 |
2865 |
echo |
done |
2866 |
|
echo |
2867 |
|
echo |
2868 |
|
fi |
2869 |
|
|
2870 |
for pkg in ${list} |
for pkg in ${list} |
2871 |
do |
do |
2903 |
local PKGTYPE |
local PKGTYPE |
2904 |
local preinstall |
local preinstall |
2905 |
local postinstall |
local postinstall |
2906 |
|
local preremove |
2907 |
|
local postremove |
2908 |
|
|
2909 |
local pcat |
local pcat |
2910 |
local pname |
local pname |
2940 |
echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
2941 |
echo -n "removing: " |
echo -n "removing: " |
2942 |
echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
2943 |
echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2944 |
|
|
2945 |
magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" |
magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
2946 |
source ${magefile} |
source ${magefile} |
2947 |
|
|
2948 |
## preremove scripts |
## preremove scripts |
2992 |
then |
then |
2993 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2994 |
echo -n "rebuilding environment ... " |
echo -n "rebuilding environment ... " |
2995 |
${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
${MLIBDIR}/env-rebuild > /dev/null && \ |
2996 |
echo "done." || echo "failure." |
echo "done." || echo "failure." |
2997 |
unset MAGE_ENV_REBUILD |
unset MAGE_ENV_REBUILD |
2998 |
fi |
fi |
3002 |
# echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
# echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" |
3003 |
# echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
# echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " |
3004 |
echo "successfully removed." |
echo "successfully removed." |
3005 |
|
|
3006 |
|
# unset these functions |
3007 |
|
unset -f preinstall |
3008 |
|
unset -f postinstall |
3009 |
|
unset -f preremove |
3010 |
|
unset -f postremove |
3011 |
} |
} |
3012 |
|
|
3013 |
show_etc_update_mesg() { |
# rerun_pkgfunctions [method] pkg1 pkg2 pkg3 |
3014 |
|
rerun_pkgfunctions() |
3015 |
|
{ |
3016 |
|
local method |
3017 |
|
local list |
3018 |
|
local pcat |
3019 |
|
local pname |
3020 |
|
local pver |
3021 |
|
local pbuild |
3022 |
|
local magefile |
3023 |
|
local i |
3024 |
|
|
3025 |
|
# very basic getops |
3026 |
|
case $1 in |
3027 |
|
--method) shift; method="$1" ;; |
3028 |
|
esac |
3029 |
|
shift |
3030 |
|
local list="$@" |
3031 |
|
|
3032 |
|
# sanity check |
3033 |
|
case ${method} in |
3034 |
|
preinstall|postinstall) ;; |
3035 |
|
preremove|postremove) ;; |
3036 |
|
*) die "rerun_pkgfunctions(): Unknown method '${method}'." ;; |
3037 |
|
esac |
3038 |
|
|
3039 |
|
if [[ -n ${MROOT} ]] |
3040 |
|
then |
3041 |
|
echo -ne ${COLRED} |
3042 |
|
echo "!! running in MROOT=${MROOT}" |
3043 |
|
echo -ne ${COLDEFAULT} |
3044 |
|
echo |
3045 |
|
fi |
3046 |
|
|
3047 |
|
for pkg in ${list} |
3048 |
|
do |
3049 |
|
pcat=$(dep2pcat ${pkg}) |
3050 |
|
pname=$(magename2pname ${pkg}) |
3051 |
|
pver=$(magename2pver ${pkg}) |
3052 |
|
pbuild=$(magename2pbuild ${pkg}) |
3053 |
|
magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
3054 |
|
|
3055 |
|
if [ -e ${magefile} ] |
3056 |
|
then |
3057 |
|
source ${magefile} |
3058 |
|
if [ -n "$(typeset -f ${method})" ] |
3059 |
|
then |
3060 |
|
echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... " |
3061 |
|
${method} |
3062 |
|
else |
3063 |
|
echo "No ${method}() for pkg '${pkg}' defined. Doing nothing." |
3064 |
|
fi |
3065 |
|
unset -f preinstall postinstall preremove postremove |
3066 |
|
else |
3067 |
|
die "Magefile '${magefile}' does not exist." |
3068 |
|
fi |
3069 |
|
done |
3070 |
|
} |
3071 |
|
|
3072 |
|
show_etc_update_mesg() |
3073 |
|
{ |
3074 |
[ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
[ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
3075 |
|
|
3076 |
echo |
echo |
3082 |
echo "Please run 'etc-update' to update your configuration files." |
echo "Please run 'etc-update' to update your configuration files." |
3083 |
echo |
echo |
3084 |
} |
} |
3085 |
|
|
3086 |
|
pkgsearch() |
3087 |
|
{ |
3088 |
|
local string="$1" |
3089 |
|
local result |
3090 |
|
local pkg |
3091 |
|
local pcat |
3092 |
|
local pname |
3093 |
|
local magefile |
3094 |
|
local pver |
3095 |
|
local pbuild |
3096 |
|
local state |
3097 |
|
local descriptiom |
3098 |
|
local homepage |
3099 |
|
local license |
3100 |
|
local i |
3101 |
|
local all_installed |
3102 |
|
local ipver |
3103 |
|
local ipbuild |
3104 |
|
local latest_available |
3105 |
|
local depsfull |
3106 |
|
local sdepsfull |
3107 |
|
local deps |
3108 |
|
local sdeps |
3109 |
|
local dep |
3110 |
|
local sign |
3111 |
|
|
3112 |
|
# only names no versions |
3113 |
|
result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" |
3114 |
|
#result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)" |
3115 |
|
|
3116 |
|
# nothing found |
3117 |
|
[[ -z ${result} ]] && die "No package found containing '${string}' in the name." |
3118 |
|
|
3119 |
|
for pkg in ${result} |
3120 |
|
do |
3121 |
|
# dirty, but does the job |
3122 |
|
pcat="$(magename2pcat ${pkg}/foo)" |
3123 |
|
pname="$(magename2pname ${pkg}-foo-foo)" |
3124 |
|
|
3125 |
|
# get highest version available |
3126 |
|
magefile=$(get_highest_magefile ${pcat} ${pname}) |
3127 |
|
|
3128 |
|
if [[ ! -z ${magefile} ]] |
3129 |
|
then |
3130 |
|
# now get all needed infos to print a nice output |
3131 |
|
pver="$(magename2pver ${magefile})" |
3132 |
|
pbuild="$(magename2pbuild ${magefile})" |
3133 |
|
state="$(get_value_from_magefile STATE ${magefile})" |
3134 |
|
description="$(get_value_from_magefile DESCRIPTION ${magefile})" |
3135 |
|
homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" |
3136 |
|
license="$(get_value_from_magefile LICENSE ${magefile})" |
3137 |
|
|
3138 |
|
# all installed |
3139 |
|
for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) |
3140 |
|
do |
3141 |
|
ipver="$(magename2pver ${i})" |
3142 |
|
ipbuild="$(magename2pbuild ${i})" |
3143 |
|
|
3144 |
|
if [[ -z ${all_installed} ]] |
3145 |
|
then |
3146 |
|
all_installed="${ipver}-${ipbuild}" |
3147 |
|
else |
3148 |
|
all_installed="${all_installed} ${ipver}-${ipbuild}" |
3149 |
|
fi |
3150 |
|
done |
3151 |
|
[[ -z ${all_installed} ]] && all_installed="none" |
3152 |
|
|
3153 |
|
case ${state} in |
3154 |
|
stable) state=${COLGREEN}"[s] ";; |
3155 |
|
testing) state=${COLYELLOW}"[t] ";; |
3156 |
|
unstable) state=${COLRED}"[u] ";; |
3157 |
|
old) state=${COLGRAY}"[o] ";; |
3158 |
|
esac |
3159 |
|
|
3160 |
|
latest_available="${pver}-${pbuild}" |
3161 |
|
else |
3162 |
|
# package is masked |
3163 |
|
state="${COLRED}[m] " |
3164 |
|
latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" |
3165 |
|
fi |
3166 |
|
|
3167 |
|
depsfull="$(get_value_from_magefile DEPEND ${magefile})" |
3168 |
|
sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" |
3169 |
|
|
3170 |
|
while read sign dep |
3171 |
|
do |
3172 |
|
case ${dep} in |
3173 |
|
"") continue;; |
3174 |
|
esac |
3175 |
|
|
3176 |
|
if [[ -z ${deps} ]] |
3177 |
|
then |
3178 |
|
deps="$(basename ${dep%-*})" |
3179 |
|
else |
3180 |
|
deps="${deps} $(basename ${dep%-*})" |
3181 |
|
fi |
3182 |
|
done << EOF |
3183 |
|
${depsfull} |
3184 |
|
EOF |
3185 |
|
|
3186 |
|
while read sign dep |
3187 |
|
do |
3188 |
|
case ${dep} in |
3189 |
|
"") continue;; |
3190 |
|
esac |
3191 |
|
|
3192 |
|
if [[ -z ${sdeps} ]] |
3193 |
|
then |
3194 |
|
sdeps="$(basename ${dep%-*})" |
3195 |
|
else |
3196 |
|
sdeps="${sdeps} $(basename ${dep%-*})" |
3197 |
|
fi |
3198 |
|
done << EOF |
3199 |
|
${sdepsfull} |
3200 |
|
EOF |
3201 |
|
|
3202 |
|
echo -e "${state}${pcat}/${pname}"${COLDEFAULT} |
3203 |
|
echo -e " Latest available: ${latest_available}" |
3204 |
|
echo " Installed versions: ${all_installed}" |
3205 |
|
echo " Description: ${description}" |
3206 |
|
echo " Homepage: ${homepage}" |
3207 |
|
if [[ ! -z ${license} ]] |
3208 |
|
then |
3209 |
|
echo " License: ${license}" |
3210 |
|
fi |
3211 |
|
echo " Depends: ${deps}" |
3212 |
|
echo " SDepends: ${sdeps}" |
3213 |
|
echo |
3214 |
|
|
3215 |
|
unset pcat |
3216 |
|
unset pname |
3217 |
|
unset magefile |
3218 |
|
unset pver |
3219 |
|
unset pbuild |
3220 |
|
unset state |
3221 |
|
unset descriptiom |
3222 |
|
unset homepage |
3223 |
|
unset all_installed |
3224 |
|
unset ipver |
3225 |
|
unset ipbuild |
3226 |
|
unset depsfull |
3227 |
|
unset sdepsfull |
3228 |
|
unset deps |
3229 |
|
unset sdeps |
3230 |
|
unset dep |
3231 |
|
unset sign |
3232 |
|
done |
3233 |
|
} |
3234 |
|
|
3235 |
|
export_inherits() |
3236 |
|
{ |
3237 |
|
local include="$1" |
3238 |
|
shift |
3239 |
|
|
3240 |
|
while [ "$1" ] |
3241 |
|
do |
3242 |
|
local functions="$1" |
3243 |
|
|
3244 |
|
# sanity checks |
3245 |
|
[ -z "${include}" ] && die "export_inherits(): \$include not given." |
3246 |
|
[ -z "${functions}" ] && die "export_inherits(): \$functions not given." |
3247 |
|
|
3248 |
|
eval "${functions}() { ${include}_${functions} ; }" |
3249 |
|
|
3250 |
|
# debug |
3251 |
|
mqueryfeature "debug" && typeset -f "${functions}" |
3252 |
|
|
3253 |
|
shift |
3254 |
|
done |
3255 |
|
} |
3256 |
|
|
3257 |
|
mlibdir() |
3258 |
|
{ |
3259 |
|
local libdir=lib |
3260 |
|
[[ ${ARCH} = x86_64 ]] && libdir=lib64 |
3261 |
|
|
3262 |
|
echo "${libdir}" |
3263 |
|
} |
3264 |
|
|
3265 |
|
## blacklisted ${magefile} |
3266 |
|
blacklisted() |
3267 |
|
{ |
3268 |
|
[[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable |
3269 |
|
|
3270 |
|
# compat |
3271 |
|
[[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable |
3272 |
|
[[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing |
3273 |
|
|
3274 |
|
# support both types for the moment |
3275 |
|
if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]] |
3276 |
|
then |
3277 |
|
local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" |
3278 |
|
else |
3279 |
|
local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}" |
3280 |
|
fi |
3281 |
|
|
3282 |
|
# return 0 if the list not exist; nothin is masked |
3283 |
|
[[ ! -f ${EXCLUDED} ]] && return 0 |
3284 |
|
|
3285 |
|
local MAGEFILE="$1" |
3286 |
|
|
3287 |
|
local PCAT="$(magename2pcat ${MAGEFILE})" |
3288 |
|
local PNAME="$(magename2pname ${MAGEFILE})" |
3289 |
|
local PVER="$(magename2pver ${MAGEFILE})" |
3290 |
|
local PBUILD="$(magename2pbuild ${MAGEFILE})" |
3291 |
|
|
3292 |
|
local EXPCAT EXPNAME EXPVER EXPBUILD |
3293 |
|
while read EXPCAT EXPNAME EXPVER EXPBUILD |
3294 |
|
do |
3295 |
|
# ignore spaces and comments |
3296 |
|
case "${EXPCAT}" in |
3297 |
|
\#*|"") continue ;; |
3298 |
|
esac |
3299 |
|
|
3300 |
|
# exclude full pver |
3301 |
|
if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
3302 |
|
[[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
3303 |
|
[[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && |
3304 |
|
[[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] |
3305 |
|
then |
3306 |
|
[[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 |
3307 |
|
fi |
3308 |
|
|
3309 |
|
# exclude pcat/pname only |
3310 |
|
if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && |
3311 |
|
[[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && |
3312 |
|
[[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] |
3313 |
|
then |
3314 |
|
[[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 |
3315 |
|
fi |
3316 |
|
done << EOF |
3317 |
|
$( cat ${EXCLUDED}; echo) |
3318 |
|
EOF |
3319 |
|
|
3320 |
|
return 0 |
3321 |
|
} |
3322 |
|
|
3323 |
|
# need_busybox_support ${cmd} |
3324 |
|
# return 0 (no error = needs busybox support) or return 1 (error = no busybox support required) |
3325 |
|
need_busybox_support() |
3326 |
|
{ |
3327 |
|
local cmd |
3328 |
|
local busybox |
3329 |
|
cmd="$1" |
3330 |
|
|
3331 |
|
for busybox in {,/usr}/bin/busybox |
3332 |
|
do |
3333 |
|
if [[ -x ${busybox} ]] |
3334 |
|
then |
3335 |
|
if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]] |
3336 |
|
then |
3337 |
|
# needs busybox support |
3338 |
|
return 0 |
3339 |
|
fi |
3340 |
|
fi |
3341 |
|
done |
3342 |
|
|
3343 |
|
# no busybox |
3344 |
|
return 1 |
3345 |
|
} |
3346 |
|
|
3347 |
|
# busybox_filter_wget_options ${wget_opts} |
3348 |
|
busybox_filter_wget_options() |
3349 |
|
{ |
3350 |
|
local opts="$@" |
3351 |
|
local i |
3352 |
|
local fixed_opts |
3353 |
|
|
3354 |
|
if need_busybox_support wget |
3355 |
|
then |
3356 |
|
for i in ${opts} |
3357 |
|
do |
3358 |
|
# show only the allowed ones |
3359 |
|
case ${i} in |
3360 |
|
-c|--continue) fixed_opts+=" -c" ;; |
3361 |
|
-s|--spider) fixed_opts+=" -s" ;; |
3362 |
|
-q|--quiet) fixed_opts+=" -q" ;; |
3363 |
|
-O|--output-document) shift; fixed_opts+=" -O $1" ;; |
3364 |
|
--header) shift; fixed_opts+=" --header $1" ;; |
3365 |
|
-Y|--proxy) shift; fixed_opts+=" -Y $1" ;; |
3366 |
|
-P) shift; fixed_opts+=" -P $1" ;; |
3367 |
|
--no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;; |
3368 |
|
-U|--user-agent) shift; fixed_opts+=" -U ${i}" ;; |
3369 |
|
# simply drop all other opts |
3370 |
|
*) continue ;; |
3371 |
|
esac |
3372 |
|
done |
3373 |
|
|
3374 |
|
echo "${fixed_opts}" |
3375 |
|
else |
3376 |
|
echo "${opts}" |
3377 |
|
fi |
3378 |
|
} |
3379 |
|
|
3380 |
|
have_root_privileges() |
3381 |
|
{ |
3382 |
|
local retval |
3383 |
|
|
3384 |
|
if [[ $(id -u) = 0 ]] |
3385 |
|
then |
3386 |
|
retval=0 |
3387 |
|
else |
3388 |
|
retval=1 |
3389 |
|
fi |
3390 |
|
|
3391 |
|
return ${retval} |
3392 |
|
} |
3393 |
|
|
3394 |
|
known_mage_feature() |
3395 |
|
{ |
3396 |
|
local feature="$1" |
3397 |
|
local retval |
3398 |
|
|
3399 |
|
case "${feature}" in |
3400 |
|
autosvc|!autosvc) retval=0 ;; |
3401 |
|
buildlog|!buildlog) retval=0 ;; |
3402 |
|
ccache|!ccache) retval=0 ;; |
3403 |
|
check|!check) retval=0 ;; |
3404 |
|
compressdoc|!compressdoc) retval=0 ;; |
3405 |
|
debug|!debug) retval=0 ;; |
3406 |
|
distcc|!distcc) retval=0 ;; |
3407 |
|
icecc|!icecc) retval=0 ;; |
3408 |
|
kernelsrcunpack|!kernelsrcunpack) retval=0 ;; |
3409 |
|
libtool|!libtool) retval=0 ;; |
3410 |
|
linuxsymlink|!linuxsymlink) retval=0 ;; |
3411 |
|
multilib|!multilib) reval=0 ;; |
3412 |
|
pkgbuild|!pkgbuild) retval=0 ;; |
3413 |
|
pkgdistrotag|!pkgdistrotag) retval=0 ;; |
3414 |
|
pkgmetadata|!pkgmetadata) retval=0 ;; |
3415 |
|
purge|!purge) retval=0 ;; |
3416 |
|
qalint|!qalint) retval=0 ;; |
3417 |
|
regentree|!regentree) retval=0 ;; |
3418 |
|
resume|!resume) retval=0 ;; |
3419 |
|
srcpkgbuild|!srcpkgbuild) retval=0 ;; |
3420 |
|
srcpkgtarball|!srcpkgtarball) retval=0 ;; |
3421 |
|
static|!static) retval=0 ;; |
3422 |
|
stepbystep|!stepbystep) retval=0 ;; |
3423 |
|
strip|!strip) retval=0 ;; |
3424 |
|
verbose|!verbose) retval=0 ;; |
3425 |
|
*) retval=1 ;; |
3426 |
|
esac |
3427 |
|
|
3428 |
|
return "${retval}" |
3429 |
|
} |
3430 |
|
|
3431 |
|
load_mage_features() |
3432 |
|
{ |
3433 |
|
for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]} |
3434 |
|
do |
3435 |
|
FVERBOSE=off msetfeature ${i} |
3436 |
|
done |
3437 |
|
} |
3438 |
|
|
3439 |
|
msetfeature() |
3440 |
|
{ |
3441 |
|
local feature |
3442 |
|
local count |
3443 |
|
local i |
3444 |
|
local found |
3445 |
|
|
3446 |
|
for feature in $@ |
3447 |
|
do |
3448 |
|
found=0 |
3449 |
|
count="${#MAGE_FEATURES_CURRENT[*]}" |
3450 |
|
|
3451 |
|
if ! known_mage_feature "${feature}" |
3452 |
|
then |
3453 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}" |
3454 |
|
return 3 |
3455 |
|
fi |
3456 |
|
|
3457 |
|
for ((i=0; i<count; i++)) |
3458 |
|
do |
3459 |
|
if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]] |
3460 |
|
then |
3461 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}" |
3462 |
|
MAGE_FEATURES_CURRENT[${i}]="${feature}" |
3463 |
|
found=1 |
3464 |
|
elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]] |
3465 |
|
then |
3466 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}" |
3467 |
|
MAGE_FEATURES_CURRENT[${i}]="${feature}" |
3468 |
|
found=1 |
3469 |
|
elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]] |
3470 |
|
then |
3471 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}" |
3472 |
|
MAGE_FEATURES_CURRENT[${i}]="${feature}" |
3473 |
|
found=1 |
3474 |
|
fi |
3475 |
|
done |
3476 |
|
|
3477 |
|
# if the feature was not found after proccessing the whole array |
3478 |
|
# it was not declared. in this case enable it |
3479 |
|
if [[ ${found} = 0 ]] |
3480 |
|
then |
3481 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}" |
3482 |
|
MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" ) |
3483 |
|
fi |
3484 |
|
|
3485 |
|
export MAGE_FEATURE_CURRENT |
3486 |
|
done |
3487 |
|
} |
3488 |
|
|
3489 |
|
mqueryfeature() |
3490 |
|
{ |
3491 |
|
local feature="$1" |
3492 |
|
local retval=1 |
3493 |
|
local i |
3494 |
|
|
3495 |
|
if known_mage_feature "${feature}" |
3496 |
|
then |
3497 |
|
for i in ${MAGE_FEATURES_CURRENT[*]} |
3498 |
|
do |
3499 |
|
if [[ ${i} = ${feature} ]] |
3500 |
|
then |
3501 |
|
retval=0 |
3502 |
|
break # found break here |
3503 |
|
fi |
3504 |
|
done |
3505 |
|
else |
3506 |
|
[[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}" |
3507 |
|
retval=3 |
3508 |
|
fi |
3509 |
|
|
3510 |
|
return ${retval} |
3511 |
|
} |
3512 |
|
|
3513 |
|
mprintfeatures() |
3514 |
|
{ |
3515 |
|
echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}" |
3516 |
|
echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}" |
3517 |
|
echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}" |
3518 |
|
} |