Closed Sen closed 4 years ago
#!/bin/sh
################################################################################
# This file is part of CoreELEC - https://coreelec.org
# Copyright (C) 2018-present CoreELEC (team (at) coreelec.org)
# Copyright (C) 2016-18 kszaq (kszaquitto (at) gmail.com)
#
# CoreELEC 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.
#
# CoreELEC 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 CoreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
IMAGE_KERNEL="/flash/kernel.img"
IMAGE_SYSTEM="/flash/SYSTEM"
IMAGE_DTB="/flash/dtb.img"
BACKUP_DATE=$(date +%Y%m%d%H%M%S)
install_to_nand() {
if [ -f $IMAGE_KERNEL -a -f $IMAGE_SYSTEM ] ; then
if grep -q /dev/system /proc/mounts ; then
echo "Unmounting SYSTEM partiton."
umount -f /dev/system
fi
mkdir -p /tmp/system
mount -o rw,remount /flash
# if [ -e /dev/dtb ] ; then
# echo -n "Backing up device tree..."
# dd if=/dev/dtb of="/flash/dtb$BACKUP_DATE.img" bs=256k conv=fsync 2> /dev/null
# echo "done."
# fi
# if [ -e /dev/recovery ] ; then
# echo -n "Backing up recovery partition..."
# dd if=/dev/recovery of="/flash/recovery$BACKUP_DATE.img" bs=64k conv=fsync 2> /dev/null
# echo "done."
# fi
echo -n "Formatting SYSTEM partition..."
mke2fs -F -q -t ext4 -m 0 /dev/system || exit 1
e2fsck -n /dev/system || exit 1
resize2fs -s /dev/system || exit 1
tune2fs -O ^metadata_csum /dev/system || exit 1
echo "done."
# echo -n "Writing kernel image..."
# dd if="$IMAGE_KERNEL" of=/dev/boot bs=1M 2> /dev/null
# echo "done."
echo -n "Copying SYSTEM files..."
mount -o rw /dev/system /tmp/system
cp -pPR /flash/. /tmp/system && sync
export $(/sbin/fw_printenv mac)
export $(/sbin/fw_printenv mac_wifi)
/bin/sed -e 's/LABEL=COREELEC/\/dev\/system/' -e "s/LABEL=STORAGE/\/dev\/data/" -e "s/mac=...../mac=${mac}/" -e "s/mac_wifi=.........../mac_wifi=${mac_wifi}/" -i /tmp/system/uEnv.ini
echo "done."
umount /tmp/system
# if [ -f $IMAGE_DTB ] ; then
# echo -n "Writing device tree image..."
# dd if=/dev/zero of=/dev/dtb bs=256k count=1 2> /dev/null
# dd if="$IMAGE_DTB" of=/dev/dtb bs=256k 2> /dev/null
# echo "done."
# fi
read -p "Do you want to copy your user data to internal data partition? [Y/n] " choice
case "$choice" in
[nN]*)
read -p "Do you want to format DATA partition? [Y/n] " choice
case "$choice" in
[nN]*)
;;
*)
echo -n "Formatting DATA partition..."
mke2fs -F -q -t ext4 -m 0 /dev/data > /dev/null
e2fsck -n /dev/data &> /dev/null
resize2fs -s /dev/data &> /dev/null
tune2fs -O ^metadata_csum /dev/data &> /dev/null
echo "done."
esac
;;
*)
echo -n "Formatting DATA partition..."
mke2fs -F -q -t ext4 -m 0 /dev/data > /dev/null
e2fsck -n /dev/data &> /dev/null
resize2fs -s /dev/data &> /dev/null
tune2fs -O ^metadata_csum /dev/data &> /dev/null
echo "done."
echo -n "Stopping Kodi..."
systemctl stop kodi
echo "done."
echo "Copying user data..."
mkdir -p /tmp/data
mount -o rw /dev/data /tmp/data
cp -pPR /storage/. /tmp/data
;;
esac
echo "All done!"
echo "WARNING: If your internal memory layout is different from standard Amlogic, you have to perform this operation again!"
echo "Your system will reboot from internal memory."
echo ""
read -p "Would you like to reboot now [y/N]? " choice
case "$choice" in
[yY]*)
/usr/sbin/fw_setenv start_autoscript "if usb start ; then run start_usb_autoscript; fi; if ext4load mmc 1:b 1020000 /n1_autoscript; then autoscr 1020000; fi;"
/usr/sbin/reboot
;;
esac
else
echo "No LE image found on /flash! Exiting..."
fi
}
if [ ! -e /dev/boot -o ! -e /dev/system -o ! -e /dev/data -o ! -e /dev/dtb ]; then
echo "One of BOOT, SYTEM, DATA or DTB partitions is missing."
echo "Make sure that you are using a correct device tree and a device with internal memory!"
exit 0
fi
echo "This script will erase BOOT, SYSTEM, DATA and DTB on your device"
echo "and install LE that you booted from SD card/USB drive."
echo ""
echo "It will create a backup of device tree and recovery partition on your boot media."
echo ""
echo "The script does not have any safeguards!"
echo ""
read -p "Type \"yes\" if you know what you are doing or anything else to exit: " choice
case "$choice" in
yes) install_to_nand ;;
esac
这是另外一个适配的coreelec的脚本,我拿过来直接用了。一起配套的还有n1_autoscript,看代码应该是用来设置重启的?
看看是否可以做到固件中,下次升级不那么麻烦
没有测试环境,希望有其他人可以实验一下。 另外,这个版本升级只需要把tar文件放到/storage/.update/下,应该并不麻烦。
官方不建议安装到emmc,我也不建议。装在u盘不管是备份还是升级都容易操作,出问题损失也可控。emmc可以装其它稳定的系统以防万一。
同意+1