1 |
#!/bin/sh |
#!/bin/bash |
2 |
# Magellan Linux Installer (mage.sh) |
# Magellan Linux Installer (mage.sh) |
3 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.8 2005-10-03 13:48:06 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.sh,v 1.17 2008-06-16 09:29:57 niro Exp $ |
4 |
|
|
5 |
# default die function |
# default die function |
6 |
die() |
die() |
7 |
{ |
{ |
8 |
|
echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
9 |
echo -e ${COLRED}"$@"${COLDEFAULT} |
echo -e ${COLRED}"$@"${COLDEFAULT} |
10 |
exit 1 |
exit 1 |
11 |
} |
} |
15 |
source /etc/mage.rc.global || \ |
source /etc/mage.rc.global || \ |
16 |
die "/etc/mage.rc.global missing" |
die "/etc/mage.rc.global missing" |
17 |
|
|
18 |
[ -f /etc/mage.rc ] && source /etc/mage.rc || \ |
[ -f ${MAGERC} ] && source ${MAGERC} || \ |
19 |
die "Your /etc/mage.rc is missing. Aborting." |
die "Your ${MAGERC} is missing. Aborting." |
20 |
|
|
21 |
[ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
[ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
22 |
source ${MLIBDIR}/mage4.functions.sh || \ |
source ${MLIBDIR}/mage4.functions.sh || \ |
23 |
die "mage functions missing" |
die "mage functions missing" |
24 |
|
|
|
# for tests only |
|
|
#source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage.rc.global |
|
|
#source /etc/mage.rc |
|
|
#source /home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh |
|
|
#MLIBDIR=/home/tjoke/alx-cvs/magellan-src/mage/usr/lib/mage |
|
|
|
|
|
## only for tests -> normally in /etc/rc.d/init.d/functions |
|
|
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 |
|
|
|
|
25 |
# export default path |
# export default path |
26 |
export PATH="${PATH}:${MLIBDIR}" |
export PATH="${PATH}:${MLIBDIR}" |
27 |
|
|
31 |
# sanity checks |
# sanity checks |
32 |
[ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} |
[ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} |
33 |
|
|
34 |
if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] |
if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]] |
35 |
then |
then |
36 |
echo |
echo |
37 |
echo "Please choose an profile from the mage tree." |
echo "Please choose an profile from the mage tree." |
40 |
fi |
fi |
41 |
|
|
42 |
# default messages |
# default messages |
43 |
showversion() { |
showversion() |
44 |
|
{ |
45 |
local MAGEVERSION="$(< ${MLIBDIR}/version)" |
local MAGEVERSION="$(< ${MLIBDIR}/version)" |
46 |
|
|
47 |
echo -en "Magellan Package Manager v${MAGEVERSION} " |
echo -en "Magellan Package Manager v${MAGEVERSION} " |
48 |
echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
49 |
} |
} |
50 |
|
|
51 |
print_usage(){ |
print_usage() |
52 |
showversion |
{ |
53 |
echo |
#showversion |
54 |
|
#echo |
55 |
echo "Usage: $(basename $0) [option] pkgname ..." |
echo "Usage: $(basename $0) [option] pkgname ..." |
56 |
echo "Options:" |
echo "Options:" |
57 |
echo " pretend - pretends dependencies of a package" |
echo " pretend - pretends dependencies of a package" |
58 |
echo " srcpretend - pretends dependencies of a package (build from source)" |
echo " srcpretend - pretends dependencies of a package (build from source)" |
59 |
echo " install - installs a package" |
echo " install - installs a package" |
60 |
echo " srcinstall - installs a package from source" |
echo " srcinstall - installs a package from source" |
61 |
echo " uninstall - removes a package" |
echo " uninstall - removes a package" |
62 |
echo " update - updates mage-tree" |
echo " update - updates the mage-tree via rsync" |
63 |
echo " uppretend - pretend dependencies for a system upgrade" |
echo " update-tarball - updates the mage-tree via a tarball" |
64 |
echo " upgrade - runs a complete system upgrade" |
echo " uppretend - pretend dependencies for a system upgrade" |
65 |
echo " srcuppretend - pretend dependencies for a system upgrade from source" |
echo " upgrade - runs a complete system upgrade" |
66 |
echo " srcupgrade - runs a complete system upgrade from source" |
echo " srcuppretend - pretend dependencies for a system upgrade from source" |
67 |
echo " search - searches mage-tree for a package" |
echo " srcupgrade - runs a complete system upgrade from source" |
68 |
echo " clean - removes *all* downloaded packages" |
echo " search - searches mage-tree for a package" |
69 |
echo " unpack - unpacks *all* needed package for 'foo'" |
echo " clean - removes *all* downloaded packages" |
70 |
echo " download - downloads *all* needed packages for 'foo'" |
echo " unpack - unpacks *all* needed package for 'foo'" |
71 |
echo " version - prints version info" |
echo " download - downloads *all* needed packages for 'foo'" |
72 |
|
echo " version - prints version info" |
73 |
|
echo " regen-mage-tree - regenerates the whole mage database (for devs only)" |
74 |
echo |
echo |
75 |
echo "Other options:" |
echo "Other options:" |
76 |
# echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE" |
# echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE" |
77 |
# echo "Builds a Package with its dependencies, but won't install anything." |
# echo "Builds a Package with its dependencies, but won't install anything." |
78 |
# echo |
# echo |
79 |
echo "USE_UNSTABLE=true $(basename $0) [src]install PACKAGE" |
echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE" |
80 |
echo "Overrides stable packages; you can install packages that are marked unstable." |
echo "Overrides stable packages; you can install packages that are marked unstable." |
81 |
echo |
echo |
82 |
echo "USE_TESTING=true $(basename $0) [src]install PACKAGE" |
echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE" |
83 |
echo "Overrides stable packages; you can install packages that are marked testing." |
echo "Overrides stable packages; you can install packages that are marked testing." |
84 |
echo |
echo |
85 |
echo "NOCOLORS=true $(basename $0) [src]install PACKAGE" |
echo "NOCOLORS=true $(basename $0) [src]install PACKAGE" |
91 |
showversion |
showversion |
92 |
echo |
echo |
93 |
|
|
|
# before anything run mage_setup |
|
|
mage_setup || die "error in mage_setup()" |
|
|
|
|
94 |
# install method |
# install method |
95 |
METHOD="$1" |
METHOD="$1" |
96 |
|
|
97 |
# initial unversionized packagename, gets overridden later |
# initial unversionized packagename, gets overridden later on |
98 |
MAGENAME="$2" |
MAGENAME="$2" |
99 |
|
|
100 |
if [[ ${METHOD} != upgrade ]] && \ |
if [[ ${METHOD} != upgrade ]] && \ |
102 |
[[ ${METHOD} != uppretend ]] && \ |
[[ ${METHOD} != uppretend ]] && \ |
103 |
[[ ${METHOD} != srcuppretend ]] && \ |
[[ ${METHOD} != srcuppretend ]] && \ |
104 |
[[ ${METHOD} != update ]] && \ |
[[ ${METHOD} != update ]] && \ |
105 |
|
[[ ${METHOD} != update-tarball ]] && \ |
106 |
[[ ${METHOD} != clean ]] && \ |
[[ ${METHOD} != clean ]] && \ |
107 |
[[ ${METHOD} != version ]] && \ |
[[ ${METHOD} != version ]] && \ |
108 |
[[ ${METHOD} != search ]] && \ |
[[ ${METHOD} != search ]] && \ |
111 |
[[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 |
[[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 |
112 |
fi |
fi |
113 |
|
|
114 |
|
# set PKGDIR and BUILDDIR to MROOT |
115 |
|
if [[ -n ${MROOT} ]] |
116 |
|
then |
117 |
|
PKGDIR=${MROOT}/${PKGDIR} |
118 |
|
BUILDDIR=${MROOT}/${BUILDDIR} |
119 |
|
fi |
120 |
|
|
121 |
|
# before anything run mage_setup |
122 |
|
mage_setup || die "error in mage_setup()" |
123 |
|
|
124 |
|
# load supported mage features |
125 |
|
load_mage_features |
126 |
|
|
127 |
case ${METHOD} in |
case ${METHOD} in |
128 |
download) |
download) |
135 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
136 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
137 |
|
|
138 |
|
# package is masked |
139 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
140 |
|
|
141 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
142 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
143 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
165 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
166 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
167 |
|
|
168 |
|
# package is masked |
169 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
170 |
|
|
171 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
172 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
173 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
194 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
195 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
196 |
|
|
197 |
|
# package is masked |
198 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
199 |
|
|
200 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
201 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
202 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
221 |
;; |
;; |
222 |
|
|
223 |
install) |
install) |
224 |
|
have_root_privileges || die "You must be root to run this operation." |
225 |
|
|
226 |
# first of all get the right pkg which going to be installed |
# first of all get the right pkg which going to be installed |
227 |
PCAT="$(pname2pcat ${MAGENAME})" |
PCAT="$(pname2pcat ${MAGENAME})" |
228 |
|
|
232 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
233 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
234 |
|
|
235 |
|
# package is masked |
236 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
237 |
|
|
238 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
239 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
240 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
265 |
;; |
;; |
266 |
|
|
267 |
srcinstall) |
srcinstall) |
268 |
|
have_root_privileges || die "You must be root to run this operation." |
269 |
|
|
270 |
# first of all get the right pkg which going to be installed |
# first of all get the right pkg which going to be installed |
271 |
PCAT="$(pname2pcat ${MAGENAME})" |
PCAT="$(pname2pcat ${MAGENAME})" |
272 |
|
|
276 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
277 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
278 |
|
|
279 |
|
# package is masked |
280 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
281 |
|
|
282 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
283 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
284 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
305 |
;; |
;; |
306 |
|
|
307 |
uninstall) |
uninstall) |
308 |
ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
have_root_privileges || die "You must be root to run this operation." |
309 |
if [ -z "${ALLDEPS}" ] |
|
310 |
then |
ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
311 |
die "No package installed named '${MAGENAME}'." |
if [ -z "${ALLDEPS}" ] |
312 |
fi |
then |
313 |
uninstall_packages ${ALLDEPS} |
die "No package installed named '${MAGENAME}'." |
314 |
|
fi |
315 |
|
uninstall_packages ${ALLDEPS} |
316 |
;; |
;; |
317 |
|
|
318 |
uppretend|srcuppretend) |
uppretend|srcuppretend) |
325 |
;; |
;; |
326 |
|
|
327 |
upgrade) |
upgrade) |
328 |
|
have_root_privileges || die "You must be root to run this operation." |
329 |
|
|
330 |
# get all dependencies of *all* installed packages |
# get all dependencies of *all* installed packages |
331 |
# fake pcat,pname,pver,pbuild ... |
# fake pcat,pname,pver,pbuild ... |
332 |
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
344 |
;; |
;; |
345 |
|
|
346 |
srcupgrade) |
srcupgrade) |
347 |
|
have_root_privileges || die "You must be root to run this operation." |
348 |
|
|
349 |
# get all dependencies of *all* installed packages |
# get all dependencies of *all* installed packages |
350 |
# fake pcat,pname,pver,pbuild ... |
# fake pcat,pname,pver,pbuild ... |
351 |
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
363 |
;; |
;; |
364 |
|
|
365 |
unpack) |
unpack) |
366 |
|
have_root_privileges || die "You must be root to run this operation." |
367 |
|
|
368 |
# first of all get the right pkg which going to be installed |
# first of all get the right pkg which going to be installed |
369 |
PCAT="$(pname2pcat ${MAGENAME})" |
PCAT="$(pname2pcat ${MAGENAME})" |
370 |
|
|
374 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
375 |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
376 |
|
|
377 |
|
# package is masked |
378 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
379 |
|
|
380 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
381 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
382 |
PNAME="$(pkgname2pname ${PKGNAME})" |
PNAME="$(pkgname2pname ${PKGNAME})" |
396 |
;; |
;; |
397 |
|
|
398 |
update) |
update) |
399 |
|
have_root_privileges || die "You must be root to run this operation." |
400 |
syncmage |
syncmage |
401 |
;; |
;; |
402 |
|
|
403 |
|
update-tarball) |
404 |
|
have_root_privileges || die "You must be root to run this operation." |
405 |
|
syncmage_tarball |
406 |
|
;; |
407 |
|
|
408 |
clean) |
clean) |
409 |
|
have_root_privileges || die "You must be root to run this operation." |
410 |
cleanpkg |
cleanpkg |
411 |
;; |
;; |
412 |
|
|
413 |
version) |
version) |
414 |
showversion |
# showversion |
415 |
|
exit 0 |
416 |
;; |
;; |
417 |
|
|
418 |
regen-mage-tree) |
regen-mage-tree) |
419 |
|
have_root_privileges || die "You must be root to run this operation." |
420 |
|
|
421 |
if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] |
if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] |
422 |
then |
then |
423 |
echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos." |
echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos." |