Skip to content

Instantly share code, notes, and snippets.

@ndgnuh
Forked from radare/void-android.sh
Last active April 30, 2020 08:26
Show Gist options
  • Save ndgnuh/4328465c47795556ba8ed17c3bae7dad to your computer and use it in GitHub Desktop.
Save ndgnuh/4328465c47795556ba8ed17c3bae7dad to your computer and use it in GitHub Desktop.
script to install voidlinux on android/firefoxos devices via adb
#!/bin/sh
# TODO
# - check free disk
# - check return values for every command
V=/data/void
DNS=8.8.8.8
URL=http://xbps.nopcode.org/rootfs/
ROOTFS=void-raspberrypi-rootfs-20191111.tar.xz
download() {
if [ ! -f "$ROOTFS" ]; then
wget -c ${URL}/${ROOTFS}
fi
}
verify() {
printf "Verify ARMv7 CPU... "
adb shell cat /proc/cpuinfo | grep -q ARMv7
if [ $? = 0 ]; then
echo OK
else
echo ERR
exit 1
fi
}
install() {
printf "Installing helper scripts..."
cat > void-enter.sh <<EOF
if [ ! -d /lib ]; then
mount -o remount,rw /
mkdir -p /lib
(
cd $V/lib
for a in ld-* ; do
echo ".. cp /lib/\$a"
cat \$a > /lib/\$a
chmod 755 /lib/\$a
done
)
#mount -o remount,ro /
fi
export TMPDIR=/tmp
export HOME=/root
export XBPS_TARGET_ARCH=armv6l
export PATH=/bin/:/usr/bin:/sbin:/usr/sbin:$V/bin:$V/sbin:$V/usr/bin:$V/sbin:\$PATH
export LD_LIBRARY_PATH=$V/lib:$V/usr/lib:/lib
export PS1='[\$USER@\$HOSTNAME\${PWD:-?}]# '
mkdir -p $V/etc $V/tmp
echo nameserver ${DNS} > $V/etc/resolv.conf
grep -q aid_inet $V/etc/group || cat >> $V/etc/group <<FOO
inet:x:3003:root
aid_inet:x:3003:root
net_raw:x:3004:
FOO
case "\$1" in
shell|'')
if [ ! -f $V/proc/cpuinfo ]; then
mkdir -p $V/rootfs
for a in proc dev sys dev/pts dev/shm sdcard ; do
echo ".. mount /\$a"
mkdir -p $V/\$a
mount -o bind /\$a $V/\$a
done
ln -s /proc/self/fd /dev/fd
fi
;;
esac
case "\$1" in
install)
mkdir $V
gzip -d < /sdcard/void.tgz | tar xv -C $V
bash
;;
umount)
for a in dev/shm dev/pts proc dev sys sdcard ; do
umount $V/\$a
done
;;
shell)
echo "Network is not enabled in shell mode"
$V/usr/bin/bash
;;
*)
# SU is necessary to gain aid_inet priviledges for networking
chroot $V su -p -s /bin/bash
;;
esac
EOF
adb shell rm /data/void-enter.sh
adb push void-enter.sh /data/void-enter.sh >/dev/null
adb shell chmod 755 /data/void-enter.sh
rm -f void-enter.sh
echo DONE
}
bootstrap() {
[ -z "`adb shell ls /data/void 2>/dev/null | grep "No such"`" ] && return
FILES="
./usr/bin/tar
./usr/bin/gzip
./usr/bin/grep
./usr/lib/ld-linux.so.3
./usr/lib/ld-2.17.so
./usr/lib/libpcre.so.1
./usr/lib/libgcc_s.so.1
./usr/lib/libc.so.6
./usr/lib/libc-2.17.so
"
echo "Bootstrapping..."
rm -rf void-out
mkdir -p void-out
(
mkdir -p out/lib out/data/void
tar xJvf ${ROOTFS} -C out/$V/ ${FILES}
mv out/$V/usr/lib/ld-* out/lib
find out
adb shell "mkdir -p $V"
)
#rm -rf out
if [ -n "`adb ls /sdcard/void.tgz 2>/dev/null | grep 'No such'`" ]; then
echo "Repacking for gunzip... "
xz -d < $ROOTFS | gzip > void.tgz
echo "Copying rootfs into /sdcard..."
adb push void.tgz /sdcard/void.tgz
fi
echo "Installing bootstrap to uncompress rootfs..."
adb shell "mount -o remount,rw /"
adb push out/ /
echo "Uncompressing rootfs on target device..."
adb shell "/data/void-enter.sh install"
}
shell() {
echo "Type:"
echo " /data/void-enter.sh"
adb shell
exit 1
if [ -n "`adb shell ls /data/void/root 2>/dev/null | grep 'No such'`" ]; then
echo "Cannot find void rootfs"
else
# XXX console is busted wtf
adb shell /data/void-enter.sh
fi
}
# main
verify
download
bootstrap
install
shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment