-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemmc_copy_rootfs.sh
executable file
·91 lines (74 loc) · 1.93 KB
/
emmc_copy_rootfs.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
#!/bin/sh
#
# Script to install a system onto the BBB eMMC.
# This script handles the root file system partition.
#
# Run it like this:
#
# ./emmc_copy_rootfs.sh <image-file> [ <hostname> ]
#
MACHINE=beaglebone
DEV=/dev/mmcblk1p2
if [ -z "${SRCDIR}" ]; then
SRCDIR=.
else
if [ ! -d "${SRCDIR}" ]; then
echo "Source directory not found: ${SRCDIR}"
exit 1
fi
fi
if [ "x${1}" = "x" ]; then
echo -e "\nUsage: ${0} <image-name> [<hostname>]\n"
exit 0
fi
if [ ! -d /media ]; then
echo "Mount point /media does not exist"
exit 1
fi
if [ ! -b $DEV ]; then
echo "Block device not found: $DEV"
exit 1
fi
if [ -f "${1}" ]; then
FULLPATH="${1}"
elif [ -f "${SRCDIR}/${1}" ]; then
FULLPATH="${SRCDIR}/${1}"
elif [ -f "${SRCDIR}/${1}-${MACHINE}.tar.xz" ]; then
FULLPATH="${SRCDIR}/${1}-${MACHINE}.tar.xz"
elif [ -f "${SRCDIR}/${1}-image-${MACHINE}.tar.xz" ]; then
FULLPATH="${SRCDIR}/${1}-image-${MACHINE}.tar.xz"
else
echo "Rootfs image file not found."
echo "Tried the following:"
echo "${1}"
echo "${SRCDIR}/${1}"
echo "${SRCDIR}/${1}-${MACHINE}.tar.xz"
echo "${SRCDIR}/${1}-image-${MACHINE}.tar.xz"
exit 1
fi
if [ "x${2}" = "x" ]; then
TARGET_HOSTNAME=$MACHINE
else
TARGET_HOSTNAME=${2}
fi
echo -e "HOSTNAME: $TARGET_HOSTNAME\n"
echo "Formatting $DEV as ext4"
mkfs.ext4 -q -L ROOT $DEV
echo "Mounting $DEV as /media"
mount $DEV /media
echo "Extracting ${FULLPATH} to /media"
tar -C /media -xJf ${FULLPATH}
echo "Writing hostname to /etc/hostname"
export TARGET_HOSTNAME
echo ${TARGET_HOSTNAME} > /media/etc/hostname
if [ -f ${SRCDIR}/interfaces ]; then
echo "Writing interfaces to /media/etc/network/"
cp ${SRCDIR}/interfaces /media/etc/network/interfaces
fi
if [ -f ${SRCDIR}/wpa_supplicant.conf ]; then
echo "Writing wpa_supplicant.conf to /media/etc/"
cp ${SRCDIR}/wpa_supplicant.conf /media/etc/wpa_supplicant.conf
fi
echo "Unmounting $DEV"
umount $DEV
echo "Done"