diff --git a/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh b/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh index 207ad0c5c0..c4067eed16 100644 --- a/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh +++ b/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh @@ -19,56 +19,54 @@ CWD="/usr/lib/nand-sata-install" EX_LIST="${CWD}/exclude.txt" nanddevice="/dev/nand" - # read in board info -[[ -f /etc/armbian-release ]] && source /etc/armbian-release || read ID > /mnt/rootfs/etc/fstab @@ -93,16 +91,18 @@ create_armbian() { mkimage -A arm -O linux -T kernel -C none -a "0x40008000" -e "0x40008000" -n "Linux kernel" -d \ /boot/zImage /mnt/bootfs/uImage >/dev/null 2>&1 cp /boot/script.bin /mnt/bootfs/ - cat > /mnt/bootfs/uEnv.txt < /mnt/bootfs/uEnv.txt + console=ttyS0,115200 + root=$2 rootwait + extraargs="console=tty1 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:0 consoleblank=0 loglevel=1" + EOF + sync - [[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt + [[ $DEVICE_TYPE = a20 ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt # ugly hack becouse we don't have sources for A10 nand uboot - if [[ "${ID}" == "Cubieboard" || "${BOARD_NAME}" == "Cubieboard" || "${ID}" == "Lime A10" || "${BOARD_NAME}" == "Lime A10" ]]; then + if [[ $ID == Cubieboard || $BOARD_NAME == Cubieboard || $ID == "Lime A10" || $BOARD_NAME == "Lime A10" ]]; then cp /mnt/bootfs/uEnv.txt /mnt/rootfs/boot/uEnv.txt cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage @@ -112,27 +112,27 @@ EOF tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1 e2fsck -f /dev/nand2 >/dev/null 2>&1 - elif [[ "$2" == "$emmccheck""p1" || "$1" == "$emmccheck""p1" ]]; then - + elif [[ $2 == ${emmccheck}p1 || $1 == ${emmccheck}p1 ]]; then + # fix that we can have one exlude file cp -R /boot/ /mnt/bootfs - - # eMMC install - sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd + + # eMMC install + sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd mkimage -C none -A arm -T script -d /mnt/bootfs/boot/boot.cmd /mnt/bootfs/boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0) - + # fstab adj - sed -e 's,'"$2"','"$emmcuuid"',g' -i /mnt/rootfs/etc/fstab - + sed -e 's,'"$2"','"$emmcuuid"',g' -i /mnt/rootfs/etc/fstab + if [[ $(type -t write_uboot_platform) != function ]]; then echo "Error: no u-boot package found, exiting" exit -1 fi write_uboot_platform $DIR $emmccheck - + elif [[ -f /boot/boot.cmd ]]; then - sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.cmd + sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.cmd mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0) mkdir -p /mnt/rootfs/media/mmc/boot if ! grep -q "/boot" /mnt/rootfs/etc/fstab; then # in two partition setup @@ -147,13 +147,13 @@ EOF umountdevice "/dev/sda" } # create_armbian - # Accept device as parameter: for example /dev/sda unmounts all their mounts -umountdevice() { - if [ -n "$1" ]; then - device=$1; +umountdevice() +{ + if [[ -n $1 ]]; then + device=$1; for n in ${device}*; do - if [ "${device}" != "$n" ]; then + if [[ $device != "$n" ]]; then if mount|grep -q ${n}; then umount -l $n >/dev/null 2>&1 fi @@ -162,9 +162,9 @@ umountdevice() { fi } # umountdevice - # Recognize root filesystem -recognize_root() { +recognize_root() +{ # replace with PARTUUID approach parsing /proc/cmdline when ready local device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0) local partitions=$(($(fdisk -l $device | grep $device | wc -l)-1)) @@ -172,19 +172,19 @@ recognize_root() { local root_device=$(mountpoint -d /) for file in /dev/* ; do local current_device=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file)) - if [ $current_device = $root_device ]; then + if [[ $current_device = $root_device ]]; then root_partition=$file break; fi done } # recognize_root - # Formatting NAND - no parameters. Fixed solution. -formatnand() { +formatnand() +{ [[ ! -e /dev/nand ]] && echo "NAND error" && exit 0 dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40 - if [[ "$DEVICE_TYPE" = "a20" ]]; then + if [[ $DEVICE_TYPE = a20 ]]; then (echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1 else (echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1 @@ -193,9 +193,9 @@ formatnand() { mkfs.ext4 /dev/nand2 >/dev/null 2>&1 } # formatnand - # Formatting eMMC [device] example /dev/mmcblk1 -formatemmc() { +formatemmc() +{ # deletes all partitions dialog --title "$title" --backtitle "$backtitle" --infobox "\n Formating eMMC ... one moment." 5 40 dd bs=1 seek=446 count=64 if=/dev/zero of=$1 >/dev/null 2>&1 @@ -203,8 +203,8 @@ formatemmc() { # to other media 'of the same size' (one sector less and cloning will fail) QUOTED_DEVICE=$(echo "${1}" | sed 's:/:\\\/:g') CAPACITY=$(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", \$2 / ( 1024 / \$4 ))}") - - if [ ${CAPACITY} -lt 4000000 ]; then + + if [[ $CAPACITY -lt 4000000 ]]; then # Leave 2 percent unpartitioned when eMMC size is less than 4GB (unlikely) LASTSECTOR=$(( 32 * $(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", ( \$2 * 98 / 3200))}") -1 )) else @@ -220,20 +220,20 @@ formatemmc() { emmcuuid=$(blkid -o export $1"p1" | grep -w UUID) } # formatemmc - # formatting SATA/USB [device] example /dev/sda3 -formatsata() { +formatsata() +{ dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40 mkfs.ext4 $1 >/dev/null 2>&1 tune2fs $1 -o journal_data_writeback >/dev/null 2>&1 } # formatsata - # choose target SATA/USB partition. -checksatatarget() { +checksatatarget() +{ IFS=" " SataTargets=$(awk '/sd/ {print "/dev/"$4}' &1 >/dev/tty) - if [ $? -ne 0 ]; then exit 1; fi + [[ $? -ne 0 ]] && exit 1 SDA_ROOT_PART=${SataOptions[(2*$SataChoices)-1]} } # checksatatarget - # show warning [TEXT] -ShowWarning() { +ShowWarning() +{ dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Zn\n$1" 17 74 - if [ $? -ne 0 ]; then exit 1; fi + [[ $? -ne 0 ]] && exit 1 } # ShowWarning -main() { +main() +{ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # This tool must run under root - if [[ ${EUID} -ne 0 ]]; then + if [[ $EUID -ne 0 ]]; then echo "This tool must run as root. Exiting ..." exit 1 fi # Check if we run it from SD card - if [[ "$(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent)" != mmcblk* ]]; then + if [[ $(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent) != mmcblk* ]]; then dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1This tool must run from SD-card!\Zn" 5 42 exit 1 fi - + #recognize_root root_partition=$(cat /proc/cmdline | sed -e 's/^.*root=//' -e 's/ .*$//') IFS="'" options=() - if [[ -n "$emmccheck" ]]; then + if [[ -n $emmccheck ]]; then ichip="eMMC"; dest_boot=$emmccheck"p1" dest_root=$emmccheck"p1" - else + else ichip="NAND" dest_boot="/dev/nand1" dest_root="/dev/nand2" fi - - [[ -n "$nandcheck" || -n "$emmccheck" ]] && options=(${options[@]} 1 'Boot from '$ichip' - system on '$ichip) - [[ ( -n "$nandcheck" || -n "$emmccheck" ) && -n "$satacheck" ]] && options=(${options[@]} 2 'Boot from '$ichip' - system on SATA or USB') - [[ -n "$satacheck" ]] && options=(${options[@]} 3 'Boot from SD - system on SATA or USB') - + + [[ -n $nandcheck || -n $emmccheck ]] && options=(${options[@]} 1 'Boot from '$ichip' - system on '$ichip) + [[ ( -n $nandcheck || -n $emmccheck ) && -n $satacheck ]] && options=(${options[@]} 2 'Boot from '$ichip' - system on SATA or USB') + [[ -n $satacheck ]] && options=(${options[@]} 3 'Boot from SD - system on SATA or USB') + [[ ${#options[@]} -eq 0 || "$root_partition" == "$emmcuuid" || "$root_partition" == "/dev/nand2" ]] && dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1There are no targets. Please check your drives.\Zn" 5 60 && exit 1 cmd=(dialog --title "Choose an option:" --backtitle "$backtitle" --menu "\nCurrent root: $root_partition \n \n" 14 60 7) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) - if [ $? -ne 0 ]; then exit 1; fi + [[ $? -ne 0 ]] && exit 1 for choice in $choices do @@ -301,28 +302,28 @@ main() { title="$ichip install" command="Power off" ShowWarning "This script will erase your $ichip. Continue?" - if [[ -n "$emmccheck" ]]; then + if [[ -n $emmccheck ]]; then umountdevice "$emmccheck" formatemmc "$emmccheck" - else + else umountdevice "/dev/nand" - formatnand - fi + formatnand + fi create_armbian "$dest_boot" "$dest_root" ;; 2) title="$ichip boot / SATA root install" command="Power off" - checksatatarget + checksatatarget ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?" - if [[ -n "$emmccheck" ]]; then + if [[ -n $emmccheck ]]; then umountdevice "$emmccheck" formatemmc "$emmccheck" else umountdevice "/dev/nand" - formatnand + formatnand fi - umountdevice "${SDA_ROOT_PART//[0-9]*/}" + umountdevice "${SDA_ROOT_PART//[0-9]*/}" formatsata "$SDA_ROOT_PART" create_armbian "$dest_boot" "$SDA_ROOT_PART" ;; @@ -338,7 +339,7 @@ main() { done dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label "Exit" --yesno "\nAll done. $command $REMOVESDTXT" 7 60 - if [ $? -eq 0 ]; then "$(echo ${command,,} | sed 's/ //')"; fi + [[ $? -eq 0 ]] && "$(echo ${command,,} | sed 's/ //')" } # main main "$@"