#!/bin/bash [[ -r /opt/livecd/util-config.sh ]] && source /opt/livecd/util-config.sh load_config "/opt/livecd/manjaro-tools.conf" # Basis settings TITLE="Manjaro Linux Installation Framework (testing)" PKG_OVERLAY="/opt/livecd/pkgs" #DIALOGRC="./setuprc" ANSWER="/tmp/.setup" # use the first VT not dedicated to a running console LOG="/dev/tty8" # don't use /mnt because it's intended to mount other things there! mkdir -p /install DESTDIR="/install" arch=$(uname -m) EDITOR="nano" _BLKID="blkid -c /dev/null" # name of the kernel image VMLINUZ="vmlinuz-${manjaro_kernel_ver}-${arch}" # name of the initramfs filesystem INITRAMFS="initramfs-${manjaro_kernel_ver}-${arch}" # abstract the common pacman args PACMAN="pacman --root ${DESTDIR} --config /etc/pacman.conf --noconfirm --noprogressbar" PACMAN_LNG="pacman --root ${DESTDIR} --config /opt/livecd/pacman-lng.conf --noconfirm --noprogressbar" # sources SYNC_URL= MIRRORLIST="/etc/pacman.d/mirrorlist" PACKAGES= # clock HARDWARECLOCK="localtime" TIMEZONE="America/Montreal" # destination of blockdevices in /sys block="/sys/block" # partitions PART_ROOT="" ROOTFS="" # Mylex DAC960 PCI RAID controller, Compaq Next Generation Drive Array, # Compaq Intelligent Drive Array EXTRA_CONTROLLER="rd cciss ida" # install stages S_SRC=0 # choose install medium S_NET=0 # network configuration S_CLOCK=0 # clock and timezone S_PART=0 # partitioning S_MKFS=0 # formatting S_MKFSAUTO=0 # auto fs part/formatting S_SELECT=0 # package selection S_INSTALL=0 # package installation S_CONFIG=0 # configuration editing S_PRECONFIG=0 # pre configuration editing # main menu selection tracker NEXTITEM="" # source /opt/livecd/functions [[ -r /opt/livecd/util-mount.sh ]] && source /opt/livecd/util-mount.sh [[ -r /opt/livecd/util-inst.sh ]] && source /opt/livecd/util-inst.sh [[ -r /opt/livecd/util-lng.sh ]] && source /opt/livecd/util-lng.sh [[ -r /opt/livecd/util.sh ]] && source /opt/livecd/util.sh # activate_dmraid() # activate dmraid devices activate_dmraid() { if [[ -e /usr/bin/dmraid ]]; then DIALOG --infobox "${_activate_dmraid}" 0 0 /usr/bin/dmraid -ay -I -Z >/dev/null 2>&1 fi } # activate_lvm2 # activate lvm2 devices activate_lvm2() { ACTIVATE_LVM2="" if [[ -e /usr/bin/lvm ]]; then OLD_LVM2_GROUPS=${LVM2_GROUPS} OLD_LVM2_VOLUMES=${LVM2_VOLUMES} DIALOG --infobox "${_scanning_lvm2}" 0 0 /usr/bin/lvm vgscan --ignorelockingfailure >/dev/null 2>&1 DIALOG --infobox "${_activate_lvm2}" 0 0 /usr/bin/lvm vgchange --ignorelockingfailure --ignoremonitoring -ay >/dev/null 2>&1 LVM2_GROUPS="$(vgs -o vg_name --noheading 2>/dev/null)" LVM2_VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)" [[ "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" && "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" ]] && ACTIVATE_LVM2="no" else ACTIVATE_LVM2="no" fi } # activate_raid # activate md devices activate_raid() { ACTIVATE_RAID="" if [[ -e /usr/bin/mdadm ]]; then DIALOG --infobox "${_activate_raid}" 0 0 /usr/bin/mdadm --assemble --scan >/dev/null 2>&1 || ACTIVATE_RAID="no" else ACTIVATE_RAID="no" fi } # activate_luks # activate luks devices activate_luks() { ACTIVATE_LUKS="" if [[ -e /usr/bin/cryptsetup ]]; then DIALOG --infobox "${_scanning_luks}" 0 0 if [[ "$(${_BLKID} | grep "TYPE=\"crypto_LUKS\"")" ]]; then for PART in $(${_BLKID} | grep "TYPE=\"crypto_LUKS\"" | sed -e 's#:.*##g'); do # skip already encrypted devices, device mapper! OPEN_LUKS="" for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control); do [[ "$(cryptsetup status ${devpath} | grep ${PART})" ]] && OPEN_LUKS="no" done if ! [[ "${OPEN_LUKS}" = "no" ]]; then RUN_LUKS="" DIALOG --yesno "${_setup_luks} $PART ?" 0 0 && RUN_LUKS="1" [[ "${RUN_LUKS}" = "1" ]] && _enter_luks_name && _enter_luks_passphrase && _opening_luks [[ "${RUN_LUKS}" = "" ]] && ACTIVATE_LUKS="no" else ACTIVATE_LUKS="no" fi done else ACTIVATE_LUKS="no" fi else ACTIVATE_LUKS="no" fi } # activate_special_devices() # activate special devices: # activate dmraid, lvm2 and raid devices, if not already activated during bootup! # run it more times if needed, it can be hidden by each other! activate_special_devices() { ACTIVATE_RAID="" ACTIVATE_LUKS="" ACTIVATE_LVM2="" activate_dmraid while ! [[ "${ACTIVATE_LVM2}" = "no" && "${ACTIVATE_RAID}" = "no" && "${ACTIVATE_LUKS}" = "no" ]]; do activate_raid activate_lvm2 activate_luks done } # destdir_mounts() # check if PART_ROOT is set and if something is mounted on ${DESTDIR} destdir_mounts(){ # Don't ask for filesystem and create new filesystems ASK_MOUNTPOINTS="" PART_ROOT="" # check if something is mounted on ${DESTDIR} PART_ROOT="$(mount | grep "${DESTDIR} " | cut -d' ' -f 1)" # Run mountpoints, if nothing is mounted on ${DESTDIR} if [[ "${PART_ROOT}" = "" ]]; then DIALOG --msgbox "${_destdir_1}${DESTDIR}${_destdir_2}" 0 0 mountpoints || return 1 fi } # lists default linux blockdevices default_blockdevices() { # ide devices for dev in $(ls ${block} 2>/dev/null | egrep '^hd'); do if [[ "$(cat ${block}/${dev}/device/media)" = "disk" ]]; then if ! [[ "$(cat ${block}/${dev}/size)" = "0" ]]; then if ! [[ "$(cat /proc/mdstat 2>/dev/null | grep "${dev}\[")" || "$(dmraid -rc | grep /dev/${dev})" ]]; then echo "/dev/${dev}" [[ "${1}" ]] && echo ${1} fi fi fi done #scsi/sata devices, and virtio blockdevices (/dev/vd*) for dev in $(ls ${block} 2>/dev/null | egrep '^[sv]d'); do # virtio device doesn't have type file! blktype="$(cat ${block}/${dev}/device/type 2>/dev/null)" if ! [[ "${blktype}" = "5" ]]; then if ! [[ "$(cat ${block}/${dev}/size)" = "0" ]]; then if ! [[ "$(cat /proc/mdstat 2>/dev/null | grep "${dev}\[")" || "$(dmraid -rc | grep /dev/${dev})" ]]; then echo "/dev/${dev}" [[ "${1}" ]] && echo ${1} fi fi fi done } # lists additional linux blockdevices additional_blockdevices() { # Include additional controllers: # Mylex DAC960 PCI RAID controller, Compaq Next Generation Drive Array, # Compaq Intelligent Drive Array for i in ${EXTRA_CONTROLLER}; do for dev in $(ls ${block} 2>/dev/null | egrep "^${i}"); do for k in $(ls ${block}/${dev} 2>/dev/null | egrep "${dev}*p"); do if [[ -d "${block}/${dev}/${k}" ]]; then echo "/dev/${i}/$(echo ${dev} | sed -e 's#.*\!##g')" [[ "${1}" ]] && echo ${1} break fi done done done # Include MMC devices for dev in $(ls ${block} 2>/dev/null | egrep '^mmcblk'); do for i in $(ls ${block}/${dev} 2>/dev/null | egrep ${dev}p); do if [[ -d "${block}/${dev}/${i}" ]]; then echo "/dev/${dev}" [[ "${1}" ]] && echo ${1} break fi done done } # lists additional linux blockdevices partitions additional_blockdevices_partitions() { # Mylex DAC960 PCI RAID controller, Compaq Next Generation Drive Array, # Compaq Intelligent Drive Array for k in ${EXTRA_CONTROLLER}; do for dev in $(ls ${block} 2>/dev/null | egrep "^${k}"); do for i in $(ls ${block}/${dev} 2>/dev/null | egrep "${dev}*p"); do if [[ -d "${block}/${dev}/${i}" ]]; then disk="${k}/$(echo ${dev} | sed -e 's#.*\!##g')" part="${k}/$(echo ${i} | sed -e 's#.*\!##g')" # exclude checks: #- part of raid device # $(cat /proc/mdstat 2>/dev/null | grep ${part}) #- part of lvm2 device # $(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "LVM2_member") #- part of luks device # $(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "crypto_LUKS") #- extended partition on device # $(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}\p##g" 2>/dev/null | grep "5") #- bios_grub partitions # $(echo ${part} | grep "[a-z]$(parted -s /dev/${disk} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$") if ! [[ "$(cat /proc/mdstat 2>/dev/null | grep ${part})" || "$(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "LVM2_member")" || "$(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "crypto_LUKS")" || "$(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}\p##g") 2>/dev/null | grep "5")" || "$(echo ${part} | grep "[a-z]$(parted -s /dev/${disk} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")" ]]; then echo "/dev/${part}" [[ "${1}" ]] && echo ${1} fi fi done done done # Include MMC devices for dev in $(ls ${block} 2>/dev/null | egrep '^mmcblk'); do for i in $(ls ${block}/${dev} 2>/dev/null | egrep ${dev}p); do if [[ -d "${block}/${dev}/${i}" ]]; then # exclude checks: #- part of raid device # $(cat /proc/mdstat 2>/dev/null | grep ${i}) #- part of lvm2 device # $(${_BLKID} -p -i -o value -s TYPE /dev/${i} | grep "LVM2_member") #- part of luks device # $(${_BLKID} -p -i -o value -s TYPE /dev/${i} | grep "crypto_LUKS") #- extended partition on device # $(sfdisk -c /dev/${dev} $(echo ${i} | sed -e "s#${dev}\p##g" 2>/dev/null | grep "5") #- bios_grub partitions # $(echo ${i} | grep "[a-z]$(parted -s /dev/${dev} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$") if ! [[ "$(cat /proc/mdstat 2>/dev/null | grep ${i})" || "$(${_BLKID} -p -i -o value -s TYPE /dev/${i} | grep "LVM2_member")" || $(${_BLKID} -p -i -o value -s TYPE /dev/${i} | grep "crypto_LUKS") || "$(sfdisk -c /dev/${dev} $(echo ${i} | sed -e "s#${dev}\p##g") 2>/dev/null | grep "5")" || "$(echo ${i} | grep "[a-z]$(parted -s /dev/${dev} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")" ]]; then echo "/dev/${i}" [[ "${1}" ]] && echo ${1} fi fi done done } # list none partitionable raid md devices raid_devices() { for devpath in $(ls ${block} 2>/dev/null | egrep '^md'); do if ! [[ "$(ls ${block}/${devpath} 2>/dev/null | egrep ${devpath}p)" ]]; then # exlude md partitions which are part of lvm or luks if ! [[ "$(${_BLKID} -p -i /dev/${devpath} | grep "TYPE=\"LVM2_member\"")" || "$(${_BLKID} -p -i /dev/${devpath} | grep "TYPE=\"crypto_LUKS\"")" ]]; then echo "/dev/${devpath}" [[ "${1}" ]] && echo ${1} fi fi done } # lists default linux partitionable raid devices partitionable_raid_devices() { for dev in $(ls ${block} 2>/dev/null | egrep '^md'); do for i in $(ls ${block}/${dev} 2>/dev/null | egrep "${dev}\!*p"); do if [[ -d "${block}/${dev}/${i}" ]]; then echo "/dev/${dev}" [[ "${1}" ]] && echo ${1} break fi done done } # lists default linux partitionable raid devices partitionable_raid_devices_partitions() { for dev in $(ls ${block} 2>/dev/null | egrep '^md'); do for i in $(ls ${block}/${dev} 2>/dev/null | egrep ${dev}p); do if [[ -d "${block}/${dev}/${i}" ]]; then # exlude md partitions which are part of lvm or luks if ! [[ "$(${_BLKID} -p -i /dev/${i} | grep "TYPE=\"LVM2_member\"")" || ! "$(${_BLKID} -p -i /dev/${i} | grep "TYPE=\"crypto_LUKS\"")" ]]; then echo "/dev/${i}" [[ "${1}" ]] && echo ${1} fi fi done done } # lists default linux dmraid devices dmraid_devices() { if [[ -d /dev/mapper ]]; then for fakeraid in $(dmraid -s -c); do if [[ "$(echo ${fakeraid} | grep '_')" ]]; then echo "/dev/mapper/${fakeraid}" [[ "${1}" ]] && echo ${1} fi done fi } # check_dm_devices # - remove part of encrypted devices # - remove part of lvm # - remove part ot raid check_dm_devices() { for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control); do k="$(${_BLKID} -p -i /dev/mapper/${devpath} 2>/dev/null | grep "TYPE=\"crypto_LUKS\"" | sed -e 's#:.*##g')" partofcrypt="${partofcrypt} ${k}" done for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control); do k="$(${_BLKID} -p -i /dev/mapper/${devpath} 2>/dev/null | grep "TYPE=\"LVM2_member\"" | sed -e 's#:.*##g')" partoflvm="${partoflvm} ${k}" done for devpath in $(ls /dev/mapper 2>/dev/null | grep -v control); do k="$(${_BLKID} -p -i /dev/mapper/${devpath} 2>/dev/null | grep "TYPE=\"linux_raid_member\"" | sed -e 's#:.*##g')" partofraid="${partofraid} ${k}" done } # dm_devices # - show device mapper devices dm_devices() { check_dm_devices for i in $(dmraid -s -c); do EXCLUDE_DMRAID="" if [[ "$(echo ${i} | grep '_')" ]]; then EXCLUDE_DMRAID="${EXCLUDE_DMRAID} -e ${i} " fi done if [[ -d /dev/mapper ]]; then for devpath in $(ls /dev/mapper 2>/dev/null | grep -v -e control ${EXCLUDE_DMRAID}); do if ! [[ "$(ls ${partofcrypt} 2>/dev/null | grep /dev/mapper/${devpath}$)" || "$(ls ${partoflvm} 2>/dev/null | grep /dev/mapper/${devpath}$)" || "$(ls ${partofraid} 2>/dev/null | grep /dev/mapper/${devpath}$)" ]]; then echo "/dev/mapper/${devpath}" [[ "${1}" ]] && echo ${1} fi done fi } # dmraid_partitions # - show dmraid partitions dmraid_partitions() { check_dm_devices if [[ -d /dev/mapper ]]; then for fakeraid in $(dmraid -s -c); do if [[ "$(echo ${fakeraid} | grep '_')" ]]; then for k in $(ls /dev/mapper/${fakeraid}*); do devpath=$(basename ${k}) if ! [[ "$(dmraid -s -c | grep ${devpath}$)" || "$(ls ${partofcrypt} 2>/dev/null | grep /dev/mapper/${devpath}$)" || "$(ls ${partoflvm} 2>/dev/null | grep /dev/mapper/${devpath}$)" || "$(ls ${partofraid} 2>/dev/null | grep /dev/mapper/${devpath}$)" ]]; then echo "/dev/mapper/${devpath}" [[ "${1}" ]] && echo ${1} fi done fi done fi } # do sanity checks on partitions, argument comes ${devpath} loop default_partition_check() { disk=$(basename ${devpath}) for part in $(ls ${block}/${disk} 2>/dev/null | egrep -v ^${disk}p | egrep ^${disk}); do # exclude checks: #- part of raid device # $(cat /proc/mdstat 2>/dev/null | grep ${part}) #- part of lvm2 device # $(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "LVM2_member") #- part of luks device # $(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "crypto_LUKS") #- extended partition # $(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}##g") 2>/dev/null | grep "5") #- extended partition on raid partition device and mmc device # $(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}\p##g" 2>/dev/null | grep "5") #- bios_grub partitions # $(echo ${part} | grep "[a-z]$(parted -s /dev/${disk} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$") if ! [[ "$(cat /proc/mdstat 2>/dev/null | grep ${part})" || "$(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "LVM2_member")" || "$(${_BLKID} -p -i -o value -s TYPE /dev/${part} | grep "crypto_LUKS")" || "$(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}##g") 2>/dev/null | grep "5")" || "$(sfdisk -c /dev/${disk} $(echo ${part} | sed -e "s#${disk}\p##g") 2>/dev/null | grep "5")" || "$(echo ${part} | grep "[a-z]$(parted -s /dev/${disk} print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")" ]]; then if [[ -d ${block}/${disk}/${part} ]]; then echo "/dev/${part}" [[ "${1}" ]] && echo ${1} fi fi done } finddisks() { default_blockdevices ${1} additional_blockdevices ${1} dmraid_devices ${1} partitionable_raid_devices ${1} } findpartitions() { for devpath in $(finddisks); do default_partition_check ${1} done additional_blockdevices_partitions ${1} dm_devices ${1} dmraid_partitions ${1} raid_devices ${1} partitionable_raid_devices_partitions ${1} } # don't check on raid devices! findbootloaderdisks() { if ! [[ "${USE_DMRAID}" = "1" ]]; then default_blockdevices ${1} additional_blockdevices ${1} else dmraid_devices ${1} fi } # don't list raid devices, lvm2 and devicemapper! findbootloaderpartitions() { if ! [[ "${USE_DMRAID}" = "1" ]]; then for devpath in $(findbootloaderdisks); do default_partition_check ${1} done additional_blockdevices_partitions ${1} else dmraid_partitions ${1} fi } # find any gpt/guid formatted disks find_gpt() { GUID_DETECTED="" for i in $(finddisks); do [[ "$(${_BLKID} -p -i -o value -s PTTYPE ${i})" == "gpt" ]] && GUID_DETECTED="1" done } # freeze and unfreeze xfs, as hack for grub(2) installing freeze_xfs() { sync if [[ -x /usr/bin/xfs_freeze ]]; then if [[ "$(cat /proc/mounts | grep "${DESTDIR}/boot " | grep " xfs ")" ]]; then /usr/bin/xfs_freeze -f ${DESTDIR}/boot >/dev/null 2>&1 /usr/bin/xfs_freeze -u ${DESTDIR}/boot >/dev/null 2>&1 fi if [[ "$(cat /proc/mounts | grep "${DESTDIR} " | grep " xfs ")" ]]; then /usr/bin/xfs_freeze -f ${DESTDIR} >/dev/null 2>&1 /usr/bin/xfs_freeze -u ${DESTDIR} >/dev/null 2>&1 fi fi } mapdev() { partition_flag=0 device_found=0 # check if we use hd sd or vd device if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/hd)" || "$(echo ${1} | grep /dev/vd)" ]]; then linuxdevice=$(echo ${1} | sed -e 's#p[0-9].*$##') else linuxdevice=$(echo ${1} | sed -e 's#[0-9].*$##g') fi if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/hd)" || "$(echo ${1} | grep /dev/vd)" ]]; then if [[ "$(echo ${1} | egrep 'p[0-9].*$')" ]]; then pnum=$(echo ${1} | sed -e 's#.*p##g') partition_flag=1 fi else if [[ "$(echo ${1} | egrep '[0-9]$')" ]]; then # /dev/hdXY pnum=$(echo ${1} | cut -b9-) partition_flag=1 fi fi for dev in ${devs}; do if [[ "(" = $(echo ${dev} | cut -b1) ]]; then grubdevice="${dev}" else if [[ "${dev}" = "${linuxdevice}" ]]; then device_found=1 break fi fi done if [[ "${device_found}" = "1" ]]; then if [[ "${partition_flag}" = "0" ]]; then echo "${grubdevice}" else grubdevice_stringlen=${#grubdevice} grubdevice_stringlen=$((${grubdevice_stringlen} - 1)) grubdevice=$(echo ${grubdevice} | cut -b1-${grubdevice_stringlen}) echo "${grubdevice},${pnum})" fi else echo "DEVICE NOT FOUND" fi } # geteditor() # prompts the user to choose an editor # sets EDITOR global variable # geteditor() { if ! [[ "${EDITOR}" ]]; then DIALOG --menu "${_geteditor}" 10 35 3 \ "1" "${_nano}" \ "2" "vi" 2>${ANSWER} || return 1 case $(cat ${ANSWER}) in "1") EDITOR="nano" ;; "2") EDITOR="vi" ;; esac fi } # set device name scheme set_device_name_scheme() { NAME_SCHEME_PARAMETER="" NAME_SCHEME_LEVELS="" MENU_DESC_TEXT="" # check if gpt/guid formatted disks are there find_gpt ## util-linux root=PARTUUID=/root=PARTLABEL= support - https://git.kernel.org/?p=utils/util-linux/util-linux.git;a=commitdiff;h=fc387ee14c6b8672761ae5e67ff639b5cae8f27c;hp=21d1fa53f16560dacba33fffb14ffc05d275c926 ## mkinitcpio's init root=PARTUUID= support - https://projects.archlinux.org/mkinitcpio.git/tree/init_functions#n185 if [[ "${GUID_DETECTED}" == "1" ]]; then NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} PARTUUID PARTUUID= PARTLABEL PARTLABEL=" MENU_DESC_TEXT="${_menu_descg}" fi NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} FSUUID UUID= FSLABEL LABEL=