Implemented script logging, export parallel compilation paramters in chroot
This commit is contained in:
parent
76bf36f20b
commit
a5e8476352
|
@ -143,27 +143,37 @@ format_partitions() {
|
|||
dev="$(get_device_by_partuuid "$PARTITION_UUID_LINUX")" \
|
||||
|| die "Could not resolve partition UUID '$PARTITION_UUID_LINUX'"
|
||||
einfo " $dev (linux)"
|
||||
mkfs.ext4 -L "linux" "$dev" \
|
||||
mkfs.ext4 -q -L "linux" "$dev" \
|
||||
|| die "Could not create ext4 filesystem"
|
||||
}
|
||||
|
||||
mount_root() {
|
||||
# Skip if root is already mounted
|
||||
mountpoint -q -- "$ROOT_MOUNTPOINT" \
|
||||
mount_by_partuuid() {
|
||||
local dev
|
||||
local partuuid="$1"
|
||||
local mountpoint="$2"
|
||||
|
||||
# Skip if already mounted
|
||||
mountpoint -q -- "$mountpoint" \
|
||||
&& return
|
||||
|
||||
# Mount root device
|
||||
einfo "Mounting root device"
|
||||
mkdir -p "$ROOT_MOUNTPOINT" \
|
||||
|| die "Could not create mountpoint directory $ROOT_MOUNTPOINT"
|
||||
local dev
|
||||
dev="$(get_device_by_partuuid "$PARTITION_UUID_LINUX")" \
|
||||
# Mount device
|
||||
einfo "Mounting device partuuid=$partuuid to '$mountpoint'"
|
||||
mkdir -p "$mountpoint" \
|
||||
|| die "Could not create mountpoint directory '$mountpoint'"
|
||||
dev="$(get_device_by_partuuid "$partuuid")" \
|
||||
|| die "Could not resolve partition UUID '$PARTITION_UUID_LINUX'"
|
||||
mount "$dev" "$ROOT_MOUNTPOINT" \
|
||||
|| die "Could not mount root device '$dev'"
|
||||
mount "$dev" "$mountpoint" \
|
||||
|| die "Could not mount device '$dev'"
|
||||
}
|
||||
|
||||
mount_root() {
|
||||
mount_by_partuuid "$PARTITION_UUID_LINUX" "$ROOT_MOUNTPOINT"
|
||||
}
|
||||
|
||||
bind_bootstrap_dir() {
|
||||
# Use new location by default
|
||||
GENTOO_BOOTSTRAP_DIR="$GENTOO_BOOTSTRAP_BIND"
|
||||
|
||||
# Bind the bootstrap dir to a location in /tmp,
|
||||
# so it can be accessed from within the chroot
|
||||
mountpoint -q -- "$GENTOO_BOOTSTRAP_BIND" \
|
||||
|
@ -173,8 +183,8 @@ bind_bootstrap_dir() {
|
|||
einfo "Bind mounting bootstrap directory"
|
||||
mkdir -p "$GENTOO_BOOTSTRAP_BIND" \
|
||||
|| die "Could not create mountpoint directory '$GENTOO_BOOTSTRAP_BIND'"
|
||||
mount --bind "$GENTOO_BOOTSTRAP_DIR" "$GENTOO_BOOTSTRAP_BIND" \
|
||||
|| die "Could not bind mount '$GENTOO_BOOTSTRAP_DIR' to '$GENTOO_BOOTSTRAP_BIND'"
|
||||
mount --bind "$GENTOO_BOOTSTRAP_DIR_ORIGINAL" "$GENTOO_BOOTSTRAP_BIND" \
|
||||
|| die "Could not bind mount '$GENTOO_BOOTSTRAP_DIR_ORIGINAL' to '$GENTOO_BOOTSTRAP_BIND'"
|
||||
}
|
||||
|
||||
download_stage3() {
|
||||
|
@ -247,9 +257,21 @@ extract_stage3() {
|
|||
|| die "Could not cd into '$TMP_DIR'"
|
||||
}
|
||||
|
||||
gentoo_umount() {
|
||||
einfo "Unmounting root filesystem"
|
||||
if mountpoint -q -- "$ROOT_MOUNTPOINT"; then
|
||||
umount -R "$ROOT_MOUNTPOINT" \
|
||||
|| die "Could not unmount filesystems"
|
||||
fi
|
||||
}
|
||||
|
||||
gentoo_chroot() {
|
||||
[[ $# -gt 0 ]] || die "Missing command argument"
|
||||
|
||||
[[ $EXECUTED_IN_CHROOT != true ]] \
|
||||
|| die "Already in chroot"
|
||||
|
||||
gentoo_umount
|
||||
mount_root
|
||||
bind_bootstrap_dir
|
||||
|
||||
|
@ -273,6 +295,6 @@ gentoo_chroot() {
|
|||
einfo "Chrooting..."
|
||||
EXECUTED_IN_CHROOT=true \
|
||||
TMP_DIR=$TMP_DIR \
|
||||
exec chroot "$ROOT_MOUNTPOINT" "$GENTOO_BOOTSTRAP_BIND/scripts/main_chroot.sh" "$@" \
|
||||
exec chroot "$ROOT_MOUNTPOINT" "$GENTOO_BOOTSTRAP_DIR/scripts/main_chroot.sh" "$@" \
|
||||
|| die "Failed to chroot into '$ROOT_MOUNTPOINT'"
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
main.sh
|
|
@ -14,9 +14,11 @@ get_source_dir() {
|
|||
echo -n "$(realpath "$(dirname "${source}")")"
|
||||
}
|
||||
|
||||
export GENTOO_BOOTSTRAP_DIR="$(dirname "$(get_source_dir)")"
|
||||
export GENTOO_BOOTSTRAP_DIR_ORIGINAL="$(dirname "$(get_source_dir)")"
|
||||
export GENTOO_BOOTSTRAP_DIR="$GENTOO_BOOTSTRAP_DIR_ORIGINAL"
|
||||
export GENTOO_BOOTSTRAP_SCRIPT_ACTIVE=true
|
||||
export GENTOO_BOOTSTRAP_SCRIPT_PID=$$
|
||||
LOGDATE="$(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
umask 0077
|
||||
|
||||
|
@ -32,7 +34,7 @@ mkdir -p "$TMP_DIR"
|
|||
################################################
|
||||
# Functions
|
||||
|
||||
main_install_stage3() {
|
||||
install_stage3() {
|
||||
[[ $# == 0 ]] || die "Too many arguments"
|
||||
|
||||
prepare_installation_environment
|
||||
|
@ -42,15 +44,27 @@ main_install_stage3() {
|
|||
extract_stage3
|
||||
}
|
||||
|
||||
main_chroot() {
|
||||
gentoo_chroot "$@"
|
||||
}
|
||||
|
||||
main_install_gentoo() {
|
||||
main_install_gentoo_in_chroot() {
|
||||
[[ $# == 0 ]] || die "Too many arguments"
|
||||
|
||||
#remove root password
|
||||
passwd -d root
|
||||
# Lock the root password, making the account unaccessible for the
|
||||
# period of installation, except by chrooting
|
||||
einfo "Locking root account"
|
||||
passwd -l root
|
||||
|
||||
einfo "Selecting portage mirrors"
|
||||
# TODO mirrorselect
|
||||
# TODO gpg portage sync
|
||||
# TODO additional binary repos
|
||||
# TODO safe dns settings (claranet)
|
||||
|
||||
einfo "Mounting efi"
|
||||
mount_by_partuuid "$PARTITION_UUID_EFI" "/boot/efi"
|
||||
|
||||
einfo "Syncing portage tree"
|
||||
emerge-webrsync
|
||||
|
||||
einfo "Selecting portage profile '$'"
|
||||
|
||||
#get kernel
|
||||
|
||||
|
@ -71,24 +85,46 @@ main_install_gentoo() {
|
|||
su
|
||||
}
|
||||
|
||||
main_install_full() {
|
||||
main_install() {
|
||||
[[ $# == 0 ]] || die "Too many arguments"
|
||||
|
||||
"$GENTOO_BOOTSTRAP_DIR/install_stage3" \
|
||||
install_stage3 \
|
||||
|| die "Failed to install stage3"
|
||||
"$GENTOO_BOOTSTRAP_DIR/chroot" "$GENTOO_BOOTSTRAP_DIR/install_gentoo" \
|
||||
|| die "Failed to prepare gentoo in chroot"
|
||||
|
||||
gentoo_chroot "$GENTOO_BOOTSTRAP_DIR/scripts/main.sh" install_gentoo_in_chroot \
|
||||
|| die "Failed to install gentoo in chroot"
|
||||
}
|
||||
|
||||
main_chroot() {
|
||||
gentoo_chroot "$@" \
|
||||
|| die "Failed to execute script in chroot"
|
||||
}
|
||||
|
||||
main_umount() {
|
||||
gentoo_umount
|
||||
}
|
||||
|
||||
|
||||
################################################
|
||||
# Main dispatch
|
||||
|
||||
# Redirect output to logfiles
|
||||
exec 3>&1
|
||||
trap 'exec 1>&3' 0 1 2 3
|
||||
exec 1>"$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out"
|
||||
ln -sf "$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out" "$GENTOO_BOOTSTRAP_DIR/log.out"
|
||||
einfo "Verbose script output is logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'"
|
||||
|
||||
SCRIPT_ALIAS="$(basename "$0")"
|
||||
if [[ "$SCRIPT_ALIAS" == "main.sh" ]]; then
|
||||
SCRIPT_ALIAS="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
case "$SCRIPT_ALIAS" in
|
||||
"chroot") main_chroot "$@" ;;
|
||||
"install") main_install_full "$@" ;;
|
||||
"install_gentoo") main_install_gentoo "$@" ;;
|
||||
"install_stage3") main_install_stage3 "$@" ;;
|
||||
"install") main_install "$@" ;;
|
||||
"install_gentoo_in_chroot") main_install_gentoo_in_chroot "$@" ;;
|
||||
"umount") main_umount "$@" ;;
|
||||
*) die "Invalid alias '$SCRIPT_ALIAS' was used to execute this script" ;;
|
||||
esac
|
||||
|
|
|
@ -3,9 +3,19 @@
|
|||
[[ "${EXECUTED_IN_CHROOT}" != true ]] \
|
||||
&& { echo "This script must not be executed directly!" >&2; exit 1; }
|
||||
|
||||
# Source the systems profile
|
||||
source /etc/profile
|
||||
export NPROC="$(($(nproc || echo 2) + 1))"
|
||||
|
||||
hostname 'gentoo'
|
||||
# Export nproc variables
|
||||
export NPROC="$(nproc || echo 2)"
|
||||
export NPROC_ONE="$(($NPROC + 1))"
|
||||
|
||||
# Set default makeflags and emerge flags for parallel emerges
|
||||
export MAKEFLAGS="-j$NPROC"
|
||||
export EMERGE_DEFAULT_OPTS="--jobs=$NPROC_ONE --load-average=$NPROC"
|
||||
|
||||
# Set the PS1 to a recognizable value
|
||||
export PS1="(chroot) $PS1"
|
||||
|
||||
# Execute the requested command
|
||||
exec "$@"
|
||||
|
|
|
@ -2,20 +2,32 @@
|
|||
|
||||
source "$GENTOO_BOOTSTRAP_DIR/scripts/protection.sh" || exit 1
|
||||
|
||||
log_stdout() {
|
||||
echo "$*"
|
||||
if { >&3; } 2<> /dev/null; then
|
||||
echo "$*" >&3
|
||||
fi
|
||||
}
|
||||
|
||||
log_stderr() {
|
||||
echo "$*" >&2
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
elog() {
|
||||
echo "[1m *[m $*"
|
||||
log_stdout "[1m *[m $*"
|
||||
}
|
||||
|
||||
einfo() {
|
||||
echo "[1;32m *[m $*"
|
||||
log_stdout "[1;32m *[m $*"
|
||||
}
|
||||
|
||||
ewarn() {
|
||||
echo "[1;33m *[m $*" >&2
|
||||
log_stderr "[1;33m *[m $*"
|
||||
}
|
||||
|
||||
eerror() {
|
||||
echo "[1;31m * ERROR:[m $*" >&2
|
||||
log_stderr "[1;31m * ERROR:[m $*"
|
||||
}
|
||||
|
||||
die() {
|
||||
|
|
Loading…
Reference in New Issue