feat: hooks (#70)
* Hooks Hook system to allow further customization at specific steps of the installation process. - before/after_prepare_environment - before/after_disk_configuration - before/after_download_stage3 - before/after_extract_stage3 - before/after_install - before/after_configure_base_system - before/after_configure_portage - before/after_install_kernel * add hook examples * fix: remove eval
This commit is contained in:
parent
e5067f0c43
commit
b2ea9b360d
|
@ -286,3 +286,76 @@ ROOT_SSH_AUTHORIZED_KEYS=""
|
||||||
# To prove that you have read and edited the config
|
# To prove that you have read and edited the config
|
||||||
# properly, set the following value to true.
|
# properly, set the following value to true.
|
||||||
I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=false
|
I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=false
|
||||||
|
|
||||||
|
################################################
|
||||||
|
# Hooks
|
||||||
|
|
||||||
|
# before_prepare_environment() {
|
||||||
|
# einfo 'before prepare environment'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_prepare_environment() {
|
||||||
|
# einfo 'after prepare environment'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_disk_configuration() {
|
||||||
|
# einfo 'before disk configuration'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_disk_configuration() {
|
||||||
|
# einfo 'after disk configuration'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_download_stage3() {
|
||||||
|
# einfo "stage3 basename: $1"
|
||||||
|
# einfo 'before download stage3'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_download_stage3() {
|
||||||
|
# einfo "stage3 downloaded file name: $1"
|
||||||
|
# einfo 'after download stage3'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_extract_stage3() {
|
||||||
|
# einfo "stage3 downloaded file path: $1"
|
||||||
|
# einfo "root mountpoint: $1"
|
||||||
|
# einfo 'before extract stage3'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_extract_stage3() {
|
||||||
|
# einfo "stage3 downloaded file path: $1"
|
||||||
|
# einfo "root mountpoint: $1"
|
||||||
|
# einfo 'after extract stage3'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_install() {
|
||||||
|
# einfo 'before install'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_install() {
|
||||||
|
# einfo 'after install'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_configure_base_system() {
|
||||||
|
# einfo 'before configure base system'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_configure_base_system() {
|
||||||
|
# einfo 'after configure base system'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_configure_portage() {
|
||||||
|
# einfo 'before configure portage'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_configure_portage() {
|
||||||
|
# einfo 'after configure portage'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# before_install_kernel() {
|
||||||
|
# einfo 'before install kernel'
|
||||||
|
# }
|
||||||
|
|
||||||
|
# after_install_kernel() {
|
||||||
|
# einfo 'after install kernel'
|
||||||
|
# }
|
||||||
|
|
|
@ -64,6 +64,8 @@ function preprocess_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_installation_environment() {
|
function prepare_installation_environment() {
|
||||||
|
maybe_exec 'before_prepare_environment'
|
||||||
|
|
||||||
einfo "Preparing installation environment"
|
einfo "Preparing installation environment"
|
||||||
|
|
||||||
local wanted_programs=(
|
local wanted_programs=(
|
||||||
|
@ -94,6 +96,8 @@ function prepare_installation_environment() {
|
||||||
|
|
||||||
# Sync time now to prevent issues later
|
# Sync time now to prevent issues later
|
||||||
sync_time
|
sync_time
|
||||||
|
|
||||||
|
maybe_exec 'after_prepare_environment'
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_encryption_key() {
|
function check_encryption_key() {
|
||||||
|
@ -735,6 +739,8 @@ function apply_disk_configuration() {
|
||||||
|| die "Aborted"
|
|| die "Aborted"
|
||||||
countdown "Applying in " 5
|
countdown "Applying in " 5
|
||||||
|
|
||||||
|
maybe_exec 'before_disk_configuration'
|
||||||
|
|
||||||
einfo "Applying disk configuration"
|
einfo "Applying disk configuration"
|
||||||
apply_disk_actions
|
apply_disk_actions
|
||||||
|
|
||||||
|
@ -742,6 +748,8 @@ function apply_disk_configuration() {
|
||||||
elog "[1mNew lsblk output:[m"
|
elog "[1mNew lsblk output:[m"
|
||||||
for_line_in <(lsblk \
|
for_line_in <(lsblk \
|
||||||
|| die "Error in lsblk") elog
|
|| die "Error in lsblk") elog
|
||||||
|
|
||||||
|
maybe_exec 'after_disk_configuration'
|
||||||
}
|
}
|
||||||
|
|
||||||
function mount_efivars() {
|
function mount_efivars() {
|
||||||
|
@ -819,6 +827,8 @@ function download_stage3() {
|
||||||
# File to indiciate successful verification
|
# File to indiciate successful verification
|
||||||
CURRENT_STAGE3_VERIFIED="${CURRENT_STAGE3}.verified"
|
CURRENT_STAGE3_VERIFIED="${CURRENT_STAGE3}.verified"
|
||||||
|
|
||||||
|
maybe_exec 'before_download_stage3' "$STAGE3_BASENAME"
|
||||||
|
|
||||||
# Download file if not already downloaded
|
# Download file if not already downloaded
|
||||||
if [[ -e $CURRENT_STAGE3_VERIFIED ]]; then
|
if [[ -e $CURRENT_STAGE3_VERIFIED ]]; then
|
||||||
einfo "$STAGE3_BASENAME tarball already downloaded and verified"
|
einfo "$STAGE3_BASENAME tarball already downloaded and verified"
|
||||||
|
@ -855,6 +865,8 @@ function download_stage3() {
|
||||||
# Create verification file in case the script is restarted
|
# Create verification file in case the script is restarted
|
||||||
touch_or_die 0644 "$CURRENT_STAGE3_VERIFIED"
|
touch_or_die 0644 "$CURRENT_STAGE3_VERIFIED"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
maybe_exec 'after_download_stage3' "${CURRENT_STAGE3}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract_stage3() {
|
function extract_stage3() {
|
||||||
|
@ -865,6 +877,8 @@ function extract_stage3() {
|
||||||
[[ -e "$TMP_DIR/$CURRENT_STAGE3" ]] \
|
[[ -e "$TMP_DIR/$CURRENT_STAGE3" ]] \
|
||||||
|| die "stage3 file does not exist"
|
|| die "stage3 file does not exist"
|
||||||
|
|
||||||
|
maybe_exec 'before_extract_stage3' "$TMP_DIR/$CURRENT_STAGE3" "$ROOT_MOUNTPOINT"
|
||||||
|
|
||||||
# Go to root directory
|
# Go to root directory
|
||||||
cd "$ROOT_MOUNTPOINT" \
|
cd "$ROOT_MOUNTPOINT" \
|
||||||
|| die "Could not move to '$ROOT_MOUNTPOINT'"
|
|| die "Could not move to '$ROOT_MOUNTPOINT'"
|
||||||
|
@ -879,6 +893,8 @@ function extract_stage3() {
|
||||||
|| die "Error while extracting tarball"
|
|| die "Error while extracting tarball"
|
||||||
cd "$TMP_DIR" \
|
cd "$TMP_DIR" \
|
||||||
|| die "Could not cd into '$TMP_DIR'"
|
|| die "Could not cd into '$TMP_DIR'"
|
||||||
|
|
||||||
|
maybe_exec 'after_extract_stage3' "$TMP_DIR/$CURRENT_STAGE3" "$ROOT_MOUNTPOINT"
|
||||||
}
|
}
|
||||||
|
|
||||||
function gentoo_umount() {
|
function gentoo_umount() {
|
||||||
|
|
|
@ -320,6 +320,8 @@ function generate_fstab() {
|
||||||
function main_install_gentoo_in_chroot() {
|
function main_install_gentoo_in_chroot() {
|
||||||
[[ $# == 0 ]] || die "Too many arguments"
|
[[ $# == 0 ]] || die "Too many arguments"
|
||||||
|
|
||||||
|
maybe_exec 'before_install'
|
||||||
|
|
||||||
# Remove the root password, making the account accessible for automated
|
# Remove the root password, making the account accessible for automated
|
||||||
# tasks during the period of installation.
|
# tasks during the period of installation.
|
||||||
einfo "Clearing root password"
|
einfo "Clearing root password"
|
||||||
|
@ -342,9 +344,12 @@ function main_install_gentoo_in_chroot() {
|
||||||
try emerge-webrsync
|
try emerge-webrsync
|
||||||
|
|
||||||
# Configure basic system things like timezone, locale, ...
|
# Configure basic system things like timezone, locale, ...
|
||||||
|
maybe_exec 'before_configure_base_system'
|
||||||
configure_base_system
|
configure_base_system
|
||||||
|
maybe_exec 'after_configure_base_system'
|
||||||
|
|
||||||
# Prepare portage environment
|
# Prepare portage environment
|
||||||
|
maybe_exec 'before_configure_portage'
|
||||||
configure_portage
|
configure_portage
|
||||||
|
|
||||||
# Install git (for git portage overlays)
|
# Install git (for git portage overlays)
|
||||||
|
@ -372,6 +377,7 @@ EOF
|
||||||
|| die "Could not delete obsolete rsync gentoo repository"
|
|| die "Could not delete obsolete rsync gentoo repository"
|
||||||
try emerge --sync
|
try emerge --sync
|
||||||
fi
|
fi
|
||||||
|
maybe_exec 'after_configure_portage'
|
||||||
|
|
||||||
einfo "Generating ssh host keys"
|
einfo "Generating ssh host keys"
|
||||||
try ssh-keygen -A
|
try ssh-keygen -A
|
||||||
|
@ -421,7 +427,9 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install kernel and initramfs
|
# Install kernel and initramfs
|
||||||
|
maybe_exec 'before_install_kernel'
|
||||||
install_kernel
|
install_kernel
|
||||||
|
maybe_exec 'after_install_kernel'
|
||||||
|
|
||||||
# Generate a valid fstab file
|
# Generate a valid fstab file
|
||||||
generate_fstab
|
generate_fstab
|
||||||
|
@ -487,6 +495,8 @@ EOF
|
||||||
|| die "Could not modify /etc/portage/make.conf"
|
|| die "Could not modify /etc/portage/make.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
maybe_exec 'after_install'
|
||||||
|
|
||||||
einfo "Gentoo installation complete."
|
einfo "Gentoo installation complete."
|
||||||
[[ $USED_LUKS == "true" ]] \
|
[[ $USED_LUKS == "true" ]] \
|
||||||
&& einfo "A backup of your luks headers can be found at '$LUKS_HEADER_BACKUP_DIR', in case you want to have a backup."
|
&& einfo "A backup of your luks headers can be found at '$LUKS_HEADER_BACKUP_DIR', in case you want to have a backup."
|
||||||
|
|
|
@ -445,3 +445,9 @@ function check_wanted_programs() {
|
||||||
ask "Continue without recommended programs?"
|
ask "Continue without recommended programs?"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# exec function if defined
|
||||||
|
# $@ function name and arguments
|
||||||
|
function maybe_exec() {
|
||||||
|
type "$1" &>/dev/null && "$@"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue