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