#!/bin/bash # === Detect instalation source === echo "1 1 1 1" > /proc/sys/kernel/printk mkdir /mnt > /dev/null 2>&1 mkdir /multiboot > /dev/null 2>&1 mkdir /run/inst > /dev/null 2>&1 #------------------------------------------------------- print_header() { clear printf "\n\033[36m\033[1m\n" if [ ! "${O_BOARD}" = "XU" ]; then printf " ======================================\n" printf " = Odroid %s Universal installer %s =\n" "${O_BOARD}" "${SCRIPT_VERSION}" printf " ======================================\n" else printf " ===========================================\n" printf " = Odroid XU3/XU4 Universal installer %s =\n" "${SCRIPT_VERSION}" printf " ===========================================\n" fi printf "\033[22m\033[37m\n" } #------------------------------------------------------- print_header # Set variables CARD1="" CARD2="" CARD1_EMMC="" CARD2_EMMC="" DEST_CARD="" DEST_EMMC="" INST_ANDROID="" INST_OELEC="" INST_LINUX="" INST_LINUX2="" A_FROMDIR="" L_FROMDIR="" L2_FROMDIR="" O_FROMDIR="" SYSTEM_SIZE=1024 SYSTEM_MINSIZE=768 DATA_SIZE=1024 DATA_MINSIZE=1024 CACHE_SIZE=256 CACHE_MINSIZE=128 USERDATA_SIZE=1024 USERDATA_MINSIZE=512 LINUX_SIZE=2048 LINUX_MINSIZE=2048 OELEC_SIZE=512 OELEC_MINSIZE=512 LINUX_FSTYPE="ext4" _dest_system="/dev/disk/by-label/sdsystem" _dest_cache="/dev/disk/by-label/sdcache" _dest_data="/dev/disk/by-label/sddata" _erase_data="no" _part6_label="auxpart" _part6_dlabel="Reserved" _instfound="no" andro_updatearchive="no" _inst_mbkernel="no" _inst_no_=0 #----------------------------------------------------- # Check card type #---------------- CARD1="/dev/mmcblk${BOOT_CARDDEV}" CARD1_EMMC="${BOOT_CARDTYPE}" if [ "${NUMCARDS}" = "2" ]; then CARD2="/dev/mmcblk${OTHER_CARDDEV}" CARD2_EMMC="${OTHER_CARDTYPE}" fi #----------------------------------------------------- #----------------------------------------------------- # Check where the installation files are located check_source() { if [ -b ${1} ]; then /bin/mountx ${1} /mnt > /dev/null 2>&1 [ $? -ne 0 ] && return 1 else return 1 fi sleep 1 # === Source drive found and 1st partition mounted on /mnt === # === Check installation files on source drive === # ANDROID if [ -d /mnt/${BKP_PREFIX}_backup/android ]; then if [ -f /mnt/${BKP_PREFIX}_backup/android/system.raw.img ]; then INST_ANDROID="yes" _instfound="yes" A_FROMDIR="yes" fi else if [ -f /mnt/update.tar.gz ] || [ -f /mnt/update.zip ]; then INST_ANDROID="yes" _instfound="yes" fi fi [ "${UPGRADE_ANDROID}" = "yes" ] && return 0 # LINUX if [ -d /mnt/${BKP_PREFIX}_backup/linux ]; then if [ -f /mnt/${BKP_PREFIX}_backup/linux/linux.img ]; then INST_LINUX="yes" _instfound="yes" L_FROMDIR="yes" fi else if [ -f /mnt/linux.img ]; then INST_LINUX="yes" _instfound="yes" fi fi # LINUX2 if [ "${INST_LINUX}" = "yes" ]; then if [ -d /mnt/${BKP_PREFIX}_backup/linux2 ]; then if [ -f /mnt/${BKP_PREFIX}_backup/linux2/linux.img ]; then INST_LINUX2="yes" _part6_label="linux2" _part6_dlabel="Linux #2" _instfound="yes" L2_FROMDIR="yes" fi else if [ -f /mnt/linux2.img ]; then INST_LINUX2="yes" _part6_label="linux2" _part6_dlabel="Linux #2" fi fi fi if [ ! "${INST_ANDROID}" = "yes" ] || [ ! "${INST_LINUX2}" = "yes" ]; then # === OpenElec instalation is possible only if Android OR Linux2 are not installed === if [ -d /mnt/${BKP_PREFIX}_backup/oelec/target ] && [ -d /mnt/${BKP_PREFIX}_backup/oelec/3rdparty ]; then INST_OELEC="yes" O_FROMDIR="yes" _part6_label="oelec" _part6_dlabel="OpenElec" else if [ -f /mnt/oelec.tar ] || [ -f /mnt/oelec.zip ]; then INST_OELEC="yes" _part6_label="oelec" _part6_dlabel="OpenElec" fi fi fi [ "${_instfound}" = "no" ] && return 1 return 0 } #----------------------------------------------------- #---------------------------------------------------------------------------------------------------- exit_script() { local _delay=60 local B="X" echo "" while [ $_delay -gt 0 ]; do printf " \033[33mPress \033[1mE\033[22m to exit to main menu (%s) \033[37m\r" "${_delay}" if read -n 1 -t 1 -s B; then _delay=60 if [ "${B}" = "E" ] || [ "${B}" = "e" ]; then break elif [ "${B}" = "s" ]; then # SCREENSHOT === fbcat > /install_exit.ppm fi else let _delay=_delay-1 fi done printf "\r\033[2K" umount /mnt1 > /dev/null 2>&1 umount /mnt2 > /dev/null 2>&1 umount /mnt > /dev/null 2>&1 udevadm trigger --action=add > /dev/null 2>&1 exit 0 } #---------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------- check_install_sources() { _inst_no_=0 if [ ! "${INST_ANDROID}" = "yes" ]; then SYSTEM_MINSIZE=8 DATA_MINSIZE=8 SYSTEM_SIZE=8 DATA_SIZE=8 CACHE_SIZE=8 CACHE_MINSIZE=8 USERDATA_MINSIZE=256 USERDATA_SIZE=256 else let _inst_no_=_inst_no_+1 fi if [ ! "${INST_OELEC}" = "yes" ] && [ ! "${INST_LINUX2}" = "yes" ]; then # Partition 6 is reserved partition OELEC_MINSIZE=8 OELEC_SIZE=256 else if [ "${INST_OELEC}" = "yes" ]; then # Partition 6 is oelec partition OELEC_MINSIZE=256 OELEC_SIZE=512 if [ $USERDATA_MINSIZE -lt 384 ]; then USERDATA_MINSIZE=384 USERDATA_SIZE=384 fi let _inst_no_=_inst_no_+1 elif [ "${INST_LINUX2}" = "yes" ]; then # Partition 6 is Linux2 OELEC_MINSIZE=1563 OELEC_SIZE=1536 let _inst_no_=_inst_no_+1 fi fi if [ ! "${INST_LINUX}" = "yes" ]; then LINUX_MINSIZE=8 LINUX_SIZE=8 else let _inst_no_=_inst_no_+1 fi } #--------------------------------------------------------------------------- print_header # =============================================================== # === Copy multiboot files from boot drive to RAMfs directory === # =============================================================== mount -t vfat /dev/mmcblk${BOOT_CARDDEV}p1 /mnt > /dev/null 2>&1 if [ $? -ne 0 ]; then printf " ERROR mounting boot card" exit_script fi cp -rf /mnt/multiboot/* /multiboot > /dev/null 2>&1 if [ $? -ne 0 ]; then printf " ERROR copying multiboot files" exit_script fi umount /mnt > /dev/null 2>&1 if [ $? -ne 0 ]; then printf " ERROR unmounting boot card" exit_script fi sleep 1 # =============================================================== #================================================= printf " Searching for installation drive ... " # === Set default dest card to NON BOOT if exists === DEST_CARD=${CARD1} DEST_EMMC=${CARD1_EMMC} if [ "${NUMCARDS}" = "2" ]; then DEST_CARD=${CARD2} DEST_EMMC=${CARD2_EMMC} fi _instfound="no" #---------------------------------------------------- for src_drive in a b c do for src_part in 1 2 3 4 do check_source "/dev/sd${src_drive}${src_part}" [ "${_instfound}" = "yes" ] && break done [ "${_instfound}" = "yes" ] && break done if [ "${_instfound}" = "no" ]; then printf " \033[33m\033[1mNOT FOUND, aborted\033[22m\033[37m\n" exit_script fi #---------------------------------------------------- _no_android="no" _no_oelec="no" _no_linux="no" _no_linux2="no" while true; do print_header printf " \033[33mInstallation sources found on \033[1msd%s%s\033[22m for:\033[32m\n" "${src_drive}${src_part}" [ "${INST_ANDROID}" = "yes" ] && printf " Android, press \033[1mA\033[22m to disable\n" [ "${_no_android}" = "yes" ] && printf " \033[31mAndroid, press \033[1mA\033[22m to enable\033[32m\n" [ "${INST_OELEC}" = "yes" ] && printf " OpenElec, press \033[1mE\033[22m to disable\n" [ "${_no_oelec}" = "yes" ] && printf " \033[31mOpenElec, press \033[1mE\033[22m to enable\033[32m\n" [ "${INST_LINUX}" = "yes" ] && printf " Linux, press \033[1mL\033[22m to disable\n" [ "${_no_linux}" = "yes" ] && printf " \033[31mLinux, press \033[1mL\033[22m to enable\033[32m\n" [ "${INST_LINUX2}" = "yes" ] && printf " Linux #2, press \033[1m2\033[22m to disable\n" [ "${_no_linux2}" = "yes" ] && printf " \033[31mLinux #2, press \033[1m2\033[22m to enable\033[32m\n" printf " \033[36mPress \033[1mC\033[22m to continue \033[32m\n" B="X" _delay=30 echo "" while [ $_delay -gt 0 ]; do if read -n 1 -t 1 -s B; then _delay=30 if [ "${B}" = "C" ] || [ "${B}" = "c" ]; then break elif [ "${B}" = "A" ] && [ "${INST_ANDROID}" = "yes" ]; then INST_ANDROID="no" _no_android="yes" break elif [ "${B}" = "E" ] && [ "${INST_OELEC}" = "yes" ]; then INST_OELEC="no" _no_oelec="yes" break elif [ "${B}" = "L" ] && [ "${INST_LINUX}" = "yes" ]; then INST_LINUX="no" _no_linux="yes" break elif [ "${B}" = "2" ] && [ "${INST_LINUX2}" = "yes" ]; then INST_LINUX2="no" _no_linux2="yes" break elif [ "${B}" = "A" ] && [ "${_no_android}" = "yes" ]; then INST_ANDROID="yes" _no_android="no" break elif [ "${B}" = "E" ] && [ "${_no_oelec}" = "yes" ]; then INST_OELEC="yes" _no_oelec="no" break elif [ "${B}" = "L" ] && [ "${_no_linux}" = "yes" ]; then INST_LINUX="yes" _no_linux="no" break elif [ "${B}" = "2" ] && [ "${_no_linux2}" = "yes" ]; then INST_LINUX2="yes" _no_linux2="no" break fi else let _delay=_delay-1 fi done if [ "${B}" = "C" ] || [ "${B}" = "c" ]; then break fi done print_header check_install_sources if [ $_inst_no_ -eq 0 ]; then printf " \033[33m\033[1mNOTHING TO INSTALL\033[22m\033[37m\n" exit_script fi #================================================= #================================================= if [ ! "${O_BOARD}" = "XU" ]; then part_start=65536 # RESERVE 32M AT CARD START else part_start=8192 #131072 # RESERVE 64MB AT CARD START fi PARTSIZE_INC=128 export CARD_SIZE=8000 export source_mount="/mnt" if [ "${UPGRADE_ANDROID}" = "yes" ]; then rm /mnt/upgrade.log > /dev/null 2>&1 log_file="/mnt/upgrade.log" #log_file="ls/dev/null" else rm /mnt/install.log > /dev/null 2>&1 log_file="/mnt/install.log" #log_file="ls/dev/null" fi #--------------------------------------------------------------------------------- # Detect and set installation card size, leave 32M at end unused set_cardsize() { _card_sectno=`fdisk -l ${DEST_CARD} | grep "Disk ${DEST_CARD}" | awk '{print $7}'` CARD_SIZE=$(( ( $_card_sectno - $part_start - 65536 ) / 2048)) } #--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- # Set linux or userdata partition size to fill card size set_auto_partsize() { if [ "${INST_LINUX}" = "yes" ]; then LINUX_SIZE=$(( $CARD_SIZE - $USERDATA_SIZE - $SYSTEM_SIZE - $DATA_SIZE -$CACHE_SIZE - $OELEC_SIZE)) if [ "${LINUX_SIZE}" -lt "${LINUX_MINSIZE}" ]; then LINUX_SIZE=${LINUX_MINSIZE} return 1 else return 0 fi else USERDATA_SIZE=$(( $CARD_SIZE - $SYSTEM_SIZE - $DATA_SIZE -$CACHE_SIZE - $OELEC_SIZE - $LINUX_SIZE)) if [ "${USERDATA_SIZE}" -lt "${USERDATA_MINSIZE}" ]; then USERDATA_SIZE=${USERDATA_MINSIZE} return 1 else return 0 fi fi } #-------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------- print_settings() { set_auto_partsize printf " Install:" if [ "${INST_ANDROID}" = "yes" ]; then printf " \033[36mAndroid\033[37m from " if [ "${A_FROMDIR}" = "yes" ]; then printf "backup" else printf "image" fi if [ "${INST_LINUX}" = "yes" ] || [ "${INST_OELEC}" = "yes" ]; then printf "\033[32m &\033[37m" fi fi if [ "${INST_LINUX}" = "yes" ]; then printf " \033[36mLinux\033[37m from " if [ "${L_FROMDIR}" = "yes" ]; then printf "backup" else printf "image" fi if [ "${INST_LINUX2}" = "yes" ] || [ "${INST_OELEC}" = "yes" ]; then printf "\033[32m &\033[37m" fi if [ "${INST_LINUX2}" = "yes" ]; then printf " \033[36mLinux2\033[37m from " if [ "${L2_FROMDIR}" = "yes" ]; then printf "backup" else printf "image" fi if [ "${INST_OELEC}" = "yes" ]; then printf "\033[32m &\033[37m" fi fi fi if [ "${INST_OELEC}" = "yes" ]; then printf " \033[36mOpenElec\033[37m from " if [ "${O_FROMDIR}" = "yes" ]; then printf "backup" else printf "image" fi fi printf "\033[37m\n" printf " Install to: \033[36m%s Card (%s)\033[37m (%sM)\033[37m\n\n" "${DEST_EMMC}" "${DEST_CARD}" "${CARD_SIZE}" printf " Card size: \033[36m%sM\033[37m\n" "${CARD_SIZE}" printf " userdata partition size: \033[36m%sM\033[37m\n" "${USERDATA_SIZE}" printf " system partition size: \033[36m%sM\033[37m\n" "${SYSTEM_SIZE}" printf " data partition size: \033[36m%sM\033[37m\n" "${DATA_SIZE}" printf " cache partition size: \033[36m%sM\033[37m\n" "${CACHE_SIZE}" printf " %s partition size: \033[36m%sM\033[37m\n" "${_part6_dlabel}" "${OELEC_SIZE}" printf " linux partition size: \033[36m%sM\033[37m\n" "${LINUX_SIZE}" if [ "${INST_LINUX}" = "yes" ]; then printf " linux file system type: \033[36m%s\033[37m\n" "${LINUX_FSTYPE}" [ "${O_BOARD}" = "C2" ] && printf " install multiboot kernel: \033[36m%s\033[37m\n" "${_inst_mbkernel}" fi printf "\033[36m\n" [ "${NUMCARDS}" = "2" ] && printf " \033[32m\033[1m1\033[22m Change installation \033[1mcard\033[22m\033[36m\n" printf " \033[32m\033[1m2\033[22m Change \033[1muserdata\033[22m partition size\033[36m\n" printf " \033[32m\033[1m3\033[22m Change \033[1msystem\033[22m partition size\033[36m\n" printf " \033[32m\033[1m4\033[22m Change \033[1mdata\033[22m partition size\033[36m\n" printf " \033[32m\033[1m5\033[22m Change \033[1mcache\033[22m partition size\033[36m\n" printf " \033[32m\033[1m6\033[22m Change \033[1m%s\033[22m partition size\033[36m\n" "${_part6_dlabel}" if [ "${INST_LINUX}" = "yes" ]; then printf " \033[32m\033[1mt\033[22m Change Linux \033[1mfile system type\033[22m\033[36m\n" if [ "${O_BOARD}" = "C2" ]; then if [ "${_inst_mbkernel}" = "yes" ]; then printf " \033[32m\033[1mM\033[22m Install \033[1moriginal Linux kernel\033[22m\033[36m\n" else printf " \033[32m\033[1mM\033[22m Install \033[1mmultiboot Linux kernel\033[22m\033[36m\n" fi fi fi printf "\n \033[35m\033[1mI\033[22m Start installation\033[36m\n" printf " \033[33m\033[1mE\033[22m EXIT\033[37m\n\n" } #--------------------------------------------------------------------------------------------------------------------------- #---- Select destination card ------------------------------------------------------------------------- set_dest() { printf " Press \033[35m+\033[37m key to change installation card, \033[35m9\033[37m to select\n\n" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " Install to: \033[36m%s Card (%s)\033[37m \r" "${DEST_EMMC}" "${DEST_CARD}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then if [ "${NUMCARDS}" = "2" ]; then if [ "${DEST_CARD}" = "${CARD1}" ]; then DEST_CARD=${CARD2} DEST_EMMC=${CARD2_EMMC} elif [ "${DEST_CARD}" = "${CARD2}" ]; then DEST_CARD=${CARD1} DEST_EMMC=${CARD1_EMMC} fi elif [ ! "${O_BOARD}" = "XU" ]; then if [ "${DEST_EMMC}" = "SD" ]; then DEST_EMMC="EMMC" else DEST_EMMC="SD" fi fi elif [ "${A}" = "9" ]; then set_cardsize break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #----------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------- set_systemsize() { printf " Press \033[35m+\033[37m|\033[35m-\033[37m key to change system partition size, \033[35m9\033[37m to select\n\n" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " system partition size: \033[36m%sM\033[37m \r" "${SYSTEM_SIZE}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then let SYSTEM_SIZE=SYSTEM_SIZE+PARTSIZE_INC [ ${SYSTEM_SIZE} -eq 136 ] && SYSTEM_SIZE=$PARTSIZE_INC set_auto_partsize if [ $? -ne 0 ]; then let SYSTEM_SIZE=SYSTEM_SIZE-PARTSIZE_INC set_auto_partsize fi elif [ "${A}" = "-" ]; then let SYSTEM_SIZE=SYSTEM_SIZE-${PARTSIZE_INC} [ $SYSTEM_SIZE -lt $SYSTEM_MINSIZE ] && SYSTEM_SIZE=$SYSTEM_MINSIZE set_auto_partsize elif [ "${A}" = "9" ]; then break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #---------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------- set_datasize() { printf " Press \033[35m+\033[37m|\033[35m-\033[37m key to change data partition size, \033[35m9\033[37m to select\n\n" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " data partition size: \033[36m%sM\033[37m \r" "${DATA_SIZE}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then let DATA_SIZE=DATA_SIZE+PARTSIZE_INC [ ${DATA_SIZE} -eq 136 ] && DATA_SIZE=$PARTSIZE_INC set_auto_partsize if [ $? -ne 0 ]; then let DATA_SIZE=DATA_SIZE-PARTSIZE_INC set_auto_partsize fi elif [ "${A}" = "-" ]; then let DATA_SIZE=DATA_SIZE-PARTSIZE_INC [ $DATA_SIZE -lt $DATA_MINSIZE ] && DATA_SIZE=$DATA_MINSIZE set_auto_partsize elif [ "${A}" = "9" ]; then break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #-------------------------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------ set_userdatasize() { printf " Press \033[35m+\033[37m|\033[35m-\033[37m key to change userdata partition size, \033[35m9\033[37m to select\n\n" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " userdata partition size: \033[36m%sM\033[37m \r" "${USERDATA_SIZE}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then let USERDATA_SIZE=USERDATA_SIZE+PARTSIZE_INC [ ${USERDATA_SIZE} -eq 136 ] && USERDATA_SIZE=$PARTSIZE_INC set_auto_partsize if [ $? -ne 0 ]; then let USERDATA_SIZE=USERDATA_SIZE-PARTSIZE_INC set_auto_partsize fi elif [ "${A}" = "-" ]; then let USERDATA_SIZE=USERDATA_SIZE-PARTSIZE_INC [ $USERDATA_SIZE -lt $USERDATA_MINSIZE ] && USERDATA_SIZE=$USERDATA_MINSIZE set_auto_partsize elif [ "${A}" = "9" ]; then break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------ set_cachesize() { printf " Press \033[35m+\033[37m|\033[35m-\033[37m key to change cache partition size, \033[35m9\033[37m to select\n\n" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " cache partition size: \033[36m%sM\033[37m \r" "${CACHE_SIZE}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then let CACHE_SIZE=CACHE_SIZE+PARTSIZE_INC [ ${CACHE_SIZE} -eq 136 ] && CACHE_SIZE=$PARTSIZE_INC set_auto_partsize if [ $? -ne 0 ]; then let CACHE_SIZE=CACHE_SIZE-PARTSIZE_INC set_auto_partsize fi elif [ "${A}" = "-" ]; then let CACHE_SIZE=CACHE_SIZE-PARTSIZE_INC [ ${CACHE_SIZE} -lt $CACHE_MINSIZE ] && CACHE_SIZE=$CACHE_MINSIZE set_auto_partsize elif [ "${A}" = "9" ]; then break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------ set_oelecsize() { printf " Press \033[35m+\033[37m|\033[35m-\033[37m key to change %s partition size, \033[35m9\033[37m to select\n\n" "${_part6_dlabel}" _wait_delay=30 while [ $_wait_delay -gt 0 ]; do printf " ${_part6_dlabel} partition size: \033[36m%sM\033[37m \r" "${OELEC_SIZE}" if read -n 1 -t 1 -s A; then _wait_delay=30 if [ "${A}" = "+" ]; then let OELEC_SIZE=OELEC_SIZE+PARTSIZE_INC [ ${OELEC_SIZE} -eq 136 ] && OELEC_SIZE=$PARTSIZE_INC set_auto_partsize if [ $? -ne 0 ]; then let OELEC_SIZE=OELEC_SIZE-PARTSIZE_INC set_auto_partsize fi elif [ "${A}" = "-" ]; then let OELEC_SIZE=OELEC_SIZE-PARTSIZE_INC [ ${OELEC_SIZE} -lt $OELEC_MINSIZE ] && OELEC_SIZE=$OELEC_MINSIZE set_auto_partsize elif [ "${A}" = "9" ]; then break fi else let _wait_delay=_wait_delay-1 fi printf "\r" done } #------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------ create_partitions_full() { # == MULTI BOOT PARTITION LAYOUT === # userdata # android system # android cache # extended # android data # oelec/linux2 # linux _userdata_size=$(( $USERDATA_SIZE * 2048 )) _system_size=$(( $SYSTEM_SIZE * 2048 )) _cache_size=$(( $CACHE_SIZE * 2048 )) userpart_end=$(( $_userdata_size + $part_start - 1 )) syspart_start=$(( $userpart_end + 1)) syspart_end=$(( $syspart_start + $_system_size - 1 )) cachepart_start=$(( $syspart_end + 1 )) cachepart_end=$(( $cachepart_start + $_cache_size - 1 )) extpart_start=$(( $cachepart_end + 1)) dd if=/dev/zero of=${DEST_CARD} bs=512 seek=${extpart_start} count=131072 >> ${log_file} 2>&1 sync echo "n p 1 $part_start $userpart_end t c n p 2 $syspart_start $syspart_end n p 3 $cachepart_start $cachepart_end n e $extpart_start n +${DATA_SIZE}M n +${OELEC_SIZE}M n +${LINUX_SIZE}M w" | fdisk ${DEST_CARD} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf " fdisk ERROR " return 1 fi return 0 } #------------------------------------------------------------------------------------------------ #---------------------------------------------------------------------------------------- # Partition and format installation card prepare_card() { echo "==== PREPARE CARD ====" >> ${log_file} printf " Partitioning %s card " "${DEST_EMMC}" # ---- Erase card ------------------------------------------------------- /bin/dd if=/dev/zero of=${DEST_CARD} bs=512 count=${part_start} >> ${log_file} 2>&1 sync sleep 1 /bin/partprobe -s ${DEST_CARD} >> ${log_file} 2>&1 sleep 1 #---- Make new partition table -------------------------- echo -e "o\nw" | /bin/fdisk ${DEST_CARD} >> ${log_file} 2>&1 sync sleep 1 /bin/partprobe -s ${DEST_CARD} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR creating partition table." return 1 fi sleep 1 create_partitions_full [ $? -ne 0 ] && return 1 sleep 2 /bin/partprobe -s ${DEST_CARD} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR creating partitions." return 1 fi sleep 1 sync echo "OK" sleep 1 # *** FORMATING partitions *************************************** printf " Formating partitions... " # === USERDATA/BOOT ======================================================= printf "\033[36muserdata\033[37m... " dd if=/dev/zero of=${DEST_CARD}p1 bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync mkfs -t vfat -F 32 -n ${label_pref}userdata ${DEST_CARD}p1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 if [ "${INST_ANDROID}" = "yes" ]; then printf "\033[36msystem\033[37m... " # === system =================================================== dd if=/dev/zero of=${DEST_CARD}p2 bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync mkfs.ext4 -L ${label_pref}system ${DEST_CARD}p2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 # === data =================================================== printf "\033[36mdata\033[37m... " dd if=/dev/zero of=${DEST_CARD}p${ADATA_PART} bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync mkfs.ext4 -L ${label_pref}data ${DEST_CARD}p${ADATA_PART} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 # === cache ================================================================= printf "\033[36mcache\033[37m... " dd if=/dev/zero of=${DEST_CARD}p${ACACHE_PART} bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync mkfs.ext4 -L ${label_pref}cache ${DEST_CARD}p${ACACHE_PART} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 fi if [ "$INST_OELEC" = "yes" ] || [ "${INST_LINUX2}" = "yes" ]; then printf "\033[36moelec\033[37m... " # === OpenElec/Linux2 ============================================== dd if=/dev/zero of=${DEST_CARD}p6 bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync mkfs.ext4 -L ${label_pref}${_part6_label} ${DEST_CARD}p6 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 fi if [ "${INST_LINUX}" = "yes" ]; then # === linux ========================================================================= printf "\033[36mlinux\033[37m... " dd if=/dev/zero of=${DEST_CARD}p7 bs=512 count=2048 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR" return 1 fi sync if [ "${LINUX_FSTYPE}" = "btrfs" ] ; then mkfs.btrfs -f -L ${label_pref}linux ${DEST_CARD}p7 >> ${log_file} 2>&1 else mkfs.ext4 -L ${label_pref}linux ${DEST_CARD}p7 >> ${log_file} 2>&1 fi if [ $? -ne 0 ]; then echo "mkfs ERROR" return 1 fi sync sleep 1 fi /bin/partprobe -s ${DEST_CARD} >> ${log_file} 2>&1 echo "OK" return 0 } #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------- # copy Odroid boot files to installation card install_boot_c2() { echo "==== INSTALL BOOT ====" >> ${log_file} printf " Installing Odroid boot files ... " dd if=/multi/bl1.bin of=${DEST_CARD} bs=1 count=442 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi dd if=/multi/bl1.bin of=${DEST_CARD} bs=512 skip=1 seek=1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi sync dd if=/multi/u-boot.bin of=${DEST_CARD} bs=512 seek=97 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing u-boot.bin." return 1 fi sync echo "OK" sleep 1 } #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # copy Odroid boot files to installation card install_boot_c1() { echo "==== INSTALL BOOT ====" >> ${log_file} printf " Installing Odroid boot files ... " dd if=/multi/bl1.bin of=${DEST_CARD} bs=1 count=442 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi dd if=/multi/bl1.bin of=${DEST_CARD} bs=512 skip=1 seek=1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi sync dd if=/multi/u-boot.bin of=${DEST_CARD} bs=512 seek=64 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing u-boot.bin." return 1 fi sync echo "OK" sleep 1 } #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # copy Odroid boot files to installation card install_boot_xu() { if [ "${label_pref}" = "sd" ]; then printf " Installing Odroid boot files to SD Card ... " dd if=/multi/bl1.bin of=${DEST_CARD} bs=512 seek=1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi sync dd if=/multi/bl2.bin of=${DEST_CARD} seek=31 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl2.bin." return 1 fi sync dd if=/multi/u-boot.bin of=${DEST_CARD} seek=63 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing u-boot.bin." return 1 fi sync dd if=/multi/tzsw.bin of=${DEST_CARD} seek=2111 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing tzsw.bin." return 1 fi sync echo "OK" else # UNLOCK boot0 _dest_card_=$(basename ${DEST_CARD}) printf " Installing Odroid boot files to EMMC Card (%s [%s])... " "${DEST_CARD}" "${_dest_card_}" if [ -e /sys/block/${_dest_card_}boot0/force_ro ]; then echo 0 > /sys/block/${_dest_card_}boot0/force_ro if [ $? -ne 0 ]; then echo "ERROR enabling boot0." return 1 fi else echo "ERROR: boot0 not found." return 1 fi dd if=/dev/zero of=${DEST_CARD}boot0 count=8192 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf "WARNING: error erasing boot0 " fi sync dd if=/multi/bl1.bin of=${DEST_CARD}boot0 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl1.bin." return 1 fi sync dd if=/multi/bl2.bin of=${DEST_CARD}boot0 seek=30 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing bl2.bin." return 1 fi sync dd if=/multi/u-boot.bin of=${DEST_CARD}boot0 seek=62 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing u-boot.bin." return 1 fi sync dd if=/multi/tzsw.bin of=${DEST_CARD}boot0 seek=2110 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR installing tzsw.bin." return 1 fi sync echo 1 > /sys/block/${_dest_card_}boot0/force_ro echo "OK" fi sleep 1 } #---------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------- install_multi_sel() { echo "==== INSTALL MULTIBOOT SUPPORT ====" >> ${log_file} umount /mnt2 >> ${log_file} 2>&1 # Update userdata partition for multiboot /bin/mountx -t vfat ${DEST_CARD}p1 /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR mounting boot partition." return 1 fi sleep 1 mkdir /mnt2/multiboot >> ${log_file} 2>&1 if [ ! -d /multiboot ]; then echo " ERROR: missing multiboot directory." return 1 fi if [ -d /multiboot/mb_kernel ]; then mkdir /mnt2/multiboot/mb_kernel >> ${log_file} 2>&1 cp -f /multiboot/mb_kernel/* /mnt2/multiboot/mb_kernel >> ${log_file} 2>&1 fi cp /multiboot/boot.ini.multi /mnt2/multiboot >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 if [ "${O_BOARD}" = "XU" ]; then cp /multiboot/boot.scr.multi /mnt2/multiboot >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 cp /mnt2/multiboot/boot.scr.multi /mnt2/boot.scr >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 else cp /mnt2/multiboot/boot.ini.multi /mnt2/boot.ini >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 if [ "${label_pref}" = "em" ]; then sed -i "s/setenv CARD_TYPE SD/setenv CARD_TYPE EMMC/g" /mnt2/multiboot/boot.ini.multi fi fi cp /multiboot/${ODROID_IMAGE}.multi /mnt2/multiboot >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 cp /multiboot/uInitrd.multi /mnt2/multiboot >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 cp /multiboot/*.dtb.multi /mnt2/multiboot >> ${log_file} 2>&1 [ $? -ne 0 ] && return 1 #chmod -wx /mnt2/multiboot/${ODROID_IMAGE}.multi >> ${log_file} 2>&1 #chmod -wx /mnt2/multiboot/uInitrd.multi >> ${log_file} 2>&1 #chmod -wx /mnt2/multiboot/*.dtb.multi >> ${log_file} 2>&1 if [ "${label_pref}" = "sd" ]; then touch /mnt2/THIS_IS_SDCARD >> ${log_file} 2>&1 [ -f /mnt2/THIS_IS_EMMC ] && rm /mnt2/THIS_IS_EMMC >> ${log_file} 2>&1 else touch /mnt2/THIS_IS_EMMC >> ${log_file} 2>&1 [ -f /mnt2/THIS_IS_SDCARD ] && rm /mnt2/THIS_IS_SDCARD >> ${log_file} 2>&1 fi return 0 } #--------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------ set_android_sizes() { _img_size=$(/bin/lsx -ls ${andro_dest}/system.raw.img | awk '{print $1}') _img_size_=$(( $_img_size / 1024 / $PARTSIZE_INC * $PARTSIZE_INC )) while [ $SYSTEM_MINSIZE -lt $_img_size_ ] do let SYSTEM_MINSIZE=SYSTEM_MINSIZE+PARTSIZE_INC done let SYSTEM_MINSIZE=SYSTEM_MINSIZE+256 SYSTEM_SIZE=${SYSTEM_MINSIZE} if [ -f ${andro_dest}/cache.raw.img ]; then _img_size=$(/bin/lsx -ls ${andro_dest}/cache.raw.img | awk '{print $1}') _img_size_=$(( $_img_size / 1024 / $PARTSIZE_INC * $PARTSIZE_INC )) while [ $CACHE_MINSIZE -lt $_img_size_ ] do let CACHE_MINSIZE=CACHE_MINSIZE+PARTSIZE_INC done CACHE_SIZE=${CACHE_MINSIZE} fi if [ -f ${andro_dest}/data.raw.img ]; then _img_size=$(/bin/lsx -ls ${andro_dest}/data.raw.img | awk '{print $1}') _img_size_=$(( $_img_size / 1024 / $PARTSIZE_INC * $PARTSIZE_INC )) while [ $DATA_MINSIZE -lt $_img_size_ ] do let DATA_MINSIZE=DATA_MINSIZE+PARTSIZE_INC done DATA_SIZE=${DATA_MINSIZE} fi } #------------------------------------------------------------------------------ #-------------------------------------------------------------------------------------------------------------------------------- check_android_backup() { andro_dest="${source_mount}/${BKP_PREFIX}_backup/android" if [ ! -f ${andro_dest}/system.raw.img ]; then echo " system.img missing." sleep 2 return 1 fi if [ ! -f ${andro_dest}/data.raw.img ]; then echo " WARNING: data.img missing." fi if [ ! -f ${andro_dest}/cache.raw.img ]; then echo " WARNING: cache.img missing." fi if [ ! -f ${andro_dest}/${ODROID_IMAGE} ]; then echo " KERNEL (%s) not found!" "${ODROID_IMAGE}" sleep 2 return 1 fi if [ ! "${O_BOARD}" = "XU" ] && [ ! -f ${andro_dest}/${ODROID_DTB} ]; then echo " %s not found!" "${ODROID_DTB}" sleep 2 return 1 fi set_android_sizes return 0 } #-------------------------------------------------------------------------------------------------------------------------------- # Extract Android images from tar and expand sparse image files #---------------------------------------------------------------------------- unpack_android() { echo "==== UNPACK ANDROID ====" >> ${log_file} andro_updatearchive="no" mkdir /run/inst >> ${log_file} 2>&1 mkdir /run/inst/android >> ${log_file} 2>&1 rm -rf /run/inst/android/* >> ${log_file} 2>&1 printf " Extracting Android partition images for %s, please wait ... \n" "${O_BOARD}" if [ -f ${source_mount}/update.tar.gz ]; then mkdir ${source_mount}/android >> ${log_file} 2>&1 rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 cp ${source_mount}/update.tar.gz ${source_mount}/android/update.tar.gz cd ${source_mount}/android tar -xf update.tar.gz --warning=no-timestamp >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR extracting archive." cd / return 1 fi rm update.tar.gz _name=$(ls) if [ ! -d "${_name}" ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " install directory not found in archive!" cd / return 1 fi if [ ! -f ${_name}/${ODROID_ASYSTEMIMAGE} ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ${ODROID_ASYSTEMIMAGE} not found!" cd / return 1 fi andro_source="${source_mount}/android/${_name}" cd / elif [ -f ${source_mount}/update.zip ] && [ ! "${O_BOARD}" = "XU" ]; then # !!! NOT WORKING - DON'T USE zip INSTALLATION ON c2!!! mkdir ${source_mount}/android >> ${log_file} 2>&1 rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 # unzip unzip -qq ${source_mount}/update.zip -d ${source_mount}/android >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR unpacking \"update.zip\"." return 1 fi sync if [ -d ${source_mount}/android/rootsystem ]; then # C2 android upgrade archive andro_updatearchive="yes" andro_source="${source_mount}/android" _img_size=$(du -s /mnt1 | awk '{print $1}') _img_size_=$(( ($_img_size / 1024) + 128 )) while [ $SYSTEM_MINSIZE -lt $_img_size_ ] do let SYSTEM_MINSIZE=SYSTEM_MINSIZE+PARTSIZE_INC done let SYSTEM_MINSIZE=SYSTEM_MINSIZE+256 SYSTEM_SIZE=${SYSTEM_MINSIZE} else rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR: not android update archive" return 1 fi elif [ -f ${source_mount}/update.zip ] && [ "${O_BOARD}" = "XU" ]; then mkdir ${source_mount}/android >> ${log_file} 2>&1 rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 # unzip, MAKE directories unzip -qq ${source_mount}/update.zip -d ${source_mount}/android >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR unpacking \"update.zip\"." return 1 fi sync andro_source="${source_mount}/android" if [ ! -f ${andro_source}/${ODROID_IMAGE} ]; then # === Installation sources in subdirectory or in installation image === cd ${source_mount}/android >> ${log_file} 2>&1 _name=$(ls *.img 2> /dev/null) cd / >> ${log_file} 2>&1 if [ ! "${_name}" = "" ] && [ "${_name}" == "${_name%[[:space:]]*}" ]; then echo " Found installation image ${_name}" # === in installation image, mount it and copy install files === mkdir ${source_mount}/android/inst_mnt >> ${log_file} 2>&1 mount -t vfat ${source_mount}/android/${_name} ${source_mount}/android/inst_mnt >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR mounting: not android archive" return 1 fi cp -f ${source_mount}/android/inst_mnt/* ${source_mount}/android >> ${log_file} 2>&1 umount ${source_mount}/android/inst_mnt >> ${log_file} 2>&1 rmdir ${source_mount}/android/inst_mnt >> ${log_file} 2>&1 rm -f ${source_mount}/android/${_name} >> ${log_file} 2>&1 andro_source="${source_mount}/android" else # === in instalation directory === cd ${source_mount}/android >> ${log_file} 2>&1 _name=$(ls) if [ ! -d "${_name}" ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " Installation directory not found" cd / return 1 fi echo " Found installation directory ${_name}" if [ ! -f ${_name}/${ODROID_ASYSTEMIMAGE} ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ${ODROID_ASYSTEMIMAGE} not found!" cd / return 1 fi cd / >> ${log_file} 2>&1 andro_source="${source_mount}/android/${_name}" fi fi else echo "ERROR: archive file not found." return 1 fi sync echo "OK." printf " Preparing Android partition images ...\n" if [ ! -f ${andro_source}/${ODROID_IMAGE} ]; then echo " KERNEL (${ODROID_IMAGE}) not found!" if [ "${O_BOARD}" = "XU" ]; then if [ -f ${andro_source}/zImage-dtb ]; then mv ${andro_source}/zImage-dtb ${andro_source}/${ODROID_IMAGE} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR renaming 'zImage-dtb'" sleep 4 return 1 fi echo " KERNEL 'zImage-dtb' found, RENAMED to ${ODROID_IMAGE}." sleep 4 else rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 sleep 4 return 1 fi elif [ "${O_BOARD}" = "C1" ]; then if [ -f ${andro_source}/kernel ]; then mv ${andro_source}/kernel ${andro_source}/${ODROID_IMAGE} >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR renaming 'kernel'" sleep 4 return 1 fi echo " KERNEL 'kernel' found, RENAMED to ${ODROID_IMAGE}." sleep 4 else rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 sleep 4 return 1 fi else rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 sleep 4 return 1 fi fi if [ ! "${O_BOARD}" = "XU" ] && [ ! -f ${andro_source}/${ODROID_DTB} ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ${ODROID_DTB} not found!" sleep 2 return 1 fi if [ "${andro_updatearchive}" = "yes" ]; then andro_dest="${andro_source}" return 0 fi if [ ! -f ${andro_source}/${ODROID_ASYSTEMIMAGE} ] || [ ! -f ${andro_source}/userdata.img ] || [ ! -f ${andro_source}/cache.img ]; then if [ ! -f ${andro_source}/userdata.img ]; then if [ "${O_BOARD}" = "XU" ]; then # CM for XU3/XU4 can have different userdata.img names if [ -f ${andro_source}/userdata_8.img ]; then mv ${andro_source}/userdata_8.img ${andro_source}/userdata.img else if [ -f ${andro_source}/userdata_16.img ]; then mv ${andro_source}/userdata_16.img ${andro_source}/userdata.img else if [ -f ${andro_source}/userdata_32.img ]; then mv ${andro_source}/userdata_32.img ${andro_source}/userdata.img else if [ -f ${andro_source}/userdata_64.img ]; then mv ${andro_source}/userdata_64.img ${andro_source}/userdata.img fi fi fi fi fi if [ ! -f ${andro_source}/userdata.img ]; then echo " WARNING: 'userdata.img' missing." sleep 2 fi fi if [ ! -f ${andro_source}/${ODROID_ASYSTEMIMAGE} ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo " ERROR: 'system.img' missing." sleep 2 return 1 fi if [ ! -f ${andro_source}/cache.img ]; then echo " WARNING: 'cache.img' missing." sleep 2 fi fi # All needed images and files are present, get sizes _ramfs_free=$(df | grep tmpfs | awk '{print $4}') _ramfs_free=$(( $_ramfs_free / 1024 - 100 )) _img_size=$(/bin/lsx -ls ${andro_source}/${ODROID_ASYSTEMIMAGE} | awk '{print $1}') size_of_images=$_img_size if [ -f ${andro_source}/userdata.img ]; then _img_size=$(/bin/lsx -ls ${andro_source}/userdata.img | awk '{print $1}') size_of_images=$(( $size_of_images + $_img_size)) fi if [ -f ${andro_source}/cache.img ]; then _img_size=$(/bin/lsx -ls ${andro_source}/cache.img | awk '{print $1}') size_of_images=$(( $size_of_images + $_img_size)) fi size_of_images=$(( $size_of_images / 1024 )) if [ $size_of_images -gt $_ramfs_free ]; then andro_dest="${andro_source}" echo " Decompressing to source drive (${size_of_images} MB)" else andro_dest="/run/inst/android" echo " Decompressing to RAMfs (${size_of_images} MB)" cp ${andro_source}/${ODROID_DTB} ${andro_dest} >> ${log_file} 2>&1 cp ${andro_source}/${ODROID_IMAGE} ${andro_dest} >> ${log_file} 2>&1 sync fi # === Decompress sparse images === printf " system ... " simg2img ${andro_source}/${ODROID_ASYSTEMIMAGE} ${andro_dest}/system.raw.img >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo "ERROR." return 1 fi sync rm ${andro_source}/${ODROID_ASYSTEMIMAGE} if [ -f ${andro_source}/cache.img ]; then printf "cache... " simg2img ${andro_source}/cache.img ${andro_dest}/cache.raw.img >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo "ERROR." return 1 fi sync rm ${andro_source}/cache.img fi if [ -f ${andro_source}/userdata.img ]; then printf "data... " simg2img ${andro_source}/userdata.img ${andro_dest}/data.raw.img >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 echo "ERROR." return 1 fi sync rm ${andro_source}/userdata.img fi echo "OK." set_android_sizes return 0 } #---------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------- install_android() { if [ "${UPGRADE_ANDROID}" = "yes" ]; then echo "==== UPGRADING ANDROID ====" >> ${log_file} printf "\n \033[33mUPGRADING \033[1mAndroid\033[22m\033[37m" else echo "==== INSTALL ANDROID ====" >> ${log_file} printf "\n \033[33mInstalling \033[1mAndroid\033[22m\033[37m" fi if [ "${A_FROMDIR}" = "yes" ]; then printf " (from backup)\n" else printf "\n" fi local src_system="/mnt1" mkdir /mnt1 >> ${log_file} 2>&1 mkdir /mnt2 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 umount /mnt1 >> ${log_file} 2>&1 # === Copy system partition === printf " Installing \033[36msystem\033[37m ... " if [ ! "${andro_updatearchive}" = "yes" ]; then # mount source mount -t ext4 -o ro,loop ${andro_dest}/system.raw.img /mnt1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR mounting system image." return 1 fi else src_system="${andro_dest}/rootsystem" fi # mount destination if [ "${UPGRADE_ANDROID}" = "yes" ]; then mountx -t ext4 ${_dest_system} /mnt2 >> ${log_file} 2>&1 else mountx -t ext4 ${DEST_CARD}p2 /mnt2 >> ${log_file} 2>&1 fi if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 echo "ERROR mounting system partition." return 1 fi sleep 1 if [ "${UPGRADE_ANDROID}" = "yes" ]; then rm -rfd /mnt2/* >> ${log_file} 2>&1 fi rsync -r -t -p -o -g -x -l -H -D --numeric-ids -s -A -X --no-specials ${src_system}/ /mnt2/ >> ${log_file} 2>&1 if [ $? -ne 0 ]; then if [ "${andro_updatearchive}" = "yes" ]; then rm -rf ${src_system:?}/* >> ${log_file} 2>&1 else umount /mnt1 >> ${log_file} 2>&1 fi umount /mnt2 >> ${log_file} 2>&1 echo "ERROR copying system." return 1 fi sync echo "==== PREPARE ANDROID FOR MULTIBOOT ====" >> ${log_file} # === Prepare fstab for changed partition layout === if [ -f /mnt2/${ODROID_FSTAB} ]; then if [ ! "${O_BOARD}" = "XU" ]; then # Change data partition number (4 -> 5) sed -i "s/\/dev\/block\/mmcblk0p4/\/dev\/block\/mmcblk0p5/g" /mnt2/${ODROID_FSTAB} else cp /mnt2/${ODROID_FSTAB} /mnt2/${ODROID_FSTAB}.original cp /mnt2/${ODROID_FSTAB}.sdboot /mnt2/${ODROID_FSTAB}.sdboot.original # Change data partition number (3 -> 5) sed -i "s/\/dev\/block\/mmcblk0p3/\/dev\/block\/mmcblk0p5/g" /mnt2/${ODROID_FSTAB} # Change cache partition number (4 -> 3) sed -i "s/\/dev\/block\/mmcblk0p4/\/dev\/block\/mmcblk0p3/g" /mnt2/${ODROID_FSTAB} cp /mnt2/${ODROID_FSTAB} /mnt2/${ODROID_FSTAB}.other sed -i "s/\/dev\/block\/mmcblk0/\/dev\/block\/mmcblk1/g" /mnt2/${ODROID_FSTAB}.other sed -i "s/12200000.dwmmc0\/mmc_host\/mmc0/12200000.dwmmcX\/mmc_host\/mmcX/g" /mnt2/${ODROID_FSTAB}.other sed -i "s/12220000.dwmmc2\/mmc_host\/mmc1/12200000.dwmmc0\/mmc_host\/mmc0/g" /mnt2/${ODROID_FSTAB}.other sed -i "s/12200000.dwmmcX\/mmc_host\/mmcX/12220000.dwmmc2\/mmc_host\/mmc1/g" /mnt2/${ODROID_FSTAB}.other sed -i "s/sdcard0:1,noemulatedsd/sdcard1:1,noemulatedsd/g" /mnt2/${ODROID_FSTAB} sed -i "s/sdcard1:auto/sdcard0:auto/g" /mnt2/${ODROID_FSTAB} cp /mnt2/${ODROID_FSTAB} /mnt2/${ODROID_FSTAB}.orig fi else echo "ERROR: ${ODROID_FSTAB} not found" if [ "${andro_updatearchive}" = "yes" ]; then rm -rf ${src_system:?}/* >> ${log_file} 2>&1 else umount /mnt1 >> ${log_file} 2>&1 fi umount /mnt2 >> ${log_file} 2>&1 return 1 fi if [ ! "${UPGRADE_ANDROID}" = "yes" ]; then if [ "${label_pref}" = "sd" ]; then touch /mnt2/THIS_IS_SDCARD >> ${log_file} 2>&1 else touch /mnt2/THIS_IS_EMMC >> ${log_file} 2>&1 fi fi if [ "${andro_updatearchive}" = "yes" ]; then rm -rf ${src_system:?}/* >> ${log_file} 2>&1 fi umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 sleep 1 printf "OK " if [ ! "${UPGRADE_ANDROID}" = "yes" ] && [ ! "${andro_updatearchive}" = "yes" ]; then # === Copy data partition === printf "\033[36mdata\033[37m ... " if [ -f ${andro_dest}/data.raw.img ]; then # mount source mountx -t ext4 -o ro,loop ${andro_dest}/data.raw.img /mnt1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf "ERROR mounting " else # mount destination mount -t ext4 ${DEST_CARD}p${ADATA_PART} /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 echo "ERROR mounting data partition." return 1 fi sleep 1 rsync -r -t -p -o -g -x -l -H -D --numeric-ids -s -A -X --no-specials /mnt1/ /mnt2/ >> ${log_file} 2>&1 if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 echo "ERROR copying userdata." return 1 fi sync umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 sleep 1 printf "OK " fi else printf "skip " fi elif [ "${UPGRADE_ANDROID}" = "yes" ] && [ "${_erase_data}" = "yes" ]; then printf "\033[36merasing data\033[37m ... " # mount destination mountx -t ext4 ${_dest_data} /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf "ERROR mounting " else rm -rf /mnt2/* >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf "ERROR erasing " else printf "OK " fi fi fi umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 # === Copy cache partition === [ ! "${andro_updatearchive}" = "yes" ] && printf "\033[36mcache\033[37m ... " # mount destination if [ "${UPGRADE_ANDROID}" = "yes" ]; then mountx -t ext4 ${_dest_cache} /mnt2 >> ${log_file} 2>&1 else mount -t ext4 ${DEST_CARD}p${ACACHE_PART} /mnt2 >> ${log_file} 2>&1 fi if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 echo "ERROR mounting cache partition." return 1 fi sleep 1 if [ ! "${UPGRADE_ANDROID}" = "yes" ] && [ ! "${andro_updatearchive}" = "yes" ]; then if [ -f ${andro_dest}/data.raw.img ]; then # mount source mountx -t ext4 -o ro,loop ${andro_dest}/cache.raw.img /mnt1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then printf "ERROR mounting " else rsync -r -t -p -o -g -x -l -H -D --numeric-ids -s -A -X --no-specials /mnt1/ /mnt2/ >> ${log_file} 2>&1 if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 echo "ERROR copying cache." return 1 fi fi else printf "skip " fi else rm -rf /mnt2/* >> ${log_file} 2>&1 fi sync umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 sleep 1 printf "OK\n" # Prepare for multiboot printf " Preparing for multi boot ... " /bin/mountx -t vfat ${DEST_CARD}p1 /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR mounting userdata partition." return 1 fi sleep 1 if [ ! "${UPGRADE_ANDROID}" = "yes" ]; then mkdir /mnt2/multiboot >> ${log_file} 2>&1 if [ "${A_FROMDIR}" = "yes" ]; then cp -rf ${andro_dest}/userdir/* /mnt2 >> ${log_file} 2>&1 fi cp /multi/boot.ini.android /mnt2/multiboot >> ${log_file} 2>&1 [ ! -f /mnt2/multiboot/boot.ini.android ] && print "ini file? " elif [ ! -f /mnt2/multiboot/boot.ini.android ]; then cp /multi/boot.ini.android /mnt2/multiboot >> ${log_file} 2>&1 [ ! -f /mnt2/multiboot/boot.ini.android ] && print "ini file? " fi if [ "${O_BOARD}" = "C1" ]; then dd if=/dev/zero of=${DEST_CARD} bs=512 seek=1432 count=64104 >> ${log_file} 2>&1 dd if=${andro_dest}/${ODROID_DTB} of=${DEST_CARD} bs=512 seek=1504 >> ${log_file} 2>&1 dd if=${andro_dest}/${ODROID_IMAGE} of=${DEST_CARD} bs=512 seek=1632 >> ${log_file} 2>&1 [ -f ${andro_dest}/recovery.img ] && dd if=${andro_dest}/recovery.img of=${DEST_CARD} bs=512 seek=34400 >> ${log_file} 2>&1 [ -f ${andro_dest}/hardkernel-720.bmp.gz ] && dd if=${andro_dest}/hardkernel-720.bmp.gz of=${DEST_CARD} bs=512 seek=58976 >> ${log_file} 2>&1 fi cp -f ${andro_dest}/${ODROID_DTB} /mnt2/multiboot/${ODROID_DTB}.android >> ${log_file} 2>&1 cp -f ${andro_dest}/${ODROID_IMAGE} /mnt2/multiboot/${ODROID_IMAGE}.android >> ${log_file} 2>&1 if [ "${O_BOARD}" = "XU" ]; then cp -f ${andro_dest}/${ODROID_IMAGE} /mnt2/multiboot/${ODROID_IMAGE}.andro_1 >> ${log_file} 2>&1 # PATCH zImage !! sed -i 's/mmcblk0p2/mmcblk1p2/g' /mnt2/multiboot/${ODROID_IMAGE}.andro_1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR PATCHING Android kernel." return 1 fi fi sync umount /mnt2 >> ${log_file} 2>&1 sleep 1 echo "OK." return 0 } #---------------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------- # Calculate partitions offsets and sizes of the linux installation image get_lin_partstruct() { echo "==== CHECK LINUX IMAGE ====" >> ${log_file} printf " Checking Linux image ... " local re='^[0-9]+$' _card_sectno=`fdisk -l ${1} | grep "Disk ${1}" | awk '{print $7}'` #printf "%s " "${_card_sectno}" if ! [[ ${_card_sectno} =~ ${re} ]]; then _card_sectno=`fdisk -l ${1} | grep total | awk '{print $8}'` fi if ! [[ ${_card_sectno} =~ ${re} ]]; then echo "ERROR: sectNo?" return 1 fi #_card_end=$(( $_card_sectno - 1024)) _card_sectsize=`fdisk -l ${1} | grep "Sector size" | awk '{print $4}'` #printf "%s " "${_card_sectsize}" if ! [[ ${_card_sectsize} =~ ${re} ]]; then echo "ERROR: sectSize?" return 1 fi # get boot partition offset _partstart=`fdisk -l ${1} | grep ${1}1 | awk '{print $2}'` #printf "%s " "${_partstart}" if [ "${_partstart}" = "*" ]; then _partstart=`fdisk -l ${1} | grep ${1}1 | awk '{print $3}'` printf "[%s] " "${_partstart}" fi if ! [[ ${_partstart} =~ ${re} ]]; then echo "ERROR: FATpartStart?" return 1 fi _fat_partstart=$(( $_partstart * $_card_sectsize )) # get linux partition offset _partstart=`fdisk -l ${1} | grep ${1}2 | awk '{print $2}'` #printf "%s " "${_partstart}" if [ "${_partstart}" = "*" ]; then _partstart=`fdisk -l ${1} | grep ${1}2 | awk '{print $3}'` #printf "[%s] " "${_partstart}" fi if ! [[ ${_partstart} =~ ${re} ]]; then echo "ERROR: LINpartStart?" return 1 fi _linux_partstart=$(( $_partstart * $_card_sectsize )) #printf "(%s,%s) " "${_fat_partstart}" "${_linux_partstart}" echo "OK." return 0 } #------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------- prepare_linux_boot() { echo "==== PREPARE LINUX BOOT ====" >> ${log_file} # Prepare for multi boot if [ -d /mnt2/etc ]; then if [ -f /mnt2/etc/fstab ]; then # === Change fstab for multiboot === # save original fstab cp /mnt2/etc/fstab /mnt2/etc/fstab.orig >> ${log_file} 2>&1 # delete original "/" & "media/boot" mount sed -i '/\/dev\/mmcblk/d' /mnt2/etc/fstab >> ${log_file} 2>&1 sed -i '/UUID=/d' /mnt2/etc/fstab >> ${log_file} 2>&1 sed -i '/LABEL=/d' /mnt2/etc/fstab >> ${log_file} 2>&1 # on DietPi, do not use ramdisk sed -i '/DietPi/d' /mnt2/etc/fstab >> ${log_file} 2>&1 # save the rest mv /mnt2/etc/fstab /mnt2/etc/_fstab >> ${log_file} 2>&1 if [ "${LINUX_FSTYPE}" = "btrfs" ] ; then echo "LABEL=${label_pref}linux / btrfs noatime,nodiratime,compress=lzo 0 1" > /mnt2/etc/fstab else echo "LABEL=${label_pref}linux / ext4 errors=remount-ro,noatime,nodiratime 0 1" > /mnt2/etc/fstab fi echo "LABEL=${label_pref}userdata /media/boot vfat rw,user,sync,exec,dev,suid,uid=1000,gid=1000,dmask=000,fmask=111,iocharset=utf8 0 0" >> /mnt2/etc/fstab # append saved fstab cat /mnt2/etc/_fstab >> /mnt2/etc/fstab rm /mnt2/etc/_fstab >> ${log_file} 2>&1 else echo "ERROR: \"etc/fstab\" not found!" return 1 fi if [ -f /mnt2/etc/rc.local ]; then # === Change rc.local to prevent partition resize === cp /mnt2/etc/rc.local /mnt2/etc/rc.local.orig >> ${log_file} 2>&1 sed -i '/first-boot/d' /mnt2/etc/rc.local >> ${log_file} 2>&1 sed -i '/aafirstboot/d' /mnt2/etc/rc.local >> ${log_file} 2>&1 sed -i '/resizefs/d' /mnt2/etc/rc.local >> ${log_file} 2>&1 sed -i '/^.*exit/d' /mnt2/etc/rc.local >> ${log_file} 2>&1 if [ -f /mnt2/aafirstboot ]; then # on original odroid Linux echo "" >> /mnt2/etc/rc.local echo "if [ -f /.first_boot ]; then" >> /mnt2/etc/rc.local echo " rm -f /.first_boot" >> /mnt2/etc/rc.local echo " [ ! -f /etc/ssh/ssh_host_rsa_key ] && dpkg-reconfigure openssh-server" >> /mnt2/etc/rc.local echo "fi" >> /mnt2/etc/rc.local fi echo "exit 0" >> /mnt2/etc/rc.local chmod 0755 /mnt2/etc/rc.local rm -f /mnt2/aafirstboot >> ${log_file} 2>&1 rm -f /mnt2/.resizefs >> ${log_file} 2>&1 fi else echo "ERROR: \"etc\" directory not found!" return 1 fi # for DietPi if [ -f /mnt2/DietPi/dietpi/boot ]; then # Prevent dietPi to resize the partition cp /mnt2/DietPi/dietpi/boot /mnt2/DietPi/dietpi/boot.orig >> ${log_file} 2>&1 sed -i "s/Partition_SD()/nopartition_sd()/g" /mnt2/DietPi/dietpi/boot >> ${log_file} 2>&1 sed -i "s/Expand_SD()/noexpand_sd()/g" /mnt2/DietPi/dietpi/boot >> ${log_file} 2>&1 sed -i "s/Partition_SD/#Partition_SD/g" /mnt2/DietPi/dietpi/boot >> ${log_file} 2>&1 sed -i "s/Expand_SD/#Expand_SD/g" /mnt2/DietPi/dietpi/boot >> ${log_file} 2>&1 # do not use DietPi ramdisk cp /mnt2/DietPi/dietpi/dietpi-ramdisk /mnt2/DietPi/dietpi/dietpi-ramdisk.orig >> ${log_file} 2>&1 echo "#!/bin/bash" > /mnt2/DietPi/dietpi/dietpi-ramdisk echo "exit 0" >> /mnt2/DietPi/dietpi/dietpi-ramdisk chmod 0755 /mnt2/DietPi/dietpi/dietpi-ramdisk # symulate ramdisk echo -e "0" > /mnt2/DietPi/.ramdisk fi # for Armbian touch /mnt2/root/.no_rootfs_resize if [ -d /mnt2/media/odroid ]; then chown 1000:1000 /mnt2/media/odroid >> ${log_file} 2>&1 chmod 0666 /mnt2/media/odroid >> ${log_file} 2>&1 fi if [ -f /mnt2/usr/local/bin/fs_resize_warning ]; then rm -f /mnt2/usr/local/bin/fs_resize_warning >> ${log_file} 2>&1 fi mkdir /mnt2/media/boot >> ${log_file} 2>&1 chown 1000:1000 /mnt2/media/boot >> ${log_file} 2>&1 chmod 0666 /mnt2/media/boot >> ${log_file} 2>&1 return 0 } #---------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------- install_linux() { echo "==== INSTALL LINUX ====" >> ${log_file} local lin_fromdir="no" if [ "${1}" = "linux.img" ] && [ "${L_FROMDIR}" = "yes" ]; then lin_fromdir="yes" elif [ "${1}" = "linux2.img" ] && [ "${L2_FROMDIR}" = "yes" ]; then lin_fromdir="yes" fi if [ "${1}" = "linux2.img" ]; then printf "\n \033[33mInstalling \033[1mLinux 2\033[22m\033[37m\n" else printf "\n \033[33mInstalling \033[1mLinux\033[22m\033[37m\n" fi if [ "${lin_fromdir}" = "no" ]; then get_lin_partstruct "/mnt/${1}" if [ $? -ne 0 ]; then printf " \033[35mWRONG Linux image partition structure!\033[37m\n" return 1 fi sleep 1 fi mkdir /mnt1 >> ${log_file} 2>&1 mkdir /mnt2 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 umount /mnt1 >> ${log_file} 2>&1 local _linpart="p7" local _linsufix="" if [ "${1}" = "linux2.img" ]; then _linpart="p6" _linsufix="2" fi # === Copy Linux partition === printf " \033[35mcopying Linux can take more than 15 min to complete on SDCard!\033[37m\n" if [ "${lin_fromdir}" = "no" ]; then printf " Installing Linux root file system from image ... " /bin/mountx -t ext4 -o ro,loop,offset=${_linux_partstart} ${source_mount}/${1} /mnt1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR mounting Linux source image." return 1 fi else printf " Installing Linux root file system from backup ... " /bin/mountx -t ext4 ${source_mount}/${BKP_PREFIX}_backup/linux${_linsufix}/linux.img /mnt1 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR mounting Linux backup image." return 1 fi fi if [ "${LINUX_FSTYPE}" = "btrfs" ] ; then /bin/mountx -t btrfs -o compress-force=lzo ${DEST_CARD}${_linpart} /mnt2 >> ${log_file} 2>&1 else /bin/mountx -t ext4 ${DEST_CARD}${_linpart} /mnt2 >> ${log_file} 2>&1 fi if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 echo " ERROR mounting Linux destination partition." return 1 fi printf "copying... " rsync -r -t -p -o -g -x -l -H -D --numeric-ids -s --stats /mnt1/ /mnt2/ >> ${log_file} 2>&1 if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 echo "ERROR copying Linux." return 1 fi sync printf "preparing... " prepare_linux_boot if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 return 1 fi if [ "${_inst_mbkernel}" = "yes" ]; then if [ -f /multiboot/mb_kernel/lib.tar.gz ]; then printf "[prepare multiboot kernel: " cd /mnt2 tar -tf /multiboot/mb_kernel/lib.tar.gz --warning=no-timestamp > /dev/null 2>&1 if [ $? -eq 0 ]; then tar -xf /multiboot/mb_kernel/lib.tar.gz --same-owner --warning=no-timestamp >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR]" cd / return 1 fi printf "ok] " else printf "cannot extract] " _inst_mbkernel="no" fi cd / else _inst_mbkernel="no" fi fi if [ ! "${O_BOARD}" = "XU" ] && [ -f /multi/linux ]; then cp /multi/linux /mnt2/usr/share/terminfo/l >> ${log_file} 2>&1 echo "tput cnorm" >> /mnt2/root/.bashrc [ -d /mnt2/home/odroid ] && echo "tput cnorm" >> /mnt2/home/odroid/.bashrc fi cp /check_kernel /mnt2/bin >> ${log_file} 2>&1 cp /check_u-boot /mnt2/bin >> ${log_file} 2>&1 mkdir -p /mnt2/opt/multiboot >> ${log_file} 2>&1 cp /multi/u-boot.bin /mnt2/opt/multiboot >> ${log_file} 2>&1 # prevent installation/update of some packages [ ! -d /mnt2/etc/apt/preferences.d ] && mkdir -p /mnt2/etc/apt/preferences.d cat > /mnt2/etc/apt/preferences.d/odroid.pref << _EOF_ Package: u-boot Pin: release * Pin-Priority: -100 Package: bootini Pin: release * Pin-Priority: -100 _EOF_ #Package: linux-image-arm64-odroid-c2 #Pin: release * #Pin-Priority: -100 umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 sleep 1 echo "OK" # ===================================================== # === Update userdata partition for Linux multiboot === printf " Copying Linux boot files ... " local boot_src="/mnt1" if [ "${lin_fromdir}" = "no" ]; then /bin/mountx -t vfat -o ro,loop,offset=${_fat_partstart} ${source_mount}/${1} /mnt1 if [ $? -ne 0 ]; then echo "ERROR mounting Linux boot image." return 1 fi else boot_src="${source_mount}/${BKP_PREFIX}_backup/linux${_linsufix}" fi /bin/mountx -t vfat ${DEST_CARD}p1 /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then umount /mnt1 >> ${log_file} 2>&1 echo "ERROR mounting boot partition." return 1 fi sync sleep 1 # Prepare boot.ini local _dtbdir="" if [ ! -f ${boot_src}/${ODROID_DTB} ]; then # on Armbian dtb is in separate directory [ -f ${boot_src}/dtb/${ODROID_DTB} ] && _dtbdir="dtb/" fi if [ -f ${boot_src}/${_dtbdir}${ODROID_DTB} ] && [ -f ${boot_src}/${ODROID_IMAGE} ] && [ -f ${boot_src}/uInitrd ]; then mkdir /mnt2/multiboot >> ${log_file} 2>&1 cp /multi/boot.ini.linux${_linsufix} /mnt2/multiboot/boot.ini.linux${_linsufix} sed -i "s/root=LABEL=XXlinux/root=LABEL=${label_pref}linux/g" /mnt2/multiboot/boot.ini.linux${_linsufix} cp ${boot_src}/${_dtbdir}${ODROID_DTB} /mnt2/multiboot/${ODROID_DTB}.linux${_linsufix} >> ${log_file} 2>&1 cp ${boot_src}/${ODROID_IMAGE} /mnt2/multiboot/${ODROID_IMAGE}.linux${_linsufix} >> ${log_file} 2>&1 cp ${boot_src}/uInitrd /mnt2/multiboot/uInitrd.linux${_linsufix} >> ${log_file} 2>&1 if [ "${_inst_mbkernel}" = "yes" ]; then if [ -f /multiboot/mb_kernel/${ODROID_DTB} ] && [ -f /multiboot/mb_kernel/${ODROID_IMAGE} ] && [ -f /multiboot/mb_kernel/uInitrd ]; then printf "[Using multiboot kernel] " cp -f /multiboot/mb_kernel/${ODROID_DTB} /mnt2/multiboot/${ODROID_DTB}.linux${_linsufix} >> ${log_file} 2>&1 cp -f /multiboot/mb_kernel/${ODROID_IMAGE} /mnt2/multiboot/${ODROID_IMAGE}.linux${_linsufix} >> ${log_file} 2>&1 cp -f /multiboot/mb_kernel/uInitrd /mnt2/multiboot/uInitrd.linux${_linsufix} >> ${log_file} 2>&1 fi fi else echo "ERROR: not all Linux boot files found! " umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 return 1 fi umount /mnt1 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 sleep 1 echo "OK" } #---------------------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------------------------------------------------------------------ install_oelec() { echo "==== INSTALL OpenElec ====" >> ${log_file} printf "\n \033[33mInstalling \033[1mOpenELEC\033[22m\033[37m\n" _oelec_source="/run/oelec" mkdir /mnt1 >> ${log_file} 2>&1 mkdir /mnt2 >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 umount /mnt1 >> ${log_file} 2>&1 if [ "${O_FROMDIR}" = "yes" ]; then _name="${source_mount}/${BKP_PREFIX}_backup/oelec" if [ -f ${_name}/oelec.img ]; then printf " Restoring oelec partition... " mkdir /oelecbkp >> ${log_file} 2>&1 /bin/mountx -t ext4 ${_name}/oelec.img /oelecbkp >> ${log_file} 2>&1 if [ $? -eq 0 ]; then /bin/mountx ${DEST_CARD}p6 /mnt2 > /dev/null 2>&1 if [ $? -eq 0 ]; then rsync -r -t -p -o -g -x -l -H -D --numeric-ids -s --stats /oelecbkp/ /mnt2/ > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "ERROR: copy" else echo "OK" fi fi else echo "ERROR: mount" fi umount /oelecbkp >> ${log_file} 2>&1 umount /mnt2 >> ${log_file} 2>&1 rmdir /oelecbkp >> ${log_file} 2>&1 fi else if [ -f ${source_mount}/oelec.tar ]; then /bin/tar -tf ${source_mount}/oelec.tar >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo " ERROR testing archive." cd / rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi _ramfs_free=$(df | grep tmpfs | awk '{print $4}') _ramfs_free=$(( $_ramfs_free / 1024 - 100 )) _tarsize_=$(/bin/tar -vtf ${source_mount}/oelec.tar | awk '{SUM += $3} END {print SUM}') _tarsize_=$(( $_tarsize_ / 1024 / 1024 )) if [ $? -ne 0 ]; then echo " ERROR testing archive." cd / rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi printf " Unpacking archive " if [ $_tarsize_ -lt $_ramfs_free ]; then mkdir /run/oelec >> ${log_file} 2>&1 printf "to RAMfs (%sM) ... " "${_tarsize_}" else mkdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 _oelec_source="${source_mount}/tmp_oelec" printf "to source drive (%sM) ... " "${_tarsize_}" fi rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 cd ${_oelec_source} /bin/tar -xf ${source_mount}/oelec.tar --warning=no-timestamp >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR extracting archive." cd / rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi _name=$(ls) echo "OK." elif [ ! "${O_BOARD}" = "XU" ] && [ -f ${source_mount}/oelec.zip ]; then printf " Unpacking archive " mkdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 # unzip unzip -qq ${source_mount}/oelec.zip -d ${source_mount}/tmp_oelec >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 echo "ERROR unpacking \"oelec.zip\"." return 1 fi sync # check if the archive contains instalation image cd ${source_mount}/tmp_oelec >> ${log_file} 2>&1 _name=$(ls *.img 2> /dev/null) cd / >> ${log_file} 2>&1 if [ "${_name}" == "${_name%[[:space:]]*}" ]; then if [ ! "${_name}" = "" ]; then # mount instalation image and copy install files mkdir ${source_mount}/tmp_oelec/inst_mnt >> ${log_file} 2>&1 /bin/mountx -t vfat -o ro,loop,offset=1048576 ${source_mount}/tmp_oelec/${_name} ${source_mount}/tmp_oelec/inst_mnt >> ${log_file} 2>&1 if [ $? -ne 0 ]; then rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 echo "ERROR: mounting ${_name}" return 1 fi cp -f ${source_mount}/tmp_oelec/inst_mnt/* ${source_mount}/tmp_oelec >> ${log_file} 2>&1 umount ${source_mount}/tmp_oelec/inst_mnt >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec/inst_mnt >> ${log_file} 2>&1 rm -f ${source_mount}/tmp_oelec/${_name} >> ${log_file} 2>&1 else rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 echo "ERROR: not oelec archive" return 1 fi else rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 echo "ERROR: not oelec archive" return 1 fi mkdir ${source_mount}/tmp_oelec/3rdparty >> ${log_file} 2>&1 mkdir ${source_mount}/tmp_oelec/3rdparty/bootloader >> ${log_file} 2>&1 mkdir ${source_mount}/tmp_oelec/target >> ${log_file} 2>&1 local ff="0" mv ${source_mount}/tmp_oelec/${ODROID_DTB} ${source_mount}/tmp_oelec/3rdparty/bootloader >> ${log_file} 2>&1 [ $? -ne 0 ] && ff="1" mv ${source_mount}/tmp_oelec/KERNEL ${source_mount}/tmp_oelec/target >> ${log_file} 2>&1 [ $? -ne 0 ] && ff="1" mv ${source_mount}/tmp_oelec/SYSTEM ${source_mount}/tmp_oelec/target >> ${log_file} 2>&1 [ $? -ne 0 ] && ff="1" if [ "${ff}" = "1" ]; then rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 echo "ERROR: not all openelec files found" return 1 fi _name="${source_mount}/tmp_oelec" else echo " ERROR: archive not found." return 1 fi fi printf " Copying files from %s ... " "${_name}" if [ ! -f ${_name}/3rdparty/bootloader/${ODROID_DTB} ]; then echo "ERROR: ${ODROID_DTB} not found!" cd / [ ! "${O_FROMDIR}" = "yes" ] && rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi if [ ! -f ${_name}/target/KERNEL ] || [ ! -f ${_name}/target/SYSTEM ]; then echo "ERROR SYSTEM or KERNEL not found" cd / [ ! "${O_FROMDIR}" = "yes" ] && rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi if [ "${O_BOARD}" = "XU" ] || [ "${O_BOARD}" = "C1" ]; then if [ ! -f ${_name}/target/INITRD ]; then echo "ERROR: INITRD not found!" cd / [ ! "${O_FROMDIR}" = "yes" ] && rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi fi echo "OK." # Update userdata partition for OpenELEC multiboot printf " Copying OpenELEC files ... " /bin/mountx -t vfat ${DEST_CARD}p1 /mnt2 >> ${log_file} 2>&1 if [ $? -ne 0 ]; then echo "ERROR mounting boot partition." [ ! "${O_FROMDIR}" = "yes" ] && rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 1 fi sleep 1 mkdir /mnt2/multiboot >> ${log_file} 2>&1 cp ${_name}/target/KERNEL /mnt2/multiboot if [ "${O_BOARD}" = "XU" ] || [ "${O_BOARD}" = "C1" ]; then cp ${_name}/target/INITRD /mnt2/multiboot fi cp ${_name}/target/SYSTEM /mnt2 cp ${_name}/3rdparty/bootloader/${ODROID_DTB} /mnt2/multiboot/${ODROID_DTB}.oelec cd / cp /multi/boot.ini.oelec /mnt2/multiboot sed -i "s/boot=LABEL=userdata disk=LABEL=oelec/boot=LABEL=${label_pref}userdata disk=LABEL=${label_pref}${_part6_label}/g" /mnt2/multiboot/boot.ini.oelec sync umount /mnt2 >> ${log_file} 2>&1 echo "OK." [ ! "${O_FROMDIR}" = "yes" ] && rm -rf ${_oelec_source:?}/* >> ${log_file} 2>&1 return 0 } #------------------------------------------------------------------------------------------------------------------------------------------------------ #----------------------------------------------------------------------------------------------------------------- check_inst() { # INSTALLATION DRIVE IS MOUNTED ON /MNT if [ "${INST_ANDROID}" != "yes" ] && [ "${INST_LINUX}" != "yes" ] && [ "${INST_OELEC}" != "yes" ]; then printf " \033[33m\033[1mNOTHING TO INSTALL !\033[22m\033[37m\n" printf " \033[33m\033[1mInstallation aborted.\033[22m\033[37m\n" umount ${source_mount} > /dev/null 2>&1 exit_script fi } #----------------------------------------------------------------------------------------------------------------- # ==================================================================================================== # START # ==================================================================================================== #======================================================================= if [ "${UPGRADE_ANDROID}" = "yes" ]; then echo "==== UNPACK AND DECOMPRESS ANDROID IMAGES ====" >> ${log_file} print_header printf "\n ANDROID UPGRADE\n\n" if [ ! -b /dev/disk/by-label/sdsystem ] && [ ! -b /dev/disk/by-label/emsystem ]; then printf " \033[35mANDROID not installed on any card!\033[37m\n" exit_script fi _num_androinst=1 if [ -b /dev/disk/by-label/sdsystem ] && [ -b /dev/disk/by-label/emystem ]; then _num_androinst=2 fi if [ $_num_androinst -eq 2 ]; then printf " \033[36mAdndroid installation on two cards detected\033[37m\n\n" printf " \033[36m\033[1m1\033[22m Android on SDcard\033[37m\n" printf " \033[36m\033[1m2\033[22m Android on EMMC\033[37m\n\n" printf " \033[36mWhich one to upgrade ? (pres \033[1mE\033[22m to abort)\033[36m" A="x" while true; do if read -n 1 -t 1 -s A; then if [ "${A}" = "1" ]; then _dest_system="/dev/disk/by-label/sdsystem" _dest_cache="/dev/disk/by-label/sdcache" _dest_data="/dev/disk/by-label/sddata" break elif [ "${A}" = "2" ]; then _dest_system="/dev/disk/by-label/emystem" _dest_cache="/dev/disk/by-label/emcache" _dest_data="/dev/disk/by-label/emdata" break elif [ "${A}" = "E" ]; then exit 0 fi fi done else if [ -b /dev/disk/by-label/sdsystem ]; then _dest_system="/dev/disk/by-label/sdsystem" _dest_cache="/dev/disk/by-label/sdcache" _dest_data="/dev/disk/by-label/sddata" else _dest_system="/dev/disk/by-label/emystem" _dest_cache="/dev/disk/by-label/emcache" _dest_data="/dev/disk/by-label/emdata" fi fi printf "\n \033[36mDo you want to erase data partition ?\033[37m\n" printf " \033[36mPress \033[1mY\033[22m to erase, \033[1mN\033[22m to leave it \033[37m" A="x" while true; do if read -n 1 -t 1 -s A; then if [ "${A}" = "Y" ]; then _erase_data="yes" break elif [ "${A}" = "N" ]; then _erase_data="no" break fi fi done echo "" if [ "${A_FROMDIR}" = "yes" ]; then check_android_backup if [ $? -ne 0 ]; then printf " \033[35mANDROID cannot be upgraded!\033[37m\n" rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 rmdir ${source_mount}/android >> ${log_file} 2>&1 exit_script fi else # Unpack and decompress android install images to RAM or disk unpack_android if [ $? -ne 0 ]; then printf " \033[35mANDROID cannot be upgraded!\033[37m\n" rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 rmdir ${source_mount}/android >> ${log_file} 2>&1 exit_script fi fi install_android if [ $? -ne 0 ]; then printf " \033[35mERROR UPGRADING ANDROID!\033[37m\n" else printf " \033[36mAndroid UPGRADED\033[37m\n" fi rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 rmdir ${source_mount}/android >> ${log_file} 2>&1 rm -rf /run/inst/android/* >> ${log_file} 2>&1 rmdir /run/inst/android >> ${log_file} 2>&1 exit_script fi #======================================================================= set_cardsize print_header check_inst #---------------------------------------------------------------- if [ "${INST_ANDROID}" = "yes" ]; then if [ "${A_FROMDIR}" = "yes" ]; then check_android_backup if [ $? -ne 0 ]; then echo " ANDROID won't be installed!" INST_ANDROID="no" sleep 1 fi else echo "==== UNPACK AND DECOMPRESS ANDROID IMAGES ====" >> ${log_file} # Unpack and decompress android install images to RAM or disk unpack_android if [ $? -ne 0 ]; then echo " ANDROID won't be installed!" INST_ANDROID="no" rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 rmdir ${source_mount}/android >> ${log_file} 2>&1 sleep 5 fi fi check_install_sources if [ $_inst_no_ -eq 0 ]; then printf " \033[33m\033[1mNOTHING TO INSTALL\033[22m\033[37m\n" exit_script fi sleep 2 fi if [ "${INST_LINUX}" = "yes" ]; then get_lin_partstruct "/mnt/linux.img" if [ $? -ne 0 ]; then echo " LINUX won't be installed!" INST_LINUX="no" check_install_sources if [ $_inst_no_ -eq 0 ]; then printf " \033[33m\033[1mNOTHING TO INSTALL\033[22m\033[37m\n" exit_script fi sleep 3 fi fi if [ "${INST_LINUX2}" = "yes" ]; then get_lin_partstruct "/mnt/linux2.img" if [ $? -ne 0 ]; then echo " LINUX 2 won't be installed!" INST_LINUX2="no" check_install_sources if [ $_inst_no_ -eq 0 ]; then printf " \033[33m\033[1mNOTHING TO INSTALL\033[22m\033[37m\n" exit_script fi sleep 3 fi fi #---------------------------------------------------------------- print_header check_inst print_settings #================================== #---- Main menu ------------------- #================================== while true; do A="z" if read -n 1 -t 1 -s A; then if [ "${A}" = "1" ] && [ "${NUMCARDS}" = "2" ]; then print_header set_dest print_header print_settings elif [ "${A}" = "2" ]; then print_header set_userdatasize print_header print_settings elif [ "${A}" = "3" ]; then print_header set_systemsize print_header print_settings elif [ "${A}" = "4" ]; then print_header set_datasize print_header print_settings elif [ "${A}" = "5" ]; then print_header set_cachesize print_header print_settings elif [ "${A}" = "6" ]; then print_header set_oelecsize print_header print_settings elif [ "${A}" = "t" ] && [ "${INST_LINUX}" = "yes" ]; then if [ "${LINUX_FSTYPE}" = "btrfs" ]; then LINUX_FSTYPE="ext4" else LINUX_FSTYPE="btrfs" fi print_header print_settings elif [ "${O_BOARD}" = "C2" ] && [ "${A}" = "M" ] && [ "${INST_LINUX}" = "yes" ]; then if [ "${_inst_mbkernel}" = "yes" ]; then _inst_mbkernel="no" else _inst_mbkernel="yes" fi print_header print_settings elif [ "${A}" = "E" ]; then echo "" _reboot_delay=10 while [ $_reboot_delay -gt 0 ]; do printf " \033[33m\033[1mEXIT in %s sec, press \033[22ma\033[1m to abort, \033[22me\033[1m to exit \033[22m\033[37m\r" "$_reboot_delay" if read -n 1 -t 1 -s B; then _reboot_delay=10 if [ "${B}" = "a" ] || [ "${B}" = "A" ]; then break elif [ "${B}" = "e" ] || [ "${B}" = "E" ]; then _reboot_delay=0 break fi else let _reboot_delay=_reboot_delay-1 fi done if [ $_reboot_delay -eq 0 ]; then umount ${source_mount} > /dev/null 2>&1 exit 0 else print_header print_settings fi elif [ "${A}" = "I" ]; then echo "" _reboot_delay=15 while [ $_reboot_delay -gt 0 ]; do printf " \033[31m\033[1mWARNING: !! ALL DATA ON %s CARD WILL BE ERASED !!, PRESS Y TO CONTINUE\033[22m\033[37m\r" "${DEST_EMMC}" B="Z" if read -n 1 -t 1 -s B; then break else let _reboot_delay=_reboot_delay-1 fi done if [ "${B}" = "Y" ]; then break else print_header print_settings fi elif [ "${A}" = "s" ]; then # SCREENSHOT === fbcat > /install.ppm fi fi done # --- Set partition label prefix --- if [ "${DEST_EMMC}" = "EMMC" ]; then label_pref="em" else label_pref="sd" fi if [ "${INST_ANDROID}" != "yes" ] && [ "${INST_LINUX}" != "yes" ] && [ "${INST_OELEC}" != "yes" ]; then printf " \033[33m\033[1mNothing to install!\033[22m\033[37m\n" printf " \033[33m\033[1mInstallation aborted.\033[22m\033[37m\n" umount ${source_mount} > /dev/null 2>&1 exit_script fi # -------------------------------------------------------------------------------------------------------------------- print_header # --- Partition and format the card ---------------------------- prepare_card if [ $? -ne 0 ]; then printf " \033[35mERROR PREPARING %s CARD!\033[37m\n" "${DEST_EMMC}" else # install bootloader if [ "${O_BOARD}" = "C2" ]; then install_boot_c2 elif [ "${O_BOARD}" = "C1" ]; then install_boot_c1 else install_boot_xu fi if [ $? -eq 0 ]; then if [ "${INST_ANDROID}" = "yes" ]; then # --- Install Android --- install_android if [ $? -ne 0 ]; then printf " \033[35mERROR INSTALLING ANDROID!\033[37m\n" else printf " \033[36mAndroid PREPARED!\033[37m\n" printf " \033[35mFIRST BOOT CAN TAKE MORE THAN 5 MIN TO COMPLETE!\033[37m\n" fi rm -rf /run/inst/android/* >> ${log_file} 2>&1 rmdir /run/inst/android >> ${log_file} 2>&1 rm -rf ${source_mount}/android/* >> ${log_file} 2>&1 rmdir ${source_mount}/android >> ${log_file} 2>&1 fi if [ "${INST_LINUX}" = "yes" ]; then # --- Install Linux --- install_linux "linux.img" if [ $? -ne 0 ]; then printf " \033[35mERROR INSTALLING LINUX!\033[37m\n" else printf " \033[36mLinux PREPARED!\033[37m\n" fi fi if [ "${INST_LINUX2}" = "yes" ]; then # --- Install Linux --- install_linux "linux2.img" if [ $? -ne 0 ]; then printf " \033[35mERROR INSTALLING LINUX 2!\033[37m\n" else printf " \033[36mLinux 2 PREPARED!\033[37m\n" fi fi if [ "${INST_OELEC}" = "yes" ]; then # --- Install OpenELEC --- install_oelec if [ $? -ne 0 ]; then printf " \033[35mERROR INSTALLING OpenELEC!\033[37m\n" else printf " \033[36mOpenELEC PREPARED!\033[37m\n" fi if [ -d ${source_mount}/tmp_oelec ]; then rm -rf ${source_mount}/tmp_oelec/* >> ${log_file} 2>&1 rmdir ${source_mount}/tmp_oelec >> ${log_file} 2>&1 fi fi printf "\n \033[33mInstalling \033[1mMulti Boot support\033[22m\033[37m\n" install_multi_sel if [ $? -ne 0 ]; then printf " \033[35mERROR INSTALLING Multi Boot!\033[37m\n" else printf " \033[36m%s CARD PREPARED FOR MULTI BOOT!\033[37m\n" "${DEST_EMMC}" fi umount /mnt2 >> ${log_file} 2>&1 fi fi echo "" umount ${source_mount} > /dev/null 2>&1 exit_script reboot