0
0
mirror of https://github.com/libretro/Lakka-LibreELEC.git synced 2024-12-15 19:09:46 +00:00
Tomáš Kelemen (vudiq) ff4d1dd698 install2emmc: use SYSTEM_SIZE and DISTRONAME in script
Script uses arbitrary values for FAT32 partition and name of the
distribution. Using placeholders in the script and replacing them at
build time offers flexibility, i.e. no need to change arbitrary values
in script when SYSTEM_SIZE is changed.
2021-10-15 21:45:09 +02:00

94 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv)
TMP=/tmp/mnt/
SYSTEM_SIZE=@SYSTEM_SIZE@
UUID_SYSTEM="$(date '+%d%m')-$(date '+%M%S')"
UUID_STORAGE="$(uuidgen)"
BOOT=$(grep /flash /proc/mounts | awk '{print $1}' | sed 's/p[012]//g')
DISK=""
for TYPE in /sys/class/block/mmcblk*/device/type; do
if grep -q "MMC" "${TYPE}"; then
DISK="/dev/$(echo "${TYPE}" | awk -F/ '{print $5}')"
break
fi
done
if [ -z "${DISK}" ]; then
echo "Can't find eMMC module!"
exit 1
fi
if [ "${BOOT}" = "${DISK}" ]; then
echo "Your device is booted from the eMMC module!"
exit 1
fi
echo ""
echo -e "\033[36m==============================="
echo "Installing @DISTRONAME@ to eMMC"
echo -e "===============================\033[37m"
echo ""
echo "eMMC found at ${DISK}"
echo ""
if [ ! -b "${DISK}" ]; then
echo "Error: eMMC not found."
exit 1
fi
echo ""
echo -n "WARNING: ALL DATA ON eMMC WILL BE ERASED! Continue (y/N)? "
read -n 1 ANSWER
if [ ! "${ANSWER}" = "y" ]; then
echo ""
echo "Aborting..."
exit 0
fi
echo ""
umount ${DISK}* > /dev/null 2>&1
echo "Erasing eMMC ..."
dd if=/dev/zero of="${DISK}" bs=1M count=1 conv=fsync > /dev/null 2>&1
echo "Creating partitions"
parted -s "${DISK}" mklabel msdos
parted -s "${DISK}" -a optimal mkpart primary fat32 0% ${SYSTEM_SIZE}MiB
parted -s "${DISK}" set 1 boot on
parted -s "${DISK}" -a optimal mkpart primary ext4 ${SYSTEM_SIZE}MiB 100%
sync
echo "Creating filesystems"
dd if=/dev/zero of="${DISK}p1" bs=1M count=1 conv=fsync > /dev/null 2>&1
mkfs.vfat -n SYSTEM -i ${UUID_SYSTEM//-/} ${DISK}p1 > /dev/null 2>&1
dd if=/dev/zero of="${DISK}p2" bs=1M count=1 conv=fsync > /dev/null 2>&1
mkfs.ext4 -L STORAGE -U ${UUID_STORAGE} ${DISK}p2 > /dev/null 2>&1
sync
echo "Installing bootloader"
dd if="${BOOT}" skip=8 of="${DISK}" bs=1k seek=8 count=768 conv=fsync > /dev/null 2>&1
echo "Copying system files"
mkdir -p ${TMP}
mount -t vfat ${DISK}p1 ${TMP}
cp -R /flash/. ${TMP}/
sync
echo "Adjusting partition UUIDs"
sed -i "s/boot=UUID=[0-9a-f\-]*/boot=UUID=${UUID_SYSTEM}/g" ${TMP}/extlinux/extlinux.conf
sed -i "s/disk=UUID=[0-9a-f\-]*/disk=UUID=${UUID_STORAGE}/g" ${TMP}/extlinux/extlinux.conf
umount ${TMP}
echo "Done"