diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-23 10:58:52 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-23 10:58:52 +0200 |
commit | f17c86eaec4e8f569437994775f0816e29054239 (patch) | |
tree | 87d5d12d1a237a59276a4ac2ed6f7596a35e37b9 | |
parent | 359ce86f43d9b2939517a3352b8d39ea174b97d2 (diff) | |
download | alpine-conf-f17c86eaec4e8f569437994775f0816e29054239.zip |
setup-disk: retry on password mismatch
Retry create luks device if the entered password does not match rather
than exit with error.
fixes https://gitlab.alpinelinux.org/alpine/alpine-conf/-/issues/10514
-rw-r--r-- | setup-disk.in | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/setup-disk.in b/setup-disk.in index c8eb329..b5b8756 100644 --- a/setup-disk.in +++ b/setup-disk.in @@ -1205,14 +1205,28 @@ native_disk_install_lvm() { setup_crypt() { local dev="$1" local dmname="$2" mkdir -p /run/cryptsetup - echo "Preparing partition for encryption." >&2 - echo "You will be prompted for your password at boot." >&2 - echo "If you forget your password, your data will be lost." >&2 - cryptsetup luksFormat --batch-mode --verify-passphrase \ - --type luks2 "$dev" >&2 || return 1 - echo "Enter password again to unlock disk for installation." >&2 - cryptsetup open "$dev" "$dmname" >&2 || return 1 + while true; do + echo "Preparing partition for encryption." >&2 + echo "You will be prompted for your password at boot." >&2 + echo "If you forget your password, your data will be lost." >&2 + cryptsetup luksFormat --batch-mode --verify-passphrase \ + --type luks2 "$dev" >&2 + # Error codes are: 1 wrong parameters, 2 no permission (bad + # passphrase), 3 out of memory, 4 wrong device specified, 5 device + # already exists or device is busy. + # https://man7.org/linux/man-pages/man8/cryptsetup.8.html#RETURN_CODES + case $? in + 2) continue;; + 0) ;; + *) return 1;; + esac + echo "Enter password again to unlock disk for installation." >&2 + cryptsetup open "$dev" "$dmname" >&2 \ + && break + echo "" >&2 + done echo "/dev/mapper/$dmname" + return 0 } native_disk_install() { |