Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Copyright (c) 2014 Canonical
- #
- # Author: Oliver Grawert <ogra@canonical.com>
- #
- # 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=$1
- CUST_TARPATH=$2
- SYSIMG=$3
- prepare_ubports_systemfs()
- {
- rm -f $WORKDIR/system.img
- dd if=/dev/zero of=$WORKDIR/system.img seek=500K bs=4096 count=0
- mkfs.ext2 -F $WORKDIR/system.img
- mkdir -p $WORKDIR/system
- mount -o loop $WORKDIR/system.img $WORKDIR/system/
- }
- cleanup()
- {
- echo
- echo "cleaning up"
- mount | grep -q $WORKDIR/system 2>/dev/null && umount $WORKDIR/system
- cleanup_device
- #rm -rf $WORKDIR
- echo
- }
- cleanup_device()
- {
- [ -e $WORKDIR/device-clean ] && return
- umount $WORKDIR/system/ && rm -rf $WORKDIR/system
- [ -e $WORKDIR ] && touch $WORKDIR/device-clean 2>/dev/null || true
- }
- trap cleanup 0 1 2 3 9 15
- SUDOARGS="$@"
- if [ -z "$TARPATH" ]; 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 "$CUST_$TARPATH" ]; then
- echo "need valid custom tarball path"
- usage
- fi
- TARTYPE=$(file --mime-type $CUST_TARPATH|sed 's/^.* //')
- case ${TARTYPE#application\/} in
- gzip|x-gzip)
- ;;
- *)
- echo "Need valid custom tarball gzip type"
- usage
- ;;
- esac
- if [ -z "$SYSIMG" ]; then
- echo "need valid systemfs tarball path"
- usage
- fi
- if [ "$(file --mime-type $SYSIMG|sed 's/^.* //')" != "application/x-xz" ]; then
- echo "system tarball needs to be valid path and type .tar.xz"
- usage
- fi
- [ $(id -u) -ne 0 ] && exec sudo $0 $SUDOARGS
- WORKDIR=$(mktemp -d /tmp/halium-install.XXXXX)
- TMPMOUNT="$WORKDIR/tmpmount"
- prepare_ubports_systemfs
- OUTDIR=$(pwd)
- TARBALL=$(readlink -f $TARPATH)
- echo -n "unpacking rootfs tarball to system-image ... "
- cd $WORKDIR/system && zcat $TARBALL | tar xf - --numeric-owner
- cd $OUTDIR
- echo "[done]"
- echo "Testing for SWAP.swap"
- [ -e $WORKDIR/system/SWAP.swap ] && rm $WORKDIR/system/SWAP.swap
- TARBALL=$(readlink -f $CUST_TARPATH)
- echo -n "adding custom tarball ... "
- # --strip-components=1 since the tarball dir is system/
- cd $WORKDIR/system && zcat $TARBALL | tar xf - --strip-components=1 --numeric-owner
- cd $OUTDIR
- echo "[done]"
- TARBALL=$(readlink -f $SYSIMG)
- echo -n "unpacking systemfs tarball to system-image ... "
- # --strip-components=1 since the tarball dir is system/
- cd $WORKDIR/system && xzcat $TARBALL | tar xf - --exclude=partitions --strip-components=1 --numeric-owner
- cd $OUTDIR
- echo "[done]"
- echo -n "prepare other stuff in system-image ... "
- cd $WORKDIR/system
- mkdir -p android/firmware
- mkdir -p android/persist
- mkdir -p userdata
- for link in cache data factory firmware persist system; do
- ln -s /android/$link $link
- done
- cd lib && ln -s /system/lib/modules modules && cd ..
- ln -s /android/system/vendor vendor
- [ -e etc/mtab ] && rm etc/mtab
- cd etc && ln -s /proc/mounts mtab && cd ..
- cd $OUTDIR
- echo "[done]"
- echo "umount .../system"
- umount $WORKDIR/system
- echo "save prepared systemfs"
- mv $WORKDIR/system.img $OUTDIR/prepared-system.img
- echo -n "cleaning up on device ... "
- cleanup_device
- echo "[done]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement