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