-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_alpine.sh
executable file
·95 lines (73 loc) · 3.01 KB
/
install_alpine.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
#!/bin/sh
SCRIPTDIR=$(dirname $(readlink -f $0))
. ${SCRIPTDIR}/settings.sh
# Define whether we build or download alpine
BUILD=0
# The size of the card image in MiB
IMAGE_SIZE=64
IMAGE_NAME=./alpine-${VERSION}.img
# Create an image file of appropriate size
dd if=/dev/zero of=${IMAGE_NAME} bs=1M count=${IMAGE_SIZE}
# Sorry if you were using any loop devices (Not all losetup supports option -D)!
sudo losetup -D > /dev/null 2>&1
sudo kpartx -av ${IMAGE_NAME}
DISK=`sudo losetup -a | grep -o -m 1 "/dev/loop[0-9].*${IMAGE_NAME}" | grep -o "/dev/loop[0-9]"`
echo "Using ${DISK} as the target device!"
if [ "N" = "N${DISK}" ]; then
echo "No Target Found!"
exit 1
fi
if [ ${BUILD} -eq 1 ]; then
# Make sure u-boot has been built, otherwise build it now
if [ ! -f uboot/u-boot/u-boot-git/MLO ]; then
echo "u-boot has not been built, building now..."
uboot/build_bbb.sh
if [ ! -f uboot/u-boot/u-boot-git/MLO ]; then
echo "u-boot did not build successfully!"
exit 1
fi
fi
# Check the linux build is complete, otherwise attempt to build it now...
if [ ! -f ./linux-grsec/kernel/deploy/boot/vmlinuz-grsec ]; then
echo "The kernel has not been built, building now..."
linux-grsec/build_bbb.sh
if [ ! -f ./linux-grsec/kernel/deploy/boot/vmlinuz-grsec ]; then
echo "The kernel didn't built. Awww shucks!"
exit 1
fi
fi
# The u-boot binaries we're going to boot from
uboot_MLO=${SCRIPTDIR}/build/u-boot/am335x_boneblack/MLO
uboot_img=${SCRIPTDIR}/build/u-boot/am335x_boneblack/u-boot.img
else
echo "Downloading Alpine ${VERSION}"
mkdir -p ${SCRIPTDIR}/build/dl
wget -P ${SCRIPTDIR}/build/dl -c http://dl-cdn.alpinelinux.org/alpine/v3.4/releases/armhf/alpine-uboot-3.4.0-armhf.tar.gz
cd ${SCRIPTDIR}/build
tar -xzf ${SCRIPTDIR}/build/dl/alpine-uboot-3.4.0-armhf.tar.gz
# The u-boot binaries we're going to boot from
uboot_MLO=${SCRIPTDIR}/build/u-boot/am335x_boneblack/MLO
uboot_img=${SCRIPTDIR}/build/u-boot/am335x_boneblack/u-boot.img
fi
# See: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
# The above is a bit out of date though, as u-boot can now handle ext4 filesystems so long as
# journalling is disabled. Disabling journalling for a flash filesystem is a good idea anyway.
sudo dd if=${uboot_MLO} of=${DISK} count=1 seek=1 bs=128k
sudo dd if=${uboot_img} of=${DISK} count=2 seek=1 bs=384k
sudo parted -s ${DISK} mklabel msdos
sudo parted -s ${DISK} mkpart primary ext4 1M ${IMAGE_SIZE}
# I'm paranoid with syncs when working with images and SD Cards!
sync
sudo partprobe ${DISK}
sync
sudo mkfs.ext4 -O ^has_journal ${DISK}p1 -L rootfs
sudo mkdir -p /media/rootfs/
sudo mount ${DISK}p1 /media/rootfs/
sudo cp -rv ${SCRIPTDIR}/build/boot /media/rootfs/
sudo cp -rv ${SCRIPTDIR}/build/apks /media/rootfs/boot/
sudo cp -rv ${SCRIPTDIR}/build/extlinux /media/rootfs/boot/
sync
sudo umount /media/rootfs
# Remove the disk we've used
sudo losetup -d ${DISK}
exit 0