From 0c1256e60ab430402ad5dcd11f2368bb065fa958 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?=
 <vomindoraan@gmail.com>
Date: Wed, 26 Dec 2018 17:01:26 +0100
Subject: [PATCH] Read user input properly in linux_install.sh for Gentoo
 (#4395)

* Change spaces to tabs on two lines

The rest of the file uses tabs

* Read user input in a non-terrible, non-hacky way

* Remove unnecessary tee call

* read -p is not POSIX

* Add missing $ to echo GENTOO_WARNING

* Replace non-POSIX echo -n with printf

* Use cd ... || exit 1 in case git clone fails

* Add missing sudo

Thanks @snortwolf

* Undo replacing tee with >>
---
 util/linux_install.sh | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/util/linux_install.sh b/util/linux_install.sh
index 70b389c0da..d6e6b86cdc 100755
--- a/util/linux_install.sh
+++ b/util/linux_install.sh
@@ -32,7 +32,7 @@ if grep ID /etc/os-release | grep -qE "fedora"; then
 elif grep ID /etc/os-release | grep -qE 'debian|ubuntu'; then
 	DEBIAN_FRONTEND=noninteractive
 	DEBCONF_NONINTERACTIVE_SEEN=true
-        export DEBIAN_FRONTEND DEBCONF_NONINTERACTIVE_SEEN
+	export DEBIAN_FRONTEND DEBCONF_NONINTERACTIVE_SEEN
 	sudo apt-get update
 	sudo apt-get install \
 		build-essential \
@@ -70,20 +70,18 @@ elif grep ID /etc/os-release | grep -q 'arch\|manjaro'; then
 		wget \
 		zip
 	git clone https://aur.archlinux.org/dfu-programmer.git /tmp/dfu-programmer
-	cd /tmp/dfu-programmer
+	cd /tmp/dfu-programmer || exit 1
 	makepkg -sic
 	rm -rf /tmp/dfu-programmer/
 
 elif grep ID /etc/os-release | grep -q gentoo; then
-	echo GENTOO_WARNING | fmt
-	echo -n "Proceed (y/N)? "
-	old_stty_cfg=$(stty -g)
-	stty raw -echo
-	answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
-	stty $old_stty_cfg
-	if echo "$answer" | grep -iq "^y" ;then
+	echo "$GENTOO_WARNING" | fmt
+	printf "\nProceed (y/N)? "
+	read -r answer
+	if echo "$answer" | grep -iq "^y"; then
 		sudo touch /etc/portage/package.use/qmkfirmware
-		echo "sys-devel/gcc multilib" | sudo tee --append /etc/portage/package.use/qmkfirmware > /dev/null
+		# tee is used here since sudo doesn't apply to >>
+		echo "sys-devel/gcc multilib" | sudo tee --append /etc/portage/package.use/qmkfirmware >/dev/null
 		sudo emerge -auN \
 			app-arch/unzip \
 			app-arch/zip \