[util-disk] fix formatting

merge-requests/273/head
Bernhard Landauer 8 years ago
parent 9e08c0ec03
commit cc91d02a6b

@ -1,5 +1,5 @@
# Unmount partitions. # Unmount partitions.
umount_partitions() { umount_partitions() {
MOUNTED="" MOUNTED=""
MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r) MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r)
swapoff -a swapoff -a
@ -9,10 +9,10 @@
done done
check_for_error check_for_error
} }
# Revised to deal with partion sizes now being displayed to the user # Revised to deal with partion sizes now being displayed to the user
confirm_mount() { confirm_mount() {
if [[ $(mount | grep $1) ]]; then if [[ $(mount | grep $1) ]]; then
DIALOG " $_MntStatusTitle " --infobox "$_MntStatusSucc" 0 0 DIALOG " $_MntStatusTitle " --infobox "$_MntStatusSucc" 0 0
sleep 2 sleep 2
@ -23,11 +23,11 @@
sleep 2 sleep 2
prep_menu prep_menu
fi fi
} }
# This function does not assume that the formatted device is the Root installation device as # 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. # more than one device may be formatted. Root is set in the mount_partitions function.
select_device() { select_device() {
DEVICE="" DEVICE=""
devices_list=$(lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print "/dev/" $1 " " $2}' | sort -u); devices_list=$(lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print "/dev/" $1 " " $2}' | sort -u);
@ -37,11 +37,11 @@
DIALOG " $_DevSelTitle " --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu DIALOG " $_DevSelTitle " --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu
DEVICE=$(cat ${ANSWER}) DEVICE=$(cat ${ANSWER})
} }
# Finds all available partitions according to type(s) specified and generates a list # Finds all available partitions according to type(s) specified and generates a list
# of them. This also includes partitions on different devices. # of them. This also includes partitions on different devices.
find_partitions() { find_partitions() {
PARTITIONS="" PARTITIONS=""
NUMBER_PARTITIONS=0 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' | \ partition_list=$(lsblk -lno NAME,SIZE,TYPE | grep $INCLUDE_PART | sed 's/part$/\/dev\//g' | sed 's/lvm$\|crypt$/\/dev\/mapper\//g' | \
@ -78,9 +78,9 @@
fi fi
;; ;;
esac esac
} }
create_partitions() { create_partitions() {
# Securely destroy all data on a given device. # Securely destroy all data on a given device.
secure_wipe() { secure_wipe() {
# Warn the user. If they proceed, wipe the selected device. # Warn the user. If they proceed, wipe the selected device.
@ -170,7 +170,7 @@
} }
# Set static list of filesystems rather than on-the-fly. Partially as most require additional flags, and # Set static list of filesystems rather than on-the-fly. Partially as most require additional flags, and
# partially because some don't seem to be viable. # partially because some don't seem to be viable.
# Set static list of filesystems rather than on-the-fly. # Set static list of filesystems rather than on-the-fly.
select_filesystem() { select_filesystem() {
@ -477,15 +477,14 @@ mount_partitions() {
if [[ $MOUNT == "/boot" ]]; then if [[ $MOUNT == "/boot" ]]; then
[[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]] && LVM_SEP_BOOT=2 || LVM_SEP_BOOT=1 [[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]] && LVM_SEP_BOOT=2 || LVM_SEP_BOOT=1
fi fi
fi fi
done done
} }
# Had to write it in this way due to (bash?) bug(?), as if/then statements in a single # Had to write it in this way due to (bash?) bug(?), as if/then statements in a single
# "create LUKS" function for default and "advanced" modes were interpreted as commands, # "create LUKS" function for default and "advanced" modes were interpreted as commands,
# not mere string statements. Not happy with it, but it works... # not mere string statements. Not happy with it, but it works...
luks_password() { luks_password() {
DIALOG " $_PrepLUKS " --clear --insecure --passwordbox "$_LuksPassBody" 0 0 2> ${ANSWER} || prep_menu DIALOG " $_PrepLUKS " --clear --insecure --passwordbox "$_LuksPassBody" 0 0 2> ${ANSWER} || prep_menu
PASSWD=$(cat ${ANSWER}) PASSWD=$(cat ${ANSWER})
@ -496,9 +495,9 @@ mount_partitions() {
DIALOG " $_ErrTitle " --msgbox "$_PassErrBody" 0 0 DIALOG " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
luks_password luks_password
fi fi
} }
luks_open() { luks_open() {
LUKS_ROOT_NAME="" LUKS_ROOT_NAME=""
INCLUDE_PART='part\|crypt\|lvm' INCLUDE_PART='part\|crypt\|lvm'
umount_partitions umount_partitions
@ -523,14 +522,13 @@ mount_partitions() {
DIALOG " $_DevShowOpt " --textbox /tmp/.devlist 0 0 DIALOG " $_DevShowOpt " --textbox /tmp/.devlist 0 0
luks_menu luks_menu
} }
luks_setup() { luks_setup() {
modprobe -a dm-mod dm_crypt modprobe -a dm-mod dm_crypt
INCLUDE_PART='part\|lvm' INCLUDE_PART='part\|lvm'
umount_partitions umount_partitions
find_partitions find_partitions
# Select partition to encrypt # Select partition to encrypt
DIALOG " $_LuksEncrypt " --menu "$_LuksCreateBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || luks_menu DIALOG " $_LuksEncrypt " --menu "$_LuksCreateBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || luks_menu
PARTITION=$(cat ${ANSWER}) PARTITION=$(cat ${ANSWER})
@ -539,9 +537,9 @@ mount_partitions() {
DIALOG " $_LuksEncrypt " --inputbox "$_LuksOpenBody" 10 50 "cryptroot" 2>${ANSWER} || luks_menu DIALOG " $_LuksEncrypt " --inputbox "$_LuksOpenBody" 10 50 "cryptroot" 2>${ANSWER} || luks_menu
LUKS_ROOT_NAME=$(cat ${ANSWER}) LUKS_ROOT_NAME=$(cat ${ANSWER})
luks_password luks_password
} }
luks_default() { luks_default() {
# Encrypt selected partition or LV with credentials given # Encrypt selected partition or LV with credentials given
DIALOG " $_LuksEncrypt " --infobox "$_PlsWaitBody" 0 0 DIALOG " $_LuksEncrypt " --infobox "$_PlsWaitBody" 0 0
sleep 2 sleep 2
@ -550,9 +548,9 @@ mount_partitions() {
# Now open the encrypted partition or LV # Now open the encrypted partition or LV
echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog
check_for_error check_for_error
} }
luks_key_define() { luks_key_define() {
DIALOG " $_PrepLUKS " --inputbox "$_LuksCipherKey" 0 0 "-s 512 -c aes-xts-plain64" 2>${ANSWER} || luks_menu DIALOG " $_PrepLUKS " --inputbox "$_LuksCipherKey" 0 0 "-s 512 -c aes-xts-plain64" 2>${ANSWER} || luks_menu
# Encrypt selected partition or LV with credentials given # Encrypt selected partition or LV with credentials given
@ -565,17 +563,17 @@ mount_partitions() {
# Now open the encrypted partition or LV # Now open the encrypted partition or LV
echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog
check_for_error check_for_error
} }
luks_show() { luks_show() {
echo -e ${_LuksEncruptSucc} > /tmp/.devlist echo -e ${_LuksEncruptSucc} > /tmp/.devlist
lsblk -o NAME,TYPE,FSTYPE,SIZE ${PARTITION} | grep "part\|crypt\|NAME\|TYPE\|FSTYPE\|SIZE" >> /tmp/.devlist lsblk -o NAME,TYPE,FSTYPE,SIZE ${PARTITION} | grep "part\|crypt\|NAME\|TYPE\|FSTYPE\|SIZE" >> /tmp/.devlist
DIALOG " $_LuksEncrypt " --textbox /tmp/.devlist 0 0 DIALOG " $_LuksEncrypt " --textbox /tmp/.devlist 0 0
luks_menu luks_menu
} }
luks_menu() { luks_menu() {
LUKS_OPT="" LUKS_OPT=""
DIALOG " $_PrepLUKS " --menu "$_LuksMenuBody$_LuksMenuBody2$_LuksMenuBody3" 0 0 4 \ DIALOG " $_PrepLUKS " --menu "$_LuksMenuBody$_LuksMenuBody2$_LuksMenuBody3" 0 0 4 \
@ -600,9 +598,9 @@ mount_partitions() {
esac esac
luks_menu luks_menu
} }
lvm_detect() { lvm_detect() {
LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null) LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null)
LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null) LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null)
LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null) LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)
@ -614,9 +612,9 @@ mount_partitions() {
vgscan >/dev/null 2>&1 vgscan >/dev/null 2>&1
vgchange -ay >/dev/null 2>&1 vgchange -ay >/dev/null 2>&1
fi fi
} }
lvm_show_vg() { lvm_show_vg() {
VG_LIST="" VG_LIST=""
vg_list=$(lvs --noheadings | awk '{print $2}' | uniq) vg_list=$(lvs --noheadings | awk '{print $2}' | uniq)
@ -633,10 +631,10 @@ mount_partitions() {
# Select VG # Select VG
DIALOG " $_PrepLVM " --menu "$_LvmSelVGBody" 0 0 5 \ DIALOG " $_PrepLVM " --menu "$_LvmSelVGBody" 0 0 5 \
${VG_LIST} 2>${ANSWER} || lvm_menu ${VG_LIST} 2>${ANSWER} || lvm_menu
} }
# Create Volume Group and Logical Volumes # Create Volume Group and Logical Volumes
lvm_create() { lvm_create() {
check_lv_size() { check_lv_size() {
LV_SIZE_INVALID=0 LV_SIZE_INVALID=0
chars=0 chars=0
@ -792,9 +790,9 @@ mount_partitions() {
NUMBER_LOGICAL_VOLUMES=$(( NUMBER_LOGICAL_VOLUMES - 1 )) NUMBER_LOGICAL_VOLUMES=$(( NUMBER_LOGICAL_VOLUMES - 1 ))
LVM=1 LVM=1
DIALOG " $_LvmCreateVG " --yesno "$_LvmCompBody" 0 0 && show_devices || lvm_menu DIALOG " $_LvmCreateVG " --yesno "$_LvmCompBody" 0 0 && show_devices || lvm_menu
} }
lvm_del_vg() { lvm_del_vg() {
# Generate list of VGs for selection # Generate list of VGs for selection
lvm_show_vg lvm_show_vg
@ -807,9 +805,9 @@ mount_partitions() {
fi fi
lvm_menu lvm_menu
} }
lvm_del_all() { lvm_del_all() {
LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null) LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null)
LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null) LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null)
LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null) LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)
@ -833,9 +831,9 @@ mount_partitions() {
fi fi
lvm_menu lvm_menu
} }
lvm_menu() { lvm_menu() {
DIALOG " $_PrepLVM $_PrepLVM2 " --infobox "$_PlsWaitBody" 0 0 DIALOG " $_PrepLVM $_PrepLVM2 " --infobox "$_PlsWaitBody" 0 0
sleep 1 sleep 1
lvm_detect lvm_detect
@ -852,4 +850,4 @@ mount_partitions() {
"$_LvMDelAll") lvm_del_all ;; "$_LvMDelAll") lvm_del_all ;;
*) prep_menu ;; *) prep_menu ;;
esac esac
} }

Loading…
Cancel
Save