Annotation of /trunk/mage/usr/lib/mage/mage4.functions.sh
Parent Directory | Revision Log
Revision 273 -
(hide annotations)
(download)
(as text)
Fri Oct 21 14:50:13 2005 UTC (18 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 59490 byte(s)
Fri Oct 21 14:50:13 2005 UTC (18 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 59490 byte(s)
fixed virtual_add and virtual_del calls with mutiple provides
1 | niro | 226 | #!/bin/bash |
2 | # Magellan Linux Installer Functions (mage.functions.sh) | ||
3 | niro | 273 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.8 2005-10-21 14:50:13 niro Exp $ |
4 | niro | 226 | |
5 | mage_setup() | ||
6 | { | ||
7 | [ ! -d ${MROOT}${INSTALLDB} ] && \ | ||
8 | install -d ${MROOT}${INSTALLDB} | ||
9 | [ ! -f ${MROOT}${VIRTUALDB_FILE} ] && \ | ||
10 | touch ${MROOT}${VIRTUALDB_FILE} | ||
11 | [ ! -d ${PKGDIR} ] && install -d ${PKGDIR} | ||
12 | [ ! -d ${BUILDDIR} ] && install -d ${BUILDDIR} | ||
13 | [ ! -d ${MAGEDIR} ] && install -d ${MAGEDIR} | ||
14 | |||
15 | return 0 | ||
16 | } | ||
17 | |||
18 | unpack_packages() | ||
19 | { | ||
20 | local list="$@" | ||
21 | local magefile | ||
22 | local pkg | ||
23 | local pkgtype | ||
24 | local count_current | ||
25 | local count_total | ||
26 | |||
27 | # get count of total packages | ||
28 | declare -i count_current=0 | ||
29 | declare -i count_total=0 | ||
30 | |||
31 | for i in ${list}; do (( count_total++ )); done | ||
32 | |||
33 | for magefile in ${list} | ||
34 | do | ||
35 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
36 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
37 | |||
38 | (( count_current++ )) | ||
39 | xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" | ||
40 | |||
41 | # abort on virtual pkg | ||
42 | if [[ ${pkgtype} = virtual ]] | ||
43 | then | ||
44 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
45 | echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
46 | continue | ||
47 | fi | ||
48 | |||
49 | # abort on sources pkg | ||
50 | if [[ ${pkgtype} = sources ]] | ||
51 | then | ||
52 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
53 | echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
54 | continue | ||
55 | fi | ||
56 | |||
57 | echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " | ||
58 | tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" | ||
59 | done | ||
60 | |||
61 | # add a crlf for a better view | ||
62 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
63 | } | ||
64 | |||
65 | |||
66 | # fix_mtime path/to/$mtime/reffile $pathto/file | ||
67 | # creates a given reference file and fixes given file | ||
68 | # returns new mtime | ||
69 | fix_mtime() | ||
70 | { | ||
71 | local reference="$1" | ||
72 | local pathto="$2" | ||
73 | local mtime | ||
74 | |||
75 | mtime=$(stat -c %Y "${reference}") | ||
76 | touch \ | ||
77 | --no-create \ | ||
78 | --time=mtime \ | ||
79 | --reference "${reference}" \ | ||
80 | "${pathto}" | ||
81 | |||
82 | echo "${mtime}" | ||
83 | } | ||
84 | |||
85 | # fix_descriptor pkgname/.dir "foo1" "foo2" | ||
86 | fix_descriptor() | ||
87 | { | ||
88 | local descriptor="$1" | ||
89 | local output | ||
90 | local i | ||
91 | shift | ||
92 | |||
93 | for i in $@ | ||
94 | do | ||
95 | if [[ -z ${output} ]] | ||
96 | then | ||
97 | output="${i}" | ||
98 | else | ||
99 | output="${output}§${i}" | ||
100 | fi | ||
101 | done | ||
102 | |||
103 | echo "${output}" >> ${BUILDDIR}/${descriptor}_fixed | ||
104 | } | ||
105 | |||
106 | ################################################### | ||
107 | # function install_direcories # | ||
108 | # install_direcories $PKGNAME # | ||
109 | ################################################### | ||
110 | install_directories() | ||
111 | { | ||
112 | local pkgname="$1" | ||
113 | local pathto | ||
114 | local posix | ||
115 | local user | ||
116 | local group | ||
117 | local IFS | ||
118 | |||
119 | # sanity checks; abort if not given | ||
120 | [ -z "${pkgname}" ] && die "install_directories() \$pkgname not given." | ||
121 | |||
122 | # check needed global vars | ||
123 | [ -z "${BUILDDIR}" ] && die "install_directories() \$BUILDDIR not set." | ||
124 | |||
125 | [ ! -f ${BUILDDIR}/${pkgname}/.dirs ] && die "install_directories() .dirs not found" | ||
126 | |||
127 | # sets fieldseperator to "§" instead of " " | ||
128 | IFS=§ | ||
129 | |||
130 | while read pathto posix user group | ||
131 | do | ||
132 | [ -z "${pathto}" ] && continue | ||
133 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" | ||
134 | |||
135 | |||
136 | # monitors /etc/env.d -> env-rebuild | ||
137 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true | ||
138 | |||
139 | # monitors /usr/share/info -> info-rebuild | ||
140 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true | ||
141 | |||
142 | install -m "${posix}" -o "${user}" -g "${group}" -d "${MROOT}${pathto}" | ||
143 | done < ${BUILDDIR}/${pkgname}/.dirs | ||
144 | |||
145 | # very important: unsetting the '§' fieldseperator | ||
146 | IFS=$'\n' | ||
147 | } | ||
148 | |||
149 | |||
150 | ################################################### | ||
151 | # function install_files # | ||
152 | # install_files $PKGNAME # | ||
153 | ################################################### | ||
154 | install_files() | ||
155 | { | ||
156 | |||
157 | local pkgname="$1" | ||
158 | local pathto | ||
159 | local posix | ||
160 | local user | ||
161 | local group | ||
162 | local mtime | ||
163 | local md5sum | ||
164 | |||
165 | local retval | ||
166 | local counter | ||
167 | local filename | ||
168 | local dest_dirname | ||
169 | local dest_protected | ||
170 | local IFS | ||
171 | |||
172 | # sanity checks; abort if not given | ||
173 | [ -z "${pkgname}" ] && die "install_files() \$pkgname not given." | ||
174 | |||
175 | # check needed global vars | ||
176 | [ -z "${BUILDDIR}" ] && die "install_files() \$BUILDDIR not set." | ||
177 | |||
178 | [ ! -f ${BUILDDIR}/${pkgname}/.files ] && die "install_files() .files not found" | ||
179 | |||
180 | # delete old files | ||
181 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && rm ${BUILDDIR}/${pkgname}/.files_fixed | ||
182 | |||
183 | # sets fieldseperator to "§" instead of " " | ||
184 | IFS=§ | ||
185 | |||
186 | while read pathto posix user group mtime md5sum | ||
187 | do | ||
188 | [ -z "${pathto}" ] && continue | ||
189 | |||
190 | # final destination dir of file ${pathto} | ||
191 | dest_dirname="$(dirname "${MROOT}${pathto}")" | ||
192 | |||
193 | ### small hotfix fix ### | ||
194 | [ ! -d "${dest_dirname}" ] && install -d "${dest_dirname}" | ||
195 | |||
196 | # check if the file is config_protected | ||
197 | # ${MROOT} will automatically added if set !! | ||
198 | is_config_protected "${pathto}" | ||
199 | retval="$?" | ||
200 | |||
201 | # 0 - not protected # | ||
202 | # 1 - error # | ||
203 | # 2 - protected # | ||
204 | # 3 - protected but masked # | ||
205 | |||
206 | case ${retval} in | ||
207 | # file is not protected - (over)write it | ||
208 | 0|3) | ||
209 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" | ||
210 | install -m "${posix}" -o "${user}" -g "${group}" \ | ||
211 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ | ||
212 | "${MROOT}${pathto}" | ||
213 | |||
214 | # fix mtime and db | ||
215 | fix_descriptor ${pkgname}/.files \ | ||
216 | "${pathto}" \ | ||
217 | "${posix}" \ | ||
218 | "${user}" \ | ||
219 | "${group}" \ | ||
220 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
221 | "${MROOT}${pathto}")" \ | ||
222 | "${md5sum}" | ||
223 | ;; | ||
224 | |||
225 | # file is protected, write backup file | ||
226 | 2) | ||
227 | if [[ ${VERBOSE} = on ]] | ||
228 | then | ||
229 | echo -en "${COLRED}" | ||
230 | echo -n "! prot " | ||
231 | echo -en "${COLDEFAULT}" | ||
232 | echo " === FILE: ${MROOT}${pathto}" | ||
233 | fi | ||
234 | filename="$(basename "${pathto}")" | ||
235 | counter=$(count_protected_files "${pathto}") | ||
236 | dest_protected="${dest_dirname}/._cfg${counter}_${filename}" | ||
237 | install -m "${posix}" -o "${user}" -g "${group}" \ | ||
238 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ | ||
239 | "${dest_protected}" | ||
240 | |||
241 | # fix mtime and db | ||
242 | fix_descriptor ${pkgname}/.files \ | ||
243 | "${pathto}" \ | ||
244 | "${posix}" \ | ||
245 | "${user}" \ | ||
246 | "${group}" \ | ||
247 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
248 | "${dest_protected}")" \ | ||
249 | "${md5sum}" | ||
250 | |||
251 | # update global MAGE_PROTECT_COUNTER | ||
252 | (( MAGE_PROTECT_COUNTER++ )) | ||
253 | export MAGE_PROTECT_COUNTER | ||
254 | ;; | ||
255 | esac | ||
256 | done < ${BUILDDIR}/${pkgname}/.files | ||
257 | |||
258 | # now copy the fixed file over the old one | ||
259 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && \ | ||
260 | cp ${BUILDDIR}/${pkgname}/.files{_fixed,} | ||
261 | |||
262 | # very important: unsetting the '§' fieldseperator | ||
263 | IFS=$'\n' | ||
264 | } | ||
265 | |||
266 | |||
267 | ################################################### | ||
268 | # function install_symlinks # | ||
269 | # install_symlinks $PKGNAME # | ||
270 | ################################################### | ||
271 | install_symlinks() | ||
272 | { | ||
273 | local pkgname="$1" | ||
274 | local pathto | ||
275 | local posix | ||
276 | local link | ||
277 | local mtime | ||
278 | local IFS | ||
279 | |||
280 | # sanity checks; abort if not given | ||
281 | [ -z "${pkgname}" ] && die "install_symlinks() \$pkgname not given." | ||
282 | |||
283 | # check needed global vars | ||
284 | [ -z "${BUILDDIR}" ] && die "install_symlinks() \$BUILDDIR not set." | ||
285 | |||
286 | [ ! -f ${BUILDDIR}/${pkgname}/.symlinks ] && die "install_symlinks() .symlinks not found" | ||
287 | |||
288 | # delete old files | ||
289 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && rm ${BUILDDIR}/${pkgname}/.symlinks_fixed | ||
290 | |||
291 | # sets fieldseperator to "§" instead of " " | ||
292 | IFS=§ | ||
293 | |||
294 | while read pathto posix link mtime | ||
295 | do | ||
296 | [ -z "${pathto}" ] && continue | ||
297 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" | ||
298 | |||
299 | ln -snf "${link}" "${MROOT}${pathto}" | ||
300 | |||
301 | # fix mtime and db | ||
302 | fix_descriptor ${pkgname}/.symlinks \ | ||
303 | "${pathto}" \ | ||
304 | "${posix}" \ | ||
305 | "${link}" \ | ||
306 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
307 | "${MROOT}${pathto}")" | ||
308 | |||
309 | done < ${BUILDDIR}/${pkgname}/.symlinks | ||
310 | |||
311 | # now copy the fixed file over the old one | ||
312 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ | ||
313 | cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} | ||
314 | |||
315 | # very important: unsetting the '§' fieldseperator | ||
316 | IFS=$'\n' | ||
317 | } | ||
318 | |||
319 | |||
320 | ################################################### | ||
321 | # function install_blockdevices # | ||
322 | # install_blockdevices $PKGNAME # | ||
323 | ################################################### | ||
324 | install_blockdevices() | ||
325 | { | ||
326 | local pkgname="$1" | ||
327 | local pathto | ||
328 | local posix | ||
329 | local IFS | ||
330 | |||
331 | # sanity checks; abort if not given | ||
332 | [ -z "${pkgname}" ] && die "install_blockdevices() \$pkgname not given." | ||
333 | |||
334 | # check needed global vars | ||
335 | [ -z "${BUILDDIR}" ] && die "install_blockdevices() \$BUILDDIR not set." | ||
336 | |||
337 | [ ! -f ${BUILDDIR}/${pkgname}/.pipes ] && die "install_blockdevices() .pipes not found" | ||
338 | |||
339 | # sets fieldseperator to "§" instead of " " | ||
340 | IFS=§ | ||
341 | |||
342 | while read pathto posix | ||
343 | do | ||
344 | [ -z "${pathto}" ] && continue | ||
345 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" | ||
346 | |||
347 | mkfifo -m "${posix}" "${MROOT}$pathto" | ||
348 | done < ${BUILDDIR}/${pkgname}/.pipes | ||
349 | |||
350 | # very important: unsetting the '§' fieldseperator | ||
351 | IFS=$'\n' | ||
352 | } | ||
353 | |||
354 | |||
355 | ################################################### | ||
356 | # function install_characterdevices # | ||
357 | # install_characterdevices $PKGNAME # | ||
358 | ################################################### | ||
359 | install_characterdevices() | ||
360 | { | ||
361 | local pkgname="$1" | ||
362 | local pathto | ||
363 | local posix | ||
364 | local IFS | ||
365 | |||
366 | # sanity checks; abort if not given | ||
367 | [ -z "${pkgname}" ] && die "install_characterdevices() \$pkgname not given." | ||
368 | |||
369 | # check needed global vars | ||
370 | [ -z "${BUILDDIR}" ] && die "install_characterdevices() \$BUILDDIR not set." | ||
371 | |||
372 | [ ! -f ${BUILDDIR}/${pkgname}/.char ] && die "install_characterdevices() .char not found" | ||
373 | |||
374 | # sets fieldseperator to "§" instead of " " | ||
375 | IFS=§ | ||
376 | |||
377 | while read pathto posix | ||
378 | do | ||
379 | [ -z "${pathto}" ] && continue | ||
380 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" | ||
381 | |||
382 | mknode -m ${posix} -c "${MROOT}${pathto}" | ||
383 | done < ${BUILDDIR}/${pkgname}/.char | ||
384 | |||
385 | # very important: unsetting the '§' fieldseperator | ||
386 | IFS=$'\n' | ||
387 | } | ||
388 | |||
389 | |||
390 | ################################################### | ||
391 | # function build_doinstall # | ||
392 | # build_doinstall $PKGNAME # | ||
393 | # NOTE: this is an wrapper do install packages # | ||
394 | ################################################### | ||
395 | build_doinstall() | ||
396 | { | ||
397 | local pkgname="$1" | ||
398 | |||
399 | # sanity checks; abort if not given | ||
400 | [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." | ||
401 | |||
402 | # this is only a wrapper | ||
403 | |||
404 | # NOTE: | ||
405 | # !! we use § as field seperator !! | ||
406 | # doing so prevent us to get errors by filenames with spaces | ||
407 | |||
408 | # create a new mtime reference file | ||
409 | touch ${BUILDDIR}/${pkgname}/.mtime | ||
410 | |||
411 | install_directories ${pkgname} || die "install directories ${pkgname}" | ||
412 | install_files ${pkgname} || die "install files ${pkgname}" | ||
413 | install_symlinks ${pkgname} || die "install symlinks ${pkgname}" | ||
414 | install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" | ||
415 | install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" | ||
416 | } | ||
417 | |||
418 | |||
419 | ################################################### | ||
420 | # function install_database_entry # | ||
421 | # install_database_entry $PKGNAME $PKGTYPE # | ||
422 | # PKGTYPE can be "virtual", "sources" or nothing # | ||
423 | ################################################### | ||
424 | install_database_entry() | ||
425 | { | ||
426 | local pcat | ||
427 | local pname | ||
428 | local pver | ||
429 | local pbuild | ||
430 | local pkgtype | ||
431 | local pkgname | ||
432 | local magefile | ||
433 | local dbrecorddir | ||
434 | local provide | ||
435 | niro | 273 | local i |
436 | niro | 226 | |
437 | # very basic getops | ||
438 | for i in $* | ||
439 | do | ||
440 | case $1 in | ||
441 | --pcat|-c) shift; pcat="$1" ;; | ||
442 | --pname|-n) shift; pname="$1" ;; | ||
443 | --pver|-v) shift; pver="$1" ;; | ||
444 | --pbuild|-b) shift; pbuild="$1" ;; | ||
445 | --pkgname|-a) shift; pkgname="$1" ;; | ||
446 | --pkgtype|-t) shift; pkgtype="$1" ;; | ||
447 | esac | ||
448 | shift | ||
449 | done | ||
450 | |||
451 | # sanity checks; abort if not given | ||
452 | [ -z "${pcat}" ] && die "install_database_entry() \$pcat not given." | ||
453 | [ -z "${pname}" ] && die "install_database_entry() \$pname not given." | ||
454 | [ -z "${pver}" ] && die "install_database_entry() \$pver not given." | ||
455 | [ -z "${pbuild}" ] && die "install_database_entry() \$pbuild not given." | ||
456 | [ -z "${pkgname}" ] && die "install_database_entry() \$pkgname not given." | ||
457 | |||
458 | # check needed global vars | ||
459 | [ -z "${MAGEDIR}" ] && die "install_database_entry() \$MAGEDIR not set." | ||
460 | [ -z "${INSTALLDB}" ] && die "install_database_entry() \$INSTALLDB not set." | ||
461 | |||
462 | # set needed vars | ||
463 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" | ||
464 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" | ||
465 | |||
466 | # abort if mage file not exists | ||
467 | [ ! -f ${magefile} ] && die "install_database_entry() ${magefile} not exist." | ||
468 | |||
469 | # add package to database | ||
470 | install -d ${dbrecorddir} | ||
471 | |||
472 | # install mage-file to database | ||
473 | install -m 0644 -o root -g root ${magefile} ${dbrecorddir} | ||
474 | |||
475 | # create fake file descriptors | ||
476 | # used by virtual and source packages | ||
477 | for i in .dirs .symlinks .files .pipes .char | ||
478 | do | ||
479 | touch ${dbrecorddir}/${i} | ||
480 | done | ||
481 | |||
482 | # put the category to database | ||
483 | echo ${pcat} > ${dbrecorddir}/.categorie | ||
484 | |||
485 | # now install PKGTYPE specific files | ||
486 | case ${pkgtype} in | ||
487 | virtual) touch ${dbrecorddir}/.virtual ;; | ||
488 | sources) touch ${dbrecorddir}/.sources ;; | ||
489 | *) | ||
490 | # !move! .mtime to database (only mv modifies not the mtime!!) | ||
491 | mv ${BUILDDIR}/${pkgname}/.mtime ${dbrecorddir}/.mtime | ||
492 | |||
493 | # normal packages needs these files | ||
494 | local i | ||
495 | for i in .char .dirs .files .pipes .symlinks | ||
496 | do | ||
497 | install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ | ||
498 | ${dbrecorddir}/${i} | ||
499 | done | ||
500 | ;; | ||
501 | esac | ||
502 | |||
503 | # last but not least register virtuals | ||
504 | provide="$(get_value_from_magefile PROVIDE ${magefile})" | ||
505 | if [ -n "${provide}" ] | ||
506 | then | ||
507 | niro | 273 | for i in ${provide} |
508 | do | ||
509 | virtuals_add "${i}" "${pcat}/${pname}" | ||
510 | done | ||
511 | niro | 226 | fi |
512 | } | ||
513 | |||
514 | |||
515 | ################################################### | ||
516 | # function remove_database_entry # | ||
517 | # remove_database_entry $PKGNAME $PKGTYPE # | ||
518 | # PKGTYPE can be "virtual", "sources" or nothing # | ||
519 | ################################################### | ||
520 | remove_database_entry() | ||
521 | { | ||
522 | local pcat | ||
523 | local pname | ||
524 | local pver | ||
525 | local pbuild | ||
526 | local magefile | ||
527 | local dbrecorddir | ||
528 | local provide | ||
529 | niro | 273 | local i |
530 | niro | 226 | |
531 | # very basic getops | ||
532 | for i in $* | ||
533 | do | ||
534 | case $1 in | ||
535 | --pcat|-c) shift; pcat="$1" ;; | ||
536 | --pname|-n) shift; pname="$1" ;; | ||
537 | --pver|-v) shift; pver="$1" ;; | ||
538 | --pbuild|-b) shift; pbuild="$1" ;; | ||
539 | esac | ||
540 | shift | ||
541 | done | ||
542 | |||
543 | # sanity checks; abort if not given | ||
544 | [ -z "${pcat}" ] && die "remove_database_entry() \$pcat not given." | ||
545 | [ -z "${pname}" ] && die "remove_database_entry() \$pname not given." | ||
546 | [ -z "${pver}" ] && die "remove_database_entry() \$pver not given." | ||
547 | [ -z "${pbuild}" ] && die "remove_database_entry() \$pbuild not given." | ||
548 | |||
549 | # check needed global vars | ||
550 | [ -z "${INSTALLDB}" ] && die "remove_database_entry() \$INSTALLDB not set." | ||
551 | |||
552 | # set needed vars | ||
553 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" | ||
554 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" | ||
555 | |||
556 | # abort if mage file not exists | ||
557 | [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." | ||
558 | |||
559 | # first unregister virtuals | ||
560 | provide="$(get_value_from_magefile PROVIDE ${magefile})" | ||
561 | if [ -n "${provide}" ] | ||
562 | then | ||
563 | niro | 273 | for i in ${provide} |
564 | do | ||
565 | virtuals_del "${i}" "${pcat}/${pname}" | ||
566 | done | ||
567 | niro | 226 | fi |
568 | |||
569 | # removes database entry | ||
570 | if [ -d ${dbrecorddir} ] | ||
571 | then | ||
572 | rm -rf ${dbrecorddir} | ||
573 | fi | ||
574 | } | ||
575 | |||
576 | |||
577 | ################################################### | ||
578 | # function compare_mtime # | ||
579 | # compare_mtime $pcat/$PKGNAME /path/to/file # | ||
580 | # # | ||
581 | # returns: # | ||
582 | # 0=delete me # | ||
583 | # 1=keep me # | ||
584 | # # | ||
585 | # compares mtime of given files in packages # | ||
586 | ################################################### | ||
587 | compare_mtime() | ||
588 | { | ||
589 | local pfull="$1" | ||
590 | local pathto="$2" | ||
591 | local mtime | ||
592 | local pcat | ||
593 | local x | ||
594 | |||
595 | mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" | ||
596 | |||
597 | # if $pathto is a symlink than compare linked binary | ||
598 | if [ -L "${MROOT}${pathto}" ] | ||
599 | then | ||
600 | # readlink -f resolves full path of linked file | ||
601 | x="$(readlink -f "${MROOT}${pathto}")" | ||
602 | |||
603 | # abort if target does not exists | ||
604 | # we keep safe here, theoretically the link can removed | ||
605 | [ ! -e "${x}" ] && return 1 | ||
606 | |||
607 | x=$(stat -c %Y "${x}") | ||
608 | else | ||
609 | x=$(stat -c %Y "${MROOT}${pathto}") | ||
610 | fi | ||
611 | |||
612 | [[ ${mtime} = ${x} ]] && return 0 | ||
613 | |||
614 | # echo "keep me : ${pathto}" | ||
615 | return 1 | ||
616 | } | ||
617 | |||
618 | |||
619 | ################################################### | ||
620 | # function remove_symlinks # | ||
621 | # remove_symlinks $PKGNAME # | ||
622 | ################################################### | ||
623 | remove_symlinks() | ||
624 | { | ||
625 | local pathto | ||
626 | local posix | ||
627 | local link | ||
628 | local mtime | ||
629 | local IFS | ||
630 | local retval | ||
631 | local pcat | ||
632 | local pname | ||
633 | local pver | ||
634 | local pbuild | ||
635 | local i | ||
636 | local pfull | ||
637 | |||
638 | IFS=$'\n' | ||
639 | |||
640 | # very basic getops | ||
641 | for i in $* | ||
642 | do | ||
643 | case $1 in | ||
644 | --pcat|-c) shift; pcat="$1" ;; | ||
645 | --pname|-n) shift; pname="$1" ;; | ||
646 | --pver|-v) shift; pver="$1" ;; | ||
647 | --pbuild|-b) shift; pbuild="$1" ;; | ||
648 | esac | ||
649 | shift | ||
650 | done | ||
651 | |||
652 | # sanity checks; abort if not given | ||
653 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
654 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
655 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
656 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
657 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
658 | |||
659 | # check needed global vars | ||
660 | [ -z "${BUILDDIR}" ] && die "remove_symlinks() \$BUILDDIR not set." | ||
661 | |||
662 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.symlinks ] && die "remove_symlinks() .symlinks not found" | ||
663 | |||
664 | # sets fieldseperator to "§" instead of " " | ||
665 | IFS=§ | ||
666 | |||
667 | while read pathto posix link mtime | ||
668 | do | ||
669 | [ -z "${pathto}" ] && continue | ||
670 | if [ ! -L "${MROOT}${pathto}" ] | ||
671 | then | ||
672 | [[ ${VERBOSE} = on ]] && \ | ||
673 | echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" | ||
674 | continue | ||
675 | fi | ||
676 | |||
677 | # *no* ${MROOT}, will be set internal | ||
678 | compare_mtime "${pfull}" "${pathto}" | ||
679 | retval=$? | ||
680 | # 0=delete me # | ||
681 | # 1=keep me # | ||
682 | case ${retval} in | ||
683 | 0) | ||
684 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" | ||
685 | rm "${MROOT}${pathto}" | ||
686 | ;; | ||
687 | |||
688 | 1) | ||
689 | [[ ${VERBOSE} = on ]] && \ | ||
690 | echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" | ||
691 | ;; | ||
692 | esac | ||
693 | done < ${MROOT}${INSTALLDB}/${pfull}/.symlinks | ||
694 | |||
695 | # very important: unsetting the '§' fieldseperator | ||
696 | IFS=$'\n' | ||
697 | } | ||
698 | |||
699 | |||
700 | ################################################### | ||
701 | # function remove_files # | ||
702 | # remove_files $PKGNAME # | ||
703 | ################################################### | ||
704 | remove_files() | ||
705 | { | ||
706 | local pathto | ||
707 | local posix | ||
708 | local user | ||
709 | local group | ||
710 | local mtime | ||
711 | local md5sum | ||
712 | local IFS | ||
713 | local retval | ||
714 | local pcat | ||
715 | local pname | ||
716 | local pver | ||
717 | local pbuild | ||
718 | local i | ||
719 | local pfull | ||
720 | |||
721 | IFS=$'\n' | ||
722 | |||
723 | # very basic getops | ||
724 | for i in $* | ||
725 | do | ||
726 | case $1 in | ||
727 | --pcat|-c) shift; pcat="$1" ;; | ||
728 | --pname|-n) shift; pname="$1" ;; | ||
729 | --pver|-v) shift; pver="$1" ;; | ||
730 | --pbuild|-b) shift; pbuild="$1" ;; | ||
731 | esac | ||
732 | shift | ||
733 | done | ||
734 | |||
735 | # sanity checks; abort if not given | ||
736 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
737 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
738 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
739 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
740 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
741 | |||
742 | # check needed global vars | ||
743 | [ -z "${BUILDDIR}" ] && die "remove_files() \$BUILDDIR not set." | ||
744 | |||
745 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.files ] && die "remove_files() .files not found" | ||
746 | |||
747 | # sets fieldseperator to "§" instead of " " | ||
748 | IFS=§ | ||
749 | |||
750 | while read pathto posix user group mtime md5sum | ||
751 | do | ||
752 | [ -z "${pathto}" ] && continue | ||
753 | |||
754 | niro | 240 | if [ ! -e "${MROOT}${pathto}" ] |
755 | niro | 226 | then |
756 | [[ ${VERBOSE} = on ]] && \ | ||
757 | echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" | ||
758 | continue | ||
759 | fi | ||
760 | |||
761 | # *no* ${MROOT}, will be set internal | ||
762 | compare_mtime "${pfull}" "${pathto}" | ||
763 | retval=$? | ||
764 | # 0=delete me # | ||
765 | # 1=keep me # | ||
766 | case ${retval} in | ||
767 | 0) | ||
768 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" | ||
769 | rm "${MROOT}${pathto}" | ||
770 | ;; | ||
771 | |||
772 | 1) | ||
773 | [[ ${VERBOSE} = on ]] && \ | ||
774 | echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" | ||
775 | ;; | ||
776 | esac | ||
777 | done < ${MROOT}${INSTALLDB}/${pfull}/.files | ||
778 | |||
779 | # very important: unsetting the '§' fieldseperator | ||
780 | IFS=$'\n' | ||
781 | } | ||
782 | |||
783 | |||
784 | ################################################### | ||
785 | # function remove_blockdevices # | ||
786 | # remove_blockdevices $PKGNAME # | ||
787 | ################################################### | ||
788 | remove_blockdevices() | ||
789 | { | ||
790 | local pathto | ||
791 | local posix | ||
792 | local IFS | ||
793 | local pcat | ||
794 | local pname | ||
795 | local pver | ||
796 | local pbuild | ||
797 | local i | ||
798 | local pfull | ||
799 | |||
800 | IFS=$'\n' | ||
801 | |||
802 | # very basic getops | ||
803 | for i in $* | ||
804 | do | ||
805 | case $1 in | ||
806 | --pcat|-c) shift; pcat="$1" ;; | ||
807 | --pname|-n) shift; pname="$1" ;; | ||
808 | --pver|-v) shift; pver="$1" ;; | ||
809 | --pbuild|-b) shift; pbuild="$1" ;; | ||
810 | esac | ||
811 | shift | ||
812 | done | ||
813 | |||
814 | # sanity checks; abort if not given | ||
815 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
816 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
817 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
818 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
819 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
820 | |||
821 | # check needed global vars | ||
822 | [ -z "${BUILDDIR}" ] && die "remove_blockdevices() \$BUILDDIR not set." | ||
823 | |||
824 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.pipes ] && die "remove_blockdevices() .pipes not found" | ||
825 | |||
826 | # sets fieldseperator to "§" instead of " " | ||
827 | IFS=§ | ||
828 | |||
829 | while read pathto posix | ||
830 | do | ||
831 | [ -z "${pathto}" ] && continue | ||
832 | |||
833 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" | ||
834 | rm "${MROOT}${pathto}" | ||
835 | done < ${MROOT}${INSTALLDB}/${pfull}/.pipes | ||
836 | |||
837 | # very important: unsetting the '§' fieldseperator | ||
838 | IFS=$'\n' | ||
839 | } | ||
840 | |||
841 | |||
842 | ################################################### | ||
843 | # function remove_characterdevices # | ||
844 | # remove_characterdevices $PKGNAME # | ||
845 | ################################################### | ||
846 | remove_characterdevices() | ||
847 | { | ||
848 | local pathto | ||
849 | local posix | ||
850 | local IFS | ||
851 | local pcat | ||
852 | local pname | ||
853 | local pver | ||
854 | local pbuild | ||
855 | local i | ||
856 | local pfull | ||
857 | |||
858 | IFS=$'\n' | ||
859 | |||
860 | # very basic getops | ||
861 | for i in $* | ||
862 | do | ||
863 | case $1 in | ||
864 | --pcat|-c) shift; pcat="$1" ;; | ||
865 | --pname|-n) shift; pname="$1" ;; | ||
866 | --pver|-v) shift; pver="$1" ;; | ||
867 | --pbuild|-b) shift; pbuild="$1" ;; | ||
868 | esac | ||
869 | shift | ||
870 | done | ||
871 | |||
872 | # sanity checks; abort if not given | ||
873 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
874 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
875 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
876 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
877 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
878 | |||
879 | # check needed global vars | ||
880 | [ -z "${BUILDDIR}" ] && die "remove_characterdevices() \$BUILDDIR not set." | ||
881 | |||
882 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_characterdevices() .char not found" | ||
883 | |||
884 | # sets fieldseperator to "§" instead of " " | ||
885 | IFS=§ | ||
886 | |||
887 | while read pathto posix | ||
888 | do | ||
889 | [ -z "${pathto}" ] && continue | ||
890 | |||
891 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" | ||
892 | rm "${MROOT}${pathto}" | ||
893 | done < ${MROOT}${INSTALLDB}/${pfull}/.char | ||
894 | |||
895 | # very important: unsetting the '§' fieldseperator | ||
896 | IFS=$'\n' | ||
897 | } | ||
898 | |||
899 | |||
900 | ################################################### | ||
901 | # function remove_direcories # | ||
902 | # remove_direcories $PKGNAME # | ||
903 | ################################################### | ||
904 | remove_directories() | ||
905 | { | ||
906 | local pathto | ||
907 | local posix | ||
908 | local IFS | ||
909 | local pcat | ||
910 | local pname | ||
911 | local pver | ||
912 | local pbuild | ||
913 | local i | ||
914 | local pfull | ||
915 | |||
916 | IFS=$'\n' | ||
917 | |||
918 | # very basic getops | ||
919 | for i in $* | ||
920 | do | ||
921 | case $1 in | ||
922 | --pcat|-c) shift; pcat="$1" ;; | ||
923 | --pname|-n) shift; pname="$1" ;; | ||
924 | --pver|-v) shift; pver="$1" ;; | ||
925 | --pbuild|-b) shift; pbuild="$1" ;; | ||
926 | esac | ||
927 | shift | ||
928 | done | ||
929 | |||
930 | # sanity checks; abort if not given | ||
931 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
932 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
933 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
934 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
935 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
936 | |||
937 | # check needed global vars | ||
938 | [ -z "${BUILDDIR}" ] && die "remove_directories() \$BUILDDIR not set." | ||
939 | |||
940 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" | ||
941 | |||
942 | # sets fieldseperator to "§" instead of " " | ||
943 | IFS=§ | ||
944 | |||
945 | niro | 240 | # reversed order is mandatory ! |
946 | tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix | ||
947 | niro | 226 | do |
948 | [ -z "${pathto}" ] && continue | ||
949 | |||
950 | if [ ! -d "${MROOT}${pathto}" ] | ||
951 | then | ||
952 | [[ ${VERBOSE} = on ]] && \ | ||
953 | echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" | ||
954 | continue | ||
955 | fi | ||
956 | |||
957 | # exclude .keep directories | ||
958 | if [ -f "${MROOT}${pathto}/.keep" ] | ||
959 | then | ||
960 | [[ ${VERBOSE} = on ]] && \ | ||
961 | niro | 240 | echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
962 | niro | 226 | continue |
963 | fi | ||
964 | |||
965 | # monitors /etc/env.d -> env-rebuild | ||
966 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true | ||
967 | |||
968 | # monitors /usr/share/info -> info-rebuild | ||
969 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true | ||
970 | |||
971 | if rmdir "${MROOT}${pathto}" &> /dev/null | ||
972 | then | ||
973 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" | ||
974 | else | ||
975 | [[ ${VERBOSE} = on ]] && \ | ||
976 | echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" | ||
977 | fi | ||
978 | niro | 240 | done |
979 | niro | 226 | |
980 | # very important: unsetting the '§' fieldseperator | ||
981 | IFS=$'\n' | ||
982 | } | ||
983 | |||
984 | |||
985 | ################################################### | ||
986 | # function build_douninstall # | ||
987 | # build_douninstall $PKGNAME # | ||
988 | # NOTE: this is an wrapper do remove packages # | ||
989 | ################################################### | ||
990 | build_douninstall() | ||
991 | { | ||
992 | local pcat | ||
993 | local pname | ||
994 | local pver | ||
995 | local pbuild | ||
996 | local i | ||
997 | |||
998 | # very basic getops | ||
999 | for i in $* | ||
1000 | do | ||
1001 | case $1 in | ||
1002 | --pcat|-c) shift; pcat="$1" ;; | ||
1003 | --pname|-n) shift; pname="$1" ;; | ||
1004 | --pver|-v) shift; pver="$1" ;; | ||
1005 | --pbuild|-b) shift; pbuild="$1" ;; | ||
1006 | esac | ||
1007 | shift | ||
1008 | done | ||
1009 | |||
1010 | # sanity checks; abort if not given | ||
1011 | [ -z "${pcat}" ] && die "build_douninstall() \$pcat not given." | ||
1012 | [ -z "${pname}" ] && die "build_douninstall() \$pname not given." | ||
1013 | [ -z "${pver}" ] && die "build_douninstall() \$pver not given." | ||
1014 | [ -z "${pbuild}" ] && die "build_douninstall() \$pbuild not given." | ||
1015 | |||
1016 | # this is only a wrapper | ||
1017 | |||
1018 | # NOTE: | ||
1019 | # !! we use § as field seperator !! | ||
1020 | # doing so prevent us to get errors by filenames with spaces | ||
1021 | |||
1022 | for i in symlinks files blockdevices characterdevices directories | ||
1023 | do | ||
1024 | remove_${i} \ | ||
1025 | --pcat "${pcat}" \ | ||
1026 | --pname "${pname}" \ | ||
1027 | --pver "${pver}" \ | ||
1028 | --pbuild "${pbuild}" \ | ||
1029 | || die "remove ${i} ${pcat}/${pname}-${pver}-${pbuild}" | ||
1030 | done | ||
1031 | } | ||
1032 | |||
1033 | # fetch_packages /path/to/mage/file1 /path/to/mage/file2 | ||
1034 | fetch_packages() | ||
1035 | { | ||
1036 | local list="$@" | ||
1037 | local pkg | ||
1038 | local mirr | ||
1039 | local magefile | ||
1040 | local md5file | ||
1041 | local opt | ||
1042 | local count_current | ||
1043 | local count_total | ||
1044 | |||
1045 | [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc." | ||
1046 | |||
1047 | # get count of total packages | ||
1048 | declare -i count_current=0 | ||
1049 | declare -i count_total=0 | ||
1050 | |||
1051 | for i in ${list}; do (( count_total++ )); done | ||
1052 | |||
1053 | for magefile in ${list} | ||
1054 | do | ||
1055 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
1056 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
1057 | |||
1058 | (( count_current++ )) | ||
1059 | xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" | ||
1060 | |||
1061 | # abort on virtual pkg | ||
1062 | if [[ ${pkgtype} = virtual ]] | ||
1063 | then | ||
1064 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
1065 | echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
1066 | continue | ||
1067 | fi | ||
1068 | |||
1069 | # abort on sources pkg | ||
1070 | if [[ ${pkgtype} = sources ]] | ||
1071 | then | ||
1072 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
1073 | echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
1074 | continue | ||
1075 | fi | ||
1076 | |||
1077 | # abort if already exist | ||
1078 | if [ -f ${PKGDIR}/${pkg} ] | ||
1079 | then | ||
1080 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
1081 | echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " | ||
1082 | continue | ||
1083 | fi | ||
1084 | |||
1085 | for mirr in ${MIRRORS} | ||
1086 | do | ||
1087 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
1088 | #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " | ||
1089 | echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " | ||
1090 | [[ ${VERBOSE} = off ]] && opt="--quiet" | ||
1091 | wget \ | ||
1092 | --passive-ftp \ | ||
1093 | --tries 3 \ | ||
1094 | --continue \ | ||
1095 | --progress bar \ | ||
1096 | --directory-prefix=${PKGDIR} \ | ||
1097 | ${opt} ${mirr}/packages/${pkg} | ||
1098 | if [[ $? = 0 ]] | ||
1099 | then | ||
1100 | break | ||
1101 | else | ||
1102 | continue | ||
1103 | fi | ||
1104 | done | ||
1105 | |||
1106 | if [ ! -f ${PKGDIR}/${pkg} ] | ||
1107 | then | ||
1108 | die "Could not download ${pkg}" | ||
1109 | fi | ||
1110 | done | ||
1111 | |||
1112 | # add a crlf for a better view | ||
1113 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
1114 | } | ||
1115 | |||
1116 | syncmage() | ||
1117 | { | ||
1118 | if [ -z "${RSYNC}" ] | ||
1119 | then | ||
1120 | die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." | ||
1121 | fi | ||
1122 | |||
1123 | local i | ||
1124 | for i in ${RSYNC} | ||
1125 | do | ||
1126 | rsync \ | ||
1127 | --recursive \ | ||
1128 | --links \ | ||
1129 | --perms \ | ||
1130 | --times \ | ||
1131 | --devices \ | ||
1132 | --timeout=600 \ | ||
1133 | --verbose \ | ||
1134 | --compress \ | ||
1135 | --progress \ | ||
1136 | --stats \ | ||
1137 | --delete \ | ||
1138 | --delete-after \ | ||
1139 | ${i} ${MAGEDIR} | ||
1140 | if [[ $? = 0 ]] | ||
1141 | then | ||
1142 | break | ||
1143 | else | ||
1144 | continue | ||
1145 | fi | ||
1146 | done | ||
1147 | |||
1148 | # clean up backup files (foo~) | ||
1149 | find ${MAGEDIR} -name *~ -exec rm '{}' ';' | ||
1150 | |||
1151 | # check if an newer mage version is available | ||
1152 | is_newer_mage_version_available | ||
1153 | } | ||
1154 | |||
1155 | cleanpkg() | ||
1156 | { | ||
1157 | if [ -d "${PKGDIR}" ] | ||
1158 | then | ||
1159 | echo -n "Removing downloaded packages... " | ||
1160 | rm -rf ${PKGDIR}/* | ||
1161 | echo "done." | ||
1162 | fi | ||
1163 | } | ||
1164 | |||
1165 | xtitle() | ||
1166 | { | ||
1167 | if [[ ${TERM} = xterm ]] | ||
1168 | then | ||
1169 | echo -ne "\033]0;Mage: $1\007" | ||
1170 | fi | ||
1171 | return 0 | ||
1172 | } | ||
1173 | |||
1174 | |||
1175 | xtitleclean() | ||
1176 | { | ||
1177 | if [[ ${TERM} = xterm ]] | ||
1178 | then | ||
1179 | echo -ne "\033]0;\007" | ||
1180 | fi | ||
1181 | return 0 | ||
1182 | } | ||
1183 | |||
1184 | |||
1185 | # cuts full pathnames or versioniezed names down to basename | ||
1186 | choppkgname() | ||
1187 | { | ||
1188 | #we want this only if full name was used | ||
1189 | if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] | ||
1190 | then | ||
1191 | #cuts ARCH and PBUILD | ||
1192 | #ARCH comes from /etc/mage.rc | ||
1193 | MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") | ||
1194 | |||
1195 | #cuts version number | ||
1196 | MAGENAME=$(basename ${MAGENAME%-*} .mage) | ||
1197 | fi | ||
1198 | } | ||
1199 | |||
1200 | # get_categorie $PNAME, returns CATEGORIE | ||
1201 | # $1=pname | ||
1202 | # ret 0=ok, 1=not_found | ||
1203 | pname2pcat() | ||
1204 | { | ||
1205 | local pname="$1" | ||
1206 | local repo="$2" | ||
1207 | local pcat | ||
1208 | local categorie | ||
1209 | |||
1210 | for pcat in ${MAGEDIR}/* | ||
1211 | do | ||
1212 | if [ -d ${pcat}/${pname} ] | ||
1213 | then | ||
1214 | categorie=$(basename ${pcat}) | ||
1215 | fi | ||
1216 | done | ||
1217 | |||
1218 | echo "${categorie}" | ||
1219 | } | ||
1220 | |||
1221 | # check_stable_package /path/to/foo.mage | ||
1222 | # returns 0=stable 1=unstable | ||
1223 | check_stable_package() | ||
1224 | { | ||
1225 | local STATE | ||
1226 | STATE="$(get_value_from_magefile STATE "$1")" | ||
1227 | |||
1228 | # state testing | ||
1229 | if [[ ${USE_TESTING} = true ]] | ||
1230 | then | ||
1231 | case ${STATE} in | ||
1232 | testing|stable) return 0 ;; | ||
1233 | *) return 1 ;; | ||
1234 | esac | ||
1235 | fi | ||
1236 | |||
1237 | # state unstable | ||
1238 | if [[ ${USE_UNSTABLE} = true ]] | ||
1239 | then | ||
1240 | case ${STATE} in | ||
1241 | unstable|testing|stable) return 0 ;; | ||
1242 | *) return 1 ;; | ||
1243 | esac | ||
1244 | fi | ||
1245 | |||
1246 | # no use_state given = stable | ||
1247 | case ${STATE} in | ||
1248 | stable) return 0 ;; | ||
1249 | *) return 1 ;; | ||
1250 | esac | ||
1251 | } | ||
1252 | |||
1253 | |||
1254 | # get_highest_magefile ${PCAT} ${PNAME} | ||
1255 | # fake at moment returns only stable pkgs (must set to be one) | ||
1256 | # return $HIGHEST_MAGEFILE | ||
1257 | get_highest_magefile() | ||
1258 | { | ||
1259 | local HIGHEST_MAGEFILE | ||
1260 | local PCAT="$1" | ||
1261 | local PNAME="$2" | ||
1262 | local magefile | ||
1263 | |||
1264 | for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*) | ||
1265 | do | ||
1266 | # we exclude subdirs (for stuff like a md5sum dir) | ||
1267 | [ -d ${magefile} ] && continue | ||
1268 | if check_stable_package ${magefile} | ||
1269 | then | ||
1270 | HIGHEST_MAGEFILE=${magefile} | ||
1271 | #for debug only | ||
1272 | [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" | ||
1273 | fi | ||
1274 | done | ||
1275 | |||
1276 | # stop here if HIGHEST_MAGEFILE is zero | ||
1277 | # this package must be unstable or old | ||
1278 | if [ -z "${HIGHEST_MAGEFILE}" ] | ||
1279 | then | ||
1280 | echo | ||
1281 | echo -n "All packages named " | ||
1282 | echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} | ||
1283 | echo -n " are marked " | ||
1284 | echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} | ||
1285 | echo "." | ||
1286 | echo "You need to declare USE_UNSTABLE=true to install this." | ||
1287 | echo | ||
1288 | echo "Example:" | ||
1289 | echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" | ||
1290 | echo | ||
1291 | echo "Be warned that these packages are not stable and may cause serious problems." | ||
1292 | echo "You should know what you are doing, so don't complain about any damage." | ||
1293 | echo | ||
1294 | return 1 | ||
1295 | fi | ||
1296 | |||
1297 | echo "${HIGHEST_MAGEFILE}" | ||
1298 | return 0 | ||
1299 | } | ||
1300 | |||
1301 | |||
1302 | ################################################### | ||
1303 | # function is_config_protected # | ||
1304 | # is_config_protected /path/to/file # | ||
1305 | # # | ||
1306 | # returns: # | ||
1307 | # 0 - not protected # | ||
1308 | # 1 - error # | ||
1309 | # 2 - protected # | ||
1310 | # 3 - protected but masked # | ||
1311 | # # | ||
1312 | ################################################### | ||
1313 | is_config_protected() | ||
1314 | { | ||
1315 | local EXPFILE | ||
1316 | local TEST | ||
1317 | local PROTECTED | ||
1318 | local IFS | ||
1319 | |||
1320 | EXPFILE="${MROOT}$1" | ||
1321 | |||
1322 | # file does not exist; it can be written | ||
1323 | [ ! -e ${EXPFILE} ] && return 0 | ||
1324 | |||
1325 | # to be safe; it may be '§' | ||
1326 | IFS=' ' | ||
1327 | |||
1328 | # check ob in config protect | ||
1329 | for i in ${CONFIG_PROTECT} | ||
1330 | do | ||
1331 | # ersetzen von $i nur wenn am anfang der variable | ||
1332 | TEST="${EXPFILE/#${MROOT}${i}/Protected}" | ||
1333 | if [ "${TEST}" != "${EXPFILE}" ] | ||
1334 | then | ||
1335 | # setzen das es protected ist | ||
1336 | PROTECTED=TRUE | ||
1337 | |||
1338 | # check ob nicht doch maskiert | ||
1339 | for x in ${CONFIG_PROTECT_MASK} | ||
1340 | do | ||
1341 | TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" | ||
1342 | if [ "${TEST}" != "${EXPFILE}" ] | ||
1343 | then | ||
1344 | PROTECTED=MASKED | ||
1345 | fi | ||
1346 | done | ||
1347 | fi | ||
1348 | done | ||
1349 | |||
1350 | unset IFS | ||
1351 | |||
1352 | case ${PROTECTED} in | ||
1353 | TRUE) | ||
1354 | #echo "I'm protected" | ||
1355 | return 2 | ||
1356 | ;; | ||
1357 | MASKED) | ||
1358 | #echo "I'm protected, but masked - delete me" | ||
1359 | return 3 | ||
1360 | ;; | ||
1361 | *) | ||
1362 | #echo "delete me" | ||
1363 | return 0 | ||
1364 | ;; | ||
1365 | esac | ||
1366 | } | ||
1367 | |||
1368 | |||
1369 | ################################################### | ||
1370 | # function count_protected_files # | ||
1371 | # count_protected_files /path/to/file # | ||
1372 | # # | ||
1373 | # note: prints number of protected files # | ||
1374 | # exp: 0012 # | ||
1375 | ################################################### | ||
1376 | count_protected_files() | ||
1377 | { | ||
1378 | ${MLIBDIR}/writeprotected "$1" | ||
1379 | } | ||
1380 | |||
1381 | # call with | ||
1382 | # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME' | ||
1383 | # returns /path/to/magefile(s) | ||
1384 | get_uninstall_candidates() | ||
1385 | { | ||
1386 | local search_pname | ||
1387 | local pkg | ||
1388 | local pcat | ||
1389 | local pname | ||
1390 | local pver | ||
1391 | local pbuild | ||
1392 | local list | ||
1393 | local pcatdir | ||
1394 | local protected | ||
1395 | |||
1396 | # very basic getops | ||
1397 | for i in $* | ||
1398 | do | ||
1399 | case $1 in | ||
1400 | --pcat|-c) shift; pcatdir="$1" ;; | ||
1401 | --pname|-n) shift; search_pname="$1" ;; | ||
1402 | --protected|-p) shift; protected="$1" ;; | ||
1403 | esac | ||
1404 | shift | ||
1405 | done | ||
1406 | |||
1407 | # sanity checks; abort if not given | ||
1408 | [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." | ||
1409 | |||
1410 | |||
1411 | # check needed global vars | ||
1412 | [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." | ||
1413 | |||
1414 | # set pcatdir to '*' if empty | ||
1415 | [ -z "${pcatdir}" ] && pcatdir=* | ||
1416 | |||
1417 | for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* | ||
1418 | do | ||
1419 | # abort if not a dir | ||
1420 | [ ! -d ${pkg} ] && continue | ||
1421 | |||
1422 | pname="$(magename2pname ${pkg})" | ||
1423 | |||
1424 | if [[ ${search_pname} = ${pname} ]] | ||
1425 | then | ||
1426 | pcat="$(magename2pcat ${pkg} installdb)" | ||
1427 | pver="$(magename2pver ${pkg})" | ||
1428 | pbuild="$(magename2pbuild ${pkg})" | ||
1429 | |||
1430 | # exclude proteced | ||
1431 | [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue | ||
1432 | |||
1433 | list="${list} ${pcat}/${pname}-${pver}-${pbuild}" | ||
1434 | fi | ||
1435 | done | ||
1436 | |||
1437 | echo "${list}" | ||
1438 | } | ||
1439 | |||
1440 | # reads virtualdb file | ||
1441 | #$1 = virtualname; $2 commands: showpkgs, showline | ||
1442 | #return 0 == installed -> shows installed pkg as well | ||
1443 | #return 1 == not installed | ||
1444 | virtuals_read() | ||
1445 | { | ||
1446 | local virtualname="$1" | ||
1447 | local command="$2" | ||
1448 | local virtline | ||
1449 | local line x i | ||
1450 | |||
1451 | # parse file to get virtual_name line | ||
1452 | IFS=$'\n' | ||
1453 | for line in $(< ${MROOT}${VIRTUALDB_FILE}) | ||
1454 | do | ||
1455 | IFS=$' ' | ||
1456 | for x in ${line} | ||
1457 | do | ||
1458 | if [[ ${x} = ${virtualname} ]] | ||
1459 | then | ||
1460 | virtline="${line}" | ||
1461 | [[ ${command} = showline ]] && echo "${line}" | ||
1462 | fi | ||
1463 | done | ||
1464 | IFS=$'\n' | ||
1465 | done | ||
1466 | |||
1467 | unset IFS | ||
1468 | |||
1469 | # now read the packages linked to VIRTUAL_NAME and output them | ||
1470 | if [ -n "${virtline}" ] | ||
1471 | then | ||
1472 | if [[ ${command} = showpkgs ]] | ||
1473 | then | ||
1474 | declare -i x=0 | ||
1475 | for i in ${virtline} | ||
1476 | do | ||
1477 | if [ ${x} -ge 1 ] | ||
1478 | then | ||
1479 | echo "${i}" | ||
1480 | fi | ||
1481 | ((x++)) | ||
1482 | done | ||
1483 | fi | ||
1484 | return 0 | ||
1485 | fi | ||
1486 | return 1 | ||
1487 | } | ||
1488 | |||
1489 | |||
1490 | #add pkg to virtualdb | ||
1491 | # $1 == virtualname $2= pkgname | ||
1492 | # retvals: 0=ok,added; 1=error; 3=pkg already in virtual | ||
1493 | virtuals_add() | ||
1494 | { | ||
1495 | local virtualname="$1" | ||
1496 | local pkgname="$2" | ||
1497 | local oldline | ||
1498 | local line i | ||
1499 | local installed_file | ||
1500 | niro | 273 | local OLDIFS |
1501 | niro | 226 | |
1502 | if virtuals_read ${virtualname} | ||
1503 | then | ||
1504 | # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already | ||
1505 | for i in $(virtuals_read ${virtualname} showpkgs) | ||
1506 | do | ||
1507 | if [[ ${i} = ${pkgname} ]] | ||
1508 | then | ||
1509 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1510 | echo "${pkgname} already linked as ${virtualname} ..." | ||
1511 | #return 3 | ||
1512 | return 0 | ||
1513 | fi | ||
1514 | done | ||
1515 | |||
1516 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
1517 | echo "updating ${virtualname} entry with ${pkgname} ..." | ||
1518 | oldline="$(virtuals_read ${virtualname} showline)" | ||
1519 | |||
1520 | # make a backup | ||
1521 | mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old | ||
1522 | |||
1523 | niro | 273 | OLDIFS="${IFS}" |
1524 | niro | 226 | IFS=$'\n' |
1525 | for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) | ||
1526 | do | ||
1527 | # if the right line, append ${pkgname}, else do nothing | ||
1528 | if [[ ${line} = ${oldline} ]] | ||
1529 | then | ||
1530 | echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1531 | else | ||
1532 | echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1533 | fi | ||
1534 | done | ||
1535 | niro | 273 | # unset IFS |
1536 | IFS="${OLDIFS}" | ||
1537 | niro | 226 | else |
1538 | niro | 273 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
1539 | niro | 226 | echo "register ${pkgname} as ${virtualname} ..." |
1540 | echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1541 | fi | ||
1542 | |||
1543 | return 0 | ||
1544 | } | ||
1545 | |||
1546 | #deletes pakages from virtual database | ||
1547 | #$1 virtualname; $2 pkgname | ||
1548 | virtuals_del() { | ||
1549 | |||
1550 | niro | 273 | local virtualname="$1" |
1551 | local pkgname="$2" | ||
1552 | local oldline | ||
1553 | local method | ||
1554 | local line i x | ||
1555 | local pkg_installed | ||
1556 | local OLDIFS | ||
1557 | |||
1558 | # first check if exists | ||
1559 | if virtuals_read ${virtualname} | ||
1560 | niro | 226 | then |
1561 | niro | 273 | # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
1562 | niro | 226 | declare -i x=0 |
1563 | niro | 273 | for i in $(virtuals_read ${virtualname} showpkgs) |
1564 | niro | 226 | do |
1565 | niro | 273 | if [[ ${i} = ${pkgname} ]] |
1566 | niro | 226 | then |
1567 | niro | 273 | pkg_installed=true |
1568 | niro | 226 | fi |
1569 | ((x++)) | ||
1570 | done | ||
1571 | niro | 273 | |
1572 | # abort if not installed | ||
1573 | if [[ ${pkg_installed} != true ]] | ||
1574 | niro | 226 | then |
1575 | niro | 273 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1576 | echo "${pkgname} does not exists in ${virtualname}." | ||
1577 | niro | 226 | return 0 |
1578 | fi | ||
1579 | niro | 273 | |
1580 | niro | 226 | if [ ${x} -ge 2 ] |
1581 | then | ||
1582 | niro | 273 | method=update |
1583 | niro | 226 | else |
1584 | niro | 273 | method=delall |
1585 | niro | 226 | fi |
1586 | niro | 273 | |
1587 | # get the complete line | ||
1588 | oldline="$(virtuals_read ${virtualname} showline)" | ||
1589 | |||
1590 | # make a backup of the db | ||
1591 | niro | 226 | mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
1592 | niro | 273 | |
1593 | # parse virtualdb | ||
1594 | OLDIFS="${IFS}" | ||
1595 | niro | 226 | IFS=$'\n' |
1596 | for line in $(< ${VIRTUALDB_FILE}.old) | ||
1597 | do | ||
1598 | niro | 273 | if [[ ${line} = ${oldline} ]] |
1599 | niro | 226 | then |
1600 | #delall or update? | ||
1601 | niro | 273 | case ${method} in |
1602 | niro | 226 | update) |
1603 | niro | 273 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1604 | echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." | ||
1605 | # del PKG_NAME from line | ||
1606 | echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} | ||
1607 | niro | 226 | ;; |
1608 | delall) | ||
1609 | niro | 273 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
1610 | echo "Deleting ${virtualname} in virtual database ..." | ||
1611 | # continue; do not write anything | ||
1612 | niro | 226 | continue |
1613 | ;; | ||
1614 | esac | ||
1615 | else | ||
1616 | echo "${line}" >> ${VIRTUALDB_FILE} | ||
1617 | fi | ||
1618 | done | ||
1619 | niro | 273 | # unset IFS |
1620 | IFS="${OLDIFS}" | ||
1621 | niro | 226 | else |
1622 | niro | 273 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1623 | echo "${virtualname} does not exists in virtual database." | ||
1624 | niro | 226 | fi |
1625 | } | ||
1626 | |||
1627 | # gets real pkgname from virtuals.default | ||
1628 | #$1=VIRTUAL_NAME; returns PKG_NAME | ||
1629 | default_virtualname_to_pkgname() | ||
1630 | { | ||
1631 | local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname | ||
1632 | |||
1633 | VIRTUAL_NAME=$1 | ||
1634 | |||
1635 | while read db_virtualname db_pkgname | ||
1636 | do | ||
1637 | if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ] | ||
1638 | then | ||
1639 | PKG_NAME="${db_pkgname}" | ||
1640 | fi | ||
1641 | done << EOF | ||
1642 | $(< ${VIRTUALDB_DEFAULTS}) | ||
1643 | EOF | ||
1644 | |||
1645 | if [ -n "${PKG_NAME}" ] | ||
1646 | then | ||
1647 | echo "${PKG_NAME}" | ||
1648 | fi | ||
1649 | } | ||
1650 | |||
1651 | minclude() | ||
1652 | { | ||
1653 | local i | ||
1654 | |||
1655 | if [ -n "$@" ] | ||
1656 | then | ||
1657 | for i in $@ | ||
1658 | do | ||
1659 | [[ ${MAGEDEBUG} = on ]] && \ | ||
1660 | echo "--- Including ${MAGEDIR}/include/${i}.minc" | ||
1661 | source ${MAGEDIR}/include/${i}.minc | ||
1662 | done | ||
1663 | [[ ${MAGEDEBUG} = on ]] && echo | ||
1664 | fi | ||
1665 | } | ||
1666 | |||
1667 | sminclude() | ||
1668 | { | ||
1669 | local i | ||
1670 | |||
1671 | if [ -n "$@" ] | ||
1672 | then | ||
1673 | for i in $@ | ||
1674 | do | ||
1675 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" | ||
1676 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc | ||
1677 | done | ||
1678 | echo | ||
1679 | fi | ||
1680 | } | ||
1681 | |||
1682 | # checks if an newer mage version is available | ||
1683 | is_newer_mage_version_available() | ||
1684 | { | ||
1685 | local newest_mage | ||
1686 | local installed_mage | ||
1687 | |||
1688 | niro | 252 | newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" |
1689 | niro | 226 | installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
1690 | |||
1691 | if [[ ${newest_mage} > ${installed_mage} ]] | ||
1692 | then | ||
1693 | echo | ||
1694 | echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} | ||
1695 | echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} | ||
1696 | echo "It is recommened to install this newer version" | ||
1697 | echo "or your current system installation may brake." | ||
1698 | echo | ||
1699 | echo -en "Please update mage by running " | ||
1700 | echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} | ||
1701 | echo | ||
1702 | fi | ||
1703 | } | ||
1704 | |||
1705 | |||
1706 | # returns pname from pkgname | ||
1707 | # pkgname2pname $PKGNAME | ||
1708 | pkgname2pname() | ||
1709 | { | ||
1710 | local pname | ||
1711 | |||
1712 | pname="${1%-*-*-*}" | ||
1713 | echo "${pname}" | ||
1714 | } | ||
1715 | |||
1716 | # returns pver from pkgname | ||
1717 | # pkgname2pver $PKGNAME | ||
1718 | pkgname2pver() | ||
1719 | { | ||
1720 | local i pver | ||
1721 | |||
1722 | i="${1/$(pkgname2pname $1)-/}" | ||
1723 | pver="${i%-*-*}" | ||
1724 | echo "${pver}" | ||
1725 | } | ||
1726 | |||
1727 | # returns pbuild from pkgname | ||
1728 | # pkgname2pbuild $PKGNAME | ||
1729 | pkgname2pbuild() | ||
1730 | { | ||
1731 | local pbuild | ||
1732 | |||
1733 | pbuild="${1##*-}" | ||
1734 | echo "${pbuild}" | ||
1735 | } | ||
1736 | |||
1737 | # returns parch from pkgname | ||
1738 | # pkgname2parch $PKGNAME | ||
1739 | pkgname2parch() | ||
1740 | { | ||
1741 | local i x parch | ||
1742 | |||
1743 | i="${1%-*-*}-" | ||
1744 | x="${1%-*}" | ||
1745 | parch="${x/${i}/}" | ||
1746 | echo "${parch}" | ||
1747 | } | ||
1748 | |||
1749 | # returns pname from magename | ||
1750 | # magename2pname /PATH/TO/MAGE/FILE | ||
1751 | magename2pname() | ||
1752 | { | ||
1753 | local i pname | ||
1754 | |||
1755 | i="$(basename $1 .mage)" | ||
1756 | pname="${i%-*-*}" | ||
1757 | echo "${pname}" | ||
1758 | } | ||
1759 | |||
1760 | # returns pver from magename | ||
1761 | # magename2pver /PATH/TO/MAGE/FILE | ||
1762 | magename2pver() | ||
1763 | { | ||
1764 | local i pver | ||
1765 | |||
1766 | i="$(basename $1 .mage)" | ||
1767 | i="${i/$(magename2pname $1)-/}" | ||
1768 | pver="${i%-*}" | ||
1769 | echo "${pver}" | ||
1770 | } | ||
1771 | |||
1772 | # returns pbuild from magename | ||
1773 | # magename2pbuild /PATH/TO/MAGE/FILE | ||
1774 | magename2pbuild() | ||
1775 | { | ||
1776 | local i pbuild | ||
1777 | |||
1778 | i="$(basename $1 .mage)" | ||
1779 | pbuild="${i##*-}" | ||
1780 | echo "${pbuild}" | ||
1781 | } | ||
1782 | |||
1783 | # returns pcat from magename | ||
1784 | # magename2pcat /PATH/TO/MAGE/FILE | ||
1785 | magename2pcat() | ||
1786 | { | ||
1787 | local i pcat | ||
1788 | |||
1789 | if [[ ${2} = installdb ]] | ||
1790 | then | ||
1791 | # go 1 dir back | ||
1792 | i="${1%/*}" | ||
1793 | else | ||
1794 | # go 2 dirs back | ||
1795 | i="${1%/*/*}" | ||
1796 | fi | ||
1797 | |||
1798 | # get basename | ||
1799 | pcat="${i##*/}" | ||
1800 | echo "${pcat}" | ||
1801 | } | ||
1802 | |||
1803 | # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION) | ||
1804 | # dep2pcat DEPEND | ||
1805 | dep2pcat() | ||
1806 | { | ||
1807 | local pcat | ||
1808 | |||
1809 | pcat="${1%/*}" | ||
1810 | echo "${pcat}" | ||
1811 | } | ||
1812 | |||
1813 | # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION) | ||
1814 | # $2=virtual is used to resolv VDEPEND from virtual packages | ||
1815 | # dep2pcat DEPEND (virtual) | ||
1816 | dep2pname() | ||
1817 | { | ||
1818 | local pname | ||
1819 | |||
1820 | pname="${1##*/}" | ||
1821 | |||
1822 | # cut version only if not virtual or it will cut the name | ||
1823 | if [[ $(dep2pcat $1) != virtual ]] && \ | ||
1824 | [[ $2 != virtual ]] | ||
1825 | then | ||
1826 | pname="${pname%-*}" | ||
1827 | fi | ||
1828 | |||
1829 | echo "${pname}" | ||
1830 | } | ||
1831 | |||
1832 | dep2highest_magefile() | ||
1833 | { | ||
1834 | local pcat | ||
1835 | local pname | ||
1836 | local magefile | ||
1837 | local installed_virtuals | ||
1838 | |||
1839 | pcat="$(dep2pcat $1)" | ||
1840 | pname="$(dep2pname $1)" | ||
1841 | |||
1842 | if [[ ${pcat} = virtual ]] | ||
1843 | then | ||
1844 | # first check if virtual is already installed | ||
1845 | installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)" | ||
1846 | if [ -n "${installed_virtuals}" ] | ||
1847 | then | ||
1848 | for vpkg in ${installed_virtuals} | ||
1849 | do | ||
1850 | realpkgname="${vpkg}" | ||
1851 | virtualpkgname="${pcat}/${pname}" | ||
1852 | pcat="$(dep2pcat ${realpkgname})" | ||
1853 | pname="$(dep2pname ${realpkgname} virtual)" | ||
1854 | done | ||
1855 | else | ||
1856 | # choose one from virtualdb defaults (virtuals.defaults) | ||
1857 | realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})" | ||
1858 | virtualpkgname="${pcat}/${pname}" | ||
1859 | pcat="$(dep2pcat ${realpkgname})" | ||
1860 | pname="$(dep2pname ${realpkgname} virtual)" | ||
1861 | fi | ||
1862 | fi | ||
1863 | |||
1864 | magefile="$(get_highest_magefile ${pcat} ${pname})" | ||
1865 | echo "${magefile}" | ||
1866 | } | ||
1867 | |||
1868 | # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} | ||
1869 | is_installed() | ||
1870 | { | ||
1871 | local fullpkgname="$1" | ||
1872 | |||
1873 | # return 0 if installed | ||
1874 | [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0 | ||
1875 | |||
1876 | return 1 | ||
1877 | } | ||
1878 | |||
1879 | install_packages() | ||
1880 | { | ||
1881 | local list="$@" | ||
1882 | local pkg | ||
1883 | local pcat | ||
1884 | local pname | ||
1885 | local pver | ||
1886 | local pbuild | ||
1887 | local total_pkgs | ||
1888 | local current_pkg | ||
1889 | local src_install | ||
1890 | local uninstall_list | ||
1891 | |||
1892 | # check for --src-install | ||
1893 | if [[ $1 = --src-install ]] | ||
1894 | then | ||
1895 | # remove --src-install from list | ||
1896 | list=${list/--src-install/} | ||
1897 | # enable src-install | ||
1898 | src_install="--src-install" | ||
1899 | fi | ||
1900 | |||
1901 | # reset MAGE_PROTECT_COUNTER | ||
1902 | declare -i MAGE_PROTECT_COUNTER=0 | ||
1903 | export MAGE_PROTECT_COUNTER | ||
1904 | |||
1905 | # get count of total packages | ||
1906 | declare -i total_pkgs=0 | ||
1907 | declare -i current_pkg=0 | ||
1908 | for i in ${list}; do (( total_pkgs++ )); done | ||
1909 | |||
1910 | echo | ||
1911 | |||
1912 | if [[ -n ${MROOT} ]] | ||
1913 | then | ||
1914 | echo -ne ${COLRED} | ||
1915 | echo "!! installing in MROOT=${MROOT}" | ||
1916 | echo -ne ${COLDEFAULT} | ||
1917 | echo | ||
1918 | fi | ||
1919 | |||
1920 | for pkg in ${list} | ||
1921 | do | ||
1922 | (( current_pkg++ )) | ||
1923 | pcat=$(magename2pcat ${pkg}) | ||
1924 | pname=$(magename2pname ${pkg}) | ||
1925 | pver=$(magename2pver ${pkg}) | ||
1926 | pbuild=$(magename2pbuild ${pkg}) | ||
1927 | |||
1928 | mage_install \ | ||
1929 | --pcat ${pcat} \ | ||
1930 | --pname ${pname} \ | ||
1931 | --pver ${pver} \ | ||
1932 | --pbuild ${pbuild} \ | ||
1933 | --count-total ${total_pkgs} \ | ||
1934 | --count-current ${current_pkg} \ | ||
1935 | ${src_install} | ||
1936 | |||
1937 | # check for allready installed packages and remove them | ||
1938 | # except the package we have installed | ||
1939 | uninstall_list="$(get_uninstall_candidates \ | ||
1940 | --pcat "${pcat}" \ | ||
1941 | --pname "${pname}" \ | ||
1942 | --protected ${pcat}/${pname}-${pver}-${pbuild})" | ||
1943 | |||
1944 | # uninstall all packges in uninstall_list if not empty | ||
1945 | if [ -n "${uninstall_list}" ] | ||
1946 | then | ||
1947 | echo | ||
1948 | uninstall_packages ${uninstall_list} \ | ||
1949 | || die "install_packges() uninstalling not-needed." | ||
1950 | fi | ||
1951 | |||
1952 | # crlf for better view in VERBOSE mode | ||
1953 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
1954 | echo | ||
1955 | done | ||
1956 | |||
1957 | #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}" | ||
1958 | show_etc_update_mesg | ||
1959 | } | ||
1960 | |||
1961 | # get_value_from_magefile VARIABLE | ||
1962 | # returns the content of this VAR | ||
1963 | get_value_from_magefile() | ||
1964 | { | ||
1965 | local var="$1" | ||
1966 | local magefile="$2" | ||
1967 | local value | ||
1968 | |||
1969 | # local all possible vars of a mage file | ||
1970 | # to prevent bad issues | ||
1971 | local PKGNAME | ||
1972 | local STATE | ||
1973 | local DESCRIPTION | ||
1974 | local HOMEPAGE | ||
1975 | local DEPEND | ||
1976 | local SDEPEND | ||
1977 | local PROVIDE | ||
1978 | local PKGTYPE | ||
1979 | local preinstall | ||
1980 | local postinstall | ||
1981 | niro | 248 | local preremove |
1982 | local postremove | ||
1983 | niro | 226 | |
1984 | # sanity checks | ||
1985 | [ -f ${magefile} ] && source ${magefile} || \ | ||
1986 | die "get_value_from_magefile: ${magefile} not found." | ||
1987 | [ -z "${var}" ] && die "get_value_from_magefile: \$var not given." | ||
1988 | |||
1989 | source ${magefile} | ||
1990 | eval value=\$$(echo ${var}) | ||
1991 | echo "${value}" | ||
1992 | niro | 248 | |
1993 | niro | 258 | # unset these functions |
1994 | unset -f preinstall | ||
1995 | unset -f postinstall | ||
1996 | unset -f preremove | ||
1997 | unset -f postremove | ||
1998 | niro | 226 | } |
1999 | |||
2000 | mage_install() | ||
2001 | { | ||
2002 | # local all possible vars of a mage file | ||
2003 | # to prevent bad issues | ||
2004 | local PKGNAME | ||
2005 | local STATE | ||
2006 | local DESCRIPTION | ||
2007 | local HOMEPAGE | ||
2008 | local DEPEND | ||
2009 | local SDEPEND | ||
2010 | local PROVIDE | ||
2011 | local PKGTYPE | ||
2012 | local preinstall | ||
2013 | local postinstall | ||
2014 | niro | 248 | local preremove |
2015 | local postremove | ||
2016 | niro | 226 | |
2017 | local pcat | ||
2018 | local pname | ||
2019 | local pver | ||
2020 | local pbuild | ||
2021 | local count_total | ||
2022 | local count_current | ||
2023 | local magefile | ||
2024 | local src_install | ||
2025 | |||
2026 | # very basic getops | ||
2027 | for i in $* | ||
2028 | do | ||
2029 | case $1 in | ||
2030 | --pcat|-c) shift; pcat="$1" ;; | ||
2031 | --pname|-n) shift; pname="$1" ;; | ||
2032 | --pver|-v) shift; pver="$1" ;; | ||
2033 | --pbuild|-b) shift; pbuild="$1" ;; | ||
2034 | --count-total) shift; count_total="$1" ;; | ||
2035 | --count-current) shift; count_current="$1" ;; | ||
2036 | --src-install|-s) shift; src_install=true ;; | ||
2037 | esac | ||
2038 | shift | ||
2039 | done | ||
2040 | |||
2041 | # sanity checks; abort if not given | ||
2042 | [ -z "${pcat}" ] && die "mage_install() \$pcat not given." | ||
2043 | [ -z "${pname}" ] && die "mage_install() \$pname not given." | ||
2044 | [ -z "${pver}" ] && die "mage_install() \$pver not given." | ||
2045 | [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given." | ||
2046 | |||
2047 | # check needed global vars | ||
2048 | [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set." | ||
2049 | [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set." | ||
2050 | [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set." | ||
2051 | |||
2052 | xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]" | ||
2053 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" | ||
2054 | echo -n "installing (${count_current}/${count_total}): " | ||
2055 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2056 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" | ||
2057 | |||
2058 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" | ||
2059 | source ${magefile} | ||
2060 | |||
2061 | # abort on sources if no srcinstall | ||
2062 | if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]] | ||
2063 | then | ||
2064 | echo | ||
2065 | echo -e "This Package is a Source Package." | ||
2066 | echo | ||
2067 | echo -e "Only 'srcinstall' works with this type of packages" | ||
2068 | echo -en "If you have done a srcinstall before, " | ||
2069 | echo -e "you will find the files in /usr/src." | ||
2070 | echo | ||
2071 | exit 1 | ||
2072 | fi | ||
2073 | |||
2074 | ## preinstall scripts | ||
2075 | if [ -n "$(typeset -f preinstall)" ] | ||
2076 | then | ||
2077 | echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... " | ||
2078 | preinstall | ||
2079 | unset preinstall | ||
2080 | fi | ||
2081 | |||
2082 | if [[ ${src_install} = true ]] | ||
2083 | then | ||
2084 | local smage2file | ||
2085 | # check needed global vars | ||
2086 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." | ||
2087 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." | ||
2088 | [ -z "${BINDIR}" ] && die "\$BINDIR not set." | ||
2089 | |||
2090 | # build the package first | ||
2091 | if [[ ${MAGEDEBUG} = on ]] | ||
2092 | then | ||
2093 | echo M:${pname} | ||
2094 | echo V:${pver} | ||
2095 | echo B:${pbuild} | ||
2096 | fi | ||
2097 | |||
2098 | smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 | ||
2099 | if [ -f "${smage2file}" ] | ||
2100 | then | ||
2101 | smage2 ${smage2file} || die "compile failed" | ||
2102 | else | ||
2103 | echo | ||
2104 | echo "$(basename ${SMAGEFILE}) not found." | ||
2105 | echo "update your smage-tree and try it again." | ||
2106 | echo | ||
2107 | die | ||
2108 | fi | ||
2109 | fi | ||
2110 | |||
2111 | if [[ ${PKGTYPE} != virtual ]] && \ | ||
2112 | [[ ${PKGTYPE} != sources ]] | ||
2113 | then | ||
2114 | # show a verbose message on src-install | ||
2115 | if [[ ${src_install} = true ]] | ||
2116 | then | ||
2117 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2118 | echo -ne "merging files: " | ||
2119 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2120 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" | ||
2121 | fi | ||
2122 | build_doinstall ${PKGNAME} | ||
2123 | fi | ||
2124 | |||
2125 | ## postinstall scripts | ||
2126 | if [ -n "$(typeset -f postinstall)" ] | ||
2127 | then | ||
2128 | echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... " | ||
2129 | postinstall | ||
2130 | unset postinstall | ||
2131 | fi | ||
2132 | |||
2133 | # install a database entry | ||
2134 | install_database_entry \ | ||
2135 | --pcat "${pcat}" \ | ||
2136 | --pname "${pname}" \ | ||
2137 | --pver "${pver}" \ | ||
2138 | --pbuild "${pbuild}" \ | ||
2139 | --pkgname "${PKGNAME}" \ | ||
2140 | --pkgtype "${PKGTYPE}" \ | ||
2141 | || die "error in mage_install() running install_database_entry()." | ||
2142 | |||
2143 | # remove the package dir now | ||
2144 | if [ -d ${BUILDDIR}/${PKGNAME} ] | ||
2145 | then | ||
2146 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
2147 | fi | ||
2148 | |||
2149 | # rebuilds toplevel info node | ||
2150 | if [[ ${MAGE_INFO_REBUILD} = true ]] | ||
2151 | then | ||
2152 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2153 | echo -n "rebuilding top-level info node ... " | ||
2154 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ | ||
2155 | > ${MROOT}/usr/share/info/dir && \ | ||
2156 | echo "done." || echo "failure." | ||
2157 | unset MAGE_INFO_REBUILD | ||
2158 | fi | ||
2159 | |||
2160 | # rebuilds the enviroment with the content of /etc/env.d | ||
2161 | if [[ ${MAGE_ENV_REBUILD} = true ]] | ||
2162 | then | ||
2163 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2164 | echo -n "rebuilding environment ... " | ||
2165 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ | ||
2166 | echo "done." || echo "failure." | ||
2167 | unset MAGE_ENV_REBUILD | ||
2168 | fi | ||
2169 | |||
2170 | xtitleclean | ||
2171 | |||
2172 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2173 | echo -n "package " | ||
2174 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2175 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " | ||
2176 | echo "successfully installed." | ||
2177 | niro | 248 | |
2178 | niro | 258 | # unset these functions |
2179 | unset -f preinstall | ||
2180 | unset -f postinstall | ||
2181 | unset -f preremove | ||
2182 | unset -f postremove | ||
2183 | niro | 226 | } |
2184 | |||
2185 | md5sum_packages() | ||
2186 | { | ||
2187 | local list="$@" | ||
2188 | local magefile | ||
2189 | local pcat | ||
2190 | local pname | ||
2191 | local pkgname | ||
2192 | local pkgfile | ||
2193 | local pkgtype | ||
2194 | local count_current | ||
2195 | local count_total | ||
2196 | |||
2197 | # get count of total packages | ||
2198 | declare -i count_current=0 | ||
2199 | declare -i count_total=0 | ||
2200 | |||
2201 | for i in ${list}; do (( count_total++ )); done | ||
2202 | |||
2203 | for magefile in ${list} | ||
2204 | do | ||
2205 | pcat=$(magename2pcat ${magefile}) | ||
2206 | pname=$(magename2pname ${magefile}) | ||
2207 | pkgname="$(get_value_from_magefile PKGNAME ${magefile})" | ||
2208 | md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" | ||
2209 | pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
2210 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
2211 | |||
2212 | (( count_current++ )) | ||
2213 | xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]" | ||
2214 | |||
2215 | # abort on virtual pkg | ||
2216 | if [[ ${pkgtype} = virtual ]] | ||
2217 | then | ||
2218 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
2219 | echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
2220 | continue | ||
2221 | fi | ||
2222 | |||
2223 | # abort on sources pkg | ||
2224 | if [[ ${pkgtype} = sources ]] | ||
2225 | then | ||
2226 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
2227 | echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
2228 | continue | ||
2229 | fi | ||
2230 | |||
2231 | if [ -f "${md5file}" ] | ||
2232 | then | ||
2233 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2234 | echo -ne "checking md5sum (${count_current}/${count_total}): " | ||
2235 | ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" | ||
2236 | else | ||
2237 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2238 | echo -e "!! no md5sum file found for ${pkgfile} :(" | ||
2239 | fi | ||
2240 | done | ||
2241 | |||
2242 | # add a crlf for a better view | ||
2243 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
2244 | } | ||
2245 | |||
2246 | ## uninstall_packages ulist | ||
2247 | uninstall_packages() | ||
2248 | { | ||
2249 | local list="$@" | ||
2250 | local pcat | ||
2251 | local pname | ||
2252 | local pver | ||
2253 | local pbuild | ||
2254 | local can_pcat | ||
2255 | local can_pname | ||
2256 | local can_ver_list | ||
2257 | |||
2258 | if [[ -n ${MROOT} ]] | ||
2259 | then | ||
2260 | echo -ne ${COLRED} | ||
2261 | echo "!! uninstalling from MROOT=${MROOT}" | ||
2262 | echo -ne ${COLDEFAULT} | ||
2263 | echo | ||
2264 | fi | ||
2265 | |||
2266 | # generate a candidates list | ||
2267 | for pkg in ${list} | ||
2268 | do | ||
2269 | pcat=$(dep2pcat ${pkg}) | ||
2270 | pname=$(magename2pname ${pkg}) | ||
2271 | pver=$(magename2pver ${pkg}) | ||
2272 | pbuild=$(magename2pbuild ${pkg}) | ||
2273 | can_pcat="${pcat}" | ||
2274 | can_pname="${pname}" | ||
2275 | |||
2276 | if [ -z "${can_ver_list}" ] | ||
2277 | then | ||
2278 | can_ver_list=" ${pver}-${pbuild}" | ||
2279 | else | ||
2280 | can_ver_list="${can_ver_list}, ${pver}-${pbuild}" | ||
2281 | fi | ||
2282 | done | ||
2283 | |||
2284 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2285 | echo "following candidate(s) will be removed:" | ||
2286 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2287 | niro | 240 | echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" |
2288 | niro | 226 | echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
2289 | echo | ||
2290 | niro | 240 | if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] |
2291 | then | ||
2292 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2293 | echo "( Press [CTRL+C] to abort )" | ||
2294 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2295 | echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." | ||
2296 | for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) | ||
2297 | do | ||
2298 | echo -ne "${COLRED} ${i}${COLDEFAULT}" | ||
2299 | sleep 1 | ||
2300 | done | ||
2301 | echo | ||
2302 | echo | ||
2303 | fi | ||
2304 | niro | 226 | |
2305 | for pkg in ${list} | ||
2306 | do | ||
2307 | pcat=$(dep2pcat ${pkg}) | ||
2308 | pname=$(magename2pname ${pkg}) | ||
2309 | pver=$(magename2pver ${pkg}) | ||
2310 | pbuild=$(magename2pbuild ${pkg}) | ||
2311 | |||
2312 | mage_uninstall \ | ||
2313 | --pcat ${pcat} \ | ||
2314 | --pname ${pname} \ | ||
2315 | --pver ${pver} \ | ||
2316 | --pbuild ${pbuild} \ | ||
2317 | --count-total ${total_pkgs} \ | ||
2318 | --count-current ${current_pkg} \ | ||
2319 | ${src_install} | ||
2320 | |||
2321 | # crlf for better view in VERBOSE mode | ||
2322 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
2323 | echo | ||
2324 | done | ||
2325 | } | ||
2326 | |||
2327 | mage_uninstall() | ||
2328 | { | ||
2329 | # local all possible vars of a mage file | ||
2330 | # to prevent bad issues | ||
2331 | local PKGNAME | ||
2332 | local STATE | ||
2333 | local DESCRIPTION | ||
2334 | local HOMEPAGE | ||
2335 | local DEPEND | ||
2336 | local SDEPEND | ||
2337 | local PROVIDE | ||
2338 | local PKGTYPE | ||
2339 | local preinstall | ||
2340 | local postinstall | ||
2341 | niro | 248 | local preremove |
2342 | local postremove | ||
2343 | niro | 226 | |
2344 | local pcat | ||
2345 | local pname | ||
2346 | local pver | ||
2347 | local pbuild | ||
2348 | local magefile | ||
2349 | local i | ||
2350 | |||
2351 | # very basic getops | ||
2352 | for i in $* | ||
2353 | do | ||
2354 | case $1 in | ||
2355 | --pcat|-c) shift; pcat="$1" ;; | ||
2356 | --pname|-n) shift; pname="$1" ;; | ||
2357 | --pver|-v) shift; pver="$1" ;; | ||
2358 | --pbuild|-b) shift; pbuild="$1" ;; | ||
2359 | esac | ||
2360 | shift | ||
2361 | done | ||
2362 | |||
2363 | # sanity checks; abort if not given | ||
2364 | [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given." | ||
2365 | [ -z "${pname}" ] && die "mage_uninstall() \$pname not given." | ||
2366 | [ -z "${pver}" ] && die "mage_uninstall() \$pver not given." | ||
2367 | [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given." | ||
2368 | |||
2369 | # check needed global vars | ||
2370 | [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set." | ||
2371 | [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set." | ||
2372 | [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set." | ||
2373 | |||
2374 | xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]" | ||
2375 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" | ||
2376 | echo -n "removing: " | ||
2377 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2378 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" | ||
2379 | |||
2380 | niro | 240 | magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
2381 | niro | 226 | source ${magefile} |
2382 | |||
2383 | ## preremove scripts | ||
2384 | if [ -n "$(typeset -f preremove)" ] | ||
2385 | then | ||
2386 | echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... " | ||
2387 | preremove | ||
2388 | unset preremove | ||
2389 | fi | ||
2390 | |||
2391 | # runs uninstall | ||
2392 | build_douninstall \ | ||
2393 | --pcat "${pcat}" \ | ||
2394 | --pname "${pname}" \ | ||
2395 | --pver "${pver}" \ | ||
2396 | --pbuild "${pbuild}" | ||
2397 | |||
2398 | ## postremove scripts | ||
2399 | if [ -n "$(typeset -f postremove)" ] | ||
2400 | then | ||
2401 | echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... " | ||
2402 | postremove | ||
2403 | unset postremove | ||
2404 | fi | ||
2405 | |||
2406 | # removes the database entry | ||
2407 | remove_database_entry \ | ||
2408 | --pcat "${pcat}" \ | ||
2409 | --pname "${pname}" \ | ||
2410 | --pver "${pver}" \ | ||
2411 | --pbuild "${pbuild}" \ | ||
2412 | || die "error in mage_uninstall() running remove_database_entry()." | ||
2413 | |||
2414 | # rebuilds toplevel info node | ||
2415 | if [[ ${MAGE_INFO_REBUILD} = true ]] | ||
2416 | then | ||
2417 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2418 | echo -n "rebuilding top-level info node ... " | ||
2419 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ | ||
2420 | > ${MROOT}/usr/share/info/dir && \ | ||
2421 | echo "done." || echo "failure." | ||
2422 | unset MAGE_INFO_REBUILD | ||
2423 | fi | ||
2424 | |||
2425 | # rebuilds the enviroment with the content of /etc/env.d | ||
2426 | if [[ ${MAGE_ENV_REBUILD} = true ]] | ||
2427 | then | ||
2428 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2429 | echo -n "rebuilding environment ... " | ||
2430 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ | ||
2431 | echo "done." || echo "failure." | ||
2432 | unset MAGE_ENV_REBUILD | ||
2433 | fi | ||
2434 | |||
2435 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2436 | echo -n "package " | ||
2437 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2438 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " | ||
2439 | echo "successfully removed." | ||
2440 | niro | 248 | |
2441 | niro | 258 | # unset these functions |
2442 | unset -f preinstall | ||
2443 | unset -f postinstall | ||
2444 | unset -f preremove | ||
2445 | unset -f postremove | ||
2446 | niro | 226 | } |
2447 | |||
2448 | show_etc_update_mesg() { | ||
2449 | [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 | ||
2450 | |||
2451 | echo | ||
2452 | echo -ne "${COLRED}" | ||
2453 | echo "Important:" | ||
2454 | echo -ne ${COLDEFAULT} | ||
2455 | echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed." | ||
2456 | echo | ||
2457 | echo "Please run 'etc-update' to update your configuration files." | ||
2458 | echo | ||
2459 | } | ||
2460 | niro | 237 | |
2461 | pkgsearch() | ||
2462 | { | ||
2463 | local string="$1" | ||
2464 | local result | ||
2465 | local pkg | ||
2466 | local pcat | ||
2467 | local pname | ||
2468 | local magefile | ||
2469 | local pver | ||
2470 | local pbuild | ||
2471 | local state | ||
2472 | local descriptiom | ||
2473 | local homepage | ||
2474 | local i | ||
2475 | local all_installed | ||
2476 | local ipver | ||
2477 | local ipbuild | ||
2478 | |||
2479 | # only names no versions | ||
2480 | result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)" | ||
2481 | #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)" | ||
2482 | |||
2483 | # nothing found | ||
2484 | [[ -z ${result} ]] && die "No package found containing '${string}' in the name." | ||
2485 | |||
2486 | for pkg in ${result} | ||
2487 | do | ||
2488 | # dirty, but does the job | ||
2489 | pcat="$(magename2pcat ${pkg}/foo)" | ||
2490 | pname="$(magename2pname ${pkg}-foo-foo)" | ||
2491 | |||
2492 | # get highest version available | ||
2493 | magefile=$(get_highest_magefile ${pcat} ${pname}) | ||
2494 | |||
2495 | # now get all needed infos to print a nice output | ||
2496 | pver="$(magename2pver ${magefile})" | ||
2497 | pbuild="$(magename2pbuild ${magefile})" | ||
2498 | state="$(get_value_from_magefile STATE ${magefile})" | ||
2499 | description="$(get_value_from_magefile DESCRIPTION ${magefile})" | ||
2500 | homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" | ||
2501 | |||
2502 | # all installed | ||
2503 | for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) | ||
2504 | do | ||
2505 | ipver="$(magename2pver ${i})" | ||
2506 | ipbuild="$(magename2pbuild ${i})" | ||
2507 | |||
2508 | if [[ -z ${all_installed} ]] | ||
2509 | then | ||
2510 | all_installed="${ipver}-${ipbuild}" | ||
2511 | else | ||
2512 | all_installed="${all_installed} ${ipver}-${ipbuild}" | ||
2513 | fi | ||
2514 | done | ||
2515 | [[ -z ${all_installed} ]] && all_installed="none" | ||
2516 | |||
2517 | case ${state} in | ||
2518 | stable) state=${COLGREEN}"[s] ";; | ||
2519 | testing) state=${COLYELLOW}"[t] ";; | ||
2520 | unstable) state=${COLRED}"[u] ";; | ||
2521 | old) state=${COLGRAY}"[o] ";; | ||
2522 | esac | ||
2523 | |||
2524 | echo -e "${state}${pcat}/${pname}"${COLDEFAULT} | ||
2525 | echo " Latest available: ${pver}-${pbuild}" | ||
2526 | echo " Installed versions: ${all_installed}" | ||
2527 | echo " Description: ${description}" | ||
2528 | echo " Homepage: ${homepage}" | ||
2529 | echo | ||
2530 | |||
2531 | unset pcat | ||
2532 | unset pname | ||
2533 | unset magefile | ||
2534 | unset pver | ||
2535 | unset pbuild | ||
2536 | unset state | ||
2537 | unset descriptiom | ||
2538 | unset homepage | ||
2539 | unset all_installed | ||
2540 | unset ipver | ||
2541 | unset ipbuild | ||
2542 | done | ||
2543 | } | ||
2544 | niro | 249 | |
2545 | export_inherits() | ||
2546 | { | ||
2547 | local include="$1" | ||
2548 | shift | ||
2549 | |||
2550 | while [ "$1" ] | ||
2551 | do | ||
2552 | local functions="$1" | ||
2553 | |||
2554 | # sanity checks | ||
2555 | [ -z "${include}" ] && die "export_inherits(): \$include not given." | ||
2556 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." | ||
2557 | |||
2558 | eval "${functions}() { ${include}_${functions} ; }" | ||
2559 | |||
2560 | # debug | ||
2561 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" | ||
2562 | |||
2563 | shift | ||
2564 | done | ||
2565 | } |