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.38 2008-10-05 10:32:24 niro Exp $ |
# $Id$ |
4 |
|
|
5 |
COLRED="\033[1;6m\033[31m" |
COLRED="\033[1;6m\033[31m" |
6 |
COLGREEN="\033[1;6m\033[32m" |
COLGREEN="\033[1;6m\033[32m" |
46 |
local method |
local method |
47 |
local cmd |
local cmd |
48 |
local retval |
local retval |
49 |
|
local sum |
50 |
|
local dest |
51 |
|
|
52 |
# very basic getops |
# very basic getops |
53 |
for i in $* |
for i in $* |
74 |
if [[ -d ${rundir} ]] |
if [[ -d ${rundir} ]] |
75 |
then |
then |
76 |
pushd ${rundir} &> /dev/null |
pushd ${rundir} &> /dev/null |
77 |
# be verbose here |
|
78 |
${cmd} -c ${file} #&> /dev/null |
# all file must be non-zero |
79 |
retval="$?" |
retval=0 |
80 |
|
while read sum dest |
81 |
|
do |
82 |
|
if [ ! -s ${dest} ] |
83 |
|
then |
84 |
|
echo "${dest}: file is empty ;(" |
85 |
|
retval=127 |
86 |
|
fi |
87 |
|
done < ${file} |
88 |
|
if [[ ${retval} != 127 ]] |
89 |
|
then |
90 |
|
# be verbose here |
91 |
|
${cmd} -c ${file} #&> /dev/null |
92 |
|
retval="$?" |
93 |
|
fi |
94 |
|
|
95 |
popd &> /dev/null |
popd &> /dev/null |
96 |
else |
else |
97 |
retval=1 |
retval=1 |
119 |
return ${retval} |
return ${retval} |
120 |
} |
} |
121 |
|
|
122 |
|
unpack_package() |
123 |
|
{ |
124 |
|
local magefile="$1" |
125 |
|
local pkgname |
126 |
|
local pkgfile |
127 |
|
local pkgtype |
128 |
|
local tar_opts |
129 |
|
|
130 |
|
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
131 |
|
pkgfile="${pkgname}.${PKGSUFFIX}" |
132 |
|
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
133 |
|
|
134 |
|
xtitle "[ Unpacking ${pkg} ]" |
135 |
|
|
136 |
|
# abort on virtual pkg |
137 |
|
if [[ ${pkgtype} = virtual ]] |
138 |
|
then |
139 |
|
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
140 |
|
echo " !unpack virtual ${pkgname} ... " |
141 |
|
continue |
142 |
|
fi |
143 |
|
|
144 |
|
# abort on sources pkg |
145 |
|
if [[ ${pkgtype} = sources ]] |
146 |
|
then |
147 |
|
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
148 |
|
echo " !unpack sources ${pkgname} ... " |
149 |
|
continue |
150 |
|
fi |
151 |
|
|
152 |
|
# busybox? |
153 |
|
if need_busybox_support tar |
154 |
|
then |
155 |
|
tar_opts="xjf" |
156 |
|
else |
157 |
|
tar_opts="xjmf" |
158 |
|
fi |
159 |
|
|
160 |
|
echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... " |
161 |
|
tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}" |
162 |
|
} |
163 |
|
|
164 |
unpack_packages() |
unpack_packages() |
165 |
{ |
{ |
166 |
local list="$@" |
local list="$@" |
167 |
local magefile |
local magefile |
|
local pkg |
|
|
local pkgtype |
|
168 |
local count_current |
local count_current |
169 |
local count_total |
local count_total |
170 |
local tar_opts |
local tar_opts |
177 |
|
|
178 |
for magefile in ${list} |
for magefile in ${list} |
179 |
do |
do |
180 |
pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
unpack_package "${magefile}" |
|
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
|
|
|
|
181 |
(( 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 |
|
|
|
|
|
# busybox? |
|
|
if need_busybox_support tar |
|
|
then |
|
|
tar_opts="xjf" |
|
|
else |
|
|
tar_opts="xjmf" |
|
|
fi |
|
|
|
|
|
echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " |
|
|
tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" |
|
182 |
done |
done |
183 |
|
|
184 |
# add a crlf for a better view |
# add a crlf for a better view |
1403 |
output+="${mirror}${addon}/${uri/${scheme}/}" |
output+="${mirror}${addon}/${uri/${scheme}/}" |
1404 |
done |
done |
1405 |
else |
else |
1406 |
output="${uri}" |
output="${uri}" |
1407 |
fi |
fi |
1408 |
|
|
1409 |
echo "${output}" |
echo "${output}" |
1470 |
{ |
{ |
1471 |
local i |
local i |
1472 |
local list="$@" |
local list="$@" |
1473 |
local pkg |
local pkgname |
1474 |
|
local pkgfile |
1475 |
|
local pcat |
1476 |
|
local pname |
1477 |
local mirr |
local mirr |
1478 |
local magefile |
local magefile |
1479 |
local md5file |
local md5file |
1481 |
local count_current |
local count_current |
1482 |
local count_total |
local count_total |
1483 |
local wget_opts |
local wget_opts |
1484 |
|
local fetching |
1485 |
|
|
1486 |
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
1487 |
|
|
1496 |
|
|
1497 |
for magefile in ${list} |
for magefile in ${list} |
1498 |
do |
do |
1499 |
pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
1500 |
|
pkgfile="${pkgname}.${PKGSUFFIX}" |
1501 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
1502 |
|
|
1503 |
|
pcat=$(magename2pcat ${magefile}) |
1504 |
|
pname=$(magename2pname ${magefile}) |
1505 |
|
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
1506 |
|
|
1507 |
(( count_current++ )) |
(( count_current++ )) |
1508 |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]" |
1509 |
|
|
1510 |
# abort on virtual pkg |
# abort on virtual pkg |
1511 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
1512 |
then |
then |
1513 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1514 |
echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... " |
1515 |
continue |
continue |
1516 |
fi |
fi |
1517 |
|
|
1519 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
1520 |
then |
then |
1521 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1522 |
echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... " |
1523 |
continue |
continue |
1524 |
fi |
fi |
1525 |
|
|
1526 |
# abort if already exist |
# check if FETCHING is required |
1527 |
if [ -f ${PKGDIR}/${pkg} ] |
if [ ! -f "${md5file}" ] |
1528 |
|
then |
1529 |
|
fetching=true |
1530 |
|
else |
1531 |
|
if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null |
1532 |
|
then |
1533 |
|
# md5's ok, no fetching required |
1534 |
|
fetching=false |
1535 |
|
else |
1536 |
|
fetching=true |
1537 |
|
fi |
1538 |
|
fi |
1539 |
|
|
1540 |
|
if [[ ${fetching} = false ]] |
1541 |
then |
then |
1542 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1543 |
echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " |
echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... " |
1544 |
continue |
continue |
1545 |
|
else |
1546 |
|
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1547 |
|
echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... " |
1548 |
|
mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}" |
1549 |
fi |
fi |
1550 |
|
|
1551 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
# sanity check, not really needed but to be sure |
1552 |
echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
if [ ! -f ${PKGDIR}/${pkgfile} ] |
|
mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}" |
|
|
if [ ! -f ${PKGDIR}/${pkg} ] |
|
1553 |
then |
then |
1554 |
die "Package '${pkg}' after download not found in '${PKGDIR}'" |
die "Package '${pkgfile}' after download not found in '${PKGDIR}'" |
1555 |
fi |
fi |
1556 |
done |
done |
1557 |
|
|
1656 |
then |
then |
1657 |
if ! mcheckemptydir ${MAGEDIR} |
if ! mcheckemptydir ${MAGEDIR} |
1658 |
then |
then |
1659 |
find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r |
find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r |
1660 |
fi |
fi |
1661 |
else |
else |
1662 |
rm -rf ${MAGEDIR} |
rm -rf ${MAGEDIR} |
1814 |
then |
then |
1815 |
HIGHEST_MAGEFILE=${magefile} |
HIGHEST_MAGEFILE=${magefile} |
1816 |
#for debug only |
#for debug only |
1817 |
mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" |
mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2 |
1818 |
fi |
fi |
1819 |
done |
done |
1820 |
|
|
1938 |
count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" |
count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" |
1939 |
done |
done |
1940 |
|
|
1941 |
# dirty hack to convert 0001 -> 1; 0120 -> 120 etc |
# convert 0001 -> 1; 0120 -> 120 etc |
1942 |
x="${#count}" |
# use bash internal base functions to this task |
1943 |
|
x="$((10#${count}))" |
1944 |
for (( i=0; i<x; i++ )) |
for (( i=0; i<x; i++ )) |
1945 |
do |
do |
1946 |
if [[ ${count:${i}:1} != 0 ]] |
if [[ ${count:${i}:1} != 0 ]] |
2256 |
then |
then |
2257 |
for i in $* |
for i in $* |
2258 |
do |
do |
2259 |
echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
[[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
2260 |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
2261 |
done |
done |
2262 |
echo |
[[ ${SILENT} = 1 ]] || echo |
2263 |
fi |
fi |
2264 |
} |
} |
2265 |
|
|
2563 |
local SDEPEND |
local SDEPEND |
2564 |
local PROVIDE |
local PROVIDE |
2565 |
local PKGTYPE |
local PKGTYPE |
|
local MAGE_TARGETS |
|
2566 |
local SPLIT_PACKAGE_BASE |
local SPLIT_PACKAGE_BASE |
2567 |
local preinstall |
local preinstall |
2568 |
local postinstall |
local postinstall |
2684 |
echo B:${pbuild} |
echo B:${pbuild} |
2685 |
fi |
fi |
2686 |
|
|
2687 |
if [[ -n ${MAGE_TARGETS} ]] |
if [[ -n ${SPLIT_PACKAGE_BASE} ]] |
|
then |
|
|
# basic svn compat |
|
|
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
|
|
then |
|
|
for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
|
|
do |
|
|
smage2file="${i}" |
|
|
done |
|
|
else |
|
|
smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
|
|
fi |
|
|
|
|
|
elif [[ -n ${SPLIT_PACKAGE_BASE} ]] |
|
2688 |
then |
then |
2689 |
# basic svn compat |
# basic svn compat |
2690 |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2726 |
if [[ ${PKGTYPE} != virtual ]] && \ |
if [[ ${PKGTYPE} != virtual ]] && \ |
2727 |
[[ ${PKGTYPE} != sources ]] |
[[ ${PKGTYPE} != sources ]] |
2728 |
then |
then |
2729 |
|
unpack_package "${magefile}" |
2730 |
echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
2731 |
build_doinstall ${PKGNAME} |
build_doinstall ${PKGNAME} |
2732 |
fi |
fi |
2815 |
pname=$(magename2pname ${magefile}) |
pname=$(magename2pname ${magefile}) |
2816 |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
2817 |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
2818 |
pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgfile="${pkgname}.${PKGSUFFIX}" |
2819 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
2820 |
|
|
2821 |
(( count_current++ )) |
(( count_current++ )) |
2825 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
2826 |
then |
then |
2827 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2828 |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... " |
2829 |
continue |
continue |
2830 |
fi |
fi |
2831 |
|
|
2833 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
2834 |
then |
then |
2835 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2836 |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... " |
2837 |
continue |
continue |
2838 |
fi |
fi |
2839 |
|
|
2881 |
pbuild=$(magename2pbuild ${pkg}) |
pbuild=$(magename2pbuild ${pkg}) |
2882 |
can_pcat="${pcat}" |
can_pcat="${pcat}" |
2883 |
can_pname="${pname}" |
can_pname="${pname}" |
2884 |
|
|
2885 |
if [ -z "${can_ver_list}" ] |
if [ -z "${can_ver_list}" ] |
2886 |
then |
then |
2887 |
can_ver_list=" ${pver}-${pbuild}" |
can_ver_list=" ${pver}-${pbuild}" |
3158 |
"") continue;; |
"") continue;; |
3159 |
esac |
esac |
3160 |
|
|
3161 |
deps="${deps} $(basename ${dep%-*})" |
if [[ -z ${deps} ]] |
3162 |
|
then |
3163 |
|
deps="$(basename ${dep%-*})" |
3164 |
|
else |
3165 |
|
deps="${deps} $(basename ${dep%-*})" |
3166 |
|
fi |
3167 |
done << EOF |
done << EOF |
3168 |
${depsfull} |
${depsfull} |
3169 |
EOF |
EOF |
3174 |
"") continue;; |
"") continue;; |
3175 |
esac |
esac |
3176 |
|
|
3177 |
sdeps="${sdeps} $(basename ${dep%-*})" |
if [[ -z ${sdeps} ]] |
3178 |
|
then |
3179 |
|
sdeps="$(basename ${dep%-*})" |
3180 |
|
else |
3181 |
|
sdeps="${sdeps} $(basename ${dep%-*})" |
3182 |
|
fi |
3183 |
done << EOF |
done << EOF |
3184 |
${sdepsfull} |
${sdepsfull} |
3185 |
EOF |
EOF |
3193 |
then |
then |
3194 |
echo " License: ${license}" |
echo " License: ${license}" |
3195 |
fi |
fi |
3196 |
echo " Depends: ${deps}" |
echo " Depends: ${deps}" |
3197 |
echo " SDepends: ${sdeps}" |
echo " SDepends: ${sdeps}" |
3198 |
echo |
echo |
3199 |
|
|
3317 |
do |
do |
3318 |
if [[ -x ${busybox} ]] |
if [[ -x ${busybox} ]] |
3319 |
then |
then |
3320 |
if [[ $(readlink $(which ${cmd})) = ${busybox} ]] |
if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]] |
3321 |
then |
then |
3322 |
# needs busybox support |
# needs busybox support |
3323 |
return 0 |
return 0 |
3380 |
{ |
{ |
3381 |
local feature="$1" |
local feature="$1" |
3382 |
local retval |
local retval |
3383 |
|
|
3384 |
case "${feature}" in |
case "${feature}" in |
3385 |
autosvc|!autosvc) retval=0 ;; |
autosvc|!autosvc) retval=0 ;; |
3386 |
buildlog|!buildlog) retval=0 ;; |
buildlog|!buildlog) retval=0 ;; |
3389 |
compressdoc|!compressdoc) retval=0 ;; |
compressdoc|!compressdoc) retval=0 ;; |
3390 |
debug|!debug) retval=0 ;; |
debug|!debug) retval=0 ;; |
3391 |
distcc|!distcc) retval=0 ;; |
distcc|!distcc) retval=0 ;; |
3392 |
|
icecc|!icecc) retval=0 ;; |
3393 |
kernelsrcunpack|!kernelsrcunpack) retval=0 ;; |
kernelsrcunpack|!kernelsrcunpack) retval=0 ;; |
3394 |
libtool|!libtool) retval=0 ;; |
libtool|!libtool) retval=0 ;; |
3395 |
linuxsymlink|!linuxsymlink) retval=0 ;; |
linuxsymlink|!linuxsymlink) retval=0 ;; |