LibreELEC.tv/scripts/mkimage-atv
Christian Hewitt 99e7690338 appletv: add 'make image' support to buildsystem
This allows ‘PROJECT=ATV ARCH=i386 make image’ to output the .img files
needed to run OE from a USB (live mode) or install to the internal HDD.

Note: this is not complete and must be fixed

Signed-off-by: Stephan Raue <stephan@openelec.tv>
2014-03-05 17:27:41 +01:00

115 lines
3.4 KiB
Bash
Executable File

#!/bin/sh -xv
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2014 Christian Hewitt (chewitt@openelec.tv)
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC 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.
#
# OpenELEC 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 OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
################################################################################
# variables such as $ROOT $PATH must be passed via env from scripts/image - the
# mkimage-atv script also requires 'kpartx' to be installed.
################################################################################
# set variables:
OE_TMP=$(mktemp -d)
VERBOSE="FALSE"
IMGSIZE="200" # size of BOOT in MB
IMGUSB="$IMAGE_NAME-usb.img"
IMGHDD="$IMAGE_NAME-hdd.img"
# set verbose output on/off:
if [ "${VERBOSE}" = "TRUE" ]; then
exec 3>&1
exec 4>&2
else
exec 3> /dev/null
exec 4> /dev/null
fi
# check for kpartx
KPARTX=$(which kpartx)
if [ -z "$KPARTX" ]; then
echo "kpartx was not found, exiting!"
exit 1
fi
# loop through image options
for IMAGE in $IMGUSB $IMGHDD; do
# set the installer function
IMGFILE="$IMAGE"
if [ "$IMGFILE" = "$IMGUSB" ]; then
FUNCTION="install-usb"
else
FUNCTION="install-hdd"
fi
# create USB image
echo "Creating $IMGFILE"
SYSTEM_PART_END=$(( $IMGSIZE * 1024 * 1024 / 512 - 40 ))
dd if=/dev/zero of=$IMGFILE bs=1M count=$IMGSIZE 1>&3 2>&4
parted -s $IMGFILE mklabel gpt 1>&3 2>&4
parted -s $IMGFILE -a min unit s mkpart primary HFS 40 $SYSTEM_PART_END 1>&3 2>&4
parted -s $IMGFILE name 1 OPENELEC 1>&3 2>&4
parted -s $IMGFILE set 1 atvrecv on 1>&3 2>&4
kpartx -a $IMGFILE 1>&3 2>&4
mkfs.hfsplus -s -v OPENELEC /dev/mapper/loop0p1 1>&3 2>&4
fsck.hfsplus -f /dev/mapper/loop0p1 1>&3 2>&4
# mount the image file
mount /dev/mapper/loop0p1 $OE_TMP 1>&3 2>&4
# copy recovery files
cp -Rv $RELEASE_DIR/3rdparty/atvboot/* $OE_TMP 1>&3 2>&4
echo $FUNCTION > $OE_TMP/function
# copy MACH_KERNEL/SYSTEM/.md5 files
cp $RELEASE_DIR/target/* $OE_TMP
# unmount the image file
sync 1>&3 2>&4
sleep 2
# umount $OE_TMP 1>&3 2>&4
# rm -rf $OE_TMP 1>&3 2>&4
# sync everything up
# echo y | gptsync /dev/loop0 1>&3 2>&4
# sleep 2
# kpartx -d $IMGFILE 1>&3 2>&4
sync 1>&3 2>&4
# wait a bit
sleep 2
# gzip the image file and move to target/
# gzip $IMGFILE
# IMGFILE="$IMGFILE.gz"
# change file owner to match target/
# USR=$(ls -dl $ROOT/target | awk '{print $3}')
# GRP=$(ls -dl $ROOT/target | awk '{print $4}')
# chown $USR:$GRP $IMGFILE
# move to target/
# mv $IMGFILE target/
# close the loop
done