gentoo-install/scripts/main.sh

163 lines
4.0 KiB
Bash
Raw Normal View History

################################################
# 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}")")"
}
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
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
install_stage3() {
[[ $# == 0 ]] || die "Too many arguments"
prepare_installation_environment
partition_device
format_partitions
download_stage3
extract_stage3
}
main_install_gentoo_in_chroot() {
[[ $# == 0 ]] || die "Too many arguments"
# 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
2020-01-03 21:48:49 -01:00
# TODO custom gentoo.conf for /var/db/repos ???
# TODO gpg portage sync
# TODO additional binary repos
# TODO safe dns settings (claranet)
2020-01-03 21:48:49 -01:00
# Mount efi partition
einfo "Mounting efi"
mount_by_partuuid "$PARTITION_UUID_EFI" "/boot/efi"
2020-01-03 21:48:49 -01:00
# Sync portage
einfo "Syncing portage tree"
2020-01-04 10:55:31 -01:00
try emerge-webrsync \
2020-01-03 21:48:49 -01:00
|| die "Failed to sync portage tree"
# Set timezone
einfo "Selecting timezone"
echo "$TIMEZONE" > /etc/timezone \
|| die "Could not write /etc/timezone"
2020-01-04 10:55:31 -01:00
try emerge -v --config sys-libs/timezone-data
2020-01-03 21:48:49 -01:00
# Set locale
einfo "Selecting locale"
echo "$LOCALES" > /etc/locale.gen \
|| die "Could not write /etc/locale.gen"
locale-gen \
|| die "Could not generate locales"
2020-01-04 10:55:31 -01:00
try eselect locale set "$LOCALE"
2020-01-03 21:48:49 -01:00
# Update environment
env_update
2020-01-04 10:55:31 -01:00
# Prepare /etc/portage for autounmask
mkdir_or_die "/etc/portage/package.use"
touch_or_die "/etc/portage/package.use/zz-autounmask"
mkdir_or_die "/etc/portage/package.keywords"
touch_or_die "/etc/portage/package.keywords/zz-autounmask"
# Install git (for git portage overlays)
einfo "Installing git"
try emerge --verbose dev-vcs/git \
|| die "Error while installing git"
#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"
2020-01-02 22:42:31 -01:00
einfo "To chroot into the new system, simply execute the provided 'chroot' wrapper"
}
main_install() {
[[ $# == 0 ]] || die "Too many arguments"
gentoo_umount
2020-01-02 22:42:31 -01:00
install_stage3
gentoo_chroot "$GENTOO_BOOTSTRAP_BIND/scripts/main.sh" install_gentoo_in_chroot
}
main_chroot() {
2020-01-02 22:42:31 -01:00
gentoo_chroot "$@"
}
main_umount() {
gentoo_umount
}
################################################
# Main dispatch
# Instantly kill when pressing ctrl-c
2020-01-04 10:55:31 -01:00
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
exec 3>&1
2020-01-02 21:42:45 -01:00
# Restore old filedescriptor on certain signals
trap 'exec 1>&3; exit 1' 0 1 2 3 RETURN
2020-01-02 21:42:45 -01:00
# Replace stdout with logfole
exec 1>"$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out"
2020-01-02 21:42:45 -01:00
# Link to latest log file
ln -sf "$GENTOO_BOOTSTRAP_DIR/log-$LOGDATE.out" "$GENTOO_BOOTSTRAP_DIR/log.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 "$@" ;;
"install_gentoo_in_chroot") main_install_gentoo_in_chroot "$@" ;;
"umount") main_umount "$@" ;;
*) die "Invalid alias '$SCRIPT_ALIAS' was used to execute this script" ;;
esac