Add debug_message func
This commit is contained in:
parent
2216fdba5d
commit
c9473c6cdf
|
@ -1,6 +1,16 @@
|
||||||
#!/bin/sh
|
#!/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
|
## Define the hard drive to use
|
||||||
if [ -b '/dev/sda' ]; then
|
if [ -b '/dev/sda' ]; then
|
||||||
hdd="/dev/sda"
|
hdd="/dev/sda"
|
||||||
|
@ -8,20 +18,33 @@ else
|
||||||
printf '%b\n' "Please check the hard drive to use"
|
printf '%b\n' "Please check the hard drive to use"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
# }}}
|
||||||
|
|
||||||
## Dependencies {{{
|
## Dependencies {{{
|
||||||
apt update
|
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
|
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
|
debug_message() { # {{{
|
||||||
new_hostname=""
|
|
||||||
|
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
|
## Try to guess the VG name by using the last VG detected
|
||||||
vgname=$(vgdisplay --short | tail -n 1 | sed 's/.*"\(.*\)" .*/\1/')
|
vgname=$(vgdisplay --short | tail -n 1 | sed 's/.*"\(.*\)" .*/\1/')
|
||||||
## If the script should create extra volume (eg. backup, virt, Proxmox,…)
|
## If the script should create extra volume (eg. backup, virt, Proxmox,…)
|
||||||
manage_extra_lv=0
|
manage_extra_lv=0
|
||||||
## Is LUKS {{{
|
## 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
|
manage_luks=0
|
||||||
## You need to set a new passphrase after the installation or at least change this one
|
## You need to set a new passphrase after the installation or at least change this one
|
||||||
luks_passphrase="generic key"
|
luks_passphrase="generic key"
|
||||||
|
@ -29,6 +52,8 @@ if blkid | grep "${hdd}.*crypto_LUKS"; then
|
||||||
luks_pv_name=$(basename "${hdd}"2_crypt)
|
luks_pv_name=$(basename "${hdd}"2_crypt)
|
||||||
else
|
else
|
||||||
manage_luks=1
|
manage_luks=1
|
||||||
|
debug_message "is_luks − \
|
||||||
|
No Luks system on ${hdd} device."
|
||||||
fi
|
fi
|
||||||
## }}}
|
## }}}
|
||||||
## Open LUKS system {{{
|
## 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}"
|
rm -f -- "${luks_key_file}" && printf '%b' "${luks_passphrase}" > "${luks_key_file}"
|
||||||
### If the volume is not already opened
|
### If the volume is not already opened
|
||||||
if [ ! -h /dev/mapper/"${luks_pv_name}" ]; then
|
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
|
### Open LUKS system
|
||||||
cryptsetup luksOpen "${hdd}"2 "${luks_pv_name}" --key-file "${luks_key_file}" || exit 2
|
cryptsetup luksOpen "${hdd}"2 "${luks_pv_name}" --key-file "${luks_key_file}" || exit 2
|
||||||
fi
|
fi
|
||||||
|
@ -46,24 +73,14 @@ fi
|
||||||
root_fs_type=$(lsblk -f /dev/mapper/"${vgname}"-root | awk '/root/ { print $2 }')
|
root_fs_type=$(lsblk -f /dev/mapper/"${vgname}"-root | awk '/root/ { print $2 }')
|
||||||
if [ "${root_fs_type}" = "btrfs" ]; then
|
if [ "${root_fs_type}" = "btrfs" ]; then
|
||||||
manage_btrfs=0
|
manage_btrfs=0
|
||||||
|
debug_message "is_btrfs − \
|
||||||
|
The root seems to be in btrfs."
|
||||||
else
|
else
|
||||||
manage_btrfs=1
|
manage_btrfs=1
|
||||||
|
debug_message "is_btrfs − \
|
||||||
|
No btrfs detected."
|
||||||
fi
|
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 {{{
|
## Mount the system {{{
|
||||||
### Root
|
### Root
|
||||||
|
|
Loading…
Reference in New Issue