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.1 2005-09-09 16:35:41 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 |
} |
} |
12 |
|
|
13 |
# include all needed files |
# include all needed files |
14 |
# [ -f ${MLIBDIR}/conf/mage.rc.global ] && \ |
[ -f /etc/mage.rc.global ] && \ |
15 |
# source ${MLIBDIR}/conf/mage.rc.global || \ |
source /etc/mage.rc.global || \ |
16 |
# die "${MLIBDIR}/conf/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}/mage.functions.sh ] && \ |
[ -f ${MLIBDIR}/mage4.functions.sh ] && \ |
22 |
# source ${MLIBDIR}/mage.functions.sh || \ |
source ${MLIBDIR}/mage4.functions.sh || \ |
23 |
# die "mage functions missing" |
die "mage functions missing" |
|
|
|
|
# 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" |
|
|
COLBLUE="\033[1;6m\033[34m" |
|
|
COLDEFAULT="\033[0m" |
|
|
|
|
|
if [[ ${NOCOLORS} = true ]] |
|
|
then |
|
|
COLRED="" |
|
|
COLGREEN="" |
|
|
COLYELLOW="" |
|
|
COLBLUE="" |
|
|
COLMAGENTA="" |
|
|
COLWHITE="" |
|
|
COLDEFAULT="" |
|
|
fi |
|
24 |
|
|
25 |
# export default path |
# export default path |
26 |
export PATH="${PATH}:${MLIBDIR}" |
export PATH="${PATH}:${MLIBDIR}" |
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 " search - searches mage-tree for a package" |
echo " update-tarball - updates the mage-tree via a tarball" |
64 |
echo " clean - removes *all* downloaded packages" |
echo " uppretend - pretend dependencies for a system upgrade" |
65 |
# echo " unpack - unpacks a package" |
echo " upgrade - runs a complete system upgrade" |
66 |
echo " download - downloads a package" |
echo " srcuppretend - pretend dependencies for a system upgrade from source" |
67 |
echo " version - prints version info" |
echo " srcupgrade - runs a complete system upgrade from source" |
68 |
|
echo " search - searches mage-tree for a package" |
69 |
|
echo " clean - removes *all* downloaded packages" |
70 |
|
echo " unpack - unpacks *all* needed package for 'foo'" |
71 |
|
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 |
[[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 |
if [[ ${METHOD} != upgrade ]] && \ |
101 |
|
[[ ${METHOD} != srcupgrade ]] && \ |
102 |
|
[[ ${METHOD} != uppretend ]] && \ |
103 |
|
[[ ${METHOD} != srcuppretend ]] && \ |
104 |
|
[[ ${METHOD} != update ]] && \ |
105 |
|
[[ ${METHOD} != update-tarball ]] && \ |
106 |
|
[[ ${METHOD} != clean ]] && \ |
107 |
|
[[ ${METHOD} != version ]] && \ |
108 |
|
[[ ${METHOD} != search ]] && \ |
109 |
|
[[ ${METHOD} != regen-mage-tree ]] |
110 |
|
then |
111 |
|
[[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1 |
112 |
|
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 |
case ${METHOD} in |
case ${METHOD} in |
125 |
download) |
download) |
130 |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
131 |
|
|
132 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
133 |
source $(get_highest_magefile ${PCAT} ${MAGENAME}) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
134 |
|
|
135 |
|
# package is masked |
136 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
137 |
|
|
138 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
139 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
149 |
--pver ${PVER} \ |
--pver ${PVER} \ |
150 |
--pbuild ${PBUILD})" |
--pbuild ${PBUILD})" |
151 |
fetch_packages ${ALLDEPS} || die "fetching packages" |
fetch_packages ${ALLDEPS} || die "fetching packages" |
152 |
|
md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
153 |
;; |
;; |
154 |
|
|
155 |
srcdownload) |
srcdownload) |
160 |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
161 |
|
|
162 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
163 |
source $(get_highest_magefile ${PCAT} ${MAGENAME}) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
164 |
|
|
165 |
|
# package is masked |
166 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
167 |
|
|
168 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
169 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
189 |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
190 |
|
|
191 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
192 |
source $(get_highest_magefile ${PCAT} ${MAGENAME}) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
193 |
|
|
194 |
|
# package is masked |
195 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
196 |
|
|
197 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
198 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
218 |
;; |
;; |
219 |
|
|
220 |
install) |
install) |
221 |
|
have_root_privileges || die "You must be root to run this operation." |
222 |
|
|
223 |
# first of all get the right pkg which going to be installed |
# first of all get the right pkg which going to be installed |
224 |
PCAT="$(pname2pcat ${MAGENAME})" |
PCAT="$(pname2pcat ${MAGENAME})" |
225 |
|
|
227 |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
228 |
|
|
229 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
230 |
source $(get_highest_magefile ${PCAT} ${MAGENAME}) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
231 |
|
|
232 |
|
# package is masked |
233 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
234 |
|
|
235 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
236 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
241 |
if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
242 |
then |
then |
243 |
echo -en "Package " |
echo -en "Package " |
244 |
echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
245 |
echo -e " already installed." |
echo -e " already installed." |
246 |
exit 3 |
exit 3 |
247 |
fi |
fi |
262 |
;; |
;; |
263 |
|
|
264 |
srcinstall) |
srcinstall) |
265 |
|
have_root_privileges || die "You must be root to run this operation." |
266 |
|
|
267 |
# first of all get the right pkg which going to be installed |
# first of all get the right pkg which going to be installed |
268 |
PCAT="$(pname2pcat ${MAGENAME})" |
PCAT="$(pname2pcat ${MAGENAME})" |
269 |
|
|
271 |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
272 |
|
|
273 |
# source the highest magefile of this pkg |
# source the highest magefile of this pkg |
274 |
source $(get_highest_magefile ${PCAT} ${MAGENAME}) |
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
275 |
|
|
276 |
|
# package is masked |
277 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
278 |
|
|
279 |
# convert PKGNAME to PNAME/PVER/PBUILD |
# convert PKGNAME to PNAME/PVER/PBUILD |
280 |
# we're working *only* with these three vars from here on |
# we're working *only* with these three vars from here on |
285 |
if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} |
286 |
then |
then |
287 |
echo -en "Package " |
echo -en "Package " |
288 |
echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" |
289 |
echo -e " already installed." |
echo -e " already installed." |
290 |
exit 3 |
exit 3 |
291 |
fi |
fi |
302 |
;; |
;; |
303 |
|
|
304 |
uninstall) |
uninstall) |
305 |
ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
have_root_privileges || die "You must be root to run this operation." |
306 |
if [ -z "${ALLDEPS}" ] |
|
307 |
then |
ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})" |
308 |
die "No package installed named '${MAGENAME}'." |
if [ -z "${ALLDEPS}" ] |
309 |
fi |
then |
310 |
uninstall_packages ${ALLDEPS} |
die "No package installed named '${MAGENAME}'." |
311 |
|
fi |
312 |
|
uninstall_packages ${ALLDEPS} |
313 |
|
;; |
314 |
|
|
315 |
|
uppretend|srcuppretend) |
316 |
|
${MLIBDIR}/depwalker.sh \ |
317 |
|
--method ${METHOD} \ |
318 |
|
--pcat ${METHOD} \ |
319 |
|
--pname ${METHOD} \ |
320 |
|
--pver ${METHOD} \ |
321 |
|
--pbuild ${METHOD} |
322 |
|
;; |
323 |
|
|
324 |
|
upgrade) |
325 |
|
have_root_privileges || die "You must be root to run this operation." |
326 |
|
|
327 |
|
# get all dependencies of *all* installed packages |
328 |
|
# fake pcat,pname,pver,pbuild ... |
329 |
|
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
330 |
|
--method ${METHOD} \ |
331 |
|
--pcat ${METHOD} \ |
332 |
|
--pname ${METHOD} \ |
333 |
|
--pver ${METHOD} \ |
334 |
|
--pbuild ${METHOD})" |
335 |
|
|
336 |
|
# first fetch all packages |
337 |
|
fetch_packages ${ALLDEPS} || die "fetching packages" |
338 |
|
md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
339 |
|
unpack_packages ${ALLDEPS} || die "unpacking packages" |
340 |
|
install_packages ${ALLDEPS} || die "installing packages" |
341 |
|
;; |
342 |
|
|
343 |
|
srcupgrade) |
344 |
|
have_root_privileges || die "You must be root to run this operation." |
345 |
|
|
346 |
|
# get all dependencies of *all* installed packages |
347 |
|
# fake pcat,pname,pver,pbuild ... |
348 |
|
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
349 |
|
--method ${METHOD} \ |
350 |
|
--pcat ${METHOD} \ |
351 |
|
--pname ${METHOD} \ |
352 |
|
--pver ${METHOD} \ |
353 |
|
--pbuild ${METHOD})" |
354 |
|
|
355 |
|
install_packages --src-install ${ALLDEPS} || die "src-installing packages" |
356 |
;; |
;; |
357 |
|
|
358 |
search) |
search) |
359 |
${MLIBDIR}/pkgsearch.sh ${MAGENAME} |
pkgsearch "${MAGENAME}" |
360 |
;; |
;; |
361 |
|
|
362 |
# unpack) |
unpack) |
363 |
# build_unpackpkg |
have_root_privileges || die "You must be root to run this operation." |
364 |
# ;; |
|
365 |
|
# first of all get the right pkg which going to be installed |
366 |
|
PCAT="$(pname2pcat ${MAGENAME})" |
367 |
|
|
368 |
|
# package does not exists |
369 |
|
[ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist." |
370 |
|
|
371 |
|
# source the highest magefile of this pkg |
372 |
|
PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME})) |
373 |
|
|
374 |
|
# package is masked |
375 |
|
[ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation." |
376 |
|
|
377 |
|
# convert PKGNAME to PNAME/PVER/PBUILD |
378 |
|
# we're working *only* with these three vars from here on |
379 |
|
PNAME="$(pkgname2pname ${PKGNAME})" |
380 |
|
PVER="$(pkgname2pver ${PKGNAME})" |
381 |
|
PBUILD="$(pkgname2pbuild ${PKGNAME})" |
382 |
|
|
383 |
|
# get all dependencies of this package |
384 |
|
ALLDEPS="$(${MLIBDIR}/depwalker.sh \ |
385 |
|
--method install \ |
386 |
|
--pcat ${PCAT} \ |
387 |
|
--pname ${PNAME} \ |
388 |
|
--pver ${PVER} \ |
389 |
|
--pbuild ${PBUILD})" |
390 |
|
fetch_packages ${ALLDEPS} || die "fetching packages" |
391 |
|
md5sum_packages ${ALLDEPS} || die "md5 sum packages" |
392 |
|
unpack_packages ${ALLDEPS} || die "unpacking packages" |
393 |
|
;; |
394 |
|
|
395 |
update) |
update) |
396 |
|
have_root_privileges || die "You must be root to run this operation." |
397 |
syncmage |
syncmage |
398 |
;; |
;; |
399 |
|
|
400 |
|
update-tarball) |
401 |
|
have_root_privileges || die "You must be root to run this operation." |
402 |
|
syncmage_tarball |
403 |
|
;; |
404 |
|
|
405 |
clean) |
clean) |
406 |
|
have_root_privileges || die "You must be root to run this operation." |
407 |
cleanpkg |
cleanpkg |
408 |
;; |
;; |
409 |
|
|
410 |
version) |
version) |
411 |
showversion |
# showversion |
412 |
|
exit 0 |
413 |
;; |
;; |
414 |
|
|
415 |
regen-mage-tree) |
regen-mage-tree) |
416 |
|
have_root_privileges || die "You must be root to run this operation." |
417 |
|
|
418 |
if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] |
if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ] |
419 |
then |
then |
420 |
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." |