Fixed bug in map saving
This commit is contained in:
parent
4c376dae12
commit
048b39ffe0
|
@ -411,11 +411,6 @@ print_summary_tree() {
|
|||
}
|
||||
|
||||
apply_disk_actions() {
|
||||
# Clean old resolved ids
|
||||
rm -rf "$RESOLVABLE_MAP_DIR" &>/dev/null
|
||||
unset DISK_ID_TO_RESOLVABLE; declare -A -g DISK_ID_TO_RESOLVABLE
|
||||
unset DISK_UUID_TO_DEVICE; declare -A -g DISK_UUID_TO_DEVICE
|
||||
|
||||
local param
|
||||
local current_params=()
|
||||
for param in "${DISK_ACTIONS[@]}"; do
|
||||
|
@ -453,6 +448,11 @@ summarize_disk_actions() {
|
|||
}
|
||||
|
||||
apply_disk_configuration() {
|
||||
# Clean old resolved ids
|
||||
rm -rf "$RESOLVABLE_MAP_DIR" &>/dev/null
|
||||
unset DISK_ID_TO_RESOLVABLE; declare -A -g DISK_ID_TO_RESOLVABLE
|
||||
unset DISK_UUID_TO_DEVICE; declare -A -g DISK_UUID_TO_DEVICE
|
||||
|
||||
summarize_disk_actions
|
||||
|
||||
ask "Do you really want to apply this disk configuration?" \
|
||||
|
|
|
@ -16,7 +16,7 @@ UUID_STORAGE_DIR="$TMP_DIR/uuids"
|
|||
# Backup dir for luks headers
|
||||
LUKS_HEADER_BACKUP_DIR="$TMP_DIR/luks-headers"
|
||||
# Backup dir for luks headers
|
||||
RESOLVABLE_MAP_DIR="$TMP_DIR/resolve-uuids"
|
||||
RESOLVABLE_MAP_DIR="$TMP_DIR/resolved-uuids"
|
||||
|
||||
# Flag to track usage of raid (needed to check for mdadm existence)
|
||||
USED_RAID=false
|
||||
|
@ -26,15 +26,15 @@ USED_LUKS=false
|
|||
# An array of disk related actions to perform
|
||||
DISK_ACTIONS=()
|
||||
# An associative array from disk id to a resolvable string
|
||||
declare -Ax DISK_ID_TO_RESOLVABLE
|
||||
declare -A DISK_ID_TO_RESOLVABLE
|
||||
# An associative from uuid to device
|
||||
declare -Ax DISK_UUID_TO_DEVICE
|
||||
declare -A DISK_UUID_TO_DEVICE
|
||||
# An associative array from disk id to parent gpt disk id (only for partitions)
|
||||
declare -Ax DISK_ID_PART_TO_GPT_ID
|
||||
declare -A DISK_ID_PART_TO_GPT_ID
|
||||
# An associative array to check for existing ids (maps to uuids)
|
||||
declare -Ax DISK_ID_TO_UUID
|
||||
declare -A DISK_ID_TO_UUID
|
||||
# An associative set to check for correct usage of size=remaining in gpt tables
|
||||
declare -Ax DISK_GPT_HAD_SIZE_REMAINING
|
||||
declare -A DISK_GPT_HAD_SIZE_REMAINING
|
||||
|
||||
only_one_of() {
|
||||
local previous=""
|
||||
|
|
|
@ -79,6 +79,24 @@ configure_base_system() {
|
|||
env_update
|
||||
}
|
||||
|
||||
configure_portage() {
|
||||
# Prepare /etc/portage for autounmask
|
||||
mkdir_or_die 0755 "/etc/portage/package.use"
|
||||
touch_or_die 0644 "/etc/portage/package.use/zz-autounmask"
|
||||
mkdir_or_die 0755 "/etc/portage/package.keywords"
|
||||
touch_or_die 0644 "/etc/portage/package.keywords/zz-autounmask"
|
||||
|
||||
einfo "Temporarily installing mirrorselect"
|
||||
try emerge --verbose --oneshot app-portage/mirrorselect
|
||||
|
||||
einfo "Selecting fastest portage mirrors"
|
||||
try mirrorselect -s 4 -b 10 -D
|
||||
|
||||
einfo "Adding ~$GENTOO_ARCH to ACCEPT_KEYWORDS"
|
||||
echo "ACCEPT_KEYWORDS=\"~$GENTOO_ARCH\"" >> /etc/portage/make.conf \
|
||||
|| die "Could not modify /etc/portage/make.conf"
|
||||
}
|
||||
|
||||
install_sshd() {
|
||||
einfo "Installing sshd"
|
||||
install -m0600 -o root -g root "$GENTOO_INSTALL_REPO_DIR/configs/sshd_config" /etc/ssh/sshd_config \
|
||||
|
@ -140,6 +158,25 @@ install_kernel() {
|
|||
fi
|
||||
}
|
||||
|
||||
generate_fstab() {
|
||||
einfo "Generating fstab"
|
||||
install -m0644 -o root -g root "$GENTOO_INSTALL_REPO_DIR/configs/fstab" /etc/fstab \
|
||||
|| die "Could not overwrite /etc/fstab"
|
||||
echo "$(resolve_device_by_id "$DISK_ID_ROOT") / ext4 defaults,noatime,errors=remount-ro,discard 0 1" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
if [[ $IS_EFI == "true" ]]; then
|
||||
echo "$(resolve_device_by_id "$DISK_ID_EFI") /boot/efi vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
else
|
||||
echo "$(resolve_device_by_id "$DISK_ID_BIOS") /boot vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
fi
|
||||
if [[ -v "DISK_ID_SWAP" ]]; then
|
||||
echo "$(resolve_device_by_id "$DISK_ID_SWAP") none swap defaults,discard 0 0" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
fi
|
||||
}
|
||||
|
||||
install_ansible() {
|
||||
einfo "Installing ansible"
|
||||
try emerge --verbose app-admin/ansible
|
||||
|
@ -192,45 +229,18 @@ main_install_gentoo_in_chroot() {
|
|||
# Configure basic system things like timezone, locale, ...
|
||||
configure_base_system
|
||||
|
||||
# Prepare /etc/portage for autounmask
|
||||
mkdir_or_die 0755 "/etc/portage/package.use"
|
||||
touch_or_die 0644 "/etc/portage/package.use/zz-autounmask"
|
||||
mkdir_or_die 0755 "/etc/portage/package.keywords"
|
||||
touch_or_die 0644 "/etc/portage/package.keywords/zz-autounmask"
|
||||
|
||||
einfo "Temporarily installing mirrorselect"
|
||||
try emerge --verbose --oneshot app-portage/mirrorselect
|
||||
|
||||
einfo "Selecting fastest portage mirrors"
|
||||
try mirrorselect -s 4 -b 10 -D
|
||||
|
||||
einfo "Adding ~$GENTOO_ARCH to ACCEPT_KEYWORDS"
|
||||
echo "ACCEPT_KEYWORDS=\"~$GENTOO_ARCH\"" >> /etc/portage/make.conf \
|
||||
|| die "Could not modify /etc/portage/make.conf"
|
||||
# Prepare portage environment
|
||||
configure_portage
|
||||
|
||||
# Install git (for git portage overlays)
|
||||
einfo "Installing git"
|
||||
try emerge --verbose dev-vcs/git
|
||||
|
||||
# Install kernel and initramfs
|
||||
install_kernel
|
||||
|
||||
# Generate a valid fstab file
|
||||
einfo "Generating fstab"
|
||||
install -m0644 -o root -g root "$GENTOO_INSTALL_REPO_DIR/configs/fstab" /etc/fstab \
|
||||
|| die "Could not overwrite /etc/fstab"
|
||||
echo "$(resolve_device_by_id "$DISK_ID_ROOT") / ext4 defaults,noatime,errors=remount-ro,discard 0 1" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
if [[ $IS_EFI == "true" ]]; then
|
||||
echo "$(resolve_device_by_id "$DISK_ID_EFI") /boot/efi vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
else
|
||||
echo "$(resolve_device_by_id "$DISK_ID_BIOS") /boot vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
fi
|
||||
if [[ -v "DISK_ID_SWAP" ]]; then
|
||||
echo "$(resolve_device_by_id "$DISK_ID_SWAP") none swap defaults,discard 0 0" >> /etc/fstab \
|
||||
|| die "Could not append entry to fstab"
|
||||
fi
|
||||
generate_fstab
|
||||
|
||||
# Install and enable dhcpcd
|
||||
einfo "Installing gentoolkit"
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1
|
||||
|
||||
elog() {
|
||||
echo "[1m *[m $*"
|
||||
echo "[[1m+[m] $*"
|
||||
}
|
||||
|
||||
einfo() {
|
||||
echo "[1;32m *[m $*"
|
||||
echo "[[1;32m+[m] $*"
|
||||
}
|
||||
|
||||
ewarn() {
|
||||
echo "[1;33m *[m $*" >&2
|
||||
echo "[[1;33m+[m] $*" >&2
|
||||
}
|
||||
|
||||
eerror() {
|
||||
|
@ -141,7 +141,7 @@ get_device_by_uuid() {
|
|||
get_device_by_stored_uuid() {
|
||||
local key="${1,,}"
|
||||
[[ -v "DISK_UUID_TO_DEVICE[$key]" ]] \
|
||||
|| die "Could not resolve uuid $key to device"
|
||||
|| die "Could not resolve uuid $key to device (not stored)"
|
||||
echo -n "${DISK_UUID_TO_DEVICE[$key]}"
|
||||
}
|
||||
|
||||
|
@ -149,6 +149,29 @@ get_device_by_luks_uuid() {
|
|||
echo -n "/dev/mapper/${1,,}"
|
||||
}
|
||||
|
||||
save_map_entry() {
|
||||
local mapname="$1"
|
||||
local key="$2"
|
||||
local value="$3"
|
||||
mkdir -p "$RESOLVABLE_MAP_DIR/$mapname" \
|
||||
|| die "Could not create '$RESOLVABLE_MAP_DIR/$mapname'"
|
||||
echo -n "$value" > "$RESOLVABLE_MAP_DIR/$mapname/$(base64 -w 0 <<< "$key")"
|
||||
}
|
||||
|
||||
load_map_entries() {
|
||||
local mapname="$1"
|
||||
local lambda="$2"
|
||||
|
||||
local base64_key
|
||||
local key
|
||||
local value
|
||||
for base64_key in "$RESOLVABLE_MAP_DIR/$mapname/"*; do
|
||||
key="$(base64 -d <<< "$(basename "$base64_key")")"
|
||||
value="$(cat "$base64_key")"
|
||||
"$lambda" "$key" "$value"
|
||||
done
|
||||
}
|
||||
|
||||
create_resolve_entry() {
|
||||
local id="$1"
|
||||
local type="$2"
|
||||
|
@ -162,35 +185,25 @@ create_resolve_entry() {
|
|||
'ptuuid') ;& # fallthrough
|
||||
'mdadm')
|
||||
DISK_UUID_TO_DEVICE[$arg]="$device"
|
||||
mkdir -p "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE" \
|
||||
|| die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'"
|
||||
echo -n "$device" > "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/$(base64 -w 0 <<< "$id")"
|
||||
save_map_entry DISK_UUID_TO_DEVICE "$arg" "$device"
|
||||
;;
|
||||
*) die "Cannot add resolvable entry for '$type:$arg' (unknown type)"
|
||||
esac
|
||||
|
||||
DISK_ID_TO_RESOLVABLE[$id]="$type:$arg"
|
||||
mkdir -p "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE" \
|
||||
|| die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'"
|
||||
echo -n "$type:$arg" > "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/$(base64 -w 0 <<< "$id")"
|
||||
save_map_entry DISK_ID_TO_RESOLVABLE "$id" "$type:$arg"
|
||||
}
|
||||
|
||||
load_resolvable_entries() {
|
||||
[[ -d $RESOLVABLE_MAP_DIR ]] \
|
||||
|| return 0
|
||||
local base64_key
|
||||
local key
|
||||
local value
|
||||
for base64_key in "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/"*; do
|
||||
key="$(base64 -d <<< "$(basename "$base64_key")")"
|
||||
value="$(cat "$base64_key")"
|
||||
DISK_ID_TO_RESOLVABLE[$key]="$value"
|
||||
done
|
||||
for base64_key in "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/"*; do
|
||||
key="$(base64 -d <<< "$(basename "$base64_key")")"
|
||||
value="$(cat "$base64_key")"
|
||||
DISK_UUID_TO_DEVICE[$key]="$value"
|
||||
done
|
||||
|
||||
lambda() {
|
||||
DISK_ID_TO_RESOLVABLE[$1]="$2"
|
||||
}; load_map_entries DISK_ID_TO_RESOLVABLE lambda
|
||||
lambda() {
|
||||
DISK_UUID_TO_DEVICE[$1]="$2"
|
||||
}; load_map_entries DISK_UUID_TO_DEVICE lambda
|
||||
}
|
||||
|
||||
resolve_device_by_id() {
|
||||
|
|
Loading…
Reference in New Issue