Magellan Linux

Contents of /trunk/mage/usr/lib/mage/mage4.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2210 - (show annotations) (download) (as text)
Mon Oct 14 13:13:46 2013 UTC (10 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 13043 byte(s)
-add support for build-prerequisites
1 #!/bin/bash
2 # Magellan Linux Installer (mage.sh)
3 # $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
6 die()
7 {
8 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
9 echo -e ${COLRED}"$@"${COLDEFAULT}
10 exit 1
11 }
12
13 # include all needed files
14 [ -f /etc/mage.rc.global ] && \
15 source /etc/mage.rc.global || \
16 die "/etc/mage.rc.global missing"
17
18 [ -f ${MAGERC} ] && source ${MAGERC} || \
19 die "Your ${MAGERC} is missing. Aborting."
20
21 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
22 source ${MLIBDIR}/mage4.functions.sh || \
23 die "mage functions missing"
24
25 # export default path
26 export PATH="${PATH}:${MLIBDIR}"
27
28 # export the default C locale
29 export LC_ALL=C
30
31 # sanity checks
32 [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE}
33
34 if [ ! -e ${VIRTUALDB_DEFAULTS} ] && [[ $1 != update ]] && [[ $1 != update-tarball ]]
35 then
36 echo
37 echo "Please choose an profile from the mage tree."
38 echo "ln -snf ${MAGEDIR}/profiles/profilename /etc/mage-profile"
39 exit 1
40 fi
41
42 # default messages
43 showversion()
44 {
45 local MAGEVERSION="$(< ${MLIBDIR}/version)"
46
47 echo -en "Magellan Package Manager v${MAGEVERSION} "
48 echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
49 }
50
51 print_usage()
52 {
53 #showversion
54 #echo
55 echo "Usage: $(basename $0) [option] pkgname ..."
56 echo "Options:"
57 echo " pretend - pretends dependencies of a package"
58 echo " srcpretend - pretends dependencies of a package (build from source)"
59 echo " install - installs a package"
60 echo " srcinstall - installs a package from source"
61 echo " uninstall - removes a package"
62 echo " update - updates the mage-tree via rsync"
63 echo " update-tarball - updates the mage-tree via a tarball"
64 echo " uppretend - pretend dependencies for a system upgrade"
65 echo " upgrade - runs a complete system upgrade"
66 echo " srcuppretend - pretend dependencies for a system upgrade from source"
67 echo " srcupgrade - runs a complete system upgrade from source"
68 echo " pretend-build-prerequisites"
69 echo " install-build-prerequisites"
70 echo " search - searches mage-tree for a package"
71 echo " clean - removes *all* downloaded packages"
72 echo " unpack - unpacks *all* needed package for 'foo'"
73 echo " download - downloads *all* needed packages for 'foo'"
74 echo " print-features - prints all enabled mage-features"
75 echo " version - prints version info"
76 echo " regen-mage-tree - regenerates the whole mage database (for devs only)"
77 echo
78 echo "Other options:"
79 # echo "NOINSTALL=yes $(basename $0) srcinstall PACKAGE"
80 # echo "Builds a Package with its dependencies, but won't install anything."
81 # echo
82 echo "MAGE_DISTRIBUTION=unstable $(basename $0) [src]install PACKAGE"
83 echo "Overrides stable packages; you can install packages that are marked unstable."
84 echo
85 echo "MAGE_DISTRIBUTION=testing $(basename $0) [src]install PACKAGE"
86 echo "Overrides stable packages; you can install packages that are marked testing."
87 echo
88 echo "NOCOLORS=true $(basename $0) [src]install PACKAGE"
89 echo "Disables all colors in the messages."
90 echo
91 }
92
93
94 showversion
95 echo
96
97 # install method
98 METHOD="$1"
99
100 # initial unversionized packagename, gets overridden later on
101 MAGENAME="$2"
102
103 if [[ ${METHOD} != upgrade ]] &&
104 [[ ${METHOD} != srcupgrade ]] &&
105 [[ ${METHOD} != uppretend ]] &&
106 [[ ${METHOD} != srcuppretend ]] &&
107 [[ ${METHOD} != update ]] &&
108 [[ ${METHOD} != update-tarball ]] &&
109 [[ ${METHOD} != clean ]] &&
110 [[ ${METHOD} != version ]] &&
111 [[ ${METHOD} != search ]] &&
112 [[ ${METHOD} != regen-mage-tree ]] &&
113 [[ ${METHOD} != print-features ]]
114 then
115 [[ -z ${METHOD} ]] || [[ -z ${MAGENAME} ]] && print_usage && exit 1
116 fi
117
118 # set PKGDIR and BUILDDIR to MROOT
119 if [[ -n ${MROOT} ]]
120 then
121 PKGDIR=${MROOT}/${PKGDIR}
122 BUILDDIR=${MROOT}/${BUILDDIR}
123 fi
124
125 # before anything run mage_setup
126 mage_setup || die "error in mage_setup()"
127
128 # load supported mage features
129 load_mage_features
130
131 case ${METHOD} in
132 download)
133 # first of all get the right pkg which going to be installed
134 PCAT="$(pname2pcat ${MAGENAME})"
135
136 # package does not exists
137 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
138
139 # source the highest magefile of this pkg
140 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
141
142 # package is masked
143 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
144
145 # convert PKGNAME to PNAME/PVER/PBUILD
146 # we're working *only* with these three vars from here on
147 PNAME="$(pkgname2pname ${PKGNAME})"
148 PVER="$(pkgname2pver ${PKGNAME})"
149 PBUILD="$(pkgname2pbuild ${PKGNAME})"
150
151 # get all dependencies of this package
152 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
153 --method install \
154 --pcat ${PCAT} \
155 --pname ${PNAME} \
156 --pver ${PVER} \
157 --pbuild ${PBUILD})"
158 fetch_packages ${ALLDEPS} || die "fetching packages"
159 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
160 ;;
161
162 srcdownload)
163 # first of all get the right pkg which going to be installed
164 PCAT="$(pname2pcat ${MAGENAME})"
165
166 # package does not exists
167 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
168
169 # source the highest magefile of this pkg
170 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
171
172 # package is masked
173 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
174
175 # convert PKGNAME to PNAME/PVER/PBUILD
176 # we're working *only* with these three vars from here on
177 PNAME="$(pkgname2pname ${PKGNAME})"
178 PVER="$(pkgname2pver ${PKGNAME})"
179 PBUILD="$(pkgname2pbuild ${PKGNAME})"
180
181 # get all dependencies of this package
182 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
183 --method srcinstall \
184 --pcat ${PCAT} \
185 --pname ${PNAME} \
186 --pver ${PVER} \
187 --pbuild ${PBUILD})"
188 fetch_packages ${ALLDEPS} || die "fetching packages"
189 ;;
190
191 pretend|srcpretend|pretend-build-prerequisites)
192 # first of all get the right pkg which going to be installed
193 PCAT="$(pname2pcat ${MAGENAME})"
194
195 # package does not exists
196 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
197
198 # source the highest magefile of this pkg
199 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
200
201 # package is masked
202 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
203
204 # convert PKGNAME to PNAME/PVER/PBUILD
205 # we're working *only* with these three vars from here on
206 PNAME="$(pkgname2pname ${PKGNAME})"
207 PVER="$(pkgname2pver ${PKGNAME})"
208 PBUILD="$(pkgname2pbuild ${PKGNAME})"
209
210 # abort if already installed
211 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
212 then
213 echo -en "Package "
214 echo -en "${COLRED}${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
215 echo -e " already installed."
216 exit 3
217 fi
218 # get all dependencies of this package
219 ${MLIBDIR}/depwalker.sh \
220 --method ${METHOD} \
221 --pcat ${PCAT} \
222 --pname ${PNAME} \
223 --pver ${PVER} \
224 --pbuild ${PBUILD}
225 ;;
226
227 install|install-build-prerequisites)
228 have_root_privileges || die "You must be root to run this operation."
229
230 # first of all get the right pkg which going to be installed
231 PCAT="$(pname2pcat ${MAGENAME})"
232
233 # package does not exists
234 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
235
236 # source the highest magefile of this pkg
237 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
238
239 # package is masked
240 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
241
242 # convert PKGNAME to PNAME/PVER/PBUILD
243 # we're working *only* with these three vars from here on
244 PNAME="$(pkgname2pname ${PKGNAME})"
245 PVER="$(pkgname2pver ${PKGNAME})"
246 PBUILD="$(pkgname2pbuild ${PKGNAME})"
247
248 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
249 then
250 echo -en "Package "
251 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
252 echo -e " already installed."
253 exit 3
254 fi
255
256 # get all dependencies of this package
257 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
258 --method ${METHOD} \
259 --pcat ${PCAT} \
260 --pname ${PNAME} \
261 --pver ${PVER} \
262 --pbuild ${PBUILD})"
263
264 # first fetch all packages
265 fetch_packages ${ALLDEPS} || die "fetching packages"
266 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
267 install_packages ${ALLDEPS} || die "installing packages"
268 ;;
269
270 srcinstall)
271 have_root_privileges || die "You must be root to run this operation."
272
273 # first of all get the right pkg which going to be installed
274 PCAT="$(pname2pcat ${MAGENAME})"
275
276 # package does not exists
277 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
278
279 # source the highest magefile of this pkg
280 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
281
282 # package is masked
283 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
284
285 # convert PKGNAME to PNAME/PVER/PBUILD
286 # we're working *only* with these three vars from here on
287 PNAME="$(pkgname2pname ${PKGNAME})"
288 PVER="$(pkgname2pver ${PKGNAME})"
289 PBUILD="$(pkgname2pbuild ${PKGNAME})"
290
291 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
292 then
293 echo -en "Package "
294 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
295 echo -e " already installed."
296 exit 3
297 fi
298
299 # get all dependencies of this package
300 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
301 --method ${METHOD} \
302 --pcat ${PCAT} \
303 --pname ${PNAME} \
304 --pver ${PVER} \
305 --pbuild ${PBUILD})"
306
307 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
308 ;;
309
310 uninstall)
311 have_root_privileges || die "You must be root to run this operation."
312
313 ALLDEPS="$(get_uninstall_candidates --pname ${MAGENAME})"
314 if [ -z "${ALLDEPS}" ]
315 then
316 die "No package installed named '${MAGENAME}'."
317 fi
318 uninstall_packages ${ALLDEPS}
319 ;;
320
321 uppretend|srcuppretend)
322 ${MLIBDIR}/depwalker.sh \
323 --method ${METHOD} \
324 --pcat ${METHOD} \
325 --pname ${METHOD} \
326 --pver ${METHOD} \
327 --pbuild ${METHOD}
328 ;;
329
330 upgrade)
331 have_root_privileges || die "You must be root to run this operation."
332
333 # get all dependencies of *all* installed packages
334 # fake pcat,pname,pver,pbuild ...
335 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
336 --method ${METHOD} \
337 --pcat ${METHOD} \
338 --pname ${METHOD} \
339 --pver ${METHOD} \
340 --pbuild ${METHOD})"
341
342 # first fetch all packages
343 fetch_packages ${ALLDEPS} || die "fetching packages"
344 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
345 install_packages ${ALLDEPS} || die "installing packages"
346 ;;
347
348 srcupgrade)
349 have_root_privileges || die "You must be root to run this operation."
350
351 # get all dependencies of *all* installed packages
352 # fake pcat,pname,pver,pbuild ...
353 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
354 --method ${METHOD} \
355 --pcat ${METHOD} \
356 --pname ${METHOD} \
357 --pver ${METHOD} \
358 --pbuild ${METHOD})"
359
360 install_packages --src-install ${ALLDEPS} || die "src-installing packages"
361 ;;
362
363 search)
364 pkgsearch "${MAGENAME}"
365 ;;
366
367 unpack)
368 have_root_privileges || die "You must be root to run this operation."
369
370 # first of all get the right pkg which going to be installed
371 PCAT="$(pname2pcat ${MAGENAME})"
372
373 # package does not exists
374 [ -z "${PCAT}" ] && die "Package '${MAGENAME}' does not exist."
375
376 # source the highest magefile of this pkg
377 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${MAGENAME}))
378
379 # package is masked
380 [ -z "${PKGNAME}" ] && die "Package '${MAGENAME}' is masked and not available for installation."
381
382 # convert PKGNAME to PNAME/PVER/PBUILD
383 # we're working *only* with these three vars from here on
384 PNAME="$(pkgname2pname ${PKGNAME})"
385 PVER="$(pkgname2pver ${PKGNAME})"
386 PBUILD="$(pkgname2pbuild ${PKGNAME})"
387
388 # get all dependencies of this package
389 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
390 --method install \
391 --pcat ${PCAT} \
392 --pname ${PNAME} \
393 --pver ${PVER} \
394 --pbuild ${PBUILD})"
395 fetch_packages ${ALLDEPS} || die "fetching packages"
396 md5sum_packages ${ALLDEPS} || die "md5 sum packages"
397 unpack_packages ${ALLDEPS} || die "unpacking packages"
398 ;;
399
400 update)
401 have_root_privileges || die "You must be root to run this operation."
402 syncmage
403 ;;
404
405 update-tarball)
406 have_root_privileges || die "You must be root to run this operation."
407 syncmage_tarball
408 ;;
409
410 clean)
411 have_root_privileges || die "You must be root to run this operation."
412 cleanpkg
413 ;;
414
415 version)
416 # showversion
417 exit 0
418 ;;
419
420 regen-mage-tree)
421 have_root_privileges || die "You must be root to run this operation."
422
423 if [ -z "${SMAGESCRIPTSDIR}" ] || [ ! -d "${SMAGESCRIPTSDIR}" ]
424 then
425 echo "SMAGESCRIPTSDIR not found. Check your mage.rc or check out smage repos."
426 exit 1
427 fi
428 for i in $(find ${SMAGESCRIPTSDIR} -type f -name "*.smage2")
429 do
430 smage2 only-regen-tree "${i}"
431 done
432 ;;
433
434 print-features)
435 mprintfeatures
436 ;;
437
438 *)
439 print_usage
440 ;;
441 esac

Properties

Name Value
svn:executable *