2019-12-31 14:28:42 -01:00
|
|
|
################################################
|
|
|
|
# Initialize script environment
|
|
|
|
|
|
|
|
# Find the directory this script is stored in. (from: http://stackoverflow.com/questions/59895)
|
|
|
|
get_source_dir() {
|
|
|
|
local source="${BASH_SOURCE[0]}"
|
|
|
|
while [[ -h "${source}" ]]
|
|
|
|
do
|
|
|
|
local tmp="$(cd -P "$(dirname "${source}")" && pwd)"
|
|
|
|
source="$(readlink "${source}")"
|
|
|
|
[[ "${source}" != /* ]] && source="${tmp}/${source}"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -n "$(realpath "$(dirname "${source}")")"
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:28:16 -01:00
|
|
|
export GENTOO_BOOTSTRAP_DIR_ORIGINAL="$(dirname "$(get_source_dir)")"
|
|
|
|
export GENTOO_BOOTSTRAP_DIR="$GENTOO_BOOTSTRAP_DIR_ORIGINAL"
|
2019-12-31 14:28:42 -01:00
|
|
|
export GENTOO_BOOTSTRAP_SCRIPT_ACTIVE=true
|
|
|
|
export GENTOO_BOOTSTRAP_SCRIPT_PID=$$
|
2020-01-02 21:28:16 -01:00
|
|
|
LOGDATE="$(date +%Y%m%d-%H%M%S)"
|
2019-12-31 14:28:42 -01:00
|
|
|
|
|
|
|
umask 0077
|
|
|
|
|
|
|
|
source "$GENTOO_BOOTSTRAP_DIR/scripts/utils.sh"
|
|
|
|
source "$GENTOO_BOOTSTRAP_DIR/scripts/config.sh"
|
|
|
|
source "$GENTOO_BOOTSTRAP_DIR/scripts/functions.sh"
|
|
|
|
|
|
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
[[ $EUID == 0 ]] \
|
|
|
|
|| die "Must be root"
|
|
|
|
|
|
|
|
|
|
|
|
################################################
|
|
|
|
# Functions
|
|
|
|
|
2020-01-02 21:28:16 -01:00
|
|
|
install_stage3() {
|
2019-12-31 14:28:42 -01:00
|
|
|
[[ $# == 0 ]] || die "Too many arguments"
|
|
|
|
|
|
|
|
prepare_installation_environment
|
|
|
|
partition_device
|
|
|
|
format_partitions
|
|
|
|
download_stage3
|
|
|
|
extract_stage3
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:28:16 -01:00
|
|
|
main_install_gentoo_in_chroot() {
|
2019-12-31 14:28:42 -01:00
|
|
|
[[ $# == 0 ]] || die "Too many arguments"
|
|
|
|
|
2020-01-02 21:28:16 -01:00
|
|
|
# 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 '$'"
|
2019-12-31 14:28:42 -01:00
|
|
|
|
|
|
|
#get kernel
|
|
|
|
|
|
|
|
#compile minimal kernel to boot system
|
|
|
|
|
|
|
|
#reboot?
|
|
|
|
|
|
|
|
#mount boot partition
|
|
|
|
|
|
|
|
#create kernel
|
|
|
|
|
|
|
|
#create_ansible_user
|
|
|
|
#generate_fresh keys to become mgmnt ansible user
|
|
|
|
#install_ansible
|
|
|
|
|
|
|
|
einfo "Gentoo installation complete"
|
|
|
|
einfo "Dropping into chrooted shell"
|
|
|
|
su
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:28:16 -01:00
|
|
|
main_install() {
|
2019-12-31 14:28:42 -01:00
|
|
|
[[ $# == 0 ]] || die "Too many arguments"
|
|
|
|
|
2020-01-02 22:29:17 -01:00
|
|
|
gentoo_umount
|
2020-01-02 21:28:16 -01:00
|
|
|
install_stage3 \
|
2019-12-31 14:28:42 -01:00
|
|
|
|| die "Failed to install stage3"
|
2020-01-02 21:28:16 -01:00
|
|
|
|
|
|
|
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
|
2019-12-31 14:28:42 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
################################################
|
|
|
|
# Main dispatch
|
|
|
|
|
2020-01-02 22:29:17 -01:00
|
|
|
# Instantly kill when pressing ctrl-c
|
|
|
|
trap "kill $GENTOO_BOOTSTRAP_SCRIPT_PID" INT
|
|
|
|
|
2020-01-02 21:42:45 -01:00
|
|
|
einfo "Verbose script output will be logged to: '$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out'"
|
|
|
|
# Save old stdout
|
2020-01-02 21:28:16 -01:00
|
|
|
exec 3>&1
|
2020-01-02 21:42:45 -01:00
|
|
|
# Restore old filedescriptor on certain signals
|
2020-01-02 22:29:17 -01:00
|
|
|
trap 'exec 1>&3; exit 1' 0 1 2 3 RETURN
|
2020-01-02 21:42:45 -01:00
|
|
|
# Replace stdout with logfole
|
2020-01-02 21:28:16 -01:00
|
|
|
exec 1>"$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out"
|
2020-01-02 21:42:45 -01:00
|
|
|
# Link to latest log file
|
2020-01-02 21:28:16 -01:00
|
|
|
ln -sf "$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out" "$GENTOO_BOOTSTRAP_DIR/log.out"
|
|
|
|
|
2019-12-31 14:28:42 -01:00
|
|
|
SCRIPT_ALIAS="$(basename "$0")"
|
2020-01-02 21:28:16 -01:00
|
|
|
if [[ "$SCRIPT_ALIAS" == "main.sh" ]]; then
|
|
|
|
SCRIPT_ALIAS="$1"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2019-12-31 14:28:42 -01:00
|
|
|
case "$SCRIPT_ALIAS" in
|
2020-01-02 21:28:16 -01:00
|
|
|
"chroot") main_chroot "$@" ;;
|
|
|
|
"install") main_install "$@" ;;
|
|
|
|
"install_gentoo_in_chroot") main_install_gentoo_in_chroot "$@" ;;
|
|
|
|
"umount") main_umount "$@" ;;
|
2019-12-31 14:28:42 -01:00
|
|
|
*) die "Invalid alias '$SCRIPT_ALIAS' was used to execute this script" ;;
|
|
|
|
esac
|