Use sane script locations and add help menu
This commit is contained in:
parent
a7225d68a5
commit
a531945dbb
|
@ -0,0 +1,6 @@
|
||||||
|
- root authorized_keys support
|
||||||
|
- generalize ansible -> any infrastructure management by allowing only root ssh login.
|
||||||
|
- zfs support
|
||||||
|
- dracut -> genkernel
|
||||||
|
- save meta information to /var/db/gentoo-install
|
||||||
|
- systemd settings pls
|
|
@ -1,7 +1,3 @@
|
||||||
source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1
|
|
||||||
source "$GENTOO_INSTALL_REPO_DIR/scripts/internal_config.sh" || exit 1
|
|
||||||
|
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
# Disk configuration
|
# Disk configuration
|
||||||
|
|
||||||
|
@ -10,7 +6,7 @@ source "$GENTOO_INSTALL_REPO_DIR/scripts/internal_config.sh" || exit 1
|
||||||
#
|
#
|
||||||
# You can also create your own scheme using the functions provided in internal_config.sh,
|
# You can also create your own scheme using the functions provided in internal_config.sh,
|
||||||
# if you need something tailored to your specific system. Generally supported is
|
# if you need something tailored to your specific system. Generally supported is
|
||||||
# any combination of RAID0/1, luks, btrfs and the usual filesystems (ext4, fat)
|
# any combination of RAID0/1, luks, zfs, btrfs and the usual filesystems (ext4, fat)
|
||||||
# Have a look at the implementation of the default schemes, but be aware that you
|
# Have a look at the implementation of the default schemes, but be aware that you
|
||||||
# most likely don't want to implement your own scheme.
|
# most likely don't want to implement your own scheme.
|
||||||
#
|
#
|
|
@ -0,0 +1,110 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
################################################
|
||||||
|
# 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_INSTALL_REPO_DIR_ORIGINAL="$(get_source_dir)"
|
||||||
|
export GENTOO_INSTALL_REPO_DIR="$GENTOO_INSTALL_REPO_DIR_ORIGINAL"
|
||||||
|
export GENTOO_INSTALL_REPO_SCRIPT_ACTIVE=true
|
||||||
|
export GENTOO_INSTALL_REPO_SCRIPT_PID=$$
|
||||||
|
|
||||||
|
umask 0077
|
||||||
|
|
||||||
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/utils.sh"
|
||||||
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/internal_config.sh"
|
||||||
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/functions.sh"
|
||||||
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/main.sh"
|
||||||
|
|
||||||
|
|
||||||
|
################################################
|
||||||
|
# Main dispatch
|
||||||
|
|
||||||
|
# Instantly kill when pressing ctrl-c
|
||||||
|
trap 'kill "$GENTOO_INSTALL_REPO_SCRIPT_PID"' INT
|
||||||
|
|
||||||
|
ACTION=""
|
||||||
|
CONFIG="$GENTOO_INSTALL_REPO_DIR/config.sh"
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
""|"help"|"--help"|"-help"|"-h")
|
||||||
|
echo "Usage: $0 [opts]... <action>"
|
||||||
|
echo "Performs a minimal gentoo installation. See https://github.com/oddlama/gentoo-install"
|
||||||
|
echo "for more information."
|
||||||
|
echo " location (config.sh)"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -c, --config <CONFIG> Use the given configuration file instead of the default"
|
||||||
|
echo " location (config.sh)"
|
||||||
|
echo ""
|
||||||
|
echo "Actions:"
|
||||||
|
echo " -i, --install Installs gentoo using the configuration"
|
||||||
|
echo " provided in config.sh"
|
||||||
|
echo " -R, --chroot Chroot into an existing system. The root filesystem"
|
||||||
|
echo " is mounted automatically based on the partition"
|
||||||
|
echo " UUIDs (generated when installing for the first time),"
|
||||||
|
echo " and unmounted when the chroot exits"
|
||||||
|
echo " -u, --umount Try to unmount all associated mountpoints. (Only needed"
|
||||||
|
echo " if anything gets forcefully interrupted)"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"-c"|"--config")
|
||||||
|
[[ -f "$2" ]] \
|
||||||
|
|| die "Config file not found: '$2'"
|
||||||
|
CONFIG="$(realpath "$2" 2>/dev/null)"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"-R"|"--chroot")
|
||||||
|
[[ -z $ACTION ]] || die "Multiple actions given"
|
||||||
|
ACTION="chroot"
|
||||||
|
;;
|
||||||
|
"-i"|"--install")
|
||||||
|
[[ -z $ACTION ]] || die "Multiple actions given"
|
||||||
|
ACTION="install"
|
||||||
|
;;
|
||||||
|
"-u"|"--umount"|"--unmount")
|
||||||
|
[[ -z $ACTION ]] || die "Multiple actions given"
|
||||||
|
ACTION="umount"
|
||||||
|
;;
|
||||||
|
"__install_gentoo_in_chroot")
|
||||||
|
ACTION="__install_gentoo_in_chroot"
|
||||||
|
;;
|
||||||
|
*) die "Invalid option '$1'" ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Load config
|
||||||
|
[[ -z "${CONFIG%%$GENTOO_INSTALL_REPO_DIR*}" ]] \
|
||||||
|
|| die "Configuration file must be inside the installation directory. This is needed so it is accessible from within the chroot environment."
|
||||||
|
|
||||||
|
source "$CONFIG"
|
||||||
|
[[ $I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY == "true" ]] \
|
||||||
|
|| die "You have not properly read the config. Edit the config file and set I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=true to continue."
|
||||||
|
|
||||||
|
preprocess_config
|
||||||
|
[[ $EUID == 0 ]] \
|
||||||
|
|| die "Must be root"
|
||||||
|
|
||||||
|
mkdir_or_die 0755 "$TMP_DIR"
|
||||||
|
|
||||||
|
case "$ACTION" in
|
||||||
|
"chroot") main_chroot "$@" ;;
|
||||||
|
"install") main_install "$@" ;;
|
||||||
|
"umount") main_umount "$@" ;;
|
||||||
|
"__install_gentoo_in_chroot") main_install_gentoo_in_chroot "$@" ;;
|
||||||
|
*) die "Invalid action '$ACTION'" ;;
|
||||||
|
esac
|
|
@ -1 +0,0 @@
|
||||||
main.sh
|
|
|
@ -1,41 +1,4 @@
|
||||||
#!/bin/bash
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
################################################
|
|
||||||
# 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_INSTALL_REPO_DIR_ORIGINAL="$(dirname "$(get_source_dir)")"
|
|
||||||
export GENTOO_INSTALL_REPO_DIR="$GENTOO_INSTALL_REPO_DIR_ORIGINAL"
|
|
||||||
export GENTOO_INSTALL_REPO_SCRIPT_ACTIVE=true
|
|
||||||
export GENTOO_INSTALL_REPO_SCRIPT_PID=$$
|
|
||||||
|
|
||||||
umask 0077
|
|
||||||
|
|
||||||
source "$GENTOO_INSTALL_REPO_DIR/scripts/utils.sh"
|
|
||||||
source "$GENTOO_INSTALL_REPO_DIR/scripts/config.sh"
|
|
||||||
source "$GENTOO_INSTALL_REPO_DIR/scripts/functions.sh"
|
|
||||||
|
|
||||||
[[ $I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY == "true" ]] \
|
|
||||||
|| die "You have not properly read the config. Set I_HAVE_READ_AND_EDITED_THE_CONFIG_PROPERLY=true to continue."
|
|
||||||
|
|
||||||
preprocess_config
|
|
||||||
|
|
||||||
mkdir_or_die 0755 "$TMP_DIR"
|
|
||||||
[[ $EUID == 0 ]] \
|
|
||||||
|| die "Must be root"
|
|
||||||
|
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
|
@ -433,35 +396,15 @@ main_install() {
|
||||||
|
|
||||||
[[ $IS_EFI == "true" ]] \
|
[[ $IS_EFI == "true" ]] \
|
||||||
&& mount_efivars
|
&& mount_efivars
|
||||||
gentoo_chroot "$GENTOO_INSTALL_REPO_BIND/scripts/main.sh" install_gentoo_in_chroot
|
gentoo_chroot "$GENTOO_INSTALL_REPO_BIND/scripts/main.sh" __install_gentoo_in_chroot
|
||||||
gentoo_umount
|
gentoo_umount
|
||||||
}
|
}
|
||||||
|
|
||||||
main_chroot() {
|
main_chroot() {
|
||||||
gentoo_chroot "$@"
|
gentoo_chroot "$@"
|
||||||
|
gentoo_umount
|
||||||
}
|
}
|
||||||
|
|
||||||
main_umount() {
|
main_umount() {
|
||||||
gentoo_umount
|
gentoo_umount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
################################################
|
|
||||||
# Main dispatch
|
|
||||||
|
|
||||||
# Instantly kill when pressing ctrl-c
|
|
||||||
trap 'kill "$GENTOO_INSTALL_REPO_SCRIPT_PID"' INT
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ elog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
einfo() {
|
einfo() {
|
||||||
echo "[[1;32m+[m] $*"
|
echo "[[1;32m+[m] [1;33m$*[m"
|
||||||
}
|
}
|
||||||
|
|
||||||
ewarn() {
|
ewarn() {
|
||||||
|
@ -13,12 +13,13 @@ ewarn() {
|
||||||
}
|
}
|
||||||
|
|
||||||
eerror() {
|
eerror() {
|
||||||
echo " [1;31m* ERROR:[m $*" >&2
|
echo "[1;31merror:[m $*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
eerror "$*"
|
eerror "$*"
|
||||||
kill "$GENTOO_INSTALL_REPO_SCRIPT_PID"
|
[[ $$ == $GENTOO_INSTALL_REPO_SCRIPT_PID ]] \
|
||||||
|
|| kill "$GENTOO_INSTALL_REPO_SCRIPT_PID"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue