-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage_boot_flag_partition.sh
executable file
·232 lines (164 loc) · 3.92 KB
/
manage_boot_flag_partition.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/sh
MOUNT_DIR=/mnt/bootflags
FLAGS_PARTITION=/dev/mmcblk0p5
echo -e -n "\nChecking for an eMMC : "
ls /dev/mmc* | grep -q mmcblk0
if [ $? -eq 1 ]; then
echo "FAIL"
echo "There is no /dev/mmcblk0"
exit 1
fi
echo "OK"
echo -e -n "Checking that there is no SD card : "
ls /dev/mmc* | grep -q mmcblk1
if [ $? -eq 0 ]; then
echo "FAIL"
echo "An SD card is present. Not going to continue."
exit 1
fi
echo "OK"
echo -e -n "Finding the current root partition : "
cat /proc/cmdline | grep -q mmcblk0p2
if [ $? -eq 0 ]; then
CURRENT_ROOT=/dev/mmcblk0p2
else
cat /proc/cmdline | grep -q mmcblk0p3
if [ $? -eq 0 ]; then
CURRENT_ROOT=/dev/mmcblk0p3
else
echo "FAIL"
echo "Current root device is not mmcblk0p2 or mmcblk0p3"
exit 1
fi
fi
echo "${CURRENT_ROOT}"
echo -e -n "Checking there is a /dev/mmcblk0p5 partition : "
fdisk -l /dev/mmcblk0 | grep -q mmcblk0p5
if [ $? -eq 1 ]; then
echo "FAIL"
echo "There is no /dev/mmcblk0p5 partition"
exit 1
fi
echo "OK"
echo -e -n "Checking that ${FLAGS_PARTITION} is not in use : "
mount | grep -q ${FLAGS_PARTITION}
if [ $? -eq 0 ]; then
echo "FAIL"
echo "${FLAGS_PARTITION} is already mounted"
exit 1
fi
echo "OK"
echo -e -n "Checking if ${MOUNT_DIR} mount point exists : "
if [ ! -d ${MOUNT_DIR} ]; then
echo "NO"
echo -e -n "Attempting to create mount point ${MOUNT_DIR} :"
mkdir ${MOUNT_DIR}
if [ $? -eq 1 ]; then
echo "FAIL"
exit 1
else
echo "OK"
fi
else
echo "OK"
echo -e -n "Checking that ${MOUNT_DIR} is not in use : "
mount | grep -q ${MOUNT_DIR}
if [ $? -eq 0 ]; then
echo "FAIL"
echo "${MOUNT_DIR} is in use by another mounted filesystem"
exit 1
fi
echo "OK"
fi
echo -e -n "Mounting ${FLAGS_PARTITION} read-only on ${MOUNT_DIR} : "
mount -t vfat -o ro ${FLAGS_PARTITION} ${MOUNT_DIR}
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Failed to mount ${FLAGS_PARTITION} on ${MOUNT_DIR} as type vfat"
exit 1
fi
echo "OK"
echo -e -n "Checking flag files on ${FLAGS_PARTITION} : "
NEED_UPDATES=0
if [ "${CURRENT_ROOT}" = "/dev/mmcblk0p2" ]; then
if [ ! -e ${MOUNT_DIR}/two ]; then
NEED_UPDATES=1
fi
if [ ! -e ${MOUNT_DIR}/two_ok ]; then
NEED_UPDATES=1
fi
if [ -e ${MOUNT_DIR}/three ]; then
NEED_UPDATES=1
fi
if [ -e ${MOUNT_DIR}/three_ok ]; then
NEED_UPDATES=1
fi
else
if [ -e ${MOUNT_DIR}/two ]; then
NEED_UPDATES=1
fi
if [ -e ${MOUNT_DIR}/two_ok ]; then
NEED_UPDATES=1
fi
if [ ! -e ${MOUNT_DIR}/three ]; then
NEED_UPDATES=1
fi
if [ ! -e ${MOUNT_DIR}/three_ok ]; then
NEED_UPDATES=1
fi
fi
echo "OK"
echo -e -n "Unmounting ${FLAGS_PARTITION} : "
umount ${FLAGS_PARTITION}
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Failed to unmount ${FLAGS_PARTITION}"
exit 1
fi
echo "OK"
if [ ${NEED_UPDATES} -eq 0 ]; then
# no updates required
echo "Boot flags are up to date"
exit 0
fi
echo -e -n "Mounting ${FLAGS_PARTITION} read-write on ${MOUNT_DIR} : "
mount -t vfat ${FLAGS_PARTITION} ${MOUNT_DIR}
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Failed to mount ${FLAGS_PARTITION} on ${MOUNT_DIR} as type vfat"
exit 1
fi
echo "OK"
echo -e -n "Updating flags partition : "
if [ "${CURRENT_ROOT}" = "/dev/mmcblk0p2" ]; then
if [ ! -e ${MOUNT_DIR}/two ]; then
touch ${MOUNT_DIR}/two
fi
if [ ! -e ${MOUNT_DIR}/two_ok ]; then
touch ${MOUNT_DIR}/two_ok
fi
if [ -e ${MOUNT_DIR}/two_tried ]; then
rm ${MOUNT_DIR}/two_tried
fi
rm -rf ${MOUNT_DIR}/three*
else
if [ ! -e ${MOUNT_DIR}/three ]; then
touch /mnt/three
fi
if [ ! -e ${MOUNT_DIR}/three_ok ]; then
touch ${MOUNT_DIR}/three_ok
fi
if [ -e ${MOUNT_DIR}/three_tried ]; then
rm ${MOUNT_DIR}/three_tried
fi
rm -rf ${MOUNT_DIR}/two*
fi
echo "OK"
echo -e -n "Unmounting ${FLAGS_PARTITION} : "
umount ${FLAGS_PARTITION}
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Failed to unmount ${FLAGS_PARTITION}"
exit 1
fi
echo "OK"