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$ |
|
|
|
|
COLRED="\033[1;6m\033[31m" |
|
|
COLGREEN="\033[1;6m\033[32m" |
|
|
COLYELLOW="\033[1;6m\033[33m" |
|
|
COLBLUE="\033[1;6m\033[34m" |
|
|
COLMAGENTA="\033[1;6m\033[35m" |
|
|
COLWHITE="\033[1;6m\033[37m" |
|
|
COLGRAY="\033[0;6m\033[37m" |
|
|
COLBOLD="\033[1m" |
|
|
COLDEFAULT="\033[0m" |
|
|
|
|
|
if [[ ${NOCOLORS} = true ]] |
|
|
then |
|
|
COLRED="" |
|
|
COLGREEN="" |
|
|
COLYELLOW="" |
|
|
COLBLUE="" |
|
|
COLMAGENTA="" |
|
|
COLWHITE="" |
|
|
COLGRAY="" |
|
|
COLBOLD="" |
|
|
COLDEFAULT="" |
|
|
fi |
|
4 |
|
|
5 |
mage_setup() |
mage_setup() |
6 |
{ |
{ |
23 |
local method |
local method |
24 |
local cmd |
local cmd |
25 |
local retval |
local retval |
26 |
|
local sum |
27 |
|
local dest |
28 |
|
|
29 |
# very basic getops |
# very basic getops |
30 |
for i in $* |
for i in $* |
51 |
if [[ -d ${rundir} ]] |
if [[ -d ${rundir} ]] |
52 |
then |
then |
53 |
pushd ${rundir} &> /dev/null |
pushd ${rundir} &> /dev/null |
54 |
${cmd} -c ${file} &> /dev/null |
|
55 |
retval="$?" |
# 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 |
popd &> /dev/null |
73 |
else |
else |
74 |
retval=1 |
retval=1 |
77 |
return "${retval}" |
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 |
local tar_opts |
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 |
|
|
|
|
|
# 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}" |
|
159 |
done |
done |
160 |
|
|
161 |
# add a crlf for a better view |
# add a crlf for a better view |
162 |
if [ ${count_total} -gt 1 ]; then echo; fi |
if [ ${count_total} -gt 1 ]; then echo; fi |
163 |
} |
} |
164 |
|
|
|
|
|
165 |
# fix_mtime path/to/$mtime/reffile $pathto/file |
# fix_mtime path/to/$mtime/reffile $pathto/file |
166 |
# creates a given reference file and fixes given file |
# creates a given reference file and fixes given file |
167 |
# returns new mtime |
# returns new mtime |
174 |
mtime=$(stat -c %Y "${reference}") |
mtime=$(stat -c %Y "${reference}") |
175 |
touch \ |
touch \ |
176 |
--no-create \ |
--no-create \ |
177 |
|
--no-dereference \ |
178 |
--time=mtime \ |
--time=mtime \ |
179 |
--reference "${reference}" \ |
--reference="${reference}" \ |
180 |
"${pathto}" |
"${pathto}" |
181 |
|
|
182 |
echo "${mtime}" |
echo "${mtime}" |
418 |
|
|
419 |
ln -snf "${link}" "${MROOT}${pathto}" |
ln -snf "${link}" "${MROOT}${pathto}" |
420 |
|
|
421 |
# # fix mtime and db |
# fix mtime and db |
422 |
# fix_descriptor ${pkgname}/.symlinks \ |
fix_descriptor ${pkgname}/.symlinks \ |
423 |
# "${pathto}" \ |
"${pathto}" \ |
424 |
# "${posix}" \ |
"${posix}" \ |
425 |
# "${link}" \ |
"${link}" \ |
426 |
# "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
"$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ |
427 |
# "${MROOT}${pathto}")" |
"${MROOT}${pathto}")" |
428 |
|
|
429 |
done < ${BUILDDIR}/${pkgname}/.symlinks |
done < ${BUILDDIR}/${pkgname}/.symlinks |
430 |
|
|
737 |
[ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
[ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." |
738 |
|
|
739 |
# remove virtuals only if no other exist |
# remove virtuals only if no other exist |
740 |
if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] |
if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]] |
741 |
then |
then |
742 |
# first unregister virtuals |
# first unregister virtuals |
743 |
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
provide="$(get_value_from_magefile PROVIDE ${magefile})" |
766 |
local i |
local i |
767 |
|
|
768 |
# very basic getops |
# very basic getops |
769 |
for i in $* |
for i in $@ |
770 |
do |
do |
771 |
case $1 in |
case ${i} in |
772 |
--pcat|-c) shift; pcat="$1" ;; |
--pcat*) pcat="${i#*=}" ;; |
773 |
--pname|-n) shift; pname="$1" ;; |
--pname*) pname="${i#*=}" ;; |
774 |
esac |
esac |
|
shift |
|
775 |
done |
done |
776 |
|
|
777 |
# sanity checks; abort if not given |
# sanity checks; abort if not given |
810 |
|
|
811 |
mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" |
812 |
|
|
813 |
# if $pathto is a symlink than compare linked binary |
# no extra handlink for symlinks anymore as fix_mtime |
814 |
if [ -L "${MROOT}${pathto}" ] |
# uses --no-dereference, compare directly |
815 |
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 |
|
816 |
|
|
817 |
[[ ${mtime} = ${x} ]] && return 0 |
[[ ${mtime} = ${x} ]] && return 0 |
818 |
|
|
1359 |
|
|
1360 |
# check known uri schemes |
# check known uri schemes |
1361 |
case ${uri} in |
case ${uri} in |
1362 |
http://*|https://*|ftp://*|ftps://*) mirrors="" ;; |
http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;; |
1363 |
mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; |
mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; |
1364 |
package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; |
package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; |
1365 |
gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; |
gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; |
1378 |
output+="${mirror}${addon}/${uri/${scheme}/}" |
output+="${mirror}${addon}/${uri/${scheme}/}" |
1379 |
done |
done |
1380 |
else |
else |
1381 |
output="${uri}" |
output="${uri}" |
1382 |
fi |
fi |
1383 |
|
|
1384 |
echo "${output}" |
echo "${output}" |
1426 |
# get the name of the output file |
# get the name of the output file |
1427 |
outputfile="${mirror##*/}" |
outputfile="${mirror##*/}" |
1428 |
|
|
1429 |
wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" |
case ${mirror} in |
1430 |
retval="$?" |
file://*) |
1431 |
|
cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}" |
1432 |
|
retval="$?" |
1433 |
|
;; |
1434 |
|
*) |
1435 |
|
wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" |
1436 |
|
retval="$?" |
1437 |
|
;; |
1438 |
|
esac |
1439 |
|
|
1440 |
if [[ ${retval} = 0 ]] |
if [[ ${retval} = 0 ]] |
1441 |
then |
then |
1442 |
break |
break |
1454 |
{ |
{ |
1455 |
local i |
local i |
1456 |
local list="$@" |
local list="$@" |
1457 |
local pkg |
local pkgname |
1458 |
|
local pkgfile |
1459 |
|
local pcat |
1460 |
|
local pname |
1461 |
local mirr |
local mirr |
1462 |
local magefile |
local magefile |
1463 |
local md5file |
local md5file |
1465 |
local count_current |
local count_current |
1466 |
local count_total |
local count_total |
1467 |
local wget_opts |
local wget_opts |
1468 |
|
local fetching |
1469 |
|
|
1470 |
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
[ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
1471 |
|
|
1480 |
|
|
1481 |
for magefile in ${list} |
for magefile in ${list} |
1482 |
do |
do |
1483 |
pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
1484 |
|
pkgfile="${pkgname}.${PKGSUFFIX}" |
1485 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
1486 |
|
|
1487 |
|
pcat=$(magename2pcat ${magefile}) |
1488 |
|
pname=$(magename2pname ${magefile}) |
1489 |
|
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
1490 |
|
|
1491 |
(( count_current++ )) |
(( count_current++ )) |
1492 |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" |
xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]" |
1493 |
|
|
1494 |
# abort on virtual pkg |
# abort on virtual pkg |
1495 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
1496 |
then |
then |
1497 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1498 |
echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... " |
1499 |
continue |
continue |
1500 |
fi |
fi |
1501 |
|
|
1503 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
1504 |
then |
then |
1505 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
1506 |
echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " |
echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... " |
1507 |
continue |
continue |
1508 |
fi |
fi |
1509 |
|
|
1510 |
# abort if already exist |
# check if FETCHING is required |
1511 |
if [ -f ${PKGDIR}/${pkg} ] |
if [ ! -f "${md5file}" ] |
1512 |
|
then |
1513 |
|
fetching=true |
1514 |
|
else |
1515 |
|
if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null |
1516 |
|
then |
1517 |
|
# md5's ok, no fetching required |
1518 |
|
fetching=false |
1519 |
|
else |
1520 |
|
fetching=true |
1521 |
|
fi |
1522 |
|
fi |
1523 |
|
|
1524 |
|
if [[ ${fetching} = false ]] |
1525 |
then |
then |
1526 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1527 |
echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " |
echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... " |
1528 |
continue |
continue |
1529 |
|
else |
1530 |
|
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1531 |
|
echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... " |
1532 |
|
mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}" |
1533 |
fi |
fi |
1534 |
|
|
1535 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
# sanity check, not really needed but to be sure |
1536 |
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} ] |
|
1537 |
then |
then |
1538 |
die "Package '${pkg}' after download not found in '${PKGDIR}'" |
die "Package '${pkgfile}' after download not found in '${PKGDIR}'" |
1539 |
fi |
fi |
1540 |
done |
done |
1541 |
|
|
1590 |
|
|
1591 |
for mirr in ${MIRRORS} |
for mirr in ${MIRRORS} |
1592 |
do |
do |
1593 |
# path without distribution |
# path without distribution |
1594 |
mymirr="${mirr%/*}" |
# (only for stable|testing|unstable and not DISTROTAG) |
1595 |
|
case ${mirr##*/} in |
1596 |
|
stable|testing|unstable) mymirr="${mirr%/*}";; |
1597 |
|
*) mymirr="${mirr}";; |
1598 |
|
esac |
1599 |
|
|
1600 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1601 |
echo "fetching latest md5 from ${mymirr} ..." |
echo "fetching latest md5 from ${mymirr} ..." |
1628 |
else |
else |
1629 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1630 |
echo -n "checking md5sum... " |
echo -n "checking md5sum... " |
1631 |
( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed" |
mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed" |
1632 |
fi |
fi |
1633 |
|
|
1634 |
if [[ -d ${MAGEDIR} ]] |
if [[ -d ${MAGEDIR} ]] |
1635 |
then |
then |
1636 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1637 |
echo "cleaning old mage-tree ${MAGEDIR}..." |
echo "cleaning old mage-tree ${MAGEDIR}..." |
1638 |
rm -rf ${MAGEDIR} |
# honor mountpoints and empty dirs |
1639 |
|
if mountpoint -q ${MAGEDIR} |
1640 |
|
then |
1641 |
|
if ! mcheckemptydir ${MAGEDIR} |
1642 |
|
then |
1643 |
|
find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r |
1644 |
|
fi |
1645 |
|
else |
1646 |
|
rm -rf ${MAGEDIR} |
1647 |
|
fi |
1648 |
fi |
fi |
1649 |
|
|
1650 |
if need_busybox_support tar |
if need_busybox_support tar |
1683 |
fi |
fi |
1684 |
} |
} |
1685 |
|
|
1686 |
xtitle() |
# unused? |
1687 |
{ |
# |
1688 |
if [[ ${TERM} = xterm ]] |
# # cuts full pathnames or versionized names down to basename |
1689 |
then |
# choppkgname() |
1690 |
echo -ne "\033]0;Mage: $1\007" |
# { |
1691 |
fi |
# #we want this only if full name was used |
1692 |
return 0 |
# if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
1693 |
} |
# then |
1694 |
|
# #cuts ARCH and PBUILD |
1695 |
|
# #ARCH comes from ${MAGERC} |
1696 |
xtitleclean() |
# MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g") |
1697 |
{ |
# |
1698 |
if [[ ${TERM} = xterm ]] |
# #cuts version number |
1699 |
then |
# MAGENAME=$(basename ${MAGENAME%-*} .mage) |
1700 |
echo -ne "\033]0;\007" |
# fi |
1701 |
fi |
# } |
|
return 0 |
|
|
} |
|
|
|
|
1702 |
|
|
|
# cuts full pathnames or versionized names down to basename |
|
|
choppkgname() |
|
|
{ |
|
|
#we want this only if full name was used |
|
|
if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] |
|
|
then |
|
|
#cuts ARCH and PBUILD |
|
|
#ARCH comes from ${MAGERC} |
|
|
MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") |
|
|
|
|
|
#cuts version number |
|
|
MAGENAME=$(basename ${MAGENAME%-*} .mage) |
|
|
fi |
|
|
} |
|
1703 |
|
|
1704 |
# get_categorie $PNAME, returns CATEGORIE |
# get_categorie $PNAME, returns CATEGORIE |
1705 |
# $1=pname |
# $1=pname |
1722 |
echo "${categorie}" |
echo "${categorie}" |
1723 |
} |
} |
1724 |
|
|
|
# check_stable_package /path/to/foo.mage |
|
|
# returns 0=stable 1=unstable |
|
|
check_stable_package() |
|
|
{ |
|
|
# first check if this magefile is not blacklisted |
|
|
blacklisted "$1" || return 1 |
|
|
|
|
|
local STATE |
|
|
STATE="$(get_value_from_magefile STATE "$1")" |
|
|
|
|
|
# state testing |
|
|
if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] |
|
|
then |
|
|
case ${STATE} in |
|
|
testing|stable) return 0 ;; |
|
|
*) return 1 ;; |
|
|
esac |
|
|
fi |
|
|
|
|
|
# state unstable |
|
|
if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] |
|
|
then |
|
|
case ${STATE} in |
|
|
unstable|testing|stable) return 0 ;; |
|
|
*) return 1 ;; |
|
|
esac |
|
|
fi |
|
|
|
|
|
# no use_state given = stable |
|
|
case ${STATE} in |
|
|
stable) return 0 ;; |
|
|
*) return 1 ;; |
|
|
esac |
|
|
} |
|
|
|
|
|
|
|
1725 |
# get_highest_magefile ${PCAT} ${PNAME} |
# get_highest_magefile ${PCAT} ${PNAME} |
1726 |
# fake at moment returns only stable pkgs (must set to be one) |
# returns $HIGHEST_MAGEFILE |
|
# return $HIGHEST_MAGEFILE |
|
1727 |
get_highest_magefile() |
get_highest_magefile() |
1728 |
{ |
{ |
1729 |
local HIGHEST_MAGEFILE |
local pcat="$1" |
1730 |
local PCAT="$1" |
local pname="$2" |
|
local PNAME="$2" |
|
|
local magefile |
|
|
|
|
|
# do not list the content of a directory, only the name (-d) |
|
|
for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null) |
|
|
do |
|
|
[[ -z ${magefile} ]] && continue |
|
|
# we exclude subdirs (for stuff like a md5sum dir) |
|
|
[[ -d ${magefile} ]] && continue |
|
|
if check_stable_package ${magefile} |
|
|
then |
|
|
HIGHEST_MAGEFILE=${magefile} |
|
|
#for debug only |
|
|
mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" |
|
|
fi |
|
|
done |
|
1731 |
|
|
1732 |
echo "${HIGHEST_MAGEFILE}" |
${MLIBDIR}/highest_magefile ${MAGEDIR}/${pcat}/${pname} |
1733 |
return 0 |
return 0 |
1734 |
} |
} |
1735 |
|
|
|
|
|
1736 |
################################################### |
################################################### |
1737 |
# function is_config_protected # |
# function is_config_protected # |
1738 |
# is_config_protected /path/to/file # |
# is_config_protected /path/to/file # |
1831 |
local filename="${file##*/}" |
local filename="${file##*/}" |
1832 |
local count |
local count |
1833 |
local output |
local output |
1834 |
|
local oldprotected |
1835 |
local i |
local i |
1836 |
|
local x |
1837 |
|
|
1838 |
|
# hack; do not honor a global set IFS like '§' |
1839 |
|
local IFS |
1840 |
|
|
1841 |
declare -i count=0 |
count=0 |
1842 |
|
|
1843 |
# check if there are already protected files |
# check if there are already protected files |
1844 |
for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | |
for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" | |
1845 |
sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | |
sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | |
1846 |
sort -t'%' -k3 -k2 | cut -f1 -d'%') |
sort -t'%' -k3 -k2 | cut -f1 -d'%') |
1847 |
do |
do |
1848 |
count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") |
count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')" |
1849 |
done |
done |
1850 |
(( count ++ )) |
|
1851 |
|
# convert 0001 -> 1; 0120 -> 120 etc |
1852 |
|
# use bash internal base functions to this task |
1853 |
|
x="$((10#${count}))" |
1854 |
|
for (( i=0; i<x; i++ )) |
1855 |
|
do |
1856 |
|
if [[ ${count:${i}:1} != 0 ]] |
1857 |
|
then |
1858 |
|
count="${count:${i}}" |
1859 |
|
break |
1860 |
|
fi |
1861 |
|
done |
1862 |
|
|
1863 |
|
count="$(( ${count}+1 ))" |
1864 |
|
|
1865 |
# fill output up with zeros |
# fill output up with zeros |
1866 |
for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done |
for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done |
2166 |
then |
then |
2167 |
for i in $* |
for i in $* |
2168 |
do |
do |
2169 |
echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
[[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
2170 |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
2171 |
done |
done |
2172 |
echo |
[[ ${SILENT} = 1 ]] || echo |
2173 |
fi |
fi |
2174 |
} |
} |
2175 |
|
|
2196 |
fi |
fi |
2197 |
} |
} |
2198 |
|
|
|
|
|
2199 |
# returns pname from pkgname |
# returns pname from pkgname |
2200 |
# pkgname2pname $PKGNAME |
# pkgname2pname $PKGNAME |
2201 |
pkgname2pname() |
pkgname2pname() |
2472 |
local SDEPEND |
local SDEPEND |
2473 |
local PROVIDE |
local PROVIDE |
2474 |
local PKGTYPE |
local PKGTYPE |
|
local MAGE_TARGETS |
|
2475 |
local SPLIT_PACKAGE_BASE |
local SPLIT_PACKAGE_BASE |
2476 |
local preinstall |
local preinstall |
2477 |
local postinstall |
local postinstall |
2593 |
echo B:${pbuild} |
echo B:${pbuild} |
2594 |
fi |
fi |
2595 |
|
|
2596 |
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} ]] |
|
2597 |
then |
then |
2598 |
# basic svn compat |
# basic svn compat |
2599 |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2635 |
if [[ ${PKGTYPE} != virtual ]] && \ |
if [[ ${PKGTYPE} != virtual ]] && \ |
2636 |
[[ ${PKGTYPE} != sources ]] |
[[ ${PKGTYPE} != sources ]] |
2637 |
then |
then |
2638 |
|
unpack_package "${magefile}" |
2639 |
echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
2640 |
build_doinstall ${PKGNAME} |
build_doinstall ${PKGNAME} |
2641 |
fi |
fi |
2680 |
then |
then |
2681 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2682 |
echo -n "rebuilding environment ... " |
echo -n "rebuilding environment ... " |
2683 |
${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
${MLIBDIR}/env-rebuild > /dev/null && \ |
2684 |
echo "done." || echo "failure." |
echo "done." || echo "failure." |
2685 |
unset MAGE_ENV_REBUILD |
unset MAGE_ENV_REBUILD |
2686 |
fi |
fi |
2724 |
pname=$(magename2pname ${magefile}) |
pname=$(magename2pname ${magefile}) |
2725 |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
pkgname="$(get_value_from_magefile PKGNAME ${magefile})" |
2726 |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" |
2727 |
pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" |
pkgfile="${pkgname}.${PKGSUFFIX}" |
2728 |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" |
2729 |
|
|
2730 |
(( count_current++ )) |
(( count_current++ )) |
2734 |
if [[ ${pkgtype} = virtual ]] |
if [[ ${pkgtype} = virtual ]] |
2735 |
then |
then |
2736 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2737 |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... " |
2738 |
continue |
continue |
2739 |
fi |
fi |
2740 |
|
|
2742 |
if [[ ${pkgtype} = sources ]] |
if [[ ${pkgtype} = sources ]] |
2743 |
then |
then |
2744 |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
echo -ne " ${COLBLUE}---${COLDEFAULT}" |
2745 |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " |
echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... " |
2746 |
continue |
continue |
2747 |
fi |
fi |
2748 |
|
|
2750 |
then |
then |
2751 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2752 |
echo -ne "checking md5sum (${count_current}/${count_total}): " |
echo -ne "checking md5sum (${count_current}/${count_total}): " |
2753 |
( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed" |
mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed" |
2754 |
else |
else |
2755 |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
2756 |
echo -e "!! no md5sum file found for ${pkgfile} :(" |
echo -e "!! no md5sum file found for ${pkgfile} :(" |
2790 |
pbuild=$(magename2pbuild ${pkg}) |
pbuild=$(magename2pbuild ${pkg}) |
2791 |
can_pcat="${pcat}" |
can_pcat="${pcat}" |
2792 |
can_pname="${pname}" |
can_pname="${pname}" |
2793 |
|
|
2794 |
if [ -z "${can_ver_list}" ] |
if [ -z "${can_ver_list}" ] |
2795 |
then |
then |
2796 |
can_ver_list=" ${pver}-${pbuild}" |
can_ver_list=" ${pver}-${pbuild}" |
2945 |
then |
then |
2946 |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
2947 |
echo -n "rebuilding environment ... " |
echo -n "rebuilding environment ... " |
2948 |
${MLIBDIR}/env-rebuild.sh > /dev/null && \ |
${MLIBDIR}/env-rebuild > /dev/null && \ |
2949 |
echo "done." || echo "failure." |
echo "done." || echo "failure." |
2950 |
unset MAGE_ENV_REBUILD |
unset MAGE_ENV_REBUILD |
2951 |
fi |
fi |
2963 |
unset -f postremove |
unset -f postremove |
2964 |
} |
} |
2965 |
|
|
2966 |
|
# rerun_pkgfunctions [method] pkg1 pkg2 pkg3 |
2967 |
|
rerun_pkgfunctions() |
2968 |
|
{ |
2969 |
|
local method |
2970 |
|
local list |
2971 |
|
local pcat |
2972 |
|
local pname |
2973 |
|
local pver |
2974 |
|
local pbuild |
2975 |
|
local magefile |
2976 |
|
local i |
2977 |
|
|
2978 |
|
# very basic getops |
2979 |
|
case $1 in |
2980 |
|
--method) shift; method="$1" ;; |
2981 |
|
esac |
2982 |
|
shift |
2983 |
|
local list="$@" |
2984 |
|
|
2985 |
|
# sanity check |
2986 |
|
case ${method} in |
2987 |
|
preinstall|postinstall) ;; |
2988 |
|
preremove|postremove) ;; |
2989 |
|
*) die "rerun_pkgfunctions(): Unknown method '${method}'." ;; |
2990 |
|
esac |
2991 |
|
|
2992 |
|
if [[ -n ${MROOT} ]] |
2993 |
|
then |
2994 |
|
echo -ne ${COLRED} |
2995 |
|
echo "!! running in MROOT=${MROOT}" |
2996 |
|
echo -ne ${COLDEFAULT} |
2997 |
|
echo |
2998 |
|
fi |
2999 |
|
|
3000 |
|
for pkg in ${list} |
3001 |
|
do |
3002 |
|
pcat=$(dep2pcat ${pkg}) |
3003 |
|
pname=$(magename2pname ${pkg}) |
3004 |
|
pver=$(magename2pver ${pkg}) |
3005 |
|
pbuild=$(magename2pbuild ${pkg}) |
3006 |
|
magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
3007 |
|
|
3008 |
|
if [ -e ${magefile} ] |
3009 |
|
then |
3010 |
|
source ${magefile} |
3011 |
|
if [ -n "$(typeset -f ${method})" ] |
3012 |
|
then |
3013 |
|
echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... " |
3014 |
|
${method} |
3015 |
|
else |
3016 |
|
echo "No ${method}() for pkg '${pkg}' defined. Doing nothing." |
3017 |
|
fi |
3018 |
|
unset -f preinstall postinstall preremove postremove |
3019 |
|
else |
3020 |
|
die "Magefile '${magefile}' does not exist." |
3021 |
|
fi |
3022 |
|
done |
3023 |
|
} |
3024 |
|
|
3025 |
show_etc_update_mesg() |
show_etc_update_mesg() |
3026 |
{ |
{ |
3027 |
[ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
[ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 |
3049 |
local state |
local state |
3050 |
local descriptiom |
local descriptiom |
3051 |
local homepage |
local homepage |
3052 |
|
local license |
3053 |
local i |
local i |
3054 |
local all_installed |
local all_installed |
3055 |
local ipver |
local ipver |
3086 |
state="$(get_value_from_magefile STATE ${magefile})" |
state="$(get_value_from_magefile STATE ${magefile})" |
3087 |
description="$(get_value_from_magefile DESCRIPTION ${magefile})" |
description="$(get_value_from_magefile DESCRIPTION ${magefile})" |
3088 |
homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" |
homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" |
3089 |
|
license="$(get_value_from_magefile LICENSE ${magefile})" |
3090 |
|
|
3091 |
# all installed |
# all installed |
3092 |
for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) |
for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) |
3093 |
do |
do |
3094 |
ipver="$(magename2pver ${i})" |
ipver="$(magename2pver ${i})" |
3095 |
ipbuild="$(magename2pbuild ${i})" |
ipbuild="$(magename2pbuild ${i})" |
3096 |
|
|
3097 |
if [[ -z ${all_installed} ]] |
if [[ -z ${all_installed} ]] |
3098 |
then |
then |
3099 |
all_installed="${ipver}-${ipbuild}" |
all_installed="${ipver}-${ipbuild}" |
3102 |
fi |
fi |
3103 |
done |
done |
3104 |
[[ -z ${all_installed} ]] && all_installed="none" |
[[ -z ${all_installed} ]] && all_installed="none" |
3105 |
|
|
3106 |
case ${state} in |
case ${state} in |
3107 |
stable) state=${COLGREEN}"[s] ";; |
stable) state=${COLGREEN}"[s] ";; |
3108 |
testing) state=${COLYELLOW}"[t] ";; |
testing) state=${COLYELLOW}"[t] ";; |
3126 |
"") continue;; |
"") continue;; |
3127 |
esac |
esac |
3128 |
|
|
3129 |
deps="${deps} $(basename ${dep%-*})" |
if [[ -z ${deps} ]] |
3130 |
|
then |
3131 |
|
deps="$(basename ${dep%-*})" |
3132 |
|
else |
3133 |
|
deps="${deps} $(basename ${dep%-*})" |
3134 |
|
fi |
3135 |
done << EOF |
done << EOF |
3136 |
${depsfull} |
${depsfull} |
3137 |
EOF |
EOF |
3142 |
"") continue;; |
"") continue;; |
3143 |
esac |
esac |
3144 |
|
|
3145 |
sdeps="${sdeps} $(basename ${dep%-*})" |
if [[ -z ${sdeps} ]] |
3146 |
|
then |
3147 |
|
sdeps="$(basename ${dep%-*})" |
3148 |
|
else |
3149 |
|
sdeps="${sdeps} $(basename ${dep%-*})" |
3150 |
|
fi |
3151 |
done << EOF |
done << EOF |
3152 |
${sdepsfull} |
${sdepsfull} |
3153 |
EOF |
EOF |
3157 |
echo " Installed versions: ${all_installed}" |
echo " Installed versions: ${all_installed}" |
3158 |
echo " Description: ${description}" |
echo " Description: ${description}" |
3159 |
echo " Homepage: ${homepage}" |
echo " Homepage: ${homepage}" |
3160 |
echo " Depends: ${deps}" |
if [[ ! -z ${license} ]] |
3161 |
|
then |
3162 |
|
echo " License: ${license}" |
3163 |
|
fi |
3164 |
|
echo " Depends: ${deps}" |
3165 |
echo " SDepends: ${sdeps}" |
echo " SDepends: ${sdeps}" |
3166 |
echo |
echo |
3167 |
|
|
3278 |
need_busybox_support() |
need_busybox_support() |
3279 |
{ |
{ |
3280 |
local cmd |
local cmd |
3281 |
|
local busybox |
3282 |
cmd="$1" |
cmd="$1" |
3283 |
|
|
3284 |
if [[ -x /bin/busybox ]] |
for busybox in {,/usr}/bin/busybox |
3285 |
then |
do |
3286 |
if [[ $(readlink $(which ${cmd})) = /bin/busybox ]] |
if [[ -x ${busybox} ]] |
3287 |
then |
then |
3288 |
# needs busybox support |
if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]] |
3289 |
return 0 |
then |
3290 |
|
# needs busybox support |
3291 |
|
return 0 |
3292 |
|
fi |
3293 |
fi |
fi |
3294 |
fi |
done |
3295 |
|
|
3296 |
# no busybox |
# no busybox |
3297 |
return 1 |
return 1 |
3348 |
{ |
{ |
3349 |
local feature="$1" |
local feature="$1" |
3350 |
local retval |
local retval |
3351 |
|
|
3352 |
case "${feature}" in |
case "${feature}" in |
3353 |
autosvc|!autosvc) retval=0 ;; |
autosvc|!autosvc) retval=0 ;; |
3354 |
buildlog|!buildlog) retval=0 ;; |
buildlog|!buildlog) retval=0 ;; |
3357 |
compressdoc|!compressdoc) retval=0 ;; |
compressdoc|!compressdoc) retval=0 ;; |
3358 |
debug|!debug) retval=0 ;; |
debug|!debug) retval=0 ;; |
3359 |
distcc|!distcc) retval=0 ;; |
distcc|!distcc) retval=0 ;; |
3360 |
|
icecc|!icecc) retval=0 ;; |
3361 |
kernelsrcunpack|!kernelsrcunpack) retval=0 ;; |
kernelsrcunpack|!kernelsrcunpack) retval=0 ;; |
3362 |
libtool|!libtool) retval=0 ;; |
libtool|!libtool) retval=0 ;; |
3363 |
linuxsymlink|!linuxsymlink) retval=0 ;; |
linuxsymlink|!linuxsymlink) retval=0 ;; |
3364 |
|
multilib|!multilib) reval=0 ;; |
3365 |
pkgbuild|!pkgbuild) retval=0 ;; |
pkgbuild|!pkgbuild) retval=0 ;; |
3366 |
|
pkgdistrotag|!pkgdistrotag) retval=0 ;; |
3367 |
|
pkgmetadata|!pkgmetadata) retval=0 ;; |
3368 |
purge|!purge) retval=0 ;; |
purge|!purge) retval=0 ;; |
3369 |
qalint|!qalint) retval=0 ;; |
qalint|!qalint) retval=0 ;; |
3370 |
regentree|!regentree) retval=0 ;; |
regentree|!regentree) retval=0 ;; |
3435 |
MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" ) |
MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" ) |
3436 |
fi |
fi |
3437 |
|
|
3438 |
export MAGE_FEATURE_CURRENT |
export MAGE_FEATURES_CURRENT |
3439 |
done |
done |
3440 |
} |
} |
3441 |
|
|
3465 |
|
|
3466 |
mprintfeatures() |
mprintfeatures() |
3467 |
{ |
{ |
3468 |
echo "Global features: ${MAGE_FEATURES_GLOBAL[*]}" |
echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}" |
3469 |
echo "Local features: ${MAGE_FEATURES[*]}" |
echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}" |
3470 |
echo "Current features: ${MAGE_FEATURES_CURRENT[*]}" |
echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}" |
3471 |
} |
} |