Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 305 - (show annotations) (download) (as text)
Mon Dec 26 23:13:42 2005 UTC (18 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 11579 byte(s)
fixed mage setup; some dir get not correctly installed if MROOTwas set; mage_setup was called too early

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

Properties

Name Value
svn:executable *