# !/bin/bash # # Architect Installation Framework (2016-2017) # # Written by Carl Duff and @mandog for Archlinux # Heavily modified and re-written by @Chrysostomus to install Manjaro instead # Contributors: @papajoker, @oberon and the Manjaro-Community. # # This program is free software, provided under the GNU General Public License # as published by the Free Software Foundation. So feel free to copy, distribute, # or modify it as you wish. # Unmount partitions. umount_partitions() { MOUNTED="" MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r) swapoff -a for i in ${MOUNTED[@]}; do umount $i >/dev/null 2>$ERR check_for_error "unmount $i" $? # local err=$(umount $i >/dev/null 2>$ERR) # (( err !=0 )) && check_for_error "$FUNCNAME $i" $err done } # This function does not assume that the formatted device is the Root installation device as # more than one device may be formatted. Root is set in the mount_partitions function. select_device() { DEVICE="" devices_list=$(lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print "/dev/" $1 " " $2}' | sort -u); for i in ${devices_list[@]}; do DEVICE="${DEVICE} ${i}" done DIALOG " $_DevSelTitle " --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu DEVICE=$(cat ${ANSWER}) } create_partitions() { # Partitioning Menu DIALOG " $_PrepPartDisk " --menu "$_PartToolBody" 0 0 7 \ "$_PartOptWipe" "BIOS & UEFI" \ "$_PartOptAuto" "BIOS & UEFI" \ "cfdisk" "BIOS" \ "cgdisk" "UEFI" \ "fdisk" "BIOS & UEFI" \ "gdisk" "UEFI" \ "parted" "BIOS & UEFI" 2>${ANSWER} clear # If something selected if [[ $(cat ${ANSWER}) != "" ]]; then if ([[ $(cat ${ANSWER}) != "$_PartOptWipe" ]] && [[ $(cat ${ANSWER}) != "$_PartOptAuto" ]]); then $(cat ${ANSWER}) ${DEVICE} else [[ $(cat ${ANSWER}) == "$_PartOptWipe" ]] && secure_wipe && create_partitions [[ $(cat ${ANSWER}) == "$_PartOptAuto" ]] && auto_partition fi fi } # Securely destroy all data on a given device. secure_wipe() { # Warn the user. If they proceed, wipe the selected device. DIALOG " $_PartOptWipe " --yesno "$_AutoPartWipeBody1 ${DEVICE} $_AutoPartWipeBody2" 0 0 if [[ $? -eq 0 ]]; then clear # Install wipe where not already installed. Much faster than dd if [[ ! -e /usr/bin/wipe ]]; then pacman -Sy --noconfirm wipe 2>$ERR check_for_error "install wipe" $? fi clear wipe -Ifre ${DEVICE} 2>$ERR check_for_error "wipe ${DEVICE}" $? # Alternate dd command - requires pv to be installed #dd if=/dev/zero | pv | dd of=${DEVICE} iflag=nocache oflag=direct bs=4096 2>$ERR fi } # BIOS and UEFI auto_partition() { # Provide warning to user DIALOG " $_PrepPartDisk " --yesno "$_AutoPartBody1 $DEVICE $_AutoPartBody2 $_AutoPartBody3" 0 0 if [[ $? -eq 0 ]]; then # Find existing partitions (if any) to remove parted -s ${DEVICE} print | awk '/^ / {print $1}' > /tmp/.del_parts for del_part in $(tac /tmp/.del_parts); do parted -s ${DEVICE} rm ${del_part} 2>$ERR check_for_error "rm ${del_part} on ${DEVICE}" $? done # Identify the partition table part_table=$(parted -s ${DEVICE} print | grep -i 'partition table' | awk '{print $3}' >/dev/null 2>&1) check_for_error "${DEVICE} is $part_table" # Create partition table if one does not already exist if [[ $SYSTEM == "BIOS" ]] && [[ $part_table != "msdos" ]] ; then parted -s ${DEVICE} mklabel msdos 2>$ERR check_for_error "${DEVICE} mklabel msdos" $? fi if [[ $SYSTEM == "UEFI" ]] && [[ $part_table != "gpt" ]] ; then parted -s ${DEVICE} mklabel gpt 2>$ERR check_for_error "${DEVICE} mklabel gpt" $? fi # Create partitions (same basic partitioning scheme for BIOS and UEFI) if [[ $SYSTEM == "BIOS" ]]; then parted -s ${DEVICE} mkpart primary ext3 1MiB 513MiB 2>$ERR check_for_error "create ext3 513MiB on ${DEVICE}" $? else parted -s ${DEVICE} mkpart ESP fat32 1MiB 513MiB 2>$ERR check_for_error "create ESP on ${DEVICE}" $? fi parted -s ${DEVICE} set 1 boot on 2>$ERR check_for_error "set boot flag for ${DEVICE}" $? parted -s ${DEVICE} mkpart primary ext3 513MiB 100% 2>$ERR check_for_error "create ext3 100% on ${DEVICE}" $? # Show created partitions lsblk ${DEVICE} -o NAME,TYPE,FSTYPE,SIZE > /tmp/.devlist DIALOG "" --textbox /tmp/.devlist 0 0 fi } # Finds all available partitions according to type(s) specified and generates a list # of them. This also includes partitions on different devices. find_partitions() { PARTITIONS="" NUMBER_PARTITIONS=0 partition_list=$(lsblk -lno NAME,SIZE,TYPE | grep $INCLUDE_PART | sed 's/part$/\/dev\//g' | sed 's/lvm$\|crypt$/\/dev\/mapper\//g' | \ awk '{print $3$1 " " $2}' | awk '!/mapper/{a[++i]=$0;next}1;END{while(x