Magellan Linux

Contents of /trunk/mlivecdbuild/files/mage3.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (show annotations) (download) (as text)
Wed Jan 5 05:36:10 2005 UTC (19 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 7942 byte(s)
mlivecdbuild-0.3.6-r7 import

1 #!/bin/bash
2 # Magellan Linux Installer Functions (mage.functions.sh)
3 # version: 0.3.1
4
5 mage_setup() {
6 install -d $INSTALLDB
7 }
8
9 fatal_error() {
10 #$1 is the missing file
11 echo -e "\nFatal Error: Package seemed to be corrupt."
12 echo -e "$1 was not found in ${PKGNAME}"
13 exit 1
14 }
15
16 build_unpackpkg() {
17 tar xjmf ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} -C ${BUILDDIR}
18 }
19
20 build_doinstall() {
21 if [ -e ${BUILDDIR}/${PKGNAME}/.dirs ]
22 then
23 # install of dirs
24 while read pathto posix
25 do
26 if [ ! -z $pathto ]
27 then
28 if [ "$VERBOSE" == "on" ]
29 then
30 echo -e "\t>>> DIR: $pathto"
31 fi
32 install -m $posix -d $pathto
33 fi
34 done << EOF
35 $(cat ${BUILDDIR}/${PKGNAME}/.dirs)
36 EOF
37 else
38 fatal_error .dir
39 fi
40
41
42 # install of files
43 if [ -e ${BUILDDIR}/${PKGNAME}/.files ]
44 then
45 while read pathto posix user group
46 do
47 if [ ! -z $pathto ]
48 then
49 if [ "$VERBOSE" == "on" ]
50 then
51 echo -e "\t>>> FILE: $pathto"
52 fi
53 ### kleiner notfall fix ###
54 if [ ! -d `dirname $pathto` ]
55 then
56 install -d `dirname $pathto`
57 fi
58 FILE="$pathto"
59 install -m $posix ${BUILDDIR}/${PKGNAME}/binfiles/$FILE $pathto
60 if [ ! -z $user ]
61 then
62 chown $user:$group $FILE ### <---- test
63 fi
64 fi
65 done << EOF
66 $(cat ${BUILDDIR}/${PKGNAME}/.files)
67 EOF
68 else
69 fatal_error .files
70 fi
71
72 # install of symlinks
73 if [ -e ${BUILDDIR}/${PKGNAME}/.symlinks ]
74 then
75 while read pathto posix link
76 do
77 if [ ! -z $pathto ]
78 then
79 if [ "$VERBOSE" == "on" ]
80 then
81 echo -e "\t>>> LINK: $pathto"
82 fi
83 ln -snf $link $pathto
84 fi
85 done << EOF
86 $(cat ${BUILDDIR}/${PKGNAME}/.symlinks)
87 EOF
88 else
89 fatal_error .symlinks
90 fi
91
92
93 if [ -e ${BUILDDIR}/${PKGNAME}/.pipes ]
94 then
95 # install of pipes
96 while read pathto posix
97 do
98 if [ ! -z $pathto ]
99 then
100 if [ "$VERBOSE" == "on" ]
101 then
102 echo -e "\t>>> PIPE: $pathto"
103 fi
104 mkfifo -m $posix $pathto
105 fi
106 done << EOF
107 $(cat ${BUILDDIR}/${PKGNAME}/.pipes)
108 EOF
109 else
110 fatal_error .pipes
111 fi
112
113
114 if [ -e ${BUILDDIR}/${PKGNAME}/.char ]
115 then
116 # install of character devices
117 while read pathto posix
118 do
119 if [ ! -z $pathto ]
120 then
121 if [ "$VERBOSE" == "on" ]
122 then
123 echo -e "\t>>> CHAR: $pathto"
124 fi
125 mknode -m $posix -c $pathto
126 fi
127 done << EOF
128 $(cat ${BUILDDIR}/${PKGNAME}/.char)
129 EOF
130 else
131 fatal_error .char
132 fi
133
134 #add package to database
135 install -d ${INSTALLDB}/${PKGNAME}
136 cp ${BUILDDIR}/${PKGNAME}/.{char,dirs,files,pipes,symlinks} ${INSTALLDB}/${PKGNAME}
137
138 #installs mage file to database
139 #install -m 0644 -o root -g root \
140 # ${MAGEDIR}/${MAGENAME} \
141 # ${INSTALLDB}/${PKGNAME}
142 install -m 0644 -o root -g root \
143 ${MAGEFILE} \
144 ${INSTALLDB}/${PKGNAME}
145
146 if [ "$VERBOSE" == "off" ]
147 then
148 if [ -f /var/tmp/proz ]
149 then
150 rm /var/tmp/proz
151 fi
152 fi
153 }
154
155
156
157 build_douninstall() {
158 #uninstall of symlinks
159 if [ -e ${INSTALLDB}/${PKGNAME}/.symlinks ]
160 then
161 while read pathto posix link
162 do
163 if [ ! -z $pathto ]
164 then
165 if [ -L $pathto ]
166 then
167 echo -e "\t<<< LINK: $pathto"
168 rm $pathto
169 else
170 echo -e "${COLRED}! exist${COLDEFAULT} <<< LINK: $pathto"
171 fi
172 fi
173 done << EOF
174 $(cat ${INSTALLDB}/${PKGNAME}/.symlinks)
175 EOF
176 else
177 fatal_error .symlinks
178 fi
179
180 #uninstall of files
181 if [ -e ${INSTALLDB}/${PKGNAME}/.files ]
182 then
183 while read pathto posix user group
184 do
185 if [ ! -z $pathto ]
186 then
187 if [ -e $pathto ]
188 then
189 echo -e "\t<<< FILE: $pathto"
190 rm $pathto
191 else
192 echo -e "${COLRED}! exist${COLDEFAULT} <<< FILE: $pathto"
193 fi
194 fi
195 done << EOF
196 $(cat ${INSTALLDB}/${PKGNAME}/.files)
197 EOF
198 else
199 fatal_error .files
200 fi
201
202
203 if [ -e ${INSTALLDB}/${PKGNAME}/.pipes ]
204 then
205 while read pathto posix
206 do
207 if [ ! -z $pathto ]
208 then
209 echo -e "\t<<< PIPE: $pathto"
210 rm $pathto
211 fi
212 done << EOF
213 $(cat ${INSTALLDB}/${PKGNAME}/.pipes)
214 EOF
215 else
216 fatal_error .pipes
217 fi
218
219 if [ -e ${INSTALLDB}/${PKGNAME}/.char ]
220 then
221 while read pathto posix
222 do
223 if [ ! -z $pathto ]
224 then
225 echo -e "\t<<< CHAR: $pathto"
226 rm $pathto
227 fi
228 done << EOF
229 $(cat ${INSTALLDB}/${PKGNAME}/.char)
230 EOF
231 else
232 fatal_error .char
233 fi
234
235 #uninstall of dirs ## added small hack to fix dirs
236 # must be reverse -> smage2 doesn't sort them
237 if [ -e ${INSTALLDB}/${PKGNAME}/.dirs ]
238 then
239 while read pathto posix
240 do
241 if [ ! -z $pathto ]
242 then
243 if [ -e $pathto ]
244 then
245 echo -e "\t<<< DIR: $pathto"
246 rmdir $pathto &> /dev/null
247 if [ "$?" -ne "0" ]
248 then
249 #moves the cursor up
250 echo -en \\033[A
251 echo -e "${COLRED}! empty${COLDEFAULT} <<< DIR: $pathto"
252 fi
253 else
254 echo -e "${COLRED}! exist${COLDEFAULT} <<< DIR: $pathto"
255 fi
256 fi
257 done << EOF
258 $(cat ${INSTALLDB}/${PKGNAME}/.dirs|sort -r) ##<--- the hack
259 EOF
260 else
261 fatal_error .dirs
262 fi
263
264 #removes database entry
265 if [ -d ${INSTALLDB}/${PKGNAME} ]
266 then
267 rm -rf ${INSTALLDB}/${PKGNAME}
268 fi
269 }
270
271 getpackages() {
272 if [ -z "$MIRRORS" ]
273 then
274 echo "You have no mirrors defined. Please edit your /etc/mage.rc."
275 exit 1
276 fi
277
278 local i
279 for i in $MIRRORS
280 do
281 wget \
282 --passive-ftp \
283 --tries 3 \
284 --continue \
285 --progress bar \
286 --directory-prefix=${PKGDIR} \
287 ${i}/packages/${PKGNAME}.${PKGSUFFIX}
288 if [ "$?" == "0" ]
289 then
290 break
291 else
292 continue
293 fi
294 done
295 }
296
297 syncmage() {
298 if [ -z "$RSYNC" ]
299 then
300 echo "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."
301 exit 1
302 fi
303
304 local i
305 for i in $RSYNC
306 do
307 rsync \
308 --recursive \
309 --links \
310 --perms \
311 --times \
312 --devices \
313 --timeout=600 \
314 --verbose \
315 --compress \
316 --progress \
317 --stats \
318 --delete \
319 --delete-after \
320 $i $MAGEDIR
321 if [ "$?" == "0" ]
322 then
323 break
324 else
325 continue
326 fi
327 done
328 }
329
330 cleanpkg(){
331 if [ -d "$PKGDIR" ]
332 then
333 echo -n "Removing downloaded packages... "
334 rm -rf ${PKGDIR}/*
335 echo "done."
336 fi
337 }
338
339 ###################################################
340 # function keepfiles #
341 # keepfiles "$CATEGORIE/$PNAME" "$filename" #
342 # note wildchars allowed #
343 ###################################################
344 keepfiles() {
345 local name
346 local keep
347 name="`echo $1| cut -d '/' -f2`"
348 keep="$2"
349
350 DELPKG="`find ${INSTALLDB} -name ${name}*.mage`"
351 DELDIR="${INSTALLDB}/$(basename ${DELPKG} .mage)"
352 cp ${DELDIR}/.files ${DELDIR}/.files-orig
353 sed "s:${keep}::" \
354 ${DELDIR}/.files-orig > ${DELDIR}/.files
355 rm ${DELDIR}/.files-orig
356 }
357
358
359 ###################################################
360 # function injectpkg #
361 # injectpkg "$CATEGORIE/$PNAME" #
362 # note wildchars allowed #
363 ###################################################
364 injectpkg() {
365 local name
366 local categorie
367 local magename
368 name="`echo $1| cut -d '/' -f2`"
369 categorie="`echo $1| cut -d '/' -f1`"
370
371 INJPKG="`find ${MAGEDIR} -name ${name}-*.mage`"
372 for i in ${INJPKG}
373 do
374 magename="$(basename ${INJPKG} .mage)"
375 echo -e "Injecting fake package for ${COLBLUE}${categorie}${COLDEFAULT}/${COLGREEN}${magename}${COLDEFAULT}"
376 install -d ${INSTALLDB}/${magename}
377 touch ${INSTALLDB}/${magename}/{.injected,.files,.dirs,.symlinks,.pipes,.char}
378
379 #installs magefile
380 install -m 0644 -o root -g root \
381 ${MAGEDIR}/${categorie}/${magename}.mage \
382 ${INSTALLDB}/${magename}
383 done
384 }
385
386 ###################################################
387 # function reminjected #
388 # reminjected #
389 # note: removes all injected packages #
390 ###################################################
391 reminjected() {
392 DELINJ="`find ${INSTALLDB} -name .injected`"
393 for i in ${DELINJ}
394 do
395 magename=$(dirname ${i})
396 if [ -d "${magename}" ]
397 then
398 # small fix to protect the mage-db deleting itself, that is not so funny :)
399 if [ "${magename}" != "${INSTALLDB}" ]
400 then
401 echo -e "removing fake package ${COLRED}${magename#${INSTALLDB}/*}${COLDEFAULT}"
402 rm -rf ${magename}
403 fi
404 fi
405 done
406 }

Properties

Name Value
svn:executable *