Annotation of /alx-src/trunk/alxinstall-ng/functions/generic.sh
Parent Directory | Revision Log
Revision 6831 -
(hide annotations)
(download)
(as text)
Thu Jul 23 12:04:49 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 1164 byte(s)
Thu Jul 23 12:04:49 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 1164 byte(s)
-introduce is_loc_mounted() function and set proper exit traps
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 | is_loc_mounted "${INSTALLPATH}/dev" && umount ${INSTALLPATH}/dev | ||
59 | is_loc_mounted "${INSTALLPATH}/proc" && umount ${INSTALLPATH}/proc | ||
60 | is_loc_mounted "${INSTALLPATH}/sys" && umount ${INSTALLPATH}/sys | ||
61 | is_loc_mounted "${INSTALLPATH}/boot" && umount ${INSTALLPATH}/boot | ||
62 | is_loc_mounted "${INSTALLPATH}" && umount ${INSTALLPATH} | ||
63 | echo "installation aborted" | ||
64 | exit 1 | ||
65 | } |