Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 739 - (show annotations) (download) (as text)
Mon Jun 16 09:29:57 2008 UTC (15 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 12546 byte(s)
-added mage update-tarball function

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

Properties

Name Value
svn:executable *