forked from volumio/Build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·206 lines (183 loc) · 5.67 KB
/
build.sh
File metadata and controls
executable file
·206 lines (183 loc) · 5.67 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash -x
# Volumio Image Builder
# Copyright Michelangelo Guarise - Volumio.org
#
# TODO: Add gé credits
#
# Dependencies:
# parted squashfs-tools dosfstools multistrap qemu binfmt-support qemu-user-static kpartx
#Set fonts for Help.
NORM=`tput sgr0`
BOLD=`tput bold`
REV=`tput smso`
tput reset
ARCH=none
#Help function
function HELP {
echo -e \\n"Help documentation for Volumio Image Builder"\\n
echo -e "Basic usage: ./build.sh -b -d all -v 2.0"\\n
echo "Switches:"
echo "-b --Build system with Multistrap, use arm or x86 to select architecture"
echo "-d --Create Image for Specific Devices. Usage: all (all), pi, udoo, cuboxi, bbb, cubietruck, compulab, odroidc1, odroidc2, odroidxu4"
echo "-l --Create docker layer. Docker Repository name as as argument"
echo "-v --Version, must be a dot separated number. Example 1.102"
echo "-p --Patch, optionally patch the builder"
echo -e "Example: Build a Raspberry PI image from scratch, version 2.0 : ./build.sh -b arm -d pi -v 2.0 -l reponame "\\n
exit 1
}
#$1 = ${BUILD} $2 = ${VERSION} $3 = ${DEVICE}"
function check_os_release {
ARCH_BUILD=$1
HAS_VERSION=$(grep -c VOLUMIO_VERSION build/${ARCH_BUILD}/root/etc/os-release)
VERSION=$2
DEVICE=$3
if [ "$HAS_VERSION" -eq "0" ]; then
echo "VOLUMIO_VERSION=\"${VERSION}\"" >> build/${ARCH_BUILD}/root/etc/os-release
echo "VOLUMIO_HARDWARE=\"${DEVICE}\"" >> build/${ARCH_BUILD}/root/etc/os-release
fi
}
#Check the number of arguments. If none are passed, print help and exit.
NUMARGS=$#
if [ $NUMARGS -eq 0 ]; then
HELP
fi
while getopts b:v:d:l:p:e FLAG; do
case $FLAG in
b)
BUILD=$OPTARG
;;
d)
DEVICE=$OPTARG
;;
v)
VERSION=$OPTARG
;;
l)
#Create docker layer
CREATE_DOCKER_LAYER=1
DOCKER_REPOSITORY_NAME=$OPTARG
;;
p)
PATCH=$OPTARG
;;
h) #show help
HELP
;;
/?) #unrecognized option - show help
echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed."
HELP
;;
esac
done
shift $((OPTIND-1))
if [ -n "$BUILD" ]; then
if [ "$BUILD" = arm ]; then
ARCH="armhf"
echo "Building ARM Base System"
elif [ "$BUILD" = x86 ]; then
echo 'Building X86 Base System'
ARCH="i386"
fi
if [ -d build/$BUILD ]
then
echo "Build folder exist, cleaning it"
rm -rf build/$BUILD/*
else
echo "Creating build folder"
mkdir build
fi
mkdir build/$BUILD
mkdir build/$BUILD/root
multistrap -a $ARCH -f recipes/$BUILD.conf
if [ "$BUILD" = arm ] || [ "$BUILD" = arm-dev ]; then
cp /usr/bin/qemu-arm-static build/arm/root/usr/bin/
fi
cp scripts/volumioconfig.sh build/$BUILD/root
sudo mount /dev build/$BUILD/root/dev -o bind
sudo mount /proc build/$BUILD/root/proc -t proc
sudo mount /sys build/$BUILD/root/sys -t sysfs
echo 'Cloning Volumio Node Backend'
mkdir build/$BUILD/root/volumio
git clone https://github.com/volumio/Volumio2.git build/$BUILD/root/volumio
echo 'Cloning Volumio UI'
git clone -b dist --single-branch https://github.com/volumio/Volumio2-UI.git build/$BUILD/root/volumio/http/www
if [ "$BUILD" = arm ] || [ "$BUILD" = arm-dev ]; then
chroot build/arm/root /bin/bash -x <<'EOF'
su -
./volumioconfig.sh
EOF
elif [ "$BUILD" = x86 ] || [ "$BUILD" = x86-dev ]; then
chroot build/x86/root /volumioconfig.sh
fi
echo "Adding information in os-release"
echo '
' >> build/${BUILD}/root/etc/os-release
echo "Base System Installed"
rm build/$BUILD/root/volumioconfig.sh
###Dirty fix for mpd.conf TODO use volumio repo
cp volumio/etc/mpd.conf build/$BUILD/root/etc/mpd.conf
## EHU fix to enable apt-get update to resolve URL while in qemu mod
sudo cp /etc/resolv.conf build/$BUILD/root/etc/resolv.conf
CUR_DATE=$(date)
#Write some Version informations
echo "Writing system information"
echo "VOLUMIO_VARIANT=\"volumio\"
VOLUMIO_TEST=\"FALSE\"
VOLUMIO_BUILD_DATE=\"${CUR_DATE}\"
" >> build/${BUILD}/root/etc/os-release
echo "Unmounting Temp devices"
sudo umount -l build/$BUILD/root/dev
sudo umount -l build/$BUILD/root/proc
sudo umount -l build/$BUILD/root/sys
sh scripts/configure.sh -b $BUILD
fi
if [ -n "$PATCH" ]; then
echo "Copying Patch to Rootfs"
cp -rp $PATCH build/$BUILD/root/
else
PATCH='volumio'
fi
if [ "$DEVICE" = pi ]; then
echo 'Writing Raspberry Pi Image File'
check_os_release "arm" $VERSION $DEVICE
sh -x scripts/raspberryimage.sh -v $VERSION -p $PATCH;
fi
if [ "$DEVICE" = udoo ]; then
echo 'Writing UDOO Image File'
sh scripts/udooimage.sh -v $VERSION ;
fi
if [ "$DEVICE" = cuboxi ]; then
echo 'Writing Cubox-i Image File'
sh scripts/cuboxiimage.sh -v $VERSION;
fi
if [ "$DEVICE" = odroidc1 ]; then
echo 'Writing Odroid-C1/C1+ Image File'
check_os_release "arm" $VERSION $DEVICE
sh scripts/odroidc1image.sh -v $VERSION -p $PATCH;
fi
if [ "$DEVICE" = odroidc2 ]; then
echo 'Writing Odroid-C2 Image File'
check_os_release "arm" $VERSION $DEVICE
sh scripts/odroidc2image.sh -v $VERSION -p $PATCH;
fi
if [ "$DEVICE" = odroidxu4 ]; then
echo 'Writing Odroid-XU4 Image File'
check_os_release "arm" $VERSION $DEVICE
sh scripts/odroidxu4image.sh -v $VERSION -p $PATCH;
fi
if [ "$DEVICE" = udooneo ]; then
echo 'Writing UDOO NEO Image File'
check_os_release "arm" $VERSION $DEVICE
sh scripts/udooneoimage.sh -v $VERSION -p $PATCH;
fi
if [ "$DEVICE" = x86 ]; then
echo 'Writing x86 Image File'
check_os_release "x86" $VERSION $DEVICE
sh scripts/x86.sh -v $VERSION -p $PATCH;
fi
#When the tar is created we can build the docker layer
if [ "$CREATE_DOCKER_LAYER" = 1 ]; then
echo 'Creating docker layer'
DOCKER_UID="$(sudo docker import VolumioRootFS$VERSION.tar.gz $DOCKER_REPOSITORY_NAME)"
echo $DOCKER_UID
fi