Advertisement
Guest User

installtointernal

a guest
Nov 4th, 2017
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.77 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ################################################################################
  4. #      This file is part of LibreELEC - https://libreelec.tv
  5. #      Copyright (C) 2016 kszaq (kszaquitto (at) gmail.com)
  6. #
  7. #  LibreELEC is free software: you can redistribute it and/or modify
  8. #  it under the terms of the GNU General Public License as published by
  9. #  the Free Software Foundation, either version 2 of the License, or
  10. #  (at your option) any later version.
  11. #
  12. #  LibreELEC is distributed in the hope that it will be useful,
  13. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #  GNU General Public License for more details.
  16. #
  17. #  You should have received a copy of the GNU General Public License
  18. #  along with LibreELEC.  If not, see <http://www.gnu.org/licenses/>.
  19. ################################################################################
  20.  
  21. IMAGE_KERNEL="/flash/kernel.img"
  22. IMAGE_SYSTEM="/flash/SYSTEM"
  23. IMAGE_DTB="/flash/dtb.img"
  24. BACKUP_DATE=$(date +%Y%m%d%H%M%S)
  25.  
  26. install_to_nand() {
  27.   if [ -f $IMAGE_KERNEL -a -f $IMAGE_SYSTEM ] ; then
  28.  
  29.     if grep -q /dev/system /proc/mounts ; then
  30.       echo "Unmounting SYSTEM partiton."
  31.       umount -f /dev/system
  32.     fi
  33.     mkdir -p /tmp/system
  34.  
  35.     mount -o rw,remount /flash
  36.     if [ -e /dev/dtb ] ; then
  37.       echo -n "Backing up device tree..."
  38.       dd if=/dev/dtb of="/flash/dtb$BACKUP_DATE.img" bs=256k conv=fsync 2> /dev/null
  39.       echo "done."
  40.     fi
  41.  
  42.     if [ -e /dev/recovery ] ; then
  43.       echo -n "Backing up recovery partition..."
  44.       dd if=/dev/recovery of="/flash/recovery$BACKUP_DATE.img" bs=64k conv=fsync 2> /dev/null
  45.       echo "done."
  46.     fi
  47.  
  48.     echo -n "Formatting SYSTEM partition..."
  49.     mke2fs -F -q -t ext4 -m 0 /dev/system || exit 1
  50.     e2fsck -n /dev/system || exit 1
  51.     echo "done."
  52.  
  53.     echo -n "Writing kernel image..."
  54.     dd if="$IMAGE_KERNEL" of=/dev/boot bs=64k 2> /dev/null
  55.     echo "done."
  56.  
  57.     echo -n "Copying SYSTEM files..."
  58.     mount -o rw /dev/system /tmp/system
  59.     cp $IMAGE_SYSTEM /tmp/system && sync
  60.     echo "done."
  61.  
  62.     echo -n "Copying remote.conf..."
  63.     cp -PR /flash/remote*.conf /tmp/system
  64.     echo "done."
  65.  
  66.     umount /tmp/system
  67.  
  68.     if [ -f $IMAGE_DTB ] ; then
  69.       echo -n "Writing device tree image..."
  70.       dd if=/dev/zero of=/dev/dtb bs=256k count=1 2> /dev/null
  71.       dd if="$IMAGE_DTB" of=/dev/dtb bs=256k 2> /dev/null
  72.       echo "done."
  73.     fi
  74.  
  75.     echo -n "Formatting DATA partition..."
  76.     mke2fs -F -q -t ext4 -m 0 /dev/data > /dev/null
  77.     e2fsck -n /dev/data &> /dev/null
  78.     echo "done."
  79.  
  80.     read -p "Do you want to copy your user data to internal data partition? [Y/n] " choice
  81.     case "$choice" in
  82.       [nN]*)
  83.         ;;
  84.       *)
  85.         echo -n "Stopping Kodi..."
  86.         systemctl stop kodi
  87.         echo "done."
  88.         echo "Copying user data..."
  89.         mkdir -p /tmp/data
  90.         mount -o rw /dev/data /tmp/data
  91.         cp -pPRv /storage/. /tmp/data
  92.         ;;
  93.     esac
  94.  
  95.     echo "All done! Rebooting now..."
  96.     echo "WARNING: If your internal memory layout is different from standard Amlogic, you have to perform this operation again!"
  97.     echo "Your system will continue booting from SD/USB until you remove it."
  98.  
  99.     reboot
  100.  
  101.   else
  102.     echo "No LE image found on /flash! Exiting..."
  103.   fi
  104. }
  105.  
  106. echo "This script will erase BOOT, SYSTEM, DATA and DTB on your device"
  107. echo "and install LE that you booted from SD card/USB drive."
  108. echo ""
  109. echo "It will create a backup of device tree and recovery partition on your boot media."
  110. echo ""
  111. echo "The script does not have any safeguards!"
  112. echo ""
  113. read -p "Type \"yes\" if you know what you are doing or anything else to exit: " choice
  114. case "$choice" in
  115.   yes) install_to_nand ;;
  116. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement