[package] block-mount,block-extroot: Modify mount.sh so that block-extroot mounts...
[openwrt/svn-archive/archive.git] / package / block-mount / files / mount.sh
1 #!/bin/sh
2 # Copyright 2010 Vertical Communications
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5 #
6
7
8 pi_include /lib/functions/block.sh
9 pi_include /lib/functions/fsck.sh
10
11 config_mount_by_section() {
12 local cfg="$1"
13 local find_rootfs="$2"
14
15 mount_cb() {
16 local cfg="$1"
17 local device="$2"
18 shift
19 local target="$2"
20 local cfgdevice="$3"
21 local fstype="$4"
22 local options="$5"
23 local enabled="$6"
24 local enabled_fsck="$7"
25 local uuid="$8"
26 local label="$9"
27 shift
28 local is_rootfs="$9"
29 shift
30 local found_device=""
31
32 found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
33 if [ -n "$found_device" ]; then
34 if [ -z "$find_rootfs" ] || [ "$find_rootfs" -eq 0 ] || ( [ "$is_rootfs" -eq 1 ] || [ "$target" = "/" ] || [ "$target" = "/overlay" ] ); then
35 [ "$enabled_fsck" -eq 1 ] && {
36 grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
37 libmount_fsck "$found_device" "$fstype" "$enabled_fsck"
38 }
39 }
40
41 if [ "$find_rootfs" -eq 1 ]; then
42 if [ "$is_rootfs" -eq 1 ]; then
43 target=/overlay
44 fi
45 else
46 if [ "$is_rootfs" -eq 1 ] || [ "$target" = "/overlay" ]; then
47 target=/tmp/overlay-disabled
48 fi
49 fi
50
51 config_create_mount_fstab_entry "$found_device" "$target" "$fstype" "$options" "$enabled"
52 grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
53 [ "$enabled" -eq 1 ] && mkdir -p "$target" && mount "$target" 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
54 }
55
56 fi
57 fi
58 [ "$find_rootfs" -eq 1 ] && {
59 [ "$target" = "/overlay" ] && {
60 rootfs_found=1
61 }
62 }
63 return 0
64 }
65 config_get_mount "$cfg"
66 reset_block_cb
67 }
68
69 config_swapon_by_section() {
70 local cfg="$1"
71
72 swap_cb() {
73 local cfg="$1"
74 local device="$2"
75 local cfgdevice="$3"
76 local enabled="$4"
77 local uuid="$5"
78 local label="$6"
79 local uuid
80 local label
81
82 local found_device=""
83
84 found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
85
86 if [ -n "$found_device" ]; then
87 config_create_swap_fstab_entry "$found_device" "$enabled"
88 grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
89 [ "$enabled" -eq 1 ] && swapon "$found_device" | tee /proc/self/fd/2 | logger -t 'fstab'
90 }
91 fi
92 return 0
93 }
94 config_get_swap "$cfg"
95 reset_block_cb
96 }