Contents of /alx-src/trunk/alxinstall-ng/functions/generic.sh
Parent Directory | Revision Log
Revision 6836 -
(show annotations)
(download)
(as text)
Thu Jul 23 12:28:53 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 2025 byte(s)
Thu Jul 23 12:28:53 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 2025 byte(s)
-renamed INSTALLPATH variable to INSTALL_ROOT
1 | #!/bin/bash |
2 | # $Id$ |
3 | |
4 | addconfig() |
5 | { |
6 | local opts |
7 | |
8 | if [[ -z ${CONFIG} ]] |
9 | then |
10 | echo "You must define \$CONFIG varibale first!" |
11 | return 1 |
12 | fi |
13 | |
14 | if [[ ! -d $(dirname ${CONFIG}) ]] |
15 | then |
16 | install -d $(dirname ${CONFIG}) |
17 | fi |
18 | |
19 | # check for opts |
20 | case $1 in |
21 | -n) shift; opts=" -n" ;; |
22 | -e) shift; opts=" -e" ;; |
23 | esac |
24 | |
25 | echo ${opts} "$@" >> ${CONFIG} |
26 | } |
27 | |
28 | clearconfig() |
29 | { |
30 | if [[ -z ${CONFIG} ]] |
31 | then |
32 | echo "You must define \$CONFIG varibale first!" |
33 | return 1 |
34 | fi |
35 | |
36 | if [[ ! -d $(dirname ${CONFIG}) ]] |
37 | then |
38 | install -d $(dirname ${CONFIG}) |
39 | fi |
40 | : > ${CONFIG} |
41 | } |
42 | |
43 | is_loc_mounted() |
44 | { |
45 | local mountpoint |
46 | local i |
47 | mountpoint=$1 |
48 | |
49 | i="$(cat /proc/mounts | grep " ${mountpoint} " | cut -d ' ' -f2)" |
50 | [[ ${i} != ${mountpoint} ]] && return 1 |
51 | |
52 | return 0 |
53 | } |
54 | |
55 | trap_exit() |
56 | { |
57 | [[ -n ${SWAPHDD} ]] && swapoff ${SWAPHDD} |
58 | is_loc_mounted "${INSTALL_ROOT}/dev" && umount ${INSTALL_ROOT}/dev |
59 | is_loc_mounted "${INSTALL_ROOT}/proc" && umount ${INSTALL_ROOT}/proc |
60 | is_loc_mounted "${INSTALL_ROOT}/sys" && umount ${INSTALL_ROOT}/sys |
61 | is_loc_mounted "${INSTALL_ROOT}/boot" && umount ${INSTALL_ROOT}/boot |
62 | is_loc_mounted "${INSTALL_ROOT}" && umount ${INSTALL_ROOT} |
63 | echo "installation aborted" |
64 | exit 1 |
65 | } |
66 | |
67 | enter_chroot() |
68 | { |
69 | local cmd="$@" |
70 | |
71 | is_loc_mounted "${INSTALL_ROOT}/proc" || mount -t proc proc ${INSTALL_ROOT}/proc |
72 | is_loc_mounted "${INSTALL_ROOT}/sys" || mount -t sysfs sysfs ${INSTALL_ROOT}/sys |
73 | is_loc_mounted "${INSTALL_ROOT}/dev" || mount -o bind /dev ${INSTALL_ROOT}/dev |
74 | |
75 | chroot ${INSTALL_ROOT} ${cmd} || die "enter_chroot() '${INSTALL_ROOT}' '${cmd}'" |
76 | |
77 | is_loc_mounted "${INSTALL_ROOT}/dev" && umount ${INSTALL_ROOT}/dev |
78 | is_loc_mounted "${INSTALL_ROOT}/sys" && umount ${INSTALL_ROOT}/sys |
79 | is_loc_mounted "${INSTALL_ROOT}/proc" && umount ${INSTALL_ROOT}/proc |
80 | } |
81 | |
82 | enter_chroot_installrc() |
83 | { |
84 | [ -f ${INSTALL_ROOT}/.installrc ] || die "enter_chroot_installrc() ${INSTALL_ROOT}/.installrc missing" |
85 | enter_chroot /bin/bash -i /.installrc || die "enter_chroot_installrc() run" |
86 | [ -f ${INSTALL_ROOT}/.installrc ] && rm ${INSTALL_ROOT}/.installrc |
87 | } |