Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
     5         kx #!/bin/bash
     5         kx 
     5         kx program=`basename $0`
     5         kx sbindir=`cd $(dirname ${BASH_SOURCE[0]}) >/dev/null 2>&1 && pwd`
     5         kx 
     5         kx # 13 = permission denied (should be root)
     5         kx # 14 = there is no '.pkglist' file
     5         kx # 15 = invalid target device
     5         kx # 16 = target device has not specified arter --root-dev option
     5         kx # 17 = source REPO directory is invalid
     5         kx # 18 = custom REPO directory has not specified by --repo option
     5         kx # 19 = target device too small
     5         kx # 20 = /sbin/fdisk returns bad status
     5         kx # 21 = cannot mount ROOT partition
     5         kx # 22 = cannot mount EFI partition
     5         kx # 92 = Cannot create '/tmp/...' directory
     5         kx # 93 = Unexpected program abort
     5         kx EXITSTATUS=0
     5         kx 
     5         kx WHERE=${sbindir}/where-we-are
     5         kx 
     5         kx #
     5         kx # Getting information about DISTRO:
     5         kx #
     5         kx push_err() {
     5         kx   message=$1
     5         kx   echo -n "$program: " >&2 ; echo "${message}" >&2
     5         kx }
     5         kx 
     5         kx if [ ! -r /etc/os-release ] ; then
     5         kx   push_err "ERROR: /etc/os-release: There are no operating system information"
     5         kx   exit 1
     5         kx fi
     5         kx 
     5         kx . /etc/os-release
     5         kx 
     5         kx if [ ! -r /etc/${ID}-release ] ; then
     5         kx   push_err "ERROR: /etc/${ID}-release: There are no ${ID} distribution information"
     5         kx   exit 1
     5         kx fi
     5         kx 
     5         kx . /etc/${ID}-release
     5         kx 
     5         kx LOG_FILE=${LOG_FILE:-/var/log/${DISTRO_NAME}-${program}.log}
     5         kx 
     5         kx DIALOG=${DIALOG:-/bin/dialog}
     5         kx 
     5         kx push_log() {
     5         kx   message=$1
     5         kx   echo -n "[`LANG=en LANGUAGE=en date +'%d-%b-%Y %H:%M:%S'`] $program: " >> ${LOG_FILE}
     5         kx   echo    "${message}" >> ${LOG_FILE}
     5         kx }
     5         kx 
     5         kx umask 022
     5         kx TMP=$(mkdir -p /tmp/${DISTRO_NAME} && mktemp -d -p /tmp/${DISTRO_NAME} $program.XXXXXXXX) || { echo "Cannot create '/tmp/...' directory" ; exit 92; }
     5         kx mkdir -p /tmp/${DISTRO_NAME}/mnt
     5         kx MNT=/tmp/${DISTRO_NAME}/mnt
     5         kx #
     5         kx # Clear screen on unexpected termination:
     5         kx #
     5         kx trap 'clear ; \
     5         kx       head -c 100 /dev/zero | tr "\0" "\n" ; \
     5         kx       echo "ERROR: $program - has been terminated." ; \
     5         kx       echo "" ; \
     5         kx       EXITSTATUS=93 ; \
     5         kx       ' INT TERM HUP QUIT
     5         kx #
     5         kx # This program cam mount filesystems to first level
     5         kx # directories relative to $MNT or directly to $MNT:
     5         kx #
     5         kx trap 'for dir in `find ${MNT} -type d -mindepth 1 -maxdepth 1` ; do \
     5         kx         umount $dir 2> /dev/null ; \
     5         kx       done ; \
     5         kx       umount ${MNT} 2> /dev/null ; \
     5         kx       rm -rf /tmp/${DISTRO_NAME} ; \
     5         kx       rm -f /etc/system-installer ; \
     5         kx       exit ${EXITSTATUS} ;\
     5         kx       ' EXIT
     5         kx 
     5         kx 
     5         kx check_current_user()
     5         kx {
     5         kx   echo "Radix System Setup" > /etc/system-installer
     5         kx 
     5         kx   if [ "$EUID" != "0" ] ; then
     5         kx     $DIALOG --colors --clear \
     5         kx             --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx             --title " \Z0Setup:\Zn \Z1\ZbERROR\ZB\Zn " \
     5         kx             --msgbox "\n\Z4${program}\Zn - \Z1program should be run by root.\Zn\n" 7 74
     5         kx 
     5         kx     push_log "ERROR: Program should be run by root"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Program should be run by root"
     5         kx     EXITSTATUS=13
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx ask_exit_setup() {
     5         kx   cat > $TMP/exit-setup-help$$ << EOF
     5         kx 
     5         kx  Do you want to terminate Radix System Installation?
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --colors --defaultno --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Setup:\Zn \Z4\ZbExit\ZB\Zn " \
     5         kx           --no-label "No" \
     5         kx           --yes-label "Ok" \
     5         kx           --yesno "$(cat $TMP/exit-setup-help$$)" 7 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/exit-setup-help$$
     5         kx   if [ $ret -eq 0 ] ; then
     5         kx     push_log "Done"
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx fatal_error_dialog()
     5         kx {
     5         kx   local msg="${1}"
     5         kx   cat > $TMP/fatal-message$$ << EOF
     5         kx 
     5         kx  ${msg}
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --colors --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Setup:\Zn \Z1\ZbERROR\ZB\Zn " \
     5         kx           --msgbox "$(cat $TMP/fatal-message$$)" 7 74
     5         kx }
     5         kx 
     5         kx error_dialog()
     5         kx {
     5         kx   local msg="${1}"
     5         kx   cat > $TMP/error-message$$ << EOF
     5         kx 
     5         kx  ${msg}
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --colors --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Setup:\Zn \Z1\ZbERROR\ZB\Zn " \
     5         kx           --no-label " Exit Setup " \
     5         kx           --yes-label " Continue " \
     5         kx           --yesno "$(cat $TMP/error-message$$)" 7 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/error-message$$
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx welcome_setup()
     5         kx {
     5         kx   cat > $TMP/welcome-setup-rc$$ << EOF
     5         kx use_colors = ON
     5         kx shadow_color = (BLACK,BLACK,OFF)
     5         kx screen_color = (WHITE,BLACK,ON)
     5         kx use_shadow = OFF
     5         kx dialog_color = (WHITE,BLACK,OFF)
     5         kx title_color = (WHITE,BLACK,ON)
     5         kx border_color = (BLACK,BLACK,OFF)
     5         kx border2_color = (BLACK,BLACK,OFF)
     5         kx button_active_color = (WHITE,BLACK,ON)
     5         kx button_inactive_color = (WHITE,BLACK,OFF)
     5         kx button_key_active_color = (RED,BLACK,ON)
     5         kx button_key_inactive_color = (WHITE,BLACK,ON)
     5         kx button_label_active_color = (WHITE,BLACK,ON)
     5         kx button_label_inactive_color = (WHITE,BLACK,ON)
     5         kx EOF
     5         kx 
     5         kx   cat > $TMP/welcome-setup-help$$ << EOF
     5         kx 
     5         kx Version \Zb${DISTRO_FULL_VERSION}\Zn
     5         kx Copyright (c) 2009-`date +%Y`, Andrey V.Kosteltsev. All rights reserved.
     5         kx ${DISTRO_HOME_URL}
     5         kx 
     5         kx Built for ${HARDWARE_SPEC} [\Zb${HARDWARE}\Zn]
     5         kx Toolchain ${TOOLCHAIN_VERSION} [\Zb${TOOLCHAIN_NAME}\Zn]
     5         kx 
     5         kx Now you can install \Zb${DISTRO_CAPTION}-${DISTRO_VERSION}\Zn to you hard drive or internal flash.
     5         kx 
     5         kx Enjoy!
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   DIALOGRC=$TMP/welcome-setup-rc$$ \
     5         kx   $DIALOG --colors --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " Setup ${DISTRO_CAPTION} \Z1cross\Zn Linux " \
     5         kx           --no-label " Exit Setup " \
     5         kx           --yes-label " Continue " \
     5         kx           --yesno "$(cat $TMP/welcome-setup-help$$)" 16 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/welcome-setup-help$$
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx usage() {
     5         kx  cat << EOF
     5         kx 
     5         kx Usage: $program [options]
     5         kx 
     5         kx $program - is used to install ${DISTRO_SPEC} from the 'repo' directory.
     5         kx 
     5         kx   The 'repo' directory sould contains ${DISTRO_CAPTION} packages set with '.pkglist'
     5         kx   file at least for one HARDWARE. The ordinary structure of the 'repo'
     5         kx   directories should seems like following:
     5         kx 
     5         kx     /var/lib/${DISTRO_NAME}/repo
     5         kx     ├── ${DISTRO_FULL_VERSION}
     5         kx         ├── TOOLCHAIN
     5         kx        ...  └── HARDWARE
     5         kx                 ├── ...
     5         kx         │      ...
     5         kx         └── ${TOOLCHAIN_NAME}
     5         kx             └── ${HARDWARE}
     5         kx                 ├── app
     5         kx                 │   ├── bash-5.2.9-`echo ${TOOLCHAIN_NAME} | cut -f1 -d'-'`-radix-${DISTRO_VERSION}.tgz
     5         kx                 │   ├── ...
     5         kx                 │  ...
     5         kx                 ├── base
     5         kx                 │   ├── ...
     5         kx                 │  ...
     5         kx                ...
     5         kx 
     5         kx                 └── .pkglist
     5         kx 
     5         kx   where, /var/lib/${DISTRO_NAME}/repo/${DISTRO_FULL_VERSION}/${TOOLCHAIN_NAME}/${HARDWARE} - applicable
     5         kx   directory for current release.
     5         kx 
     5         kx options:
     5         kx    -h | --help              - Display this information;
     5         kx    -r | --root-dev <DEVICE> - Target device to install [/dev/sda,
     5         kx                               /dev/mmcblk0, /dev/loop0, etc.];
     5         kx    --repo <DIR>             - Absolute path to the REPO source directory
     5         kx                               (Default: /var/lib/${DISTRO_NAME}/repo/${DISTRO_FULL_VERSION}/${TOOLCHAIN_NAME}/${HARDWARE}).
     5         kx                               The user defined absolute path to the REPO directory must match
     5         kx                               the standard pattern: '/custom-dir/VERSION/TOOLCHAIN/HARDWARE';
     5         kx 
     5         kx   The /etc/${DISTRO_NAME}-rlease file contains detailed info about
     5         kx   setup parameters.
     5         kx 
     5         kx EOF
     5         kx }
     5         kx 
     5         kx #
     5         kx # Start installation:
     5         kx #
     5         kx push_log "Start of ${DISTRO_CAPTION}-${DISTRO_VERSION} installation"
     5         kx 
     5         kx # Only root can execute:
     5         kx check_current_user
     5         kx 
     5         kx device=
     5         kx version=${DISTRO_FULL_VERSION}
     5         kx toolchain=${TOOLCHAIN_NAME}
     5         kx hardware=${HARDWARE}
     5         kx repo=/var/lib/${DISTRO_NAME}/repo/${DISTRO_FULL_VERSION}/${TOOLCHAIN_NAME}/${HARDWARE}
     5         kx 
     5         kx custom_repo=no
     5         kx 
     5         kx current_device=
     5         kx current_root=
     5         kx rootfs_min_bytes=
     5         kx 
     5         kx partition_table_type=o
     5         kx 
     5         kx uefi_part_number=1
     5         kx root_part_number=1
     5         kx home_part_number=2
     5         kx swap_part_number=3
     5         kx 
     5         kx uefi_bytes=
   385         kx if [ "${hardware}" = "baikal-m1"   -o \
   385         kx      "${hardware}" = "orange-pi5"  -o \
   385         kx      "${hardware}" = "visionfive2" -o \
     5         kx      "${hardware}" = "intel-pc64" ] ; then
     5         kx   partition_table_type=g
     5         kx   uefi_bytes=268435456
     5         kx fi
     5         kx 
     5         kx if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx   root_part_number=2
     5         kx   home_part_number=3
     5         kx   swap_part_number=4
     5         kx fi
     5         kx 
     5         kx uefi_start_sector=
     5         kx uefi_end_sector=
     5         kx root_bytes=
     5         kx root_start_sector=
     5         kx root_end_sector=
     5         kx home_bytes=
     5         kx home_start_sector=
     5         kx home_end_sector=
     5         kx swap_bytes=
     5         kx swap_start_sector=
     5         kx swap_end_sector=
     5         kx 
     5         kx p=
     5         kx 
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Disk Geometry functions:
     5         kx #
     5         kx 
     5         kx # Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
     5         kx # Sector size (logical/physical): 512 bytes / 512 bytes
     5         kx 
     5         kx bytes=
     5         kx sectors=
     5         kx unit_size=
     5         kx log_sector_size=
     5         kx phy_sector_size=
     5         kx alignment=4096
     5         kx format="512N"
     5         kx start_sector=
     5         kx ram_bytes=
     5         kx #
     5         kx #   Format | logical sector size | physical sector size
     5         kx #  --------+---------------------+----------------------
     5         kx #     512N |         512         |          512
     5         kx #  --------+---------------------+----------------------
     5         kx #     512E |         512         |         4096
     5         kx #  --------+---------------------+----------------------
     5         kx #    4096N |        4096         |         4096
     5         kx #  --------+---------------------+----------------------
     5         kx #
     5         kx 
     5         kx disk_size_in_bytes() {
     5         kx   disk=${1}
     5         kx   echo "`LANG=en_US.UTF-8 fdisk -l ${disk}`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep "^Disk ${disk}"`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local bytes=`echo ${found} | sed 's,.* \([0-9]*\) bytes.*,\1,'`
     5         kx       echo "${bytes}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx disk_size_in_sectors() {
     5         kx   disk=${1}
     5         kx   echo "`LANG=en_US.UTF-8 fdisk -l ${disk}`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep "^Disk ${disk}"`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local sectors=`echo ${found} | sed 's,.* \([0-9]*\) sectors$,\1,'`
     5         kx       echo "${sectors}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx disk_unit_size() {
     5         kx   disk=${1}
     5         kx   echo "`LANG=en_US.UTF-8 fdisk -l ${disk}`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep "^Unit"`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local usize=`echo ${found} | sed 's,.*= \([0-9]*\) bytes$,\1,'`
     5         kx       echo "${usize}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx disk_log_sector_size() {
     5         kx   disk=${1}
     5         kx   echo "`LANG=en_US.UTF-8 fdisk -l ${disk}`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep '^Sector size'`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local lsize=`echo ${found} | sed 's,.* \([0-9]*\) bytes / \([0-9]*\) bytes$,\1,'`
     5         kx       echo "${lsize}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx disk_phy_sector_size() {
     5         kx   disk=${1}
     5         kx   echo "`LANG=en_US.UTF-8 fdisk -l ${disk}`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep '^Sector size'`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local psize=`echo ${found} | sed 's,.* \([0-9]*\) bytes / \([0-9]*\) bytes$,\2,'`
     5         kx       echo "${psize}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx memory_size() {
     5         kx   echo "`LANG=en_US.UTF-8 free -b -w`" | while read -r line ; do
     5         kx     local found=`echo "${line}" | grep '^Mem'`
     5         kx     if [ "x${found}" != "x" ] ; then
     5         kx       local msize=`echo ${found} | tr -s ' ' | cut -f2 -d' '`
     5         kx       echo "${msize}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx disk_geometry() {
     5         kx   disk=${1}
     5         kx 
     5         kx   bytes=`disk_size_in_bytes ${disk}`
     5         kx   sectors=`disk_size_in_sectors ${disk}`
     5         kx   unit_size=`disk_unit_size ${disk}`
     5         kx   log_sector_size=`disk_log_sector_size ${disk}`
     5         kx   phy_sector_size=`disk_phy_sector_size ${disk}`
     5         kx 
     5         kx   ram_bytes=`memory_size`
     5         kx 
     5         kx   if [ $unit_size -eq $alignment ] ; then
     5         kx     # Copy of GPT at end of disk:
     5         kx     let "sectors = sectors - 5"
     5         kx   else
     5         kx     # Copy of GPT at end of disk:
     5         kx     let "sectors = sectors - 33"
     5         kx   fi
     5         kx 
     5         kx   if [ $phy_sector_size -eq $alignment ] ; then
     5         kx     if [ $log_sector_size -lt $phy_sector_size ] ; then
     5         kx       format="512E"
     5         kx       start_sector=2048
     5         kx     else
     5         kx       format="4096N"
     5         kx       start_sector=256
     5         kx     fi
     5         kx   else
     5         kx     format="512N"
     5         kx     start_sector=2048
     5         kx   fi
     5         kx }
     5         kx #
     5         kx # End of Disk Geometry functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Disk Format functions:
     5         kx #
     5         kx clean_disk()
     5         kx {
     5         kx   local disk=${1}
     5         kx   fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx ${partition_table_type}
     5         kx w
     5         kx EOF
   385         kx 
   385         kx   partprobe ${disk}
     5         kx }
     5         kx 
     5         kx create_EFI_partition()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local name="EFI System"
     5         kx   local guid="c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
     5         kx   local type="ef"
     5         kx 
     5         kx   uefi_start_sector=${start_sector}
     5         kx 
     5         kx   let 'uefi_bytes = uefi_bytes / alignment * alignment'
     5         kx 
     5         kx   let 'uefi_end_sector = uefi_start_sector + ( uefi_bytes / unit_size - 1 )'
     5         kx   let 'root_start_sector = uefi_end_sector + 1'
     5         kx 
     5         kx   if [ "${partition_table_type}" = "g" ] ; then
     5         kx     fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx $uefi_part_number
     5         kx $uefi_start_sector
     5         kx $uefi_end_sector
     5         kx t
     5         kx $guid
     5         kx x
     5         kx n
     5         kx $name
     5         kx r
     5         kx w
     5         kx EOF
     5         kx   else
     5         kx     fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx p
     5         kx $uefi_part_number
     5         kx $uefi_start_sector
     5         kx $uefi_end_sector
     5         kx t
     5         kx $type
     5         kx w
     5         kx EOF
     5         kx   fi
     5         kx 
   385         kx   partprobe ${disk}
   385         kx 
     5         kx   mkfs.fat -F 32 -n UEFI ${disk}${p}1  2>/dev/null 1>/dev/null
     5         kx }
     5         kx 
     5         kx create_ROOT_partition()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local name="Linux filesystem"
     5         kx   local guid="0fc63daf-8483-4772-8e79-3d69d8477de4"
     5         kx   local type="83"
     5         kx 
     5         kx   local half=
     5         kx   local third=
     5         kx   local GiB=1073741824
     5         kx   local MiB=1048576
     5         kx 
     5         kx   if [ "${bytes}" -gt "${GiB}" ] ; then
     5         kx     half=`echo  "scale=0; ( $bytes / $GiB / 2 - 1 ) * $GiB" | bc`
     5         kx     third=`echo "scale=0; ( $bytes / $GiB / 3 + 1 ) * $GiB" | bc`
     5         kx   else
     5         kx     half=`echo  "scale=0; ( $bytes / $MiB / 2 - 1 ) * $MiB" | bc`
     5         kx     third=`echo "scale=0; ( $bytes / $MiB / 3 + 1 ) * $MiB" | bc`
     5         kx   fi
     5         kx 
     5         kx   let 'half  =  half / alignment * alignment'
     5         kx   let 'third = third / alignment * alignment'
     5         kx 
     5         kx   if [ "x${uefi_bytes}" = "x" ] ; then
     5         kx     root_start_sector=${start_sector}
     5         kx     if [ "${hardware}" = "leez-p710" ] ; then
     5         kx       root_start_sector=32768
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   if [ "${third}" -gt "${rootfs_min_bytes}" ] ; then
     5         kx     let 'root_end_sector = root_start_sector + ( third / unit_size - 1 )'
     5         kx     let 'home_start_sector = root_end_sector + 1'
     5         kx   elif [ "${half}" -gt "${rootfs_min_bytes}" ] ; then
     5         kx     let 'root_end_sector = root_start_sector + ( half / unit_size - 1 )'
     5         kx     let 'home_start_sector = root_end_sector + 1'
     5         kx   elif [ "${bytes}" -gt "${rootfs_min_bytes}" ] ; then
     5         kx     let 'root_end_sector = root_start_sector + ( rootfs_min_bytes / unit_size - 1 )'
     5         kx     let 'home_start_sector = root_end_sector + 1'
     5         kx   else
     5         kx     fatal_error_dialog "Target device too small. Exit ${program}."
     5         kx     push_log "ERROR: Target device too small"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Target device too small"
     5         kx     EXITSTATUS=19
     5         kx     exit
     5         kx   fi
     5         kx 
   385         kx   root_bytes=`echo "(${root_end_sector} - ${root_start_sector} + 1) * ${log_sector_size}" | bc`
     5         kx 
     5         kx   if [ "${root_part_number}" -eq "1" ] ; then
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx $root_part_number
     5         kx $root_start_sector
     5         kx $root_end_sector
     5         kx t
     5         kx $guid
     5         kx x
     5         kx n
     5         kx $name
     5         kx r
     5         kx w
     5         kx EOF
     5         kx     else
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx p
     5         kx $root_part_number
     5         kx $root_start_sector
     5         kx $root_end_sector
     5         kx t
     5         kx $type
     5         kx w
     5         kx EOF
     5         kx     fi
     5         kx   else
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx $root_part_number
     5         kx $root_start_sector
     5         kx $root_end_sector
     5         kx t
     5         kx $root_part_number
     5         kx $guid
     5         kx x
     5         kx n
     5         kx $root_part_number
     5         kx $name
     5         kx r
     5         kx w
     5         kx EOF
     5         kx     else
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx p
     5         kx $root_part_number
     5         kx $root_start_sector
     5         kx $root_end_sector
     5         kx t
     5         kx $root_part_number
     5         kx $type
     5         kx w
     5         kx EOF
     5         kx     fi
     5         kx   fi
   385         kx 
   385         kx   partprobe ${disk}
     5         kx }
     5         kx 
     5         kx create_HOME_partition()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local name="Linux filesystem"
     5         kx   local guid="0fc63daf-8483-4772-8e79-3d69d8477de4"
     5         kx   local type="83"
     5         kx 
     5         kx   local left=
     5         kx   local octa=
     5         kx   local swap=
     5         kx   local GiB=1073741824
     5         kx   local MiB=1048576
     5         kx 
     5         kx   let 'left = ( sectors - root_end_sector ) * unit_size'
     5         kx 
     5         kx   if [ "x${home_start_sector}" != "x" -a "${left}" -gt "$GiB" ] ; then
     5         kx 
     5         kx     let 'swap =  ram_bytes * 2 / alignment * alignment'
     5         kx 
     5         kx     if [ "${bytes}" -gt "${GiB}" ] ; then
     5         kx       octa=`echo  "scale=0; $bytes / $GiB / 8 * $GiB" | bc`
     5         kx     else
     5         kx       octa=`echo  "scale=0; $bytes / $MiB / 8 * $MiB" | bc`
     5         kx     fi
     5         kx 
     5         kx     let 'octa =  octa / alignment * alignment'
     5         kx 
     5         kx     if [ "${octa}" -gt "${swap}" ] ; then
     5         kx       let 'left = ( left - swap ) / alignment * alignment'
     5         kx       swap_bytes=${swap}
     5         kx     elif [ "${octa}" -gt "${ram_bytes}" ] ; then
     5         kx       let 'left = ( left - ram_bytes ) / alignment * alignment'
     5         kx       swap_bytes=${ram_bytes}
     5         kx     else
     5         kx       swap_bytes=0
     5         kx       swap_start_sector=0
     5         kx     fi
     5         kx 
     5         kx     if [ "${swap_bytes}" -gt "0" ] ; then
     5         kx       let 'home_end_sector = home_start_sector + ( left / unit_size - 1 )'
     5         kx       let 'swap_start_sector = home_end_sector + 1'
     5         kx     else
     5         kx       let 'home_end_sector = sectors - 1'
     5         kx     fi
     5         kx 
     5         kx     let 'home_bytes = ( home_end_sector - home_start_sector + 1 ) * unit_size'
     5         kx 
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx $home_part_number
     5         kx $home_start_sector
     5         kx $home_end_sector
     5         kx t
     5         kx $home_part_number
     5         kx $guid
     5         kx x
     5         kx n
     5         kx $home_part_number
     5         kx $name
     5         kx r
     5         kx w
     5         kx EOF
     5         kx     else
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx p
     5         kx $home_part_number
     5         kx $home_start_sector
     5         kx $home_end_sector
     5         kx t
     5         kx $home_part_number
     5         kx $type
     5         kx w
     5         kx EOF
     5         kx     fi
     5         kx   else
     5         kx     home_bytes=0
     5         kx     home_start_sector=0
     5         kx     swap_bytes=0
     5         kx     swap_start_sector=0
     5         kx   fi
   385         kx 
   385         kx   partprobe ${disk}
     5         kx }
     5         kx 
     5         kx create_SWAP_partition()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local name="Linux swap"
     5         kx   local guid="0657fd6d-a4ab-43c4-84e5-0933c84b4f4f"
     5         kx   local type="82"
     5         kx 
     5         kx   if [ "${swap_bytes}" -gt "0" ] ; then
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx $swap_part_number
     5         kx 
     5         kx 
     5         kx t
     5         kx $swap_part_number
     5         kx $guid
     5         kx x
     5         kx n
     5         kx $swap_part_number
     5         kx $name
     5         kx r
     5         kx w
     5         kx EOF
     5         kx     else
     5         kx       fdisk --wipe=always --wipe-partition=always ${disk} 1>/dev/null 2>/dev/null <<EOF
     5         kx n
     5         kx p
     5         kx $swap_part_number
     5         kx 
     5         kx 
     5         kx t
     5         kx $swap_part_number
     5         kx $type
     5         kx w
     5         kx EOF
     5         kx     fi
     5         kx   fi
   385         kx 
   385         kx   partprobe ${disk}
     5         kx }
     5         kx 
     5         kx umount_target_partitions()
     5         kx {
     5         kx   local disk=${1}
     5         kx   for dev in `mount | grep "^${disk}" | tr -s ' ' | cut -f1 -d' '` ; do
     5         kx     umount ${dev} 2>/dev/null 1>/dev/null
     5         kx   done
     5         kx }
     5         kx 
     5         kx format_disk()
     5         kx {
     5         kx   local dev=${1}
     5         kx 
     5         kx   umount_target_partitions "${dev}"
     5         kx 
     5         kx   clean_disk "${dev}"
     5         kx   if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx     create_EFI_partition "${dev}"
     5         kx   fi
     5         kx 
     5         kx   create_ROOT_partition "${dev}"
     5         kx   create_HOME_partition "${dev}"
     5         kx   create_SWAP_partition "${dev}"
     5         kx }
     5         kx 
     5         kx format_by_fdisk()
     5         kx {
     5         kx   local disk=${1}
     5         kx   local fdiskprg=`which fdisk 2> /dev/null`
     5         kx 
     5         kx   umount_target_partitions "${disk}"
     5         kx 
     5         kx   clean_disk "${disk}"
     5         kx   if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx     create_EFI_partition "${disk}"
     5         kx   fi
     5         kx 
     5         kx   clear
     5         kx   ${fdiskprg} ${disk}
     5         kx   ret=$?
     5         kx   if [ ${ret} -ne 0 ] ; then
     5         kx     fatal_error_dialog "${fdiskprg} returns bad status. Exit ${program}."
     5         kx     push_log "ERROR: ${fdiskprg} returns bad status"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: ${fdiskprg} returns bad status"
     5         kx     EXITSTATUS=20
     5         kx     exit
     5         kx   fi
   385         kx 
   385         kx   partprobe ${disk}
     5         kx }
     5         kx 
     5         kx ask_formatting()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local height=16
     5         kx   local items=3
     5         kx 
     5         kx   local fdiskprg=`which fdisk 2> /dev/null`
     5         kx 
     5         kx   cat > $TMP/menu-format$$ << EOF
     5         kx --colors --clear $nocancel \\
     5         kx --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \\
     5         kx --title " \Z0Format the\Zn \Z4${disk}\Zn \Z0target device\Zn " \\
     5         kx --menu "\\n\\
     5         kx EOF
     5         kx 
     5         kx   cat >> $TMP/menu-format$$ << EOF
     5         kx  The target disk should has at least one \Z1Linux\Zn partition for root\\n\\
     5         kx  file system. Also you may want to have \Z1/home\Zn and \Z1swap\Zn partitions.\\n\\
     5         kx EOF
     5         kx 
     5         kx   if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx     let 'height += 3'
     5         kx     cat >> $TMP/menu-format$$ << EOF
     5         kx \\n\\
     5         kx  The target disk also should has \Z1EFI\Zn partition for boot the system.\\n\\
     5         kx  The drive must be formated using \Z1G\ZnUID \Z1P\Znartition \Z1T\Znable (\Z1GPT\Zn).\\n\\
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   cat >> $TMP/menu-format$$ << EOF
     5         kx \\n\\
     5         kx  \Z1NOTE\Zn: All data on the target \Z4${disk}\Zn device will be destroyed.\\
     5         kx EOF
     5         kx 
     5         kx   cat >> $TMP/menu-format$$ << EOF
     5         kx \\n\\n\\
     5         kx  Please select method of formatting:\\
     5         kx " ${height} 74 ${items} \\
     5         kx EOF
     5         kx 
     5         kx   if [ "x${fdiskprg}" != "x" -a -x "${fdiskprg}" ] ; then
     5         kx     cat >> $TMP/menu-format$$ << EOF
     5         kx "Fdisk" "Use '\Zb${fdiskprg}\ZB' for formatting" \\
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   cat >> $TMP/menu-format$$ << EOF
     5         kx "Default" "Use default procedure for formatting" \\
     5         kx EOF
     5         kx 
     5         kx   cat >> $TMP/menu-format$$ << EOF
     5         kx "Exit" "Terminate the Radix cross Linux installation" \\
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --default-item "Default" --file $TMP/menu-format$$ 2> $TMP/format$$
     5         kx   ret=$?
     5         kx   if [ ${ret} -eq 1 -o ${ret} -eq 255 ]; then
     5         kx     rm -f $TMP/format$$
     5         kx     rm -f $TMP/menu-format$$
     5         kx     return $ret
     5         kx   fi
     5         kx   result=`cat $TMP/format$$`
     5         kx   rm -f $TMP/format$$
     5         kx   rm -f $TMP/menu-format$$
     5         kx   if [ "${result}" = "Exit" ]; then
     5         kx     push_log "Done"
     5         kx     exit
     5         kx   elif [ "${result}" = "Fdisk" ]; then
     5         kx     format_by_fdisk "${disk}"
     5         kx   else
     5         kx     format_disk "${disk}"
     5         kx   fi
     5         kx }
     5         kx 
     5         kx #
     5         kx # End of Disk Format functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Check Custom REPO functions:
     5         kx #
     5         kx welcome_custom_setup()
     5         kx {
     5         kx   cat > $TMP/welcome-setup-rc$$ << EOF
     5         kx use_colors = ON
     5         kx shadow_color = (BLACK,BLACK,OFF)
     5         kx screen_color = (WHITE,BLACK,ON)
     5         kx use_shadow = OFF
     5         kx dialog_color = (WHITE,BLACK,OFF)
     5         kx title_color = (WHITE,BLACK,ON)
     5         kx border_color = (BLACK,BLACK,OFF)
     5         kx border2_color = (BLACK,BLACK,OFF)
     5         kx button_active_color = (WHITE,BLACK,ON)
     5         kx button_inactive_color = (WHITE,BLACK,OFF)
     5         kx button_key_active_color = (RED,BLACK,ON)
     5         kx button_key_inactive_color = (WHITE,BLACK,ON)
     5         kx button_label_active_color = (WHITE,BLACK,ON)
     5         kx button_label_inactive_color = (WHITE,BLACK,ON)
     5         kx EOF
     5         kx 
     5         kx   cat > $TMP/welcome-setup-help$$ << EOF
     5         kx 
     5         kx Version \Zb${version}\Zn
     5         kx Copyright (c) 2009-`date +%Y`, Andrey V.Kosteltsev. All rights reserved.
     5         kx ${DISTRO_HOME_URL}
     5         kx 
     5         kx Built for: \Zb${hardware}\Zn
     5         kx Toolchain: \Zb${toolchain}\Zn
     5         kx 
     5         kx Now you can install \Zb${DISTRO_CAPTION}-${version}\Zn from:
     5         kx 
     5         kx   ${repo}/
     5         kx 
     5         kx directory to you hard drive or internal flash.
     5         kx 
     5         kx Enjoy!
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   DIALOGRC=$TMP/welcome-setup-rc$$ \
     5         kx   $DIALOG --colors --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " Setup ${DISTRO_CAPTION} \Z1cross\Zn Linux " \
     5         kx           --no-label " Exit Setup " \
     5         kx           --yes-label " Continue " \
     5         kx           --yesno "$(cat $TMP/welcome-setup-help$$)" 19 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/welcome-setup-help$$
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx ask_custom_repo()
     5         kx {
     5         kx   cat > $TMP/select-custom-repo$$ << EOF
     5         kx 
     5         kx  The selected custom REPO is invalid.
     5         kx  Do you want to select Custom REPO to install from?
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --colors --defaultno --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Setup:\Zn \Z4\ZbSelect Custom Repository\ZB\Zn " \
     5         kx           --no-label "Exit Setup" \
     5         kx           --yes-label " Select " \
     5         kx           --yesno "$(cat $TMP/select-custom-repo$$)" 9 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/select-custom-repo$$
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     push_log "Done"
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx select_custom_repo()
     5         kx {
     5         kx   cat > $TMP/dselect-help$$ << EOF
     5         kx 
     5         kx   Use the space-bar to copy the current selection into the text-entry
     5         kx   window. Press '/' and then Up Arrow to go to selected directoy.
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   result=`$DIALOG --stdout  --colors \
     5         kx                   --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx                   --title " \Z0\ZbSelect the\ZB\Zn \Z0\ZbCustom \Z1REPO\Zn \Z0\ZbDirectory (\ZB\Zn\Z4press F1 for help\Zn\Z0\Zb):\ZB\Zn " \
     5         kx                   --hfile $TMP/dselect-help$$ \
     5         kx                   --no-shadow \
     5         kx                   --dselect ${repo} 7 74`
     5         kx   ret=$?
     5         kx   if [ $ret -eq 0 ]; then
     5         kx     custom_repo="`echo ${result} | sed 's,/$,,'`"
     5         kx   else
     5         kx     custom_repo=no
     5         kx     # continue with default REPO
     5         kx   fi
     5         kx }
     5         kx 
     5         kx check_custom_repo()
     5         kx {
     5         kx   rp="${1}"
     5         kx 
     5         kx   rp="`echo ${rp} | sed 's,/$,,'`"
     5         kx 
     5         kx   if ! `echo "${rp}" | grep -q "^/"` ; then
     5         kx     ask_custom_repo
     5         kx     select_custom_repo
     5         kx     if [ "x${custom_repo}" != "xno" ] ; then
     5         kx       check_custom_repo "${custom_repo}"
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   if [ ! -d "${rp}" ] ; then
     5         kx     ask_custom_repo
     5         kx     select_custom_repo
     5         kx     if [ "x${custom_repo}" != "xno" ] ; then
     5         kx       check_custom_repo "${custom_repo}"
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   local depth=`echo "${rp}" | grep -o '/' - | wc -l`
     5         kx   if [ "${depth}" -lt "3" ] ; then
     5         kx     ask_custom_repo
     5         kx     select_custom_repo
     5         kx     if [ "x${custom_repo}" != "xno" ] ; then
     5         kx       check_custom_repo "${custom_repo}"
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   local  d=`dirname  "${rp}"`
     5         kx   local hw=`basename "${rp}"`
     5         kx   local th=`basename "${d}"`
     5         kx          d=`dirname  "${d}"`
     5         kx   local  v=`basename "${d}"`
     5         kx 
     5         kx   if ! `echo ${v} | grep -q '^[0-9]*\.[0-9]*\.[0-9]*'` ; then
     5         kx     ask_custom_repo
     5         kx     select_custom_repo
     5         kx     if [ "x${custom_repo}" != "xno" ] ; then
     5         kx       check_custom_repo "${custom_repo}"
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   if [ ! -r "${rp}/${hw}.pkglist" ] ; then
     5         kx     ask_custom_repo
     5         kx     select_custom_repo
     5         kx     if [ "x${custom_repo}" != "xno" ] ; then
     5         kx       check_custom_repo "${custom_repo}"
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx   elif [ ! -L "${rp}/.pkglist" ] ; then
     5         kx     ( cd "${rp}" ; ln -sf ${hw}.pkglist .pkglist )
     5         kx   fi
     5         kx 
     5         kx   version=$v
     5         kx   toolchain=$th
     5         kx   hardware=$hw
     5         kx   repo=${rp}
     5         kx 
     5         kx   custom_repo=yes
     5         kx }
     5         kx 
     5         kx #
     5         kx # End of Check Custom REPO functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Check Source REPO functions:
     5         kx #
     5         kx check_repo()
     5         kx {
     5         kx   local rp="${1}"
     5         kx 
     5         kx   if [ ! -d "${rp}" ] ; then
     5         kx     return 1
     5         kx   fi
     5         kx 
     5         kx   if [ ! -r "${rp}/${HARDWARE}.pkglist" ] ; then
     5         kx     return 1
     5         kx   elif [ ! -L "${rp}/.pkglist" ] ; then
     5         kx     ( cd "${rp}" ; ln -sf ${HARDWARE}.pkglist .pkglist )
     5         kx   fi
     5         kx 
     5         kx   return 0
     5         kx }
     5         kx #
     5         kx # End of Check Source REPO functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Check Target device functions:
     5         kx #
     5         kx major_number()
     5         kx {
     5         kx   local part=${1}
     5         kx   local name=`basename ${part}`
     5         kx 
     5         kx   local major=`ls -l /dev | grep -v ^l | grep ${name} | tr -s ' ' | sed 's/,//g' | cut -f5 -d' ' | sort -u | tr '\n' ',' | sed 's/,$//'`
     5         kx   echo "${major}"
     5         kx }
     5         kx 
     5         kx #
     5         kx # returns the prefix 'p' of partition number if applicable
     5         kx #
     5         kx part_prefix()
     5         kx {
     5         kx   local dev=${1}
     5         kx   if `echo ${dev: -1} | grep -q '[0-1]'` ; then
     5         kx     p=p
     5         kx   fi
     5         kx }
     5         kx 
     5         kx check_current_device()
     5         kx {
     5         kx   current_device=`${WHERE} -n -o disk`
     5         kx   current_root=`${WHERE} -n -o root`
     5         kx   pline=`LANG=en_US.UTF-8 fdisk -l --bytes ${current_device} | grep "^${current_root}" | tr -s ' '`
     5         kx   active=`echo "${pline}" | cut -f2 -d' '`
     5         kx   if [ "${partition_table_type}" = "o" ] ; then
     5         kx     if [ "${active}" = "*" ] ; then
     5         kx       rootfs_min_bytes=`echo "${pline}" | cut -f6 -d' '`
     5         kx     fi
     5         kx   else
     5         kx     rootfs_min_bytes=`echo "${pline}" | cut -f5 -d' '`
     5         kx   fi
     5         kx }
     5         kx 
     5         kx ask_target_device()
     5         kx {
     5         kx   cat > $TMP/select-target-device$$ << EOF
     5         kx 
     5         kx  Target device is not selected or invalid.
     5         kx  Do you want to select Target Device to install?
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   $DIALOG --colors --defaultno --clear \
     5         kx           --backtitle "\Z7${DISTRO_CAPTION}\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Setup:\Zn \Z4\ZbSelect Target Device\ZB\Zn " \
     5         kx           --no-label "Exit Setup" \
     5         kx           --yes-label " Select " \
     5         kx           --yesno "$(cat $TMP/select-target-device$$)" 9 74
     5         kx   ret=$?
     5         kx   rm -f $TMP/select-target-device$$
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     push_log "Done"
     5         kx     exit
     5         kx   fi
     5         kx }
     5         kx 
     5         kx select_target_device()
     5         kx {
     5         kx   cat > $TMP/device-help$$ << EOF
     5         kx --colors --clear \\
     5         kx --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \\
     5         kx --title " \Z0\ZbSelect the destination\ZB\Zn " \\
     5         kx --menu "\\n\\
     5         kx  If the desired device is not displayed in the following list,\\n\\
     5         kx  please insert the disk and repeat installation.\\n\\
     5         kx \\n\\
     5         kx  Please select the target device:\\
     5         kx " 14 74 3 \\
     5         kx EOF
     5         kx 
     5         kx   for dev in `lsblk -ldn -o name` ; do
     5         kx     #
   385         kx     # Skip 'ram.*', 'zram.*', 'mtd.*', 'mmcblk[0-9]*boot.*':
     5         kx     #
   385         kx     if `echo ${dev} | grep -q 'ram.*\|zram.*\|mtd.*\|mmcblk[0-9]*boot.*'` ; then
     5         kx       continue
     5         kx     fi
     5         kx     #
     5         kx     # Exclude current device:
     5         kx     #
     5         kx     local sfound=`echo "${current_device}" | grep "/dev/${dev}"`
     5         kx     if [ "x${sfound}" = "x" ] ; then
     5         kx       echo "\"/dev/$dev\" \" \" \\" >> $TMP/device-help$$
     5         kx     fi
     5         kx   done
     5         kx 
     5         kx   ${DIALOG} --file $TMP/device-help$$ 2> $TMP/devmame$$
     5         kx   ret=$?
     5         kx   if [ $ret -eq 1 -o $ret -eq 255 ]; then
     5         kx     rm -f $TMP/devmame$$
     5         kx     rm -f $TMP/device-help$$
     5         kx     # continue: see check_target_device()
     5         kx   fi
     5         kx   result=`cat $TMP/devmame$$`
     5         kx   rm -f $TMP/devmame$$
     5         kx   rm -f $TMP/device-help$$
     5         kx 
     5         kx   device=$result
     5         kx }
     5         kx 
     5         kx check_target_device()
     5         kx {
     5         kx   while [ "x${device}" = "x" -o "x${device}" = "x${current_device}" ] ; do
     5         kx     ask_target_device
     5         kx     select_target_device
     5         kx   done
     5         kx 
     5         kx   if [ -b "${device}" ] ; then
     5         kx     local base=`basename ${device}`
     5         kx     local mjrs=`major_number ${device}`
     5         kx     local line="`lsblk -I ${mjrs} -l -o name,type | grep \"${base} \" | tr -s ' ' | head -n 1`"
     5         kx     if [ "$line" != "" ] ; then
     5         kx       local name=`echo "${line}" | tr -s ' ' | cut -f1 -d' '`
     5         kx       local type=`echo "${line}" | tr -s ' ' | cut -f2 -d' '`
     5         kx       if [ "${base}" = "${name}" -a "${type}" != "disk" -a "${type}" != "loop" ] ; then
     5         kx         push_log "ERROR: The DEVICE (${device}) is not a physical disk"
     5         kx         device=
     5         kx         check_target_device
     5         kx       fi
     5         kx     else
     5         kx       push_log "ERROR: The DEVICE ($device) not found"
     5         kx       device=
     5         kx       check_target_device
     5         kx     fi
     5         kx   else
     5         kx     push_log "ERROR: The DEVICE ($device) not a block device"
     5         kx     device=
     5         kx     check_target_device
     5         kx   fi
     5         kx 
     5         kx   part_prefix ${device}
     5         kx   disk_geometry ${device}
     5         kx }
     5         kx #
     5         kx # End of Check Target device functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ################################################################
     5         kx #
     5         kx # Partitions functions.
     5         kx #
     5         kx make_ext2() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1ext2\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.ext2 -q -F -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.ext2 -q -F ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_ext3() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1ext3\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.ext3 -q -F -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.ext3 -q -F ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_ext4() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1ext4\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.ext4 -q -F -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.ext4 -q -F ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_vfat() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1vfat\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.fat -F 32 -n "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.fat -F 32 ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_btrfs() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1btrfs\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.btrfs -d single -m single -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.btrfs -d single -m single ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_jfs() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1jfs\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.jfs -q -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.jfs -q ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_xfs() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1xfs\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkfs.xfs -q -f -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkfs.xfs -q -f ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx make_swap() {
     5         kx   local  pname=${1}
     5         kx   local plabel=${2}
     5         kx 
     5         kx   local psize=`get_partition_size ${pname}`
     5         kx   let "psize = psize / 1024"
     5         kx 
     5         kx   $DIALOG --colors \
     5         kx           --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx           --title " \Z0Formatting\Zn \Z4\Zb$pname\ZB\Zn " \
     5         kx           --infobox "\n Formatting \Z1${pname}\ZB\Zn\n\n\
     5         kx  Size in 1K blocks: \Z4${psize}\Zn\n\
     5         kx    Filesystem type: \Z1swap\Zn\n" 8 74
     5         kx   if `mount | grep -q "^${pname} " 1>/dev/null 2>/dev/null` ; then
     5         kx     umount ${pname} 2>/dev/null
     5         kx   fi
     5         kx   if [ "x${plabel}" != "x" ] ; then
     5         kx     mkswap -v1 -L "${plabel}" ${pname} 1>/dev/null 2>/dev/null
     5         kx   else
     5         kx     mkswap -v1 ${pname} 1>/dev/null 2>/dev/null
     5         kx   fi
     5         kx }
     5         kx 
     5         kx partlist=$TMP/plist.$$
     5         kx partitems=$TMP/pitems.$$
     5         kx 
     5         kx gen_parts_list()
     5         kx {
     5         kx   local disk=${1}
     5         kx   local devname=`echo ${disk} | sed -e 's,^/dev/,,'`
     5         kx 
     5         kx   if [ "${partition_table_type}" = "g" ] ; then
     5         kx     uefi_id="EFI System"
     5         kx     linux_id="Linux filesystem"
     5         kx     swap_id="Linux swap"
     5         kx   else
     5         kx     uefi_id="ef"
     5         kx     linux_id="83"
     5         kx     swap_id="82"
     5         kx   fi
     5         kx 
     5         kx   truncate -s0 $partlist
     5         kx 
     5         kx   local first_uefi= ; local first_root= ; local first_home=
     5         kx 
     5         kx   local plist=`LANG=en_US.UTF-8 lsblk -lb -o name,size,type,fstype,mountpoint | grep ${devname} | tr -s ' '`
     5         kx   echo -e "${plist}" | while read -r line ; do
     5         kx     words=`echo "${line}" | wc -w`
     5         kx 
     5         kx     pname= ; psize= ; ptype= ; fstype= ; mpoint= ; partuuid= ; uuid=
     5         kx 
     5         kx     pname=`echo "${line}" | cut -f1 -d ' '`
     5         kx     if [ ${words} -ge 2 ] ; then
     5         kx       psize=`echo "${line}" | cut -f2 -d ' '`
     5         kx     fi
     5         kx     if [ ${words} -ge 3 ] ; then
     5         kx       ptype=`echo "${line}" | cut -f3 -d ' '`
     5         kx       if [ "${ptype}" != "part" ] ; then
     5         kx         continue
     5         kx       fi
     5         kx     fi
     5         kx     if [ ${words} -ge 4 ] ; then
     5         kx       fstype=`echo "${line}" | cut -f4 -d ' '`
     5         kx     fi
     5         kx     if [ ${words} -ge 5 ] ; then
     5         kx       mpoint=`echo "${line}" | cut -f5 -d ' '`
     5         kx     fi
     5         kx 
     5         kx     #
     5         kx     # recomended values:
     5         kx     #
     5         kx     used=
     5         kx     # skip active partition sign [asterisk '*']
     5         kx     local pline=`LANG=en_US.UTF-8 fdisk -l /dev/${devname} | grep "^/dev/${pname}" | tr -s ' '`
     5         kx     active=`echo "${pline}" | cut -f2 -d' '`
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       partid=`echo "${pline}" | cut -f6,7 -d' '`
     5         kx     else
     5         kx       if [ "${active}" = "*" ] ; then
     5         kx         partid=`echo "${pline}" | cut -f7 -d' '`
     5         kx       else
     5         kx         partid=`echo "${pline}" | cut -f6 -d' '`
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     if [ "${partid}" = "${swap_id}" ] ; then
     5         kx       mpoint="swap"
     5         kx       fstype="swap"
     5         kx     fi
     5         kx     if [ "x${first_uefi}" = "x" ] ; then
     5         kx       if [ "${partid}" = "${uefi_id}" ] ; then
     5         kx         first_boot="/dev/${pname}"
     5         kx         mpoint="/boot/efi"
     5         kx         fstype="vfat"
     5         kx         used="use"
     5         kx       fi
     5         kx     fi
     5         kx     if [ "x${first_root}" = "x" ] ; then
     5         kx       if [ "${partid}" = "${linux_id}" ] ; then
     5         kx         first_root="/dev/${pname}"
     5         kx         mpoint="/"
     5         kx         fstype="ext4"
     5         kx       fi
     5         kx     fi
     5         kx     if [ "x${first_root}" != "x" -a "x${first_home}" = "x" ] ; then
     5         kx       if [ "${partid}" = "${linux_id}" ] ; then
     5         kx          if [ "${first_root}" != "/dev/${pname}" ] ; then
     5         kx            first_home="/dev/${pname}"
     5         kx            mpoint="/home"
     5         kx            fstype="ext4"
     5         kx         fi
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     echo "/dev/${pname}:${psize}:${fstype}:${mpoint}:${used}:${partuuid}:${uuid}" | tr -s ' ' >> ${partlist}
     5         kx   done
     5         kx }
     5         kx 
     5         kx gen_parts_menu_items()
     5         kx {
     5         kx   local disk=${1}
     5         kx   local devname=`echo ${disk} | sed -e 's,^/dev/,,'`
     5         kx 
     5         kx   local first_uefi= ; local first_root= ; local first_home=
     5         kx 
     5         kx   truncate -s0 $partitems
     5         kx 
     5         kx   cat "$partlist" | while read -r line ; do
     5         kx     pname= ; psize= ; ptype= ; fstype= ; mpoint=
     5         kx 
     5         kx     pname=`echo "$line" | cut -f1 -d':'`
     5         kx 
     5         kx     #
     5         kx     # get partition type (skipping active partition sign [asterisk '*']):
     5         kx     #
     5         kx     pline=`LANG=en_US.UTF-8 fdisk -l ${disk} | grep "^${pname}" | tr -s ' '`
     5         kx     active=`echo "${pline}" | cut -f2 -d' '`
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       ptype=`echo "${pline}" | cut -f6,7 -d' '`
     5         kx     else
     5         kx       if [ "${active}" = "*" ] ; then
     5         kx         ptype=`echo "${pline}" | cut -f7 -d' '`
     5         kx       else
     5         kx         ptype=`echo "${pline}" | cut -f6 -d' '`
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     if [ "${partition_table_type}" = "g" ] ; then
     5         kx       if [ "${ptype}" = "EFI System" ] ; then
     5         kx         ptype="ef"
     5         kx       fi
     5         kx       if [ "${ptype}" = "Linux filesystem" ] ; then
     5         kx         ptype="83"
     5         kx       fi
     5         kx       if [ "${ptype}" = "Linux swap" ] ; then
     5         kx         ptype="82"
     5         kx       fi
     5         kx     fi
     5         kx 
     5         kx     ptype=`printf ' %02s ' "${ptype}"`
     5         kx 
     5         kx     psize=`echo "${line}" | cut -f2 -d':'`
     5         kx     let "psize = psize / 1048576"
     5         kx     psize=`printf '%6d' $psize`
     5         kx 
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     fstype=`printf '%-8s' "${fstype}"`
     5         kx 
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx 
     5         kx     used=`echo "${line}" | cut -f5 -d':'`
     5         kx     if [ "${used}" == "use" ] ; then
     5         kx       fstype="\\Z4${fstype}\\Zn"
     5         kx       mpoint="\\Z4${mpoint}\\Zn"
     5         kx     fi
     5         kx     echo "\"${pname}\" \"${psize}M ${ptype} ${fstype} ${mpoint}\" \\" | sed -e 's,\s\+$,,g' >> ${partitems}
     5         kx   done
     5         kx }
     5         kx 
     5         kx get_partition_size()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local psize=`cat ${partlist} | grep "^${dev}" | cut -f2 -d':'`
     5         kx   echo -n "${psize}"
     5         kx }
     5         kx 
     5         kx get_recomended_fstype()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local fstype=`cat ${partlist} | grep "^${dev}" | cut -f3 -d':'`
     5         kx   echo -n "${fstype}"
     5         kx }
     5         kx 
     5         kx set_recomended_fstype() {
     5         kx   local dev=${1}
     5         kx   local fstype=${2}
     5         kx   local   name=`echo ${dev} | sed -e 's,/dev/,,'`
     5         kx   local  psize=`cat ${partlist} | grep "^${dev}" | cut -f2 -d':'`
     5         kx   local mpoint=`cat ${partlist} | grep "^${dev}" | cut -f4 -d':'`
     5         kx   local  puuid=`cat ${partlist} | grep "^${dev}" | cut -f6 -d':'`
     5         kx   local   uuid=`cat ${partlist} | grep "^${dev}" | cut -f7 -d':'`
     5         kx   sed -i "/${name}/c\/dev/${name}:${psize}:${fstype}:${mpoint}:use:${puuid}:${uuid}" ${partlist}
     5         kx }
     5         kx 
     5         kx get_recomended_mpoint()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local mpoint=`cat ${partlist} | grep "^${dev}" | cut -f4 -d':'`
     5         kx   echo -n "${mpoint}"
     5         kx }
     5         kx 
     5         kx set_recomended_mpoint()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local mpoint=${2}
     5         kx   local   name=`echo ${dev} | sed -e 's,/dev/,,'`
     5         kx   local  psize=`cat ${partlist} | grep "^${dev}" | cut -f2 -d':'`
     5         kx   local fstype=`cat ${partlist} | grep "^${dev}" | cut -f3 -d':'`
     5         kx   local  puuid=`cat ${partlist} | grep "^${dev}" | cut -f6 -d':'`
     5         kx   local   uuid=`cat ${partlist} | grep "^${dev}" | cut -f7 -d':'`
     5         kx   sed -i "/${name}/c\/dev/${name}:${psize}:${fstype}:${mpoint}:use:${puuid}:${uuid}" ${partlist}
     5         kx }
     5         kx 
     5         kx get_rootfs_devname()
     5         kx {
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx 
     5         kx     if [ "${mpoint}" = "/" ] ; then
     5         kx       echo -n "${pname}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx get_uefi_devname()
     5         kx {
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx 
     5         kx     if [ "${mpoint}" = "/boot/efi" ] ; then
     5         kx       echo -n "${pname}"
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx get_part_uuid()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local puuid=`cat ${partlist} | grep "^${dev}" | cut -f6 -d':'`
     5         kx   echo -n "${puuid}"
     5         kx }
     5         kx 
     5         kx set_part_uuid()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local  puuid=${2}
     5         kx   local   name=`echo ${dev} | sed -e 's,/dev/,,'`
     5         kx   local  psize=`cat ${partlist} | grep "^${dev}" | cut -f2 -d':'`
     5         kx   local fstype=`cat ${partlist} | grep "^${dev}" | cut -f3 -d':'`
     5         kx   local mpoint=`cat ${partlist} | grep "^${dev}" | cut -f4 -d':'`
     5         kx   local   used=`cat ${partlist} | grep "^${dev}" | cut -f5 -d':'`
     5         kx   local   uuid=`cat ${partlist} | grep "^${dev}" | cut -f7 -d':'`
     5         kx   sed -i "/${name}/c\/dev/${name}:${psize}:${fstype}:${mpoint}:${used}:${puuid}:${uuid}" ${partlist}
     5         kx }
     5         kx 
     5         kx get_uuid()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local uuid=`cat ${partlist} | grep "^${dev}" | cut -f7 -d':'`
     5         kx   echo -n "${uuid}"
     5         kx }
     5         kx 
     5         kx set_uuid()
     5         kx {
     5         kx   local dev=${1}
     5         kx   local   uuid=${2}
     5         kx   local   name=`echo ${dev} | sed -e 's,/dev/,,'`
     5         kx   local  psize=`cat ${partlist} | grep "^${dev}" | cut -f2 -d':'`
     5         kx   local fstype=`cat ${partlist} | grep "^${dev}" | cut -f3 -d':'`
     5         kx   local mpoint=`cat ${partlist} | grep "^${dev}" | cut -f4 -d':'`
     5         kx   local   used=`cat ${partlist} | grep "^${dev}" | cut -f5 -d':'`
     5         kx   local  puuid=`cat ${partlist} | grep "^${dev}" | cut -f6 -d':'`
     5         kx   sed -i "/${name}/c\/dev/${name}:${psize}:${fstype}:${mpoint}:${used}:${puuid}:${uuid}" ${partlist}
     5         kx }
     5         kx 
     5         kx create_file_system()
     5         kx {
     5         kx   local  pname=${1}
     5         kx   local fstype=${2}
     5         kx   local plabel=
     5         kx 
     5         kx   mpoint=`get_recomended_mpoint ${pname}`
     5         kx   if [ "${mpoint}" = "/" ] ; then
     5         kx     plabel="root"
     5         kx   fi
     5         kx   if [ "${mpoint}" == "/home" ] ; then
     5         kx     plabel="home"
     5         kx   fi
     5         kx 
     5         kx   cat > $TMP/partlabel-help$$ << EOF
     5         kx 
     5         kx  Please specify the volume label for file system
     5         kx  on the \Z1${pname}\Zn partition.
     5         kx 
     5         kx  Set the volume label or leave following field blank:
     5         kx EOF
     5         kx 
     5         kx   result=`$DIALOG --stdout  --colors \
     5         kx                   --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx                   --title " \Z0Select Volume Label\Zn " \
     5         kx                   --inputbox "$(cat $TMP/partlabel-help$$)" 12 74 "${plabel}"`
     5         kx   ret=$?
     5         kx   rm -f $TMP/partlabel-help$$
     5         kx   if [ ${ret} -eq 0 ]; then
     5         kx     plabel="${result}"
     5         kx   fi
     5         kx 
     5         kx   case "${fstype}" in
     5         kx     ext2 )
     5         kx       make_ext2 "${pname}" "${plabel}"
     5         kx       ;;
     5         kx     ext3 )
     5         kx       make_ext3 "${pname}" "${plabel}"
     5         kx       ;;
     5         kx     ext4 )
     5         kx       make_ext4 "${pname}" "${plabel}"
     5         kx       ;;
     5         kx     vfat )
     5         kx       make_vfat "${pname}" "${plabel}"
     5         kx       ;;
     5         kx     btrfs )
     5         kx       make_btrfs "${pname}" "${plabel}"
     5         kx       ;;
     5         kx     * )
     5         kx       ;;
     5         kx   esac
     5         kx 
     5         kx   set_recomended_fstype "${pname}" "${fstype}"
     5         kx }
     5         kx 
     5         kx set_mount_point()
     5         kx {
     5         kx   local pname=${1}
     5         kx   local mpoint=${2}
     5         kx 
     5         kx   cat > $TMP/mountpoint-help$$ << EOF
     5         kx 
     5         kx  Please specify the mount directory of the \Z1${pname}\Zn partition.
     5         kx 
     5         kx  Set the mount directory:
     5         kx EOF
     5         kx 
     5         kx   result=`$DIALOG --stdout  --colors \
     5         kx                   --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx                   --title " \Z0Select Mount Point for\Zn \Z4${pname}\Zn " \
     5         kx                   --inputbox "$(cat $TMP/mountpoint-help$$)" 11 74 "${mpoint}"`
     5         kx   ret=$?
     5         kx   rm -f $TMP/mountpoint-help$$
     5         kx   if [ ${ret} -eq 0 ]; then
     5         kx     mpoint="${result}"
     5         kx   fi
     5         kx   set_recomended_mpoint "${pname}" "${mpoint}"
     5         kx }
     5         kx 
     5         kx format_partition()
     5         kx {
     5         kx   local pname=${1}
     5         kx 
     5         kx   local fstype=`get_recomended_fstype ${pname}`
     5         kx   local mpoint=`get_recomended_mpoint ${pname}`
     5         kx 
     5         kx   if [ "${fstype}" == "swap" ] ; then
     5         kx     cat > $TMP/mountpoint-help$$ << EOF
     5         kx 
     5         kx  Radix Setup will now prepare your system's \Z1swap\Zn space.
     5         kx 
     5         kx  Would you like to format \Z1${pname}\Zn using \Z4mkswap\Zn ?
     5         kx EOF
     5         kx 
     5         kx     result=`$DIALOG --stdout  --colors \
     5         kx                     --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx                     --title " \Z0Format Swap Partition\Zn \Z4${pname}\Zn " \
     5         kx                     --yes-label " OK " \
     5         kx                     --yesno "$(cat $TMP/mountpoint-help$$)" 9 74`
     5         kx     ret=$?
     5         kx     rm -f $TMP/mountpoint-help$$
     5         kx     if [ ${ret} -eq 0 ]; then
     5         kx       make_swap ${pname} swap
     5         kx     else
     5         kx       return
     5         kx     fi
     5         kx     set_recomended_fstype "${pname}" "swap"
     5         kx     set_recomended_mpoint "${pname}" "swap"
     5         kx     return
     5         kx   else
     5         kx     unset EXT2 EXT3 EXT4 REISERFS BTRFS VFAT JFS XFS
     5         kx     if grep -wq ext2 /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       EXT2="Ext2 is the traditional Linux file system and is fast and stable."
     5         kx     fi
     5         kx     if grep -wq ext3 /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       EXT3="Ext3 is the journaling version of the Ext2 filesystem."
     5         kx     fi
     5         kx     if grep -wq ext4 /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       EXT4="Ext4 is the successor to the ext3 filesystem."
     5         kx     fi
     5         kx     if grep -wq btrfs /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       BTRFS="Btrfs is a B-tree copy-on-write filesystem."
     5         kx     fi
     5         kx     if grep -wq vfat /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       VFAT="VFAT is a updated version of the FAT filesystem for Windows. VFAT's updates are mainly support for longer file names."
     5         kx     fi
     5         kx     if grep -wq jfs /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       JFS="JFS is IBM's Journaled Filesystem, currently used in IBM enterprise servers."
     5         kx     fi
     5         kx     if grep -wq xfs /proc/filesystems 1>/dev/null 2>/dev/null ; then
     5         kx       XFS="XFS is SGI's journaling filesystem that originated on IRIX."
     5         kx     fi
     5         kx 
     5         kx     cat > $TMP/filesystem-help$$ << EOF
     5         kx --colors --default-item "${fstype}" \\
     5         kx --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \\
     5         kx --title " \Z0Select File System for\Zn \Z4${pname}\Zn " \\
     5         kx --menu "\\n\\
     5         kx  Please select the type of filesystem to use for the specified device\\n\\
     5         kx  or hit <\Z1\ZbC\ZB\Zn\Zbancel\ZB> to leave existed filesystem. \\
     5         kx \\n\\n\\
     5         kx  Here are descriptions of the available filesystems:\\
     5         kx " 15 74 4 \\
     5         kx EOF
     5         kx 
     5         kx     if [ "x${EXT2}" != "x" ]; then
     5         kx       echo "\"ext2\" \"Standard Linux Ext2 Filesystem\" \\" >> $TMP/filesystem-help$$
     5         kx     fi
     5         kx     if [ "x${EXT3}" != "x" ]; then
     5         kx       echo "\"ext3\" \"Ext3 Journaling Filesystem\" \\" >> $TMP/filesystem-help$$
     5         kx     fi
     5         kx     if [ "x${EXT4}" != "x" ]; then
     5         kx       echo "\"ext4\" \"Ext4 Journaling Filesystem\" \\" >> $TMP/filesystem-help$$
     5         kx     fi
     5         kx     if [ "x${VFAT}" != "x" ]; then
     5         kx       echo "\"vfat\" \"VFAT updated version of the FAT filesystem\" \\" >> $TMP/filesystem-help$$
     5         kx     fi
     5         kx     if [ "x${BTRFS}" != "x" ]; then
     5         kx       echo "\"btrfs\" \"Btrfs Copy-on-Write B-tree Filesystem\" \\" >> $TMP/filesystem-help$$
     5         kx     fi
     5         kx 
     5         kx     $DIALOG --file $TMP/filesystem-help$$ 2> $TMP/filesystem$$
     5         kx     ret=$?
     5         kx     result=`cat $TMP/filesystem$$`
     5         kx     rm -f $TMP/filesystem$$
     5         kx     rm -f $TMP/filesystem-help$$
     5         kx     if [ ${ret} -eq 0 ]; then
     5         kx       fstype=${result}
     5         kx 
     5         kx       # Create File System:
     5         kx       create_file_system "${pname}" "${fstype}"
     5         kx 
     5         kx       # Set Mount Point:
     5         kx       set_mount_point "${pname}" "${mpoint}"
     5         kx     else
     5         kx       # Leave existed file system:
     5         kx       set_recomended_fstype "${pname}" "${fstype}"
     5         kx       # Set Mount Point:
     5         kx       set_mount_point "${pname}" "${mpoint}"
     5         kx     fi
     5         kx   fi
     5         kx }
     5         kx 
     5         kx prepare_partitions()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   if [ "x${disk}" = "x" ] ; then
     5         kx     return 255
     5         kx   fi
     5         kx 
     5         kx   local items=4
     5         kx   local height=21
     5         kx 
     5         kx   gen_parts_list "${disk}"
     5         kx 
     5         kx   while [ 0 ] ; do
     5         kx     cat > $TMP/menu-format$$ << EOF
     5         kx --colors --clear --cancel-label "Continue" \\
     5         kx --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \\
     5         kx --title " \Z0Create File Systems and Select\Zn \Z0Mountpoints\Zn " \\
     5         kx --menu "\\n\\
     5         kx EOF
     5         kx 
     5         kx     cat >> $TMP/menu-format$$ << EOF
     5         kx  The target disk has fillowing partitions. Each menu item show the\\n\\
     5         kx  device name, size in MiB, and type of existing partition. Last two\\n\\
     5         kx  columns may shows recomended filesystem and mount point for the\\n\\
     5         kx  target system. Now you can create filesystem on each existing\\n\\
     5         kx  partitions (if needed) and choose or confirm mount point.\\n\\n\\
     5         kx  Already changed values will be shown in \Z4\ZbBlue\ZB\Zn (0x0000FF) color.\\
     5         kx EOF
     5         kx 
     5         kx     cat >> $TMP/menu-format$$ << EOF
     5         kx \\n\\n\\
     5         kx  Please select each of partitions listed below,\\n\\
     5         kx  or if you're done, hit <Continue>:\\
     5         kx " $height 73 $items \\
     5         kx EOF
     5         kx 
     5         kx     gen_parts_menu_items "${disk}"
     5         kx 
     5         kx     cat "${partitems}" >> $TMP/menu-format$$
     5         kx 
     5         kx     $DIALOG --file $TMP/menu-format$$ 2> $TMP/format$$
     5         kx     ret=$?
     5         kx     if [ ${ret} -eq 1 -o ${ret} -eq 255 ]; then
     5         kx       rm -f $TMP/format$$
     5         kx       rm -f $TMP/menu-format$$
     5         kx       # continue the installation
     5         kx       return ${ret}
     5         kx     fi
     5         kx     local pname=`cat $TMP/format$$`
     5         kx     rm -f $TMP/format$$
     5         kx     rm -f $TMP/menu-format$$
     5         kx 
     5         kx     format_partition "${pname}"
     5         kx   done
     5         kx }
     5         kx 
     5         kx partitions_loop()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   while [ 0 ] ; do
     5         kx     prepare_partitions "${disk}"
     5         kx     ret=$?
     5         kx     if [ ${ret} -eq 255 ]; then
     5         kx       # User can interrupt format partitions cycle by press Esc button
     5         kx       # on keyboard. In this case we have to exit setup because we not
     5         kx       # sure that user done all needs.  If user say Esc again, then we
     5         kx       # will return him back to the cycle until user press <Continue>.
     5         kx       ask_exit_setup
     5         kx       continue
     5         kx     fi
     5         kx     if [ ${ret} -eq 1 ]; then
     5         kx       break
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx 
     5         kx check_partitions()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local has_uefi=
     5         kx   local has_linux=
     5         kx   local retvalue=0
     5         kx 
     5         kx   if [ "${partition_table_type}" = "g" ] ; then
     5         kx     if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx       has_uefi=`LANG=en_US.UTF-8 fdisk -l ${disk} | tr -s ' ' | grep "^${disk}.* EFI System"`
     5         kx       if [ "x${has_uefi}" = "x" ] ; then
     5         kx         retvalue=1
     5         kx       fi
     5         kx     fi
     5         kx     has_linux=`LANG=en_US.UTF-8 fdisk -l ${disk} | tr -s ' '  | grep "^${disk}.* Linux filesystem"`
     5         kx     if [ "x${has_linux}" = "x" ] ; then
     5         kx       retvalue=2
     5         kx     fi
     5         kx   else
     5         kx     if [ "x${uefi_bytes}" != "x" ] ; then
     5         kx       has_uefi=`LANG=en_US.UTF-8 fdisk -l ${disk} | tr -s ' '  | grep "^${disk}.* ef .*"`
     5         kx       if [ "x${has_uefi}" = "x" ] ; then
     5         kx         retvalue=1
     5         kx       fi
     5         kx     fi
     5         kx     has_linux=`LANG=en_US.UTF-8 fdisk -l ${disk} | tr -s ' '  | grep "^${disk}.* 83 .*"`
     5         kx     if [ "x${has_linux}" = "x" ] ; then
     5         kx       retvalue=2
     5         kx     fi
     5         kx   fi
     5         kx 
     5         kx   if [ "${retvalue}" -eq "1" ] ; then
     5         kx     error_dialog "Target device must have \Z1EFI\Zn partition."
     5         kx     ask_formatting "${disk}"
     5         kx   fi
     5         kx   if [ "${retvalue}" -eq "2" ] ; then
     5         kx     error_dialog "Target device must have at least one \Z1Linux\Zn partition."
     5         kx     ask_formatting "${disk}"
     5         kx   fi
     5         kx }
     5         kx 
     5         kx check_filesystems()
     5         kx {
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx       used=`echo "${line}" | cut -f5 -d':'`
     5         kx 
     5         kx     if [ "${used}" = "use" ] ; then
     5         kx       if [ "${mpoint}" = "/" ] ; then
     5         kx         name=`echo ${pname} | sed -e 's,/dev/,,'`
     5         kx         PARTUUID=`LANG=en_US.UTF-8 lsblk -ln -o name,partuuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx             UUID=`LANG=en_US.UTF-8 lsblk -ln -o name,uuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx         set_part_uuid "${pname}" "${PARTUUID}"
     5         kx              set_uuid "${pname}" "${UUID}"
     5         kx       elif [ "${mpoint}" = "/home" ] ; then
     5         kx         name=`echo ${pname} | sed -e 's,/dev/,,'`
     5         kx         PARTUUID=`LANG=en_US.UTF-8 lsblk -ln -o name,partuuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx             UUID=`LANG=en_US.UTF-8 lsblk -ln -o name,uuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx         set_part_uuid "${pname}" "${PARTUUID}"
     5         kx              set_uuid "${pname}" "${UUID}"
     5         kx       elif [ "${fstype}" = "vfat" -a "${mpoint}" = "/boot/efi" ] ; then
     5         kx         name=`echo ${pname} | sed -e 's,/dev/,,'`
     5         kx         PARTUUID=`LANG=en_US.UTF-8 lsblk -ln -o name,partuuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx             UUID=`LANG=en_US.UTF-8 lsblk -ln -o name,uuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx         set_part_uuid "${pname}" "${PARTUUID}"
     5         kx              set_uuid "${pname}" "${UUID}"
     5         kx       elif [ "${fstype}" = "swap" ] ; then
     5         kx         name=`echo ${pname} | sed -e 's,/dev/,,'`
     5         kx         PARTUUID=`LANG=en_US.UTF-8 lsblk -ln -o name,partuuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx             UUID=`LANG=en_US.UTF-8 lsblk -ln -o name,uuid | grep "^${name}" | tr -s ' ' | cut -f2 -d' '`
     5         kx         set_part_uuid "${pname}" "${PARTUUID}"
     5         kx              set_uuid "${pname}" "${UUID}"
     5         kx       fi
     5         kx     fi
     5         kx   done
     5         kx }
     5         kx #
     5         kx # End of Partitions functions.
     5         kx #
     5         kx ################################################################
     5         kx 
     5         kx ####################################################################
     5         kx #
     5         kx # prepare /etc/fstab - create temporary /etc/fstab according to
     5         kx #                      the table of formated partitions.
     5         kx #
     5         kx fstab=$TMP/fstab.$$
     5         kx 
     5         kx prepare_dev_etc_fstab() {
     5         kx   cat > $fstab << EOF
     5         kx #
     5         kx # /etc/fstab
     5         kx #
     5         kx # --------------+----------------+-----------+------------------------------------+------+------
     5         kx #        device | mount point    | FS type   | options                            | dump | pass
     5         kx # --------------+----------------+-----------+------------------------------------+------+------
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint= ; dump= ; pass=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx       used=`echo "${line}" | cut -f5 -d':'`
     5         kx 
     5         kx     if [ "${used}" = "use" ] ; then
     5         kx       if [ "${mpoint}" = "/" ] ; then
     5         kx         dump=1 ; pass=1
     5         kx       elif [ "${mpoint}" = "/home" ] ; then
     5         kx         dump=1 ; pass=2
     5         kx       elif [ "${fstype}" = "vfat" -a "${mpoint}" = "/boot/efi" ] ; then
     5         kx         dump=1 ; pass=0
     5         kx       elif [ "${mpoint}" = "swap" ] ; then
     5         kx         dump=0 ; pass=0
     5         kx       else
     5         kx         dump=1 ; pass=2
     5         kx       fi
     5         kx       printf "%-16s %-16s %-11s %-36s %-6s %s\n" "${pname}" "${mpoint}" "${fstype}" "defaults" "${dump}" "${pass}" >> ${fstab}
     5         kx     fi
     5         kx   done
     5         kx   echo "" >> ${fstab}
     5         kx   printf "%-16s %-16s %-11s %-36s %-6s %s\n" "devpts" "/dev/pts" "devpts" "gid=5,mode=620"      "0" "0" >> ${fstab}
     5         kx   printf "%-16s %-16s %-11s %-36s %-6s %s\n" "proc"   "/proc"    "proc"   "defaults"            "0" "0" >> ${fstab}
     5         kx   printf "%-16s %-16s %-11s %-36s %-6s %s\n" "tmpfs"  "/dev/shm" "tmpfs"  "nosuid,nodev,noexec" "0" "0" >> ${fstab}
     5         kx 
     5         kx   cat >> ${fstab} << EOF
     5         kx 
     5         kx # --------------+----------------+-----------+------------------------------------+------+------
     5         kx EOF
     5         kx }
     5         kx 
     5         kx prepare_uuid_etc_fstab() {
     5         kx   cat > $fstab << EOF
     5         kx #
     5         kx # /etc/fstab
     5         kx #
     5         kx # ----------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx #                  device                 | mount point    | FS type   | options                            | dump | pass
     5         kx # ----------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx 
     5         kx EOF
     5         kx 
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint= ; dump= ; pass=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx       used=`echo "${line}" | cut -f5 -d':'`
     5         kx       uuid=`echo "${line}" | cut -f7 -d':'`
     5         kx 
     5         kx     if [ "${used}" = "use" ] ; then
     5         kx       if [ "${mpoint}" = "/" ] ; then
     5         kx         dump=1 ; pass=1
     5         kx       elif [ "${mpoint}" = "/home" ] ; then
     5         kx         dump=1 ; pass=2
     5         kx       elif [ "${fstype}" = "vfat" -a "${mpoint}" = "/boot/efi" ] ; then
     5         kx         dump=1 ; pass=0
     5         kx       elif [ "${mpoint}" = "swap" ] ; then
     5         kx         dump=0 ; pass=0
     5         kx       else
     5         kx         dump=1 ; pass=2
     5         kx       fi
     5         kx       printf "%-42s %-16s %-11s %-36s %-6s %s\n" "UUID=${uuid}" "${mpoint}" "${fstype}" "defaults" "${dump}" "${pass}" >> ${fstab}
     5         kx     fi
     5         kx   done
     5         kx   echo "" >> ${fstab}
     5         kx   printf "%-42s %-16s %-11s %-36s %-6s %s\n" "devpts" "/dev/pts" "devpts" "gid=5,mode=620"      "0" "0" >> ${fstab}
     5         kx   printf "%-42s %-16s %-11s %-36s %-6s %s\n" "proc"   "/proc"    "proc"   "defaults"            "0" "0" >> ${fstab}
     5         kx   printf "%-42s %-16s %-11s %-36s %-6s %s\n" "tmpfs"  "/dev/shm" "tmpfs"  "nosuid,nodev,noexec" "0" "0" >> ${fstab}
     5         kx 
     5         kx   cat >> ${fstab} << EOF
     5         kx 
     5         kx # ----------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx EOF
     5         kx }
     5         kx 
     5         kx prepare_partuuid_etc_fstab() {
     5         kx   if [ "${partition_table_type}" = "g" ] ; then
     5         kx     local dlen=46
     5         kx     cat > $fstab << EOF
     5         kx #
     5         kx # /etc/fstab
     5         kx #
     5         kx # --------------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx #                    device                   | mount point    | FS type   | options                            | dump | pass
     5         kx # --------------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx 
     5         kx EOF
     5         kx   else
     5         kx     local dlen=21
     5         kx     cat > $fstab << EOF
     5         kx #
     5         kx # /etc/fstab
     5         kx #
     5         kx # -------------------+----------------+-----------+------------------------------------+------+------
     5         kx #             device | mount point    | FS type   | options                            | dump | pass
     5         kx # -------------------+----------------+-----------+------------------------------------+------+------
     5         kx 
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   cat "${partlist}" | while read -r line ; do
     5         kx     pname= ; fstype= ; mpoint= ; dump= ; pass=
     5         kx 
     5         kx      pname=`echo "${line}" | cut -f1 -d':'`
     5         kx     fstype=`echo "${line}" | cut -f3 -d':'`
     5         kx     mpoint=`echo "${line}" | cut -f4 -d':'`
     5         kx       used=`echo "${line}" | cut -f5 -d':'`
     5         kx      puuid=`echo "${line}" | cut -f6 -d':'`
     5         kx 
     5         kx     if [ "${used}" = "use" ] ; then
     5         kx       if [ "${mpoint}" = "/" ] ; then
     5         kx         dump=1 ; pass=1
     5         kx       elif [ "${mpoint}" = "/home" ] ; then
     5         kx         dump=1 ; pass=2
     5         kx       elif [ "${fstype}" = "vfat" -a "${mpoint}" = "/boot/efi" ] ; then
     5         kx         dump=1 ; pass=0
     5         kx       elif [ "${mpoint}" = "swap" ] ; then
     5         kx         dump=0 ; pass=0
     5         kx       else
     5         kx         dump=1 ; pass=2
     5         kx       fi
     5         kx       printf "%-${dlen}s %-16s %-11s %-36s %-6s %s\n" "PARTUUID=${puuid}" "${mpoint}" "${fstype}" "defaults" "${dump}" "${pass}" >> ${fstab}
     5         kx     fi
     5         kx   done
     5         kx   echo "" >> ${fstab}
     5         kx   printf "%-${dlen}s %-16s %-11s %-36s %-6s %s\n" "devpts" "/dev/pts" "devpts" "gid=5,mode=620"      "0" "0" >> ${fstab}
     5         kx   printf "%-${dlen}s %-16s %-11s %-36s %-6s %s\n" "proc"   "/proc"    "proc"   "defaults"            "0" "0" >> ${fstab}
     5         kx   printf "%-${dlen}s %-16s %-11s %-36s %-6s %s\n" "tmpfs"  "/dev/shm" "tmpfs"  "nosuid,nodev,noexec" "0" "0" >> ${fstab}
     5         kx 
     5         kx   if [ "${partition_table_type}" = "g" ] ; then
     5         kx     cat >> ${fstab} << EOF
     5         kx 
     5         kx # --------------------------------------------+----------------+-----------+------------------------------------+------+------
     5         kx EOF
     5         kx   else
     5         kx     cat >> ${fstab} << EOF
     5         kx 
     5         kx # -------------------+----------------+-----------+------------------------------------+------+------
     5         kx EOF
     5         kx   fi
     5         kx }
     5         kx #
     5         kx # End of prepare /etc/fstab functions.
     5         kx #
     5         kx ####################################################################
     5         kx 
     5         kx ####################################################################
     5         kx #
     5         kx # prepare /boot/grub/grub.cfg - create temporary
     5         kx #                               /boot/grub/grub.cfg according to
     5         kx #                               the table of formated partitions.
     5         kx #
     5         kx grub_cfg=$TMP/grub.cfg.$$
     5         kx grub_load_cfg=$TMP/grub.load.cfg.$$
     5         kx grub_core_img=$TMP/grub.core.img.$$
     5         kx 
     5         kx prepare_grub_config()
     5         kx {
     5         kx   local root_uuid=`cat "${partlist}" | grep ':/:' | cut -f7 -d':'`
     5         kx   local root_partuuid=`cat "${partlist}" | grep ':/:' | cut -f6 -d':'`
     5         kx 
     5         kx   cat > ${grub_cfg} << EOF
     5         kx 
     5         kx set menu_color_normal=black/light-gray
     5         kx set menu_color_highlight=white/light-gray
     5         kx set background_color=black
     5         kx 
     5         kx set timeout=5
     5         kx 
     5         kx EOF
     5         kx 
   385         kx   if [ "${hardware}" = "baikal-m1"  -o \
   385         kx        "${hardware}" = "orange-pi5" -o \
   385         kx        "${hardware}" = "visionfive2" ] ; then
     5         kx     cat >> ${grub_cfg} << EOF
     5         kx font '/boot/grub/fonts/dejavusansmono.pf2'
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   cat >> ${grub_cfg} << EOF
     5         kx loadfont dejavusansmono
     5         kx 
     5         kx menuentry 'Radix cross Linux' {
     5         kx   set root_uuid=${root_uuid}
     5         kx   set part_uuid=${root_partuuid}
     5         kx 
     5         kx   insmod gzio
     5         kx   insmod xzio
     5         kx EOF
     5         kx 
     5         kx   if [ "${hardware}" = "intel-pc32" ] ; then
     5         kx     cat >> ${grub_cfg} << EOF
     5         kx   insmod part_msdos
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   cat >> ${grub_cfg} << EOF
     5         kx   insmod part_gpt
     5         kx   insmod ext2
     5         kx 
     5         kx   search --set=root --fs-uuid \$root_uuid
     5         kx EOF
     5         kx 
     5         kx   if [ "${hardware}" = "ebox-3350dx2" -o \
     5         kx        "${hardware}" = "intel-pc32"   -o \
     5         kx        "${hardware}" = "intel-pc64" ] ; then
     5         kx     cat >> ${grub_cfg} << EOF
     5         kx   linux (\$root)/boot/vmlinuz root=PARTUUID=\$part_uuid ro rootwait console=tty0
     5         kx EOF
     5         kx   fi
     5         kx 
     5         kx   if [ "${hardware}" = "baikal-m1" ] ; then
     5         kx     cat >> ${grub_cfg} << EOF
   385         kx   devicetree (\$root)/boot/bm1000-mbm20.dtb
     5         kx   linux (\$root)/boot/Image root=PARTUUID=\$part_uuid ro rootwait console=tty1 earlyprintk=uart8250-32bit,0x20230000,115200
     5         kx EOF
     5         kx   fi
     5         kx 
   385         kx   if [ "${hardware}" = "orange-pi5" ] ; then
   385         kx     cat >> ${grub_cfg} << EOF
   385         kx   devicetree (\$root)/boot/rockchip/rk3588s-orangepi-5.dtb
   385         kx   linux (\$root)/boot/Image root=PARTUUID=\$part_uuid ro rootwait console=ttyS2,1500000n8 console=tty1
   385         kx EOF
   385         kx   fi
   385         kx 
   385         kx   if [ "${hardware}" = "visionfive2" ] ; then
   385         kx     cat >> ${grub_cfg} << EOF
   385         kx   devicetree (\$root)/boot/starfive/jh7110-visionfive-v2.dtb
   385         kx   linux (\$root)/boot/Image root=PARTUUID=\$part_uuid ro rootwait console=ttyS0,115200n8 earlycon=sbi console=tty1
   385         kx EOF
   385         kx   fi
   385         kx 
     5         kx   cat >> ${grub_cfg} << EOF
     5         kx }
     5         kx EOF
     5         kx }
     5         kx 
     5         kx prepare_grub_load_config()
     5         kx {
     5         kx   local root_uuid=`cat "${partlist}" | grep ':/:' | cut -f7 -d':'`
     5         kx 
     5         kx   cat > ${grub_load_cfg} << EOF
     5         kx 
     5         kx set color_normal=black/black
     5         kx 
     5         kx set pager=1
     5         kx search.fs_uuid ${root_uuid} root
     5         kx set prefix=(\$root)/boot/grub
     5         kx 
     5         kx set color_normal=light-gray/black
     5         kx clear
     5         kx EOF
     5         kx }
     5         kx #
     5         kx # End of prepare /boot/grub/grub.cfg functions.
     5         kx #
     5         kx ####################################################################
     5         kx 
     5         kx ####################################################################
     5         kx #
     5         kx # Install packages:
     5         kx #
     5         kx errlist=$TMP/errlist.$$
     5         kx 
     5         kx ROOT=
     5         kx ROOT_MPOINT=
     5         kx 
     5         kx install_packages()
     5         kx {
     5         kx   ROOT=`get_rootfs_devname`
     5         kx   ROOT_MPOINT=$MNT/root
     5         kx 
     5         kx   if [ "x${ROOT}" = "x" ] ; then
     5         kx     fatal_error_dialog "Cannot mount ROOT partition. Exit ${program}."
     5         kx     push_log "ERROR: Cannot mount ROOT partition"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Cannot mount ROOT partition"
     5         kx     EXITSTATUS=21
     5         kx     exit
     5         kx   fi
     5         kx 
     5         kx   if `mount | grep -q ${ROOT}` ; then
     5         kx     umount ${ROOT}
     5         kx   fi
     5         kx   mkdir -p ${ROOT_MPOINT}
     5         kx   if [ "x`mount | grep ${ROOT_MPOINT}`" != "x" ] ; then
     5         kx     umount ${ROOT_MPOINT}
     5         kx   fi
     5         kx   mount ${ROOT} ${ROOT_MPOINT}
     5         kx 
     5         kx   TMP=/tmp install-pkglist --errlist --info-dialog --priority all --root=${ROOT_MPOINT}/ ${repo} 2>${errlist}
     5         kx 
     5         kx   mkdir -p ${ROOT_MPOINT}/etc
     5         kx   cat ${fstab} > ${ROOT_MPOINT}/etc/fstab
     5         kx 
     5         kx   if [ "${hardware}" = "baikal-m1"    -o \
   385         kx        "${hardware}" = "orange-pi5"   -o \
   385         kx        "${hardware}" = "visionfive2"  -o \
     5         kx        "${hardware}" = "ebox-3350dx2" -o \
     5         kx        "${hardware}" = "intel-pc32"   -o \
     5         kx        "${hardware}" = "intel-pc64" ] ; then
     5         kx     mkdir -p ${ROOT_MPOINT}/boot/grub
     5         kx     cat ${grub_cfg} > ${ROOT_MPOINT}/boot/grub/grub.cfg
     5         kx   fi
     5         kx }
     5         kx #
    29         kx # End of install packages.
     5         kx #
     5         kx ####################################################################
     5         kx 
     5         kx ####################################################################
     5         kx #
    29         kx # Set EFI boot entry:
    29         kx #
    29         kx set_efiboot_entry() {
    29         kx   local uefi=${1}
    29         kx   local loader="${2}"
    29         kx 
    29         kx   local devlen=${#device}
    29         kx   local partlen=
    29         kx 
    29         kx   let 'partlen = devlen + 1'
    29         kx   if [ "${#p}" -gt "0" ] ; then
    29         kx     let 'plen++'
    29         kx   fi
    29         kx 
    29         kx   local uefi_device=
    29         kx   local uefi_partition=
    29         kx 
    29         kx   modprobe efivarfs 1> /dev/null 2> /dev/null
    29         kx 
    29         kx   if [ ! -d '/sys/firmware/efi/efivars' ] ; then return ; fi
    29         kx   if [ -z "${uefi}" -o -z "${loader}" ] ; then return ; fi
    29         kx 
    29         kx   uefi_device=$(echo "${uefi}" | cut -b 1-${devlen})
    29         kx   uefi_partition=$(echo "${uefi}" | cut -b ${partlen}- | sed 's/[^0-9]*//g')
    29         kx 
    29         kx   #
    29         kx   # Remove the previous boot entry if set:
    29         kx   #
    29         kx   efibootmgr -v | rev | cut -f2- | rev | grep Boot0 | grep "${DISTRO_CAPTION}" | while read line ; do
    29         kx     if ! $(echo ${line} | cut -f2- -d' ' | grep -q "${DISTRO_CAPTION}") ; then
    29         kx       continue
    29         kx     fi
    29         kx     efibootmgr -q -B -b $(echo ${line} | cut -b5-8)
    29         kx     sleep 1
    29         kx   done
    29         kx 
    29         kx   #
    29         kx   # Set boot entry:
    29         kx   #
    29         kx   efibootmgr -q -c -d ${uefi_device} -p ${uefi_partition} -l "${loader}" -L "${DISTRO_CAPTION}-${DISTRO_FULL_VERSION}"
    29         kx }
    29         kx #
    29         kx # End of set EFI boot entry.
    29         kx #
    29         kx ####################################################################
    29         kx 
    29         kx ####################################################################
    29         kx #
     5         kx # Install GRUB:
     5         kx #
     5         kx UEFI=
     5         kx UEFI_MPOINT=
     5         kx 
     5         kx install_baikal_m1_grub()
     5         kx {
     5         kx   UEFI=`get_uefi_devname`
     5         kx   UEFI_MPOINT=$MNT/UEFI
     5         kx 
     5         kx   if [ "x${UEFI}" = "x" ] ; then
     5         kx     fatal_error_dialog "Cannot mount EFI partition. Exit ${program}."
     5         kx     push_log "ERROR: Cannot mount EFI partition"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Cannot mount EFI partition"
     5         kx     EXITSTATUS=22
     5         kx     exit
     5         kx   fi
     5         kx 
     5         kx   if `mount | grep -q ${UEFI}` ; then
     5         kx     umount ${UEFI}
     5         kx   fi
     5         kx   mkdir -p ${UEFI_MPOINT}
     5         kx   if [ "x`mount | grep ${UEFI_MPOINT}`" != "x" ] ; then
     5         kx     umount ${UEFI_MPOINT}
     5         kx   fi
     5         kx   mount ${UEFI} ${UEFI_MPOINT}
     5         kx 
     5         kx   local grub_modules="all_video archelp bfs bitmap bitmap_scale blocklist boot btrfs"
     5         kx   grub_modules="${grub_modules} cat chain configfile cpio date datehook datetime disk diskfilter"
     5         kx   grub_modules="${grub_modules} echo efi_gop efifwsetup efinet elf eval exfat ext2 extcmd f2fs fat"
     5         kx   grub_modules="${grub_modules} fdt file font fshelp gettext gfxmenu gfxterm gfxterm_background"
     5         kx   grub_modules="${grub_modules} gfxterm_menu gptsync gzio halt hashsum help hexdump iso9660 jpeg"
     5         kx   grub_modules="${grub_modules} json keystatus linux loadenv loopback ls lsefi lzopio mdraid1x"
     5         kx   grub_modules="${grub_modules} memdisk minicmd msdospart net newc normal part_gpt part_msdos"
     5         kx   grub_modules="${grub_modules} png probe procfs read reboot regexp reiserfs search search_fs_file"
     5         kx   grub_modules="${grub_modules} search_fs_uuid search_label serial squash4 tar terminal terminfo"
     5         kx   grub_modules="${grub_modules} test tftp time tr trig true udf ufs1 ufs2 video video_colors"
     5         kx   grub_modules="${grub_modules} video_fb videoinfo xzio zstd"
     5         kx 
     5         kx   /usr/sbin/grub-install --skip-fs-probe \
     5         kx                          --fonts=dejavusansmono \
     5         kx                          --boot-directory=${ROOT_MPOINT}/boot \
     5         kx                          --directory=/usr/lib/grub/arm64-efi \
     5         kx                          --target=arm64-efi --no-efi \
     5         kx                          --no-bootsector --no-nvram  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/efi
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/arm64-efi
     5         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/arm64-efi/load.cfg
     5         kx 
     5         kx   mkdir -p ${UEFI_MPOINT}/efi/boot
     5         kx   /usr/bin/grub-mkimage --format=arm64-efi \
     5         kx                         --directory=/usr/lib/grub/arm64-efi \
     5         kx                         --compression=xz \
     5         kx                         --prefix=/efi/boot \
     5         kx                         --config="${grub_load_cfg}" \
     5         kx                         --output=${UEFI_MPOINT}/efi/boot/bootaa64.efi \
     5         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
     5         kx }
     5         kx 
   385         kx install_orange_pi5_grub()
   385         kx {
   385         kx   UEFI=`get_uefi_devname`
   385         kx   UEFI_MPOINT=$MNT/UEFI
   385         kx 
   385         kx   if [ "x${UEFI}" = "x" ] ; then
   385         kx     fatal_error_dialog "Cannot mount EFI partition. Exit ${program}."
   385         kx     push_log "ERROR: Cannot mount EFI partition"
   385         kx     push_log "Aborted due to an error"
   385         kx     push_err "ERROR: Cannot mount EFI partition"
   385         kx     EXITSTATUS=22
   385         kx     exit
   385         kx   fi
   385         kx 
   385         kx   if `mount | grep -q ${UEFI}` ; then
   385         kx     umount ${UEFI}
   385         kx   fi
   385         kx   mkdir -p ${UEFI_MPOINT}
   385         kx   if [ "x`mount | grep ${UEFI_MPOINT}`" != "x" ] ; then
   385         kx     umount ${UEFI_MPOINT}
   385         kx   fi
   385         kx   mount ${UEFI} ${UEFI_MPOINT}
   385         kx 
   385         kx   local grub_modules="all_video archelp bfs bitmap bitmap_scale blocklist boot btrfs"
   385         kx   grub_modules="${grub_modules} cat chain configfile cpio date datehook datetime disk diskfilter"
   385         kx   grub_modules="${grub_modules} echo efi_gop efifwsetup efinet elf eval exfat ext2 extcmd f2fs fat"
   385         kx   grub_modules="${grub_modules} fdt file font fshelp gettext gfxmenu gfxterm gfxterm_background"
   385         kx   grub_modules="${grub_modules} gfxterm_menu gptsync gzio halt hashsum help hexdump iso9660 jpeg"
   385         kx   grub_modules="${grub_modules} json keystatus linux loadenv loopback ls lsefi lzopio mdraid1x"
   385         kx   grub_modules="${grub_modules} memdisk minicmd msdospart net newc normal part_gpt part_msdos"
   385         kx   grub_modules="${grub_modules} png probe procfs read reboot regexp reiserfs search search_fs_file"
   385         kx   grub_modules="${grub_modules} search_fs_uuid search_label serial squash4 tar terminal terminfo"
   385         kx   grub_modules="${grub_modules} test tftp time tr trig true udf ufs1 ufs2 video video_colors"
   385         kx   grub_modules="${grub_modules} video_fb videoinfo xzio zstd"
   385         kx 
   385         kx   /usr/sbin/grub-install --skip-fs-probe \
   385         kx                          --fonts=dejavusansmono \
   385         kx                          --boot-directory=${ROOT_MPOINT}/boot \
   385         kx                          --directory=/usr/lib/grub/arm64-efi \
   385         kx                          --target=arm64-efi --no-efi \
   385         kx                          --no-bootsector --no-nvram  2>/dev/null 1>/dev/null
   385         kx 
   385         kx   mkdir -p ${ROOT_MPOINT}/boot/efi
   385         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/arm64-efi
   385         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/arm64-efi/load.cfg
   385         kx 
   385         kx   mkdir -p ${UEFI_MPOINT}/efi/boot
   385         kx   /usr/bin/grub-mkimage --format=arm64-efi \
   385         kx                         --directory=/usr/lib/grub/arm64-efi \
   385         kx                         --compression=xz \
   385         kx                         --prefix=/efi/boot \
   385         kx                         --config="${grub_load_cfg}" \
   385         kx                         --output=${UEFI_MPOINT}/efi/boot/bootaa64.efi \
   385         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
   385         kx }
   385         kx 
   385         kx install_orange_pi5_edk2() {
   385         kx   FLASHCP=`PATH=/sbin:/usr/sbin:$PATH which flashcp`
   385         kx   if [ -c /dev/mtd0 -a "`basename ${FLASHCP}`" = "flashcp" -a -f "/boot/edk2/spi-flash.image" ] ; then
   385         kx     ${FLASHCP} /boot/edk2/spi-flash.image /dev/mtd0
   385         kx   fi
   385         kx }
   385         kx 
   385         kx install_starfive_vf2_grub()
   385         kx {
   385         kx   UEFI=`get_uefi_devname`
   385         kx   UEFI_MPOINT=$MNT/UEFI
   385         kx 
   385         kx   if [ "x${UEFI}" = "x" ] ; then
   385         kx     fatal_error_dialog "Cannot mount EFI partition. Exit ${program}."
   385         kx     push_log "ERROR: Cannot mount EFI partition"
   385         kx     push_log "Aborted due to an error"
   385         kx     push_err "ERROR: Cannot mount EFI partition"
   385         kx     EXITSTATUS=22
   385         kx     exit
   385         kx   fi
   385         kx 
   385         kx   if `mount | grep -q ${UEFI}` ; then
   385         kx     umount ${UEFI}
   385         kx   fi
   385         kx   mkdir -p ${UEFI_MPOINT}
   385         kx   if [ "x`mount | grep ${UEFI_MPOINT}`" != "x" ] ; then
   385         kx     umount ${UEFI_MPOINT}
   385         kx   fi
   385         kx   mount ${UEFI} ${UEFI_MPOINT}
   385         kx 
   385         kx   local grub_modules="all_video archelp bfs bitmap bitmap_scale blocklist boot btrfs"
   385         kx   grub_modules="${grub_modules} cat chain configfile cpio date datehook datetime disk diskfilter"
   385         kx   grub_modules="${grub_modules} echo efi_gop efifwsetup efinet elf eval exfat ext2 extcmd f2fs fat"
   385         kx   grub_modules="${grub_modules} fdt file font fshelp gettext gfxmenu gfxterm gfxterm_background"
   385         kx   grub_modules="${grub_modules} gfxterm_menu gptsync gzio halt hashsum help hexdump iso9660 jpeg"
   385         kx   grub_modules="${grub_modules} json keystatus linux loadenv loopback ls lsefi lzopio mdraid1x"
   385         kx   grub_modules="${grub_modules} memdisk minicmd msdospart net newc normal part_gpt part_msdos"
   385         kx   grub_modules="${grub_modules} png probe procfs read reboot regexp reiserfs search search_fs_file"
   385         kx   grub_modules="${grub_modules} search_fs_uuid search_label serial squash4 tar terminal terminfo"
   385         kx   grub_modules="${grub_modules} test tftp time tr trig true udf ufs1 ufs2 video video_colors"
   385         kx   grub_modules="${grub_modules} video_fb videoinfo xzio zstd"
   385         kx 
   385         kx   /usr/sbin/grub-install --skip-fs-probe \
   385         kx                          --fonts=dejavusansmono \
   385         kx                          --boot-directory=${ROOT_MPOINT}/boot \
   385         kx                          --directory=/usr/lib/grub/riscv64-efi \
   385         kx                          --target=riscv64-efi --no-efi \
   385         kx                          --no-bootsector --no-nvram  2>/dev/null 1>/dev/null
   385         kx 
   385         kx   mkdir -p ${ROOT_MPOINT}/boot/efi
   385         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/riscv64-efi
   385         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/riscv64-efi/load.cfg
   385         kx 
   385         kx   mkdir -p ${UEFI_MPOINT}/efi/boot
   385         kx   /usr/bin/grub-mkimage --format=riscv64-efi \
   385         kx                         --directory=/usr/lib/grub/riscv64-efi \
   385         kx                         --compression=xz \
   385         kx                         --prefix=/efi/boot \
   385         kx                         --config="${grub_load_cfg}" \
   385         kx                         --output=${UEFI_MPOINT}/efi/boot/bootriscv64.efi \
   385         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
   385         kx }
   385         kx 
     5         kx install_intel_pc64_grub()
     5         kx {
     5         kx   UEFI=`get_uefi_devname`
     5         kx   UEFI_MPOINT=$MNT/UEFI
     5         kx 
     5         kx   if [ "x${UEFI}" = "x" ] ; then
     5         kx     fatal_error_dialog "Cannot mount EFI partition. Exit ${program}."
     5         kx     push_log "ERROR: Cannot mount EFI partition"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Cannot mount EFI partition"
     5         kx     EXITSTATUS=22
     5         kx     exit
     5         kx   fi
     5         kx 
     5         kx   if `mount | grep -q ${UEFI}` ; then
     5         kx     umount ${UEFI}
     5         kx   fi
     5         kx   mkdir -p ${UEFI_MPOINT}
     5         kx   if [ "x`mount | grep ${UEFI_MPOINT}`" != "x" ] ; then
     5         kx     umount ${UEFI_MPOINT}
     5         kx   fi
     5         kx   mount ${UEFI} ${UEFI_MPOINT}
     5         kx 
     5         kx   local grub_modules="part_gpt part_msdos fat f2fs ext2 hfs hfsplus iso9660 udf ufs1 ufs2 chain linux"
     5         kx   grub_modules="${grub_modules} boot appleldr configfile normal regexp minicmd reboot halt search search_fs_file"
     5         kx   grub_modules="${grub_modules} search_fs_uuid search_label gfxterm gfxmenu efi_gop efi_uga all_video loadbios"
     5         kx   grub_modules="${grub_modules} gzio echo true probe loadenv bitmap_scale font cat help ls png jpeg tga test"
     5         kx   grub_modules="${grub_modules} at_keyboard usb_keyboard zstd"
     5         kx 
     5         kx   /usr/sbin/grub-install --skip-fs-probe \
     5         kx                          --fonts=dejavusansmono \
     5         kx                          --boot-directory=${ROOT_MPOINT}/boot \
     5         kx                          --directory=/usr/lib/grub/x86_64-efi \
     5         kx                          --target=x86_64-efi --no-efi \
     5         kx                          --no-bootsector --no-nvram  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/efi
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/x86_64-efi
     5         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/x86_64-efi/load.cfg
     5         kx 
     5         kx   mkdir -p ${UEFI_MPOINT}/efi/boot
     5         kx   /usr/bin/grub-mkimage --format=x86_64-efi \
     5         kx                         --directory=/usr/lib/grub/x86_64-efi \
     5         kx                         --compression=xz \
     5         kx                         --prefix=/efi/boot \
     5         kx                         --config="${grub_load_cfg}" \
     5         kx                         --output=${UEFI_MPOINT}/efi/boot/bootx64.efi \
     5         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
    29         kx 
    29         kx   set_efiboot_entry "${UEFI}" "\\efi\\boot\\bootx64.efi"
     5         kx }
     5         kx 
     5         kx install_intel_pc32_grub()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local grub_modules="part_gpt part_msdos fat f2fs ext2 hfs hfsplus iso9660 udf ufs1 ufs2 chain linux"
     5         kx   grub_modules="${grub_modules} boot biosdisk configfile normal regexp minicmd reboot halt search search_fs_file"
     5         kx   grub_modules="${grub_modules} search_fs_uuid search_label gfxterm gfxmenu all_video gzio echo true probe loadenv"
     5         kx   grub_modules="${grub_modules} bitmap_scale font cat help ls png jpeg tga test at_keyboard usb_keyboard zstd"
     5         kx 
     5         kx   /usr/sbin/grub-install --skip-fs-probe \
     5         kx                          --fonts=dejavusansmono \
     5         kx                          --boot-directory=${ROOT_MPOINT}/boot \
     5         kx                          --directory=/usr/lib/grub/i386-pc \
     5         kx                          --target=i386-pc \
     5         kx                          --modules="${grub_modules}" \
     5         kx                          --disk-module=biosdisk \
     5         kx                          ${disk}  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/i386-pc
     5         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/i386-pc/load.cfg
     5         kx 
     5         kx   /usr/bin/grub-mkimage --format=i386-pc \
     5         kx                         --directory=/usr/lib/grub/i386-pc \
     5         kx                         --prefix=/boot/grub \
     5         kx                         --config="${grub_load_cfg}" \
     5         kx                         --output=${grub_core_img} \
     5         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   dd if=${grub_core_img} of=${disk} obs=512 seek=1 conv=notrunc  2>/dev/null 1>/dev/null
     5         kx }
     5         kx 
     5         kx install_ebox_3350dx2_grub()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   local grub_modules="part_gpt part_msdos fat f2fs ext2 hfs hfsplus iso9660 udf ufs1 ufs2 chain linux"
     5         kx   grub_modules="${grub_modules} boot biosdisk configfile normal regexp minicmd reboot halt search search_fs_file"
     5         kx   grub_modules="${grub_modules} search_fs_uuid search_label gfxterm gfxmenu all_video gzio echo true probe loadenv"
     5         kx   grub_modules="${grub_modules} bitmap_scale font cat help ls png jpeg tga test at_keyboard usb_keyboard zstd"
     5         kx 
     5         kx   /usr/sbin/grub-install --skip-fs-probe \
     5         kx                          --fonts=dejavusansmono \
     5         kx                          --boot-directory=${ROOT_MPOINT}/boot \
     5         kx                          --directory=/usr/lib/grub/i386-pc \
     5         kx                          --target=i386-pc \
     5         kx                          --modules="${grub_modules}" \
     5         kx                          --disk-module=biosdisk \
     5         kx                          ${disk}  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   mkdir -p ${ROOT_MPOINT}/boot/grub/i386-pc
     5         kx   cat ${grub_load_cfg} > ${ROOT_MPOINT}/boot/grub/i386-pc/load.cfg
     5         kx 
     5         kx   /usr/bin/grub-mkimage --format=i386-pc \
     5         kx                         --directory=/usr/lib/grub/i386-pc \
     5         kx                         --prefix=/boot/grub \
     5         kx                         --config="${grub_load_cfg}" \
     5         kx                         --output=${grub_core_img} \
     5         kx                         ${grub_modules}  2>/dev/null 1>/dev/null
     5         kx 
     5         kx   dd if=${grub_core_img} of=${disk} obs=512 seek=1 conv=notrunc  2>/dev/null 1>/dev/null
     5         kx }
     5         kx #
     5         kx # End of install GRUB:
     5         kx #
     5         kx ####################################################################
     5         kx 
     5         kx ####################################################################
     5         kx #
     5         kx # Install U-Boot:
     5         kx #
     5         kx install_leez_p710_uboot()
     5         kx {
     5         kx   local disk=${1}
     5         kx 
     5         kx   dd if=${ROOT_MPOINT}/boot/u-boot/idbloader.img of=${disk} bs=512 seek=64     2>/dev/null 2>/dev/null
     5         kx   dd if=${ROOT_MPOINT}/boot/u-boot/u-boot.itb    of=${disk} bs=512 seek=16384  2>/dev/null 2>/dev/null
     5         kx 
     5         kx   ln -sfr ${ROOT_MPOINT}/boot/boot.emmc.scr ${ROOT_MPOINT}/boot/boot.scr
     5         kx }
     5         kx #
   385         kx # End of install U-Boot.
     5         kx #
     5         kx ####################################################################
     5         kx 
   385         kx ####################################################################
   385         kx #
   385         kx # Select Desktop Environment:
   385         kx #
   385         kx select_desktop_environment()
   385         kx {
   385         kx   local height=10
   385         kx   local items=0
     5         kx 
   385         kx   cat > $TMP/select-desktop-envitonment$$ << EOF
   385         kx --colors --clear $nocancel \\
   385         kx --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \\
   385         kx --title " \Z0Select Desktop Environment\Zn " \\
   385         kx --menu "\\n\\
   385         kx EOF
   385         kx 
   385         kx 
   385         kx   cat >> $TMP/select-desktop-envitonment$$ << EOF
   385         kx \\n\\
   385         kx  Please select your preferred Desktop Environment:\\
   385         kx " ${height} 74 ${items} \\
   385         kx EOF
   385         kx 
   385         kx   #
   385         kx   # Currently we have only 'OpenBox' and 'Mate' Environments:
   385         kx   #
   385         kx   for session in `ls ${ROOT_MPOINT}/etc/X11/xinit/xinitrc.*-session` ; do
   385         kx     case ${session} in
   385         kx       *openbox*)
   385         kx         let 'items += 1'
   385         kx         let 'height += 1'
   385         kx         cat >> $TMP/select-desktop-envitonment$$ << EOF
   385         kx "OpenBox" "- Lightweight window manager for X Window" \\
   385         kx EOF
   385         kx        ;;
   385         kx       *mate*)
   385         kx         let 'items += 1'
   385         kx         let 'height += 1'
   385         kx         cat >> $TMP/select-desktop-envitonment$$ << EOF
   385         kx "MATE" "- MATE Desktop Environment (based on GNOME 2)" \\
   385         kx EOF
   385         kx        ;;
   385         kx     esac
   385         kx   done
   385         kx 
   385         kx   $DIALOG --default-item "OpenBox" --file $TMP/select-desktop-envitonment$$ 2> $TMP/desktop$$
   385         kx   ret=$?
   385         kx   if [ ${ret} -eq 255 ]; then
   385         kx     rm -f $TMP/desktopt$$
   385         kx     rm -f $TMP/select-desktop-envitonment$$
   385         kx     result="OpenBox"
   385         kx   else
   385         kx     result=`cat $TMP/desktop$$`
   385         kx   fi
   385         kx   rm -f $TMP/desktop$$
   385         kx   rm -f $TMP/select-desktop-envitonment$$
   385         kx   if [ "${result}" = "MATE" ]; then
   385         kx     ln -srf ${ROOT_MPOINT}/etc/X11/xinit/xinitrc.mate-session ${ROOT_MPOINT}/etc/X11/xinit/xinitrc
   385         kx   else
   385         kx     ln -srf ${ROOT_MPOINT}/etc/X11/xinit/xinitrc.openbox-session ${ROOT_MPOINT}/etc/X11/xinit/xinitrc
   385         kx   fi
   385         kx }
     5         kx #
   385         kx # End of Select Desktop Environment.
   385         kx #
   385         kx ####################################################################
   385         kx 
   385         kx 
   385         kx #
     5         kx # Parse Options:
     5         kx #
     5         kx while [ 0 ]; do
     5         kx   if [ "$1" = "-h" -o "$1" = "--help" ] ; then
     5         kx     usage
     5         kx     exit
     5         kx   elif [ "$1" = "-r" -o "$1" = "--root-dev" ]; then
     5         kx     if [ "$2" = "" ]; then
     5         kx       usage
     5         kx       push_log "ERROR: Target DEVICE has not specified by --root-dev option"
     5         kx       push_log "Aborted due to an error"
     5         kx       push_err "ERROR: Target DEVICE has not specified by --root-dev option"
     5         kx       EXITSTATUS=16
     5         kx       exit
     5         kx     fi
     5         kx     device="`echo $2 | sed 's,/$,,'`"
     5         kx     shift 2
     5         kx   elif [ "$1" = "--repo" ]; then
     5         kx     if [ "$2" = "" ]; then
     5         kx       usage
     5         kx       push_log "ERROR: Custom REPO directory has not specified by --repo option"
     5         kx       push_err "ERROR: Custom REPO directory has not specified by --repo option"
     5         kx       EXITSTATUS=18
     5         kx       exit
     5         kx     fi
     5         kx     custom_repo="$2"
     5         kx     if ! `echo ${custom_repo: -1} | grep -q '/'` ; then
     5         kx       custom_repo="${custom_repo}/"
     5         kx     fi
     5         kx     shift 2
     5         kx   else
     5         kx     break
     5         kx   fi
     5         kx done
     5         kx 
     5         kx if [ "x${custom_repo}" != "xno" ] ; then
     5         kx   check_custom_repo "${custom_repo}"
     5         kx else
     5         kx   check_repo "${repo}"
     5         kx   ret=$?
     5         kx   if [ $ret -ne 0 ] ; then
     5         kx     fatal_error_dialog "Source REPO directory is invalid. Exit ${program}."
     5         kx     push_log "ERROR: Source REPO directory is invalid"
     5         kx     push_log "Aborted due to an error"
     5         kx     push_err "ERROR: Source REPO directory is invalid"
     5         kx     EXITSTATUS=17
     5         kx     exit
     5         kx   fi
     5         kx fi
     5         kx 
     5         kx #
     5         kx # Show DISTRO spec:
     5         kx # ----------------
     5         kx #
     5         kx if [ "x${custom_repo}" != "xyes" ] ; then
     5         kx   welcome_setup
     5         kx else
     5         kx   welcome_custom_setup
     5         kx fi
     5         kx 
     5         kx check_current_device
     5         kx check_target_device
     5         kx 
     5         kx #
     5         kx # Ask for format target device:
     5         kx # ----------------------------
     5         kx #
     5         kx ask_formatting "${device}"
     5         kx blockdev -q --rereadpt "${device}"
     5         kx 
     5         kx #
     5         kx # File Systems:
     5         kx # ------------
     5         kx #
     5         kx check_partitions "${device}"
     5         kx partitions_loop "${device}"
     5         kx $DIALOG --colors \
     5         kx         --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx         --title " \Z0Install Packages\Zn " \
     5         kx         --infobox "\n Please wait for packages installation.\n\n" 5 74
     5         kx check_filesystems
     5         kx 
     5         kx #
     5         kx # /etc/fstab:
     5         kx # ----------
     5         kx #
   385         kx if [ "${hardware}" = "baikal-m1"   -o \
   385         kx      "${hardware}" = "orange-pi5"  -o \
   385         kx      "${hardware}" = "visionfive2" -o \
     5         kx      "${hardware}" = "intel-pc64" ] ; then
     5         kx   prepare_partuuid_etc_fstab
     5         kx else
     5         kx   prepare_uuid_etc_fstab
     5         kx   #prepare_dev_etc_fstab
     5         kx fi
     5         kx 
     5         kx #
     5         kx # /boot/grub/grub.cfg:
     5         kx # -------------------
     5         kx #
     5         kx if [ "${hardware}" = "baikal-m1"    -o \
   385         kx      "${hardware}" = "orange-pi5"   -o \
   385         kx      "${hardware}" = "visionfive2"  -o \
     5         kx      "${hardware}" = "ebox-3350dx2" -o \
     5         kx      "${hardware}" = "intel-pc32"   -o \
     5         kx      "${hardware}" = "intel-pc64" ] ; then
     5         kx   prepare_grub_config
     5         kx   prepare_grub_load_config
     5         kx fi
     5         kx 
     5         kx #
     5         kx # Install all packages:
     5         kx # --------------------
     5         kx #
     5         kx install_packages
     5         kx 
     5         kx #
     5         kx # Install GRUB:
     5         kx # ------------
     5         kx #
     5         kx if [ "${hardware}" = "baikal-m1" ] ; then
     5         kx   install_baikal_m1_grub
     5         kx fi
   385         kx if [ "${hardware}" = "orange-pi5" ] ; then
   385         kx   install_orange_pi5_grub
   385         kx fi
   385         kx if [ "${hardware}" = "visionfive2" ] ; then
   385         kx   install_starfive_vf2_grub
   385         kx fi
     5         kx if [ "${hardware}" = "intel-pc64" ] ; then
     5         kx   install_intel_pc64_grub
     5         kx fi
     5         kx if [ "${hardware}" = "intel-pc32" ] ; then
     5         kx   install_intel_pc32_grub "${device}"
     5         kx fi
     5         kx if [ "${hardware}" = "ebox-3350dx2" ] ; then
     5         kx   install_ebox_3350dx2_grub "${device}"
     5         kx fi
     5         kx 
     5         kx #
   385         kx # Install U-Boot:
   385         kx # --------------
     5         kx #
     5         kx if [ "${hardware}" = "leez-p710" ] ; then
     5         kx   install_leez_p710_uboot "${device}"
     5         kx fi
     5         kx 
     5         kx #
   385         kx # Install EDK2:
   385         kx # ------------
   385         kx #
   385         kx if [ "${hardware}" = "orange-pi5" ] ; then
   385         kx   install_orange_pi5_edk2
   385         kx fi
   385         kx 
   385         kx #
     5         kx # post-install settings:
     5         kx #
     5         kx if [ -x ${ROOT_MPOINT}/usr/sbin/timeconfig ] ; then
     5         kx   ${ROOT_MPOINT}/usr/sbin/timeconfig --root ${ROOT_MPOINT}
     5         kx fi
     5         kx 
   385         kx #
   385         kx # Select Desktop Environment:
   385         kx #
   385         kx enabled=$(echo "`ls /etc/X11/xinit/xinitrc.*-session`" | wc -l)
   385         kx if [ ${enabled} -gt 1 ] ; then
   385         kx   select_desktop_environment
   385         kx fi
   385         kx 
     5         kx $DIALOG --colors --clear \
     5         kx         --backtitle "\Z7Radix\Zn \Z1cross\Zn\Z7 Linux\Zn" \
     5         kx         --title " \Z0System Installation is Complete\Zn " \
     5         kx         --msgbox "\nSetup is complete. Please set \Z1root\Zn password at first login.\n" 7 74
     5         kx 
     5         kx exit