#!/bin/sh # # Copyright (c) 2014 Canonical # # Author: Oliver Grawert # Adapted by: Olivier 'Reivilibre' for systems where loop mounting is unavailable/bugged(?) # # 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 of the # License, 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 this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # set -e TARPATH=`realpath "$1"` SYSIMG=`realpath "$2"` check_prereq() { if [ ! $(which make_ext4fs) ] || [ ! -x $(which simg2img) ] || \ [ ! -x $(which adb) ]; then echo "please install the android-tools-fsutils and android-tools-adb packages" && exit 1 fi } do_shell() { adb shell "$@" } convert_android_img() { if file $SYSIMG | grep -v ": Linux rev 1.0 ext4" >/dev/null; then # image is not ext4 filesystem; convert it simg2img $SYSIMG $WORKDIR/system.img.raw mkdir $TMPMOUNT mount -t ext4 -o loop $WORKDIR/system.img.raw $TMPMOUNT make_ext4fs -l 160M $WORKDIR/system.img $TMPMOUNT umount $TMPMOUNT rmdir $TMPMOUNT SYSIMAGE=$WORKDIR/system.img else SYSIMAGE=$SYSIMG fi } check_mounts(){ MOUNTS=$(do_shell "cat /proc/mounts") if ! echo $MOUNTS | grep -qs '/data'; then do_shell "mount /data" fi } prepare_halium_rootfs() { # reivilibre: do not do processing on target device #do_shell "rm -f /data/rootfs.img" #do_shell "dd if=/dev/zero of=/data/rootfs.img seek=500K bs=4096 count=0" #do_shell "mkfs.ext2 -F /data/rootfs.img" #do_shell "mkdir -p /cache/system" #do_shell "mount -o loop /data/rootfs.img /cache/system/" dd if=/dev/zero of=$WORKDIR/rootfs.img seek=500K bs=4096 count=0 mkfs.ext2 -F $WORKDIR/rootfs.img mkdir -p $WORKDIR/mnt-rootfs mount -o loop $WORKDIR/rootfs.img $WORKDIR/mnt-rootfs } cleanup() { cat </dev/null || true #} trap cleanup 0 1 2 3 9 15 usage() { echo "usage: $(basename $0) [options] options: -h|--help this message" exit 1 } SUDOARGS="$@" while [ $# -gt 0 ]; do case "$1" in -h|--help) usage ;; esac shift done if [ -z "$TARPATH" ]; then echo "need valid rootfs tarball path" usage fi TARBALL=$(basename $TARPATH) if [ -z "$TARBALL" ]; then echo "need valid rootfs tarball path" usage fi TARTYPE=$(file --mime-type $TARPATH|sed 's/^.* //') case ${TARTYPE#application\/} in gzip|x-gzip) ;; *) echo "Need valid rootfs tarball gzip type" usage ;; esac if [ -z "$SYSIMG" ] || \ [ "$(file --mime-type $SYSIMG|sed 's/^.* //')" != "application/octet-stream" ]; then echo "need valid system.img path and type application/octet-stream" usage fi [ $(id -u) -ne 0 ] && exec sudo $0 $SUDOARGS check_prereq if ! adb devices | grep -q recovery; then echo "please make sure the device is attached via USB in recovery mode" exit 1 fi check_mounts WORKDIR=$(mktemp -d /tmp/halium-install.XXXXX) TMPMOUNT="$WORKDIR/tmpmount" ANDROID_DIR="/data" ### rootfs.img preparation cat <