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 $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $ |
4 |
|
|
5 |
|
COLRED="\033[1;6m\033[31m" |
6 |
|
COLGREEN="\033[1;6m\033[32m" |
7 |
|
COLYELLOW="\033[1;6m\033[33m" |
8 |
|
COLBLUE="\033[1;6m\033[34m" |
9 |
|
COLMAGENTA="\033[1;6m\033[35m" |
10 |
|
COLWHITE="\033[1;6m\033[37m" |
11 |
|
COLGRAY="\033[0;6m\033[37m" |
12 |
|
COLBOLD="\033[1m" |
13 |
|
COLDEFAULT="\033[0m" |
14 |
|
|
15 |
|
if [[ ${NOCOLORS} = true ]] |
16 |
|
then |
17 |
|
COLRED="" |
18 |
|
COLGREEN="" |
19 |
|
COLYELLOW="" |
20 |
|
COLBLUE="" |
21 |
|
COLMAGENTA="" |
22 |
|
COLWHITE="" |
23 |
|
COLGRAY="" |
24 |
|
COLBOLD="" |
25 |
|
COLDEFAULT="" |
26 |
|
fi |
27 |
|
|
28 |
mage_setup() |
mage_setup() |
29 |
{ |
{ |
30 |
[ ! -d ${MROOT}${INSTALLDB} ] && \ |
[ ! -d ${MROOT}${INSTALLDB} ] && \ |
38 |
return 0 |
return 0 |
39 |
} |
} |
40 |
|
|
41 |
|
mchecksum() |
42 |
|
{ |
43 |
|
local i |
44 |
|
local rundir |
45 |
|
local file |
46 |
|
local method |
47 |
|
local cmd |
48 |
|
local retval |
49 |
|
|
50 |
|
# very basic getops |
51 |
|
for i in $* |
52 |
|
do |
53 |
|
case $1 in |
54 |
|
--rundir|-r) shift; rundir="$1" ;; |
55 |
|
--file|-f) shift; file="$1" ;; |
56 |
|
--method|-m) shift; method="$1" ;; |
57 |
|
esac |
58 |
|
shift |
59 |
|
done |
60 |
|
|
61 |
|
# sanity checks |
62 |
|
[[ -z ${rundir} ]] && die "mchecksum(): rundir missing" |
63 |
|
[[ -z ${file} ]] && die "mchecksum(): file missing" |
64 |
|
[[ -z ${method} ]] && die "mchecksum(): method missing" |
65 |
|
|
66 |
|
case ${method} in |
67 |
|
md5) cmd="md5sum" ;; |
68 |
|
sha256) cmd="sha256sum" ;; |
69 |
|
*) die "mchecksum(): unkown method '${method}'" ;; |
70 |
|
esac |
71 |
|
|
72 |
|
if [[ -d ${rundir} ]] |
73 |
|
then |
74 |
|
pushd ${rundir} &> /dev/null |
75 |
|
${cmd} -c ${file} &> /dev/null |
76 |
|
retval="$?" |
77 |
|
popd &> /dev/null |
78 |
|
else |
79 |
|
retval=1 |
80 |
|
fi |
81 |
|
|
82 |
|
return "${retval}" |
83 |
|
} |
84 |
|
|
85 |
unpack_packages() |
unpack_packages() |
86 |
{ |
{ |
87 |
local list="$@" |
local list="$@" |
208 |
[ -z "${pathto}" ] && continue |
[ -z "${pathto}" ] && continue |
209 |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
[[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" |
210 |
|
|
|
|
|
211 |
# monitors /etc/env.d -> env-rebuild |
# monitors /etc/env.d -> env-rebuild |
212 |
[[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
[[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true |
213 |
|
|
1327 |
done |
done |
1328 |
} |
} |
1329 |
|
|
1330 |
|
# convertmirrors [uri] |
1331 |
|
convertmirrors() |
1332 |
|
{ |
1333 |
|
local uri="$1" |
1334 |
|
local scheme |
1335 |
|
local mirror |
1336 |
|
local mirrors |
1337 |
|
local addon |
1338 |
|
local real_uri |
1339 |
|
local output |
1340 |
|
|
1341 |
|
# needs |
1342 |
|
[[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!" |
1343 |
|
[[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!" |
1344 |
|
[[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!" |
1345 |
|
[[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!" |
1346 |
|
[[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!" |
1347 |
|
|
1348 |
|
# check known uri schemes |
1349 |
|
case ${uri} in |
1350 |
|
http://*|https://*|ftp://*|ftps://*) mirrors="" ;; |
1351 |
|
mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;; |
1352 |
|
package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;; |
1353 |
|
gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;; |
1354 |
|
sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;; |
1355 |
|
gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;; |
1356 |
|
kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;; |
1357 |
|
*) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;; |
1358 |
|
esac |
1359 |
|
|
1360 |
|
if [[ ! -z ${mirrors} ]] |
1361 |
|
then |
1362 |
|
for mirror in ${mirrors} |
1363 |
|
do |
1364 |
|
# add a whitespace to the output |
1365 |
|
[[ -z ${output} ]] || output+=" " |
1366 |
|
output+="${mirror}${addon}/${uri/${scheme}/}" |
1367 |
|
done |
1368 |
|
else |
1369 |
|
output="${uri}" |
1370 |
|
fi |
1371 |
|
|
1372 |
|
echo "${output}" |
1373 |
|
} |
1374 |
|
|
1375 |
|
mdownload() |
1376 |
|
{ |
1377 |
|
local i |
1378 |
|
local uri |
1379 |
|
local real_uris |
1380 |
|
local mirror |
1381 |
|
local outputfile |
1382 |
|
local outputdir |
1383 |
|
local retval |
1384 |
|
local wget_opts |
1385 |
|
|
1386 |
|
# very basic getops |
1387 |
|
for i in $* |
1388 |
|
do |
1389 |
|
case $1 in |
1390 |
|
--uri|-u) shift; uri="$1" ;; |
1391 |
|
--dir|-d) shift; outputdir="$1" ;; |
1392 |
|
esac |
1393 |
|
shift |
1394 |
|
done |
1395 |
|
|
1396 |
|
# sanity checks; abort if not given |
1397 |
|
[[ -z ${uri} ]] && die "mdownload(): no uri given!" |
1398 |
|
[[ -z ${outputdir} ]] && die "mdownload(): no dir given!" |
1399 |
|
|
1400 |
|
# convert mirrored uris to the real ones |
1401 |
|
real_uris="$(convertmirrors ${uri})" |
1402 |
|
|
1403 |
|
# verbose or not |
1404 |
|
[[ ${VERBOSE} = off ]] && wget_opts="--quiet" |
1405 |
|
|
1406 |
|
# filter wget options if busybox was found |
1407 |
|
wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})" |
1408 |
|
|
1409 |
|
# create outputdir |
1410 |
|
[[ ! -d ${outputdir} ]] && install -d "${outputdir}" |
1411 |
|
|
1412 |
|
for mirror in ${real_uris} |
1413 |
|
do |
1414 |
|
# get the name of the output file |
1415 |
|
outputfile="${mirror##*/}" |
1416 |
|
|
1417 |
|
wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}" |
1418 |
|
retval="$?" |
1419 |
|
if [[ ${retval} = 0 ]] |
1420 |
|
then |
1421 |
|
break |
1422 |
|
else |
1423 |
|
continue |
1424 |
|
fi |
1425 |
|
done |
1426 |
|
|
1427 |
|
# return wget retval |
1428 |
|
return "${retval}" |
1429 |
|
} |
1430 |
|
|
1431 |
# fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
# fetch_packages /path/to/mage/file1 /path/to/mage/file2 |
1432 |
fetch_packages() |
fetch_packages() |
1433 |
{ |
{ |
1434 |
|
local i |
1435 |
local list="$@" |
local list="$@" |
1436 |
local pkg |
local pkg |
1437 |
local mirr |
local mirr |
1485 |
continue |
continue |
1486 |
fi |
fi |
1487 |
|
|
1488 |
for mirr in ${MIRRORS} |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
1489 |
do |
echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
1490 |
echo -ne " ${COLBLUE}***${COLDEFAULT}" |
mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}" |
|
#echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " |
|
|
echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " |
|
|
[[ ${VERBOSE} = off ]] && opt="--quiet" |
|
|
wget \ |
|
|
${wget_opts} \ |
|
|
--directory-prefix=${PKGDIR} \ |
|
|
${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} |
|
|
if [[ $? = 0 ]] |
|
|
then |
|
|
break |
|
|
else |
|
|
continue |
|
|
fi |
|
|
done |
|
1491 |
|
|
1492 |
if [ ! -f ${PKGDIR}/${pkg} ] |
if [ ! -f ${PKGDIR}/${pkg} ] |
1493 |
then |
then |
1494 |
die "Could not download ${pkg}" |
die "Package '${pkg}' after download not found in '${PKGDIR}'" |
1495 |
fi |
fi |
1496 |
done |
done |
1497 |
|
|
1519 |
done |
done |
1520 |
|
|
1521 |
# clean up backup files (foo~) |
# clean up backup files (foo~) |
1522 |
find ${MAGEDIR} -name *~ -exec rm '{}' ';' |
find ${MAGEDIR} -name \*~ -exec rm '{}' ';' |
1523 |
|
|
1524 |
# check if a newer mage version is available |
# check if a newer mage version is available |
1525 |
is_newer_mage_version_available |
is_newer_mage_version_available |
1646 |
} |
} |
1647 |
|
|
1648 |
|
|
1649 |
# cuts full pathnames or versioniezed names down to basename |
# cuts full pathnames or versionized names down to basename |
1650 |
choppkgname() |
choppkgname() |
1651 |
{ |
{ |
1652 |
#we want this only if full name was used |
#we want this only if full name was used |
1729 |
local magefile |
local magefile |
1730 |
|
|
1731 |
# do not list the content of a directory, only the name (-d) |
# do not list the content of a directory, only the name (-d) |
1732 |
for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*) |
for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null) |
1733 |
do |
do |
1734 |
[[ -z ${magefile} ]] && continue |
[[ -z ${magefile} ]] && continue |
1735 |
# we exclude subdirs (for stuff like a md5sum dir) |
# we exclude subdirs (for stuff like a md5sum dir) |
1742 |
fi |
fi |
1743 |
done |
done |
1744 |
|
|
|
# do not so anything |
|
|
# # 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 |
|
|
|
|
1745 |
echo "${HIGHEST_MAGEFILE}" |
echo "${HIGHEST_MAGEFILE}" |
1746 |
return 0 |
return 0 |
1747 |
} |
} |
2594 |
if [[ -n ${MAGE_TARGETS} ]] |
if [[ -n ${MAGE_TARGETS} ]] |
2595 |
then |
then |
2596 |
# basic svn compat |
# basic svn compat |
2597 |
if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2598 |
then |
then |
2599 |
for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 |
2600 |
do |
do |
2601 |
smage2file="${i}" |
smage2file="${i}" |
2602 |
done |
done |
2607 |
elif [[ -n ${SPLIT_PACKAGE_BASE} ]] |
elif [[ -n ${SPLIT_PACKAGE_BASE} ]] |
2608 |
then |
then |
2609 |
# basic svn compat |
# basic svn compat |
2610 |
if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2611 |
then |
then |
2612 |
for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 |
2613 |
do |
do |
2614 |
smage2file="${i}" |
smage2file="${i}" |
2615 |
done |
done |
2619 |
|
|
2620 |
else |
else |
2621 |
# basic svn compat |
# basic svn compat |
2622 |
if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] |
if [[ -d ${SMAGESCRIPTSDIR}/.svn ]] |
2623 |
then |
then |
2624 |
for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 |
for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2 |
2625 |
do |
do |
2626 |
smage2file="${i}" |
smage2file="${i}" |
2627 |
done |
done |
3221 |
then |
then |
3222 |
# needs busybox support |
# needs busybox support |
3223 |
return 0 |
return 0 |
|
else |
|
|
# no busybox |
|
|
return 1 |
|
3224 |
fi |
fi |
3225 |
fi |
fi |
3226 |
|
|
3227 |
|
# no busybox |
3228 |
|
return 1 |
3229 |
} |
} |
3230 |
|
|
3231 |
# busybox_filter_wget_options ${wget_opts} |
# busybox_filter_wget_options ${wget_opts} |
3260 |
echo "${opts}" |
echo "${opts}" |
3261 |
fi |
fi |
3262 |
} |
} |
3263 |
|
|
3264 |
|
have_root_privileges() |
3265 |
|
{ |
3266 |
|
local retval |
3267 |
|
|
3268 |
|
if [[ $(id -u) = 0 ]] |
3269 |
|
then |
3270 |
|
retval=0 |
3271 |
|
else |
3272 |
|
retval=1 |
3273 |
|
fi |
3274 |
|
|
3275 |
|
return ${retval} |
3276 |
|
} |