installer: autodetect cpu vendor

This commit is contained in:
Daniel Langbein 2021-05-13 20:12:57 +02:00
parent 2125bd0c9b
commit 8fc8fa8944
4 changed files with 46 additions and 15 deletions

View File

@ -2,8 +2,8 @@
_pkgname=installer _pkgname=installer
_reponame=arch _reponame=arch
pkgname="de-p1st-$_pkgname" pkgname="de-p1st-$_pkgname"
pkgver=0.1.0 pkgver=0.1.1
pkgrel=2 pkgrel=1
pkgdesc="Bash script to install Arch Linux" pkgdesc="Bash script to install Arch Linux"
arch=('any') arch=('any')
url="https://codeberg.org/privacy1st/${_reponame}" url="https://codeberg.org/privacy1st/${_reponame}"

View File

@ -152,6 +152,25 @@ function run_pacstrap() {
;; ;;
esac esac
# If CPU_VENDOR is not empty, then
if [ -n "${CPU_VENDOR}" ]; then
case "${CPU_VENDOR}" in
amd)
PKGS+=('de-p1st-ucode-amd')
;;
intel)
PKGS+=('de-p1st-ucode-intel')
;;
none)
PKGS+=('de-p1st-ucode-placeholder')
;;
*)
echo "Invalid option '${CPU_VENDOR}'!"
return 1
;;
esac
fi
local args=() local args=()
if [ "${PACSTRAP_INTERACTIVE}" = "1" ]; then if [ "${PACSTRAP_INTERACTIVE}" = "1" ]; then
args+=('-i') # run interactively args+=('-i') # run interactively
@ -286,6 +305,9 @@ function main() {
check_network || return $? check_network || return $?
# out: BIOS_TYPE, FS, HOSTNAME, USERNAME, USER_PWD, LUKS_PWD # out: BIOS_TYPE, FS, HOSTNAME, USERNAME, USER_PWD, LUKS_PWD
get_user_input || return $? get_user_input || return $?
# in: CPU_VENDOR (optional)
# out: CPU_VENDOR
get_cpu_vendor || return $?
# in: FS # in: FS
# out: FS_DEFAULT_MOUNT_OPTIONS # out: FS_DEFAULT_MOUNT_OPTIONS

View File

@ -19,8 +19,8 @@ FS=BTRFS
FS_CHOSEN_MOUNT_OPTIONS=('noatime') FS_CHOSEN_MOUNT_OPTIONS=('noatime')
# If not booted into the target system, these values should be set: # If not booted into the target system, these values should be set:
# CPU_VENDOR: "amd", "intel" or "none" # CPU_VENDOR: "autodetect", "amd", "intel" or "none"
CPU_VENDOR=none CPU_VENDOR=autodetect
BIOS_TYPE=uefi BIOS_TYPE=uefi
# If set to "1", then the data, boot and luks partitions # If set to "1", then the data, boot and luks partitions

View File

@ -52,22 +52,31 @@ function space_separated_to_array() {
} }
function get_cpu_vendor() { function get_cpu_vendor() {
# @pre
# CPU_VENDOR ("", "autodetect")
# @post # @post
# CPU_VENDOR ("amd", "intel", "none") # CPU_VENDOR ("amd", "intel", "none", "")
if [ -z "${CPU_VENDOR}" ]; then if [[ -z "${CPU_VENDOR}" ]] || [[ "${CPU_VENDOR}" == "autodetect" ]]; then
# if CPU_VENDOR has no value yet, ask user for input!
local vendor_id # If run virtual environment (e.g. VirtualBox) then no CPU microcode is required
vendor_id=$(cat /proc/cpuinfo | grep vendor_id | head -1 | sed 's|vendor_id\s*:\s*||') if cat /proc/cpuinfo | grep '^flags.*hypervisor'; then
echo "Detected virtual environment."
CPU_VENDOR="none"
if [ "$vendor_id" = "AuthenticAMD" ]; then
CPU_VENDOR="amd"
elif [ "$vendor_id" = "GenuineIntel" ]; then
CPU_VENDOR="intel"
else else
echo "Unknown CPU vendor: $vendor_id" local vendor_id
return 1 vendor_id=$(cat /proc/cpuinfo | grep vendor_id | head -1 | sed 's|vendor_id\s*:\s*||')
if [ "$vendor_id" = "AuthenticAMD" ]; then
CPU_VENDOR="amd"
elif [ "$vendor_id" = "GenuineIntel" ]; then
CPU_VENDOR="intel"
else
echo "Unknown CPU vendor"
return 1
fi
fi fi
fi fi
} }