-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflash-wifisd.sh
executable file
·59 lines (47 loc) · 1.2 KB
/
flash-wifisd.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
#!/bin/bash -e
#
if [ -z "${1}" ]; then
echo "specify the card device as first argument, e.g. /dev/sde"
exit 1
fi
# set sd-card device
DEVICE=${1}
# check if device is mounted
if [ -n "$(mount | grep /dev/sde)" ]; then
echo "Device is currently mounted. Please unmount first!"
exit 2
fi
echo "delete existing partitions"
(echo d; echo 2; echo d; echo w) | fdisk ${DEVICE} >/dev/null 2>&1
echo "create first partition"
(echo n; echo p; echo 1; echo; echo +12G; echo t; echo c; echo w) | fdisk ${DEVICE} >/dev/null 2>&1
echo "create second partition"
(echo n; echo p; echo 2; echo; echo; echo t; echo 2; echo c; echo w) | fdisk ${DEVICE} >/dev/null 2>&1
echo "format first partition"
mkfs.vfat ${DEVICE}1 >/dev/null
echo "format second partition"
mkfs.vfat ${DEVICE}2 >/dev/null
echo "mount first partition and copy files"
mount ${DEVICE}1 mnt-sd/
cp -fr sd/* mnt-sd/
RET=1
while [ ${RET} -gt 0 ]; do
sync
sleep 1
set +e
umount ${DEVICE}1
RET=$?
set -e
done
echo "mount second partition and copy files"
mount ${DEVICE}2 mnt-sd-ext/
cp -fr sd-ext/* mnt-sd-ext/
RET=1
while [ ${RET} -gt 0 ]; do
sync
sleep 1
set +e
umount ${DEVICE}2
RET=$?
set -e
done