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