-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathimage.sh
More file actions
executable file
·51 lines (47 loc) · 1.27 KB
/
image.sh
File metadata and controls
executable file
·51 lines (47 loc) · 1.27 KB
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
#!/bin/bash
imgfile=$1
action=$2
if [[ ! -e "$imgfile" ]];then echo "no filename given";exit;fi
board=$(echo $imgfile | sed -e 's/_.*$//')
source config.sh
function mount_image()
{
newimgfile=$1
LDEV=$(sudo losetup -f)
echo "unpack imgfile ($newimgfile)..."
gunzip $newimgfile
echo "setting up imgfile to loopdev..."
sudo losetup ${LDEV} ${newimgfile%.*} 1> /dev/null
if [[ $? -ne 0 ]];then echo "losetup ${LDEV} failed (${newimgfile%.*})"; exit 1; fi
echo "mounting loopdev..."
sudo partprobe ${LDEV}
if [[ $? -ne 0 ]];then echo "partprobe failed"; exit 1; fi
mkdir -p mnt/BPI-{B,R}OOT
echo "mount ${LDEV}p${mmcbootpart} => mnt/BPI-BOOT"
sudo mount ${LDEV}p${mmcbootpart} mnt/BPI-BOOT
if [[ $? -ne 0 ]];then echo "mounting BPI-BOOT failed"; exit 1; fi
echo "mount ${LDEV}p${mmcrootpart} => mnt/BPI-ROOT"
sudo mount ${LDEV}p${mmcrootpart} mnt/BPI-ROOT
if [[ $? -ne 0 ]];then echo "mounting BPI-ROOT failed"; exit 1; fi
}
function umount_image()
{
imgfile=$1
LDEV=$(sudo losetup -l | grep $imgfile | awk '{print $1}')
sudo umount ${LDEV}p*
sudo losetup -d $LDEV
}
case $action in
"mount")
echo "mounting image $imgfile ..."
mount_image $imgfile
;;
"umount")
echo "umounting image $imgfile ..."
umount_image $imgfile
;;
*)
echo "invalid action"
exit 1
;;
esac