forked from xbianonpi/xbian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.buildroot
267 lines (233 loc) · 10.6 KB
/
create.buildroot
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
##
## Copyright (C) 2012 - 2014 XBian
##
## Find us at: http://www.xbian.org http://github.com/xbianonpi/xbian
##
## This Program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This Program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with XBMC; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
##
##
[ -n "$XBIANROOT" ] || export XBIANROOT=$(readlink -f ./)
if [ -e $XBIANROOT/common.functions ]; then
. $XBIANROOT/common.functions
else
echo "Wrong setup. Open folder containing xbianonpi/xbian clone and rerun \"./run.me prepare\""
exit 500
fi
do_wipe()
{
dir="$1"
do_run rm -fr "$dir/working"
}
do_prepare()
{
### CentOS doesn't have /sbin and /bin in $PATH by default
echo "Writing loader file /etc/profile.d/xbiangit.sh"
cat<<EOF>/etc/profile.d/xbiangit.sh
export xbiangit=$(pwd)/run.me
export XBIANROOT=$(pwd)
export PATH=/usr/lib/ccache:/sbin:/bin:\$PATH
export MAKEFLAGS="-j\$(grep -c processor /proc/cpuinfo )"
EOF
echo "Installing $config_deb_base"
if [ -f /etc/centos-release ]; then
VERSION_ID=0
if grep -q "5." /etc/centos-release; then VERSION_ID=5; fi
if grep -q "6." /etc/centos-release; then VERSION_ID=6; fi
if grep -q "7." /etc/centos-release; then VERSION_ID=7; fi
if [ $VERSION_ID -eq 5 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm --quiet -Uvh epel-release-5*.rpm
rm epel-release-5*.rpm
elif [ $VERSION_ID -eq 6 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --quiet -Uvh epel-release-6*.rpm
rm epel-release-6*.rpm
elif [ $VERSION_ID -eq 7 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm --quiet -Uvh epel-release-7*.rpm
rm epel-release-7*.rpm
else
echo "Cannot install EPEL repository in CentOS"
exit 500;
fi
yum install -y $config_yum_base 2>/dev/null 1>/dev/null
else
apt-get install -y --force-yes -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_deb_base 1>/dev/null
fi
echo "Installing done..."
}
do_deps()
{
dir=$(readlink -f "$1")
cp "$dir/extra-files/$config_platform.conf" /etc/schroot/chroot.d
sed -i "s%__DIR__%$config_root_prefix/$config_platform%" /etc/schroot/chroot.d/$config_platform.conf
mkdir -p $config_root_prefix/$config_platform
mkdir -p $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/04autoremove" $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/05xbian" $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/schroot-fstab" /etc/schroot/schroot-fstab-$config_platform
sed -i "s%__DIR__%$(readlink -f $fstabbind)%g" /etc/schroot/schroot-fstab-$config_platform
}
do_prep()
{
[ -e $config_root_prefix/$config_platform/debootstrap ] && return
dir=$(readlink -f "$1")
debootstrap --no-check-gpg --include=eatmydata --arch $config_distro_arch --foreign $config_distro_name $dir $config_distro_url
mkdir -p $dir/usr/bin; cp /usr/bin/qemu-arm-static $dir/usr/bin
eatmydata=($(grep eatmydata $config_root_prefix/$config_platform/debootstrap/debpaths | awk '{print $2}'))
for pkg in ${eatmydata[@]}; do
dpkg -x $config_root_prefix/$config_platform/$pkg $config_root_prefix/$config_platform
done
schroot --directory / -p -c $config_platform -- debootstrap/debootstrap --second-stage
echo "deb $config_distro_url $config_distro_name main" > $dir/etc/apt/sources.list
case "$config_platform" in
"amd64jessie")
echo "deb http://emdebian.org/tools/debian/ jessie main" >> $dir/etc/apt/sources.list
schroot -c $config_platform --directory / -p -- wget -qO- http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | schroot -c $config_platform -p -- apt-key add -
schroot -c $config_platform --directory / -p -- dpkg --add-architecture armhf
schroot -c $config_platform --directory / -p -- apt-get update
schroot -c $config_platform --directory / -p -- apt-get install -y --force-yes crossbuild-essential-armhf
;;
esac
schroot --directory / -p -c $config_platform -- apt-get clean
}
do_other()
{
dir=$(readlink -f "$1")
printf "#!/bin/sh\n\necho $config_xbian_arch\n" > $dir/usr/local/bin/xbian-arch; chmod +x $dir/usr/local/bin/xbian-arch
schroot --directory / -p -c $config_platform -- apt-get update
schroot --directory /tmp -p -c $config_platform -- apt-get install -y --force-yes lsb-release
schroot --directory /tmp -p -c $config_platform -- wget -r -l1 -q --no-parent $config_package_repo
repofile="$(schroot --directory /tmp -p -c $config_platform -- find ./ -name 'xbian-package-repo*.deb' 2>/dev/null | sort -r | grep -m1 xbian-package-repo)"
echo "Latest repo file is $repofile"
schroot --directory /tmp -p -c $config_platform -- dpkg -i --force-confdef --force-confnew $repofile
schroot --directory / -p -c $config_platform -- sed -i 's/curl/notcurl/g' /etc/apt/preferences.d/xbian
case $config_xbian_arch in
RPI) rpref="rpi" ;;
RPI2) rpref="rpi2" ;;
iMX6) rpref="imx6" ;;
*) ;;
esac
schroot --directory / -p -c $config_platform -- sed -i "s/unknown-/$rpref-/g" /etc/apt/sources.list.d/xbian.list
schroot --directory / -p -c $config_platform -- sed -i 's/### //g' /etc/apt/sources.list.d/xbian.list
case "$config_platform" in
"amd64jessie")
schroot --directory / -c $config_platform -p -- sed -i -e 's/^deb m/deb [arch=armhf] m/g' /etc/apt/sources.list.d/xbian.list
;;
esac
schroot --directory / -p -c $config_platform -- apt-get update
schroot --directory / -p -c $config_platform -- apt-get install -y --force-yes -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_install_deb
case "$config_xbian_arch" in
"iMX6")
# Install firmware files for RPi manually
cd /tmp
wget -r -l1 -q --no-parent $config_package_firmware
FW="$(find ./ -name 'xbian-package-firmware*.deb' 2>/dev/null | sort -r | grep -m1 xbian-package-firmware)"
echo "Latest firmware is $FW"
dpkg -x $FW $dir
rm -f $FW
# Copy OpenGLES libs for i.MX6 to the right place
schroot --directory / -c $config_platform -p -- find /usr/lib/xbmc -name "*" -exec cp -av {} /usr/lib/ \;
# Copy some .pc files to the correct place
schroot --directory / -c $config_platform -p -- cp -a /usr/lib/pkgconfig/libcdio.pc /usr/lib/arm-linux-gnueabihf/pkgconfig
schroot --directory / -c $config_platform -p -- cp -a /usr/lib/pkgconfig/libcec.pc /usr/lib/arm-linux-gnueabihf/pkgconfig
;;
esac
case "$config_platform" in
"amd64jessie")
GPP=$(schroot --directory / -c $config_platform -p -- which arm-linux-gnueabihf-g++)
schroot --directory / -c $config_platform -p -- ln -s $GPP /usr/bin/g++
GCC=$(schroot --directory / -c $config_platform -p -- which arm-linux-gnueabihf-gcc)
schroot --directory / -c $config_platform -p -- ln -s $GCC /usr/bin/gcc
# install libtool. Unfortunately because of wrong dependicies can't do it in the normal way
schroot --directory /tmp -c $config_platform -p -- apt-get download libtool
cd /tmp
dpkg -x libtool*.deb $dir
rm -f libtool*.deb
;;
esac
schroot --directory / -p -c $config_platform -- apt-get clean
}
# ----------------------
[ $(id -u) -ne 0 ] && do_exit "for buildroot preparation run again with root privileges" 20
if [ $1 = prepare ]; then
[ -e xbian-prep-root/build/config ] && rexp build/config || :
do_prepare
exit $?
fi
GETOPT=$(getopt \
--longoptions=action:,arch:,config_source_refresh:,help,debug \
--options=a:m:h \
-- "$@" ) \
|| exit 128
for dir in $(find build/ -mindepth 1 -maxdepth 1 -type d | sort); do
unset $(env | grep config_ | awk -F'=' '{print $1}')
result=0
[ -e build/config ] && rexp build/config
[ -e "$dir/config" ] && rexp "$dir/config"
eval set -- ${GETOPT}
while [ "$#" -gt '0' ]; do
case "$1" in
(--debug)
set -x
shift 1
;;
(--action|-a)
opt_action=$2
shift 2
;;
(--arch|-m)
opt_arch=$2
shift 2
;;
(--config_*)
param=$1
param="${param##--}=$2"
do_run export $param
shift 2
;;
(--help|-h)
do_show_help
exit 0
;;
*)
shift 1
;;
esac
done
[ -n "$opt_arch" -a "$opt_arch" != $(basename "$dir") ] && continue
[ -z "$opt_arch" ] && opt_arch=$(basename "$dir")
export config_platform=${opt_arch%%-*}
export config_platform_branch=$opt_arch
export config_branch=${opt_arch##*-}
if [ -z "$config_root_prefix" ]; then
export config_root_prefix=$(readlink -f $XBIANROOT/build-root-dirs)
else
mkdir -p $(readlink -f $XBIANROOT/build-root-dirs)
ln -s $config_root_prefix/$config_platform $(readlink -f $XBIANROOT/build-root-dirs)/$config_platform
fi
export fstabbind=$(readlink -f $(dirname $0))
case $opt_action in
other)
( do_other "$config_root_prefix/$config_platform" )
;;
""|build)
( do_deps "$XBIANROOT/xbian-prep-root" )
( do_prep "$config_root_prefix/$config_platform" )
( do_other "$config_root_prefix/$config_platform" )
;;
esac
done
printf "\n-------------------------------\nFINISHED OK\n-------------------------------\n"