Magellan Linux

Annotation of /alx-src/trunk/alxinstall-ng/functions/generic.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6836 - (hide 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)
-renamed INSTALLPATH variable to INSTALL_ROOT
1 niro 6829 #!/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 niro 6831
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 niro 6836 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 niro 6831 echo "installation aborted"
64     exit 1
65     }
66 niro 6833
67     enter_chroot()
68     {
69     local cmd="$@"
70    
71 niro 6836 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 niro 6833
75 niro 6836 chroot ${INSTALL_ROOT} ${cmd} || die "enter_chroot() '${INSTALL_ROOT}' '${cmd}'"
76 niro 6833
77 niro 6836 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 niro 6833 }
81    
82     enter_chroot_installrc()
83     {
84 niro 6836 [ -f ${INSTALL_ROOT}/.installrc ] || die "enter_chroot_installrc() ${INSTALL_ROOT}/.installrc missing"
85 niro 6833 enter_chroot /bin/bash -i /.installrc || die "enter_chroot_installrc() run"
86 niro 6836 [ -f ${INSTALL_ROOT}/.installrc ] && rm ${INSTALL_ROOT}/.installrc
87 niro 6833 }