3 # Copyright © 2016 Canonical Ltd.
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License version 3,
7 # as published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Taken from the Mir Project (https://launchpad.net/mir)
24 echo "Usage: ${name} [options] mychroot-dir"
26 echo " -a arch Select architecture, i.e. armhf, arm64, ppc... Default is armhf"
27 echo " -d dist Select distribution, i.e. vivid, wily. Default is vivid"
28 echo " -r rep Select an additional repository for bootstrap. Default is none"
30 echo "please supply at least a directory to create partial chroot in. (eg, ./setup-partial-armhf-chroot.sh mychroot-dir)"
33 # Default to vivid as we don't seem to have any working wily devices right now.
34 # Also Jenkins expects this script to default to vivid (TODO: update CI?)
41 while getopts a:d:r:h opt; do
50 repositories="$repositories $OPTARG"
52 sources="$sources source$sourceid"
55 echo "Option -$OPTARG requires an argument"
64 echo "Invalid option: -$OPTARG"
79 echo "creating phablet-compatible $arch partial chroot for anbox compilation in directory ${directory}"
81 if [ ! -d ${directory} ]; then
85 DEBCONTROL=$(pwd)/../debian/control
87 pushd ${directory} > /dev/null
89 # Empty dpkg status file, so that ALL dependencies are listed with dpkg-checkbuilddeps
92 # Manual error code checking is needed for dpkg-checkbuilddeps
95 # Parse dependencies from debian/control
96 # dpkg-checkbuilddeps returns non-zero when dependencies are not met and the list is sent to stderr
97 builddeps=$(dpkg-checkbuilddeps -a ${arch} --admindir=. ${DEBCONTROL} 2>&1 )
98 if [ $? -eq 0 ] ; then
103 # now turn exit on error option
106 # Sanitize dependencies list for submission to multistrap
107 # build-essential is not needed as we are cross-compiling
108 builddeps=$(echo ${builddeps} | sed -e 's/dpkg-checkbuilddeps://g' \
110 -e 's/Unmet build dependencies://g' \
111 -e 's/build-essential:native//g')
112 builddeps=$(echo ${builddeps} | sed 's/([^)]*)//g')
113 builddeps=$(echo ${builddeps} | sed -e 's/abi-compliance-checker//g')
114 builddeps=$(echo ${builddeps} | sed -e 's/multistrap//g')
118 source_url=http://archive.ubuntu.com/ubuntu
121 source_url=http://ports.ubuntu.com/ubuntu-ports
127 directory=${directory}
130 bootstrap=Ubuntu UbuntuUpdates UbuntuSecurity ${sources}
133 packages=${builddeps}
136 components=main universe
139 packages=${builddeps}
141 suite=${dist}-updates
142 components=main universe
145 packages=${builddeps}
147 suite=${dist}-security
148 components=main universe
152 for x in ${repositories};
155 echo "[source${sourceid}]
161 multistrap -f mstrap.conf
163 rm -f var/cache/apt/archives/lock
165 # Remove libc libraries that confuse the cross-compiler
166 rm -f var/cache/apt/archives/libc-dev*.deb
167 rm -f var/cache/apt/archives/libc6*.deb
169 for deb in var/cache/apt/archives/* ; do
170 if [ ! -d ${deb} ] ; then
171 echo "unpacking: ${deb}"
176 # Fix up symlinks which asssumed the usual root path
177 for broken_symlink in $(find . -name \*.so -type l -xtype l) ; do
178 ln -sf $(pwd)$(readlink ${broken_symlink}) ${broken_symlink}