forked from asyrique/picake
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·85 lines (68 loc) · 2.33 KB
/
build.sh
File metadata and controls
executable file
·85 lines (68 loc) · 2.33 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
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
#!/bin/bash
# Bash strict mode
set -euv
IFS=$'\n\t'
echo "$(which bash)"
# Get script directory
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo -e "\e[1;32mCurrent directory is $DIR\e[0m"
# Create directories for image build
echo -e "\e[1;32mCreating build directories\e[0m"
mkdir -p /srv/builddir
mkdir -p /srv/builddir/src /srv/builddir/img /srv/builddir/tmpmnt
mkdir -p /srv/builddir/tmpmnt/boot /srv/builddir/tmpmnt/root
# Download latest Arch ARM image to builddir
echo -e "\e[1;32mStarted downloading Arch image\e[0m"
wget -q http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz -O /srv/builddir/src/ArchLinuxARM-rpi-2-latest.tar.gz
if [ $? -eq 0 ]; then
echo -e "\e[1;32mGot arch image\e[0m"
else
echo -e "\e[1;31mArch image download failed\e[0m"
fi
# Allocate build image
echo -e "\e[1;32mStarted allocate disk image\e[0m"
# truncate is only tested on Ubuntu 14.04. Please replace with the correct command for your distro
truncate -s 4G /srv/builddir/img/rpi2-musedboxbase.img
echo -e "\e[1;32mDisk image created at /srv/builddir/img/rpi2-musedboxbase.img\e[0m"
# Begin partitioning disk image.
# Creating two partitions:
# BOOT = 100 MB
# ROOT = 3900 MB
fdisk /srv/builddir/img/rpi2-musedboxbase.img <<EOF
o
n
p
1
+100M
t
c
n
p
2
w
EOF
# Create a loop device and mount the disk image
export LOOPDEV="$(losetup --show --find /srv/builddir/img/rpi2-musedboxbase.img)"
echo -e "\e[1;32mLoop device is ${LOOPDEV}\e[0m"
# Use kpartx to create partitions in /dev/mapper
kpartx -av $LOOPDEV
dmsetup --noudevsync mknodes
# Create partition names to mount
export BOOTPART=$(echo $LOOPDEV | sed 's|'/dev'/|'/dev/mapper/'|')p1
export ROOTPART=$(echo $LOOPDEV | sed 's|'/dev'/|'/dev/mapper/'|')p2
# Create filesystems for the partitions
mkfs.vfat $BOOTPART
mkfs.ext4 $ROOTPART
# Mount filesystems in tmpmnt
mount $BOOTPART -t vfat /srv/builddir/tmpmnt/boot
mount $ROOTPART -t ext4 /srv/builddir/tmpmnt/root
# Extract all the files to the image root
bsdtar -xpf /srv/builddir/src/ArchLinuxARM-rpi-2-latest.tar.gz -C /srv/builddir/tmpmnt/root
sync
mv /srv/builddir/tmpmnt/root/boot/* /srv/builddir/tmpmnt/boot/
# Mount proot and run commands inside
proot -q qemu-arm-static -S /srv/builddir/tmpmnt/root -b /srv/builddir/tmpmnt/boot:/boot /bin/bash < $DIR/src/config/env <<EOF
source /host-rootfs$DIR/src/scripts/arch-build.sh
EOF
sync
exit 0