diff --git a/debian/chroot.mount b/debian/chroot.mount index 74bb0be..90c7db2 100755 --- a/debian/chroot.mount +++ b/debian/chroot.mount @@ -1,6 +1,16 @@ #!/bin/sh -# Vars +# Vars {{{ +[ -z "${DEBUG}" ] && readonly DEBUG=0 +## Export DEBUG for sub-script +export DEBUG + +## Colors +readonly PURPLE='\033[1;35m' +readonly RED='\033[0;31m' +readonly RESET='\033[0m' +readonly COLOR_DEBUG="${PURPLE}" + ## Define the hard drive to use if [ -b '/dev/sda' ]; then hdd="/dev/sda" @@ -8,20 +18,33 @@ else printf '%b\n' "Please check the hard drive to use" exit 0 fi +# }}} ## Dependencies {{{ apt update apt install aptitude btrfs-progs bzip2 cryptsetup debconf-i18n dialog dmsetup htop ipcalc isc-dhcp-client isc-dhcp-common locales lvm2 openssh-server pciutils tmux vim-nox wget zsh ## }}} -## If empty, the script will try to get one with nslookup -new_hostname="" +debug_message() { # {{{ + + local_message="${1}" + + ## Print message if DEBUG is enable (=0) + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME}: ${local_message}" + + return 0 +} +# }}} + ## Try to guess the VG name by using the last VG detected vgname=$(vgdisplay --short | tail -n 1 | sed 's/.*"\(.*\)" .*/\1/') ## If the script should create extra volume (eg. backup, virt, Proxmox,…) manage_extra_lv=0 ## Is LUKS {{{ -if blkid | grep "${hdd}.*crypto_LUKS"; then + +if blkid | grep -q -- "${hdd}.*crypto_LUKS"; then + debug_message "is_luks − \ +Luks seems available on ${hdd} device." manage_luks=0 ## You need to set a new passphrase after the installation or at least change this one luks_passphrase="generic key" @@ -29,6 +52,8 @@ if blkid | grep "${hdd}.*crypto_LUKS"; then luks_pv_name=$(basename "${hdd}"2_crypt) else manage_luks=1 + debug_message "is_luks − \ +No Luks system on ${hdd} device." fi ## }}} ## Open LUKS system {{{ @@ -37,6 +62,8 @@ if [ "${manage_luks}" -eq 0 ]; then rm -f -- "${luks_key_file}" && printf '%b' "${luks_passphrase}" > "${luks_key_file}" ### If the volume is not already opened if [ ! -h /dev/mapper/"${luks_pv_name}" ]; then + debug_message "open_luks − \ +Try to open Luks on ${luks_pv_name} − ${hdd}2" ### Open LUKS system cryptsetup luksOpen "${hdd}"2 "${luks_pv_name}" --key-file "${luks_key_file}" || exit 2 fi @@ -46,24 +73,14 @@ fi root_fs_type=$(lsblk -f /dev/mapper/"${vgname}"-root | awk '/root/ { print $2 }') if [ "${root_fs_type}" = "btrfs" ]; then manage_btrfs=0 + debug_message "is_btrfs − \ +The root seems to be in btrfs." else manage_btrfs=1 + debug_message "is_btrfs − \ +No btrfs detected." fi ## }}} -## Colors definition {{{ -BLACK='\033[49;30m' -BLACKB='\033[49;90m' -RED='\033[0;31m' -REDB='\033[1;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -BLUE='\033[94;49m' -MAGENTA='\033[0;35m' -CYAN='\033[36;49m' -WHITE='\033[0;37m' -BOLD='\033[1m' -RESET='\033[0m' -## }}} ## Mount the system {{{ ### Root