Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 7ca8929

Browse files
author
Alistair Strachan
committed
Push down the sudo / root commands into buildstrap.
Instead of running the whole buildstrap script with sudo, have each command requiring sudo rights run with the $root prefix. This is preparatory work for introducing support for 'fakeroot'. Signed-off-by: Alistair Strachan <astrachan@google.com>
1 parent bd92ade commit 7ca8929

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

androdeb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,9 @@ fi
298298
PACKAGES+="$DEFAULT_PACKAGES"
299299
c_info "Using temporary directory: $TDIR"
300300

301-
if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi
302-
303301
ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files
304302

305-
sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" \
303+
$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" \
306304
$ex_files $INSTALL_BCC $SKIP_DEVICE $MIRROR
307305
rm $ex_files
308306

buildstrap

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,57 @@ SKIP_DEVICE=$8 # Skip any device-specific stages
1515
MIRROR=$9
1616
VARIANT="--variant=minbase"
1717

18-
time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
18+
root=sudo
19+
20+
if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
21+
22+
# It's easier to just really be root for debootstrap
23+
time $root qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
1924
$DISTRO $OUT_TMP $MIRROR
2025

2126
# Some reason debootstrap leaves these mounted
22-
umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
23-
umount $OUT_TMP/proc || true
27+
$root umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
28+
$root umount $OUT_TMP/proc || true
2429

2530
# Make bash the default shell
26-
chroot $OUT_TMP rm /bin/sh || true
27-
chroot $OUT_TMP ln -s /bin/bash /bin/sh || true
28-
cp $spath/addons/bashrc $OUT_TMP/.bashrc
29-
cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common
30-
cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent
31-
cp $spath/addons/get_kvers.sh $OUT_TMP/
31+
$root ln -sf /bin/bash $OUT_TMP/bin/sh || true
32+
$root cp $spath/addons/bashrc $OUT_TMP/.bashrc
33+
$root cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common
34+
$root cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent
35+
$root cp $spath/addons/get_kvers.sh $OUT_TMP/
3236

3337
for f in $EXTRA_FILES; do
3438
if [ $f == "none" ]; then continue; fi
35-
cp $f $OUT_TMP/
39+
$root cp $f $OUT_TMP/
3640
done
3741

3842
# Cleanup
39-
rm -rf $OUT_TMP/lib/udev/*
40-
rm -rf $OUT_TMP/var/lib/apt/lists/*
41-
rm -rf $OUT_TMP/var/cache/apt/archives/*deb
42-
rm -rf $OUT_TMP/usr/share/locale/*
43-
rm -rf $OUT_TMP/usr/lib/share/locale/*
44-
rm -rf $OUT_TMP/usr/share/doc/*
45-
rm -rf $OUT_TMP/usr/lib/share/doc/*
46-
rm -rf $OUT_TMP/usr/share/ieee-data/*
47-
rm -rf $OUT_TMP/usr/lib/share/ieee-data/*
48-
rm -rf $OUT_TMP/usr/share/man/*
49-
rm -rf $OUT_TMP/usr/lib/share/man/*
43+
$root rm -rf $OUT_TMP/lib/udev/*
44+
$root rm -rf $OUT_TMP/var/lib/apt/lists/*
45+
$root rm -rf $OUT_TMP/var/cache/apt/archives/*deb
46+
$root rm -rf $OUT_TMP/usr/share/locale/*
47+
$root rm -rf $OUT_TMP/usr/lib/share/locale/*
48+
$root rm -rf $OUT_TMP/usr/share/doc/*
49+
$root rm -rf $OUT_TMP/usr/lib/share/doc/*
50+
$root rm -rf $OUT_TMP/usr/share/ieee-data/*
51+
$root rm -rf $OUT_TMP/usr/lib/share/ieee-data/*
52+
$root rm -rf $OUT_TMP/usr/share/man/*
53+
$root rm -rf $OUT_TMP/usr/lib/share/man/*
5054

5155
# Fix apt-get issue: Android requires _apt user to be in the
5256
# AID_INET group which is also android specific.
5357
grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1
5458
if [ $? -ne 0 ]; then
5559
c_warning "_apt user cannot be added to AID_INET group"
5660
else
57-
sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd
61+
$root sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' \
62+
$OUT_TMP/etc/passwd
5863
fi
5964

6065
# Add a default DNS server
61-
echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf
66+
$root tee -a $OUT_TMP/etc/resolv.conf >/dev/null <<EOF
67+
nameserver 4.2.2.2
68+
EOF
6269

6370
# Clone BCC if needed
6471
if [ $INSTALL_BCC -eq 1 ]; then
@@ -71,12 +78,10 @@ if [ $INSTALL_BCC -eq 1 ]; then
7178
popd
7279
fi
7380

74-
# Should be really do this?
75-
chmod -R 0777 $TDIR/
76-
7781
[ $SKIP_DEVICE -eq 0 ] || exit 0
7882

7983
c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/"
80-
tar -zcf $TDIR/deb.tar.gz -C $TDIR debian
8184

82-
chmod 0777 $TDIR/deb.tar.gz
85+
$root tar -zpcf $TDIR/deb.tar.gz -C $TDIR debian
86+
87+
$root chown --reference=$TDIR $TDIR/deb.tar.gz

0 commit comments

Comments
 (0)