Skip to content

Commit

Permalink
refactor(webinstall): Make lines shorter than ~80 characters
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Apr 25, 2024
1 parent eb06256 commit 4bd702c
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions tools/webinstall/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@ get_user_response() {
_RETVAL="$_gur_read_answer"
}

# prompt_user_yes_no asks the user a question which must be answered with yes or no. Returns a boolean value.
# prompt_yes_no asks the user a question which must be answered with yes or no.
# Returns a boolean value.
# $1: question
# $2: default answer
# Returns:
# _RETVAL: true for "yes", false for "no"
prompt_user_yes_no() {
prompt_yes_no() {
while true;
do
get_user_response "$1" "$2"
Expand Down Expand Up @@ -241,8 +242,8 @@ do_cmd() {

# Retry with root if the user wants to, otherwise exit
# with the return value of the command
if [ "$ASK_SUDO" = "n" ] || \
prompt_user_yes_no "do you want to retry with root from now on? [y/N]: " "n"; then
if [ "$ASK_SUDO" = "n" ] || prompt_yes_no \
"do you want to retry with root from now on? [y/N]: " "n"; then
# Check if we have a tty and run with it if we do,
# otherwise exit with an error
# This is because sudo requires a tty to input the password
Expand Down Expand Up @@ -1070,7 +1071,7 @@ install_linux_gnu() {

_idd_recommended=""

if prompt_user_yes_no "install recommended dependencies? [y/N]: " "n"; then
if prompt_yes_no "install recommended dependencies? [y/N]: " "n"; then
_idd_recommended="--no-install-recommends"
else
_idd_recommended="--install-recommends"
Expand All @@ -1089,9 +1090,9 @@ install_linux_gnu() {
cd - 1> /dev/null || exit
$RM -rf /tmp/kraftkit-bin
else
_ilg_msg=$(printf "error: %s%s%s" \
"Unsupported Linux distribution. " \
"Try downloading the tar.gz file from " \
_ilg_msg=$(printf "error: %s%s%s" \
"Unsupported Linux distribution. " \
"Try downloading the tar.gz file from " \
"https://github.com/unikraft/kraftkit or switch to manual mode" \
)
err "$_ilg_msg"
Expand All @@ -1113,9 +1114,9 @@ install_linux_musl() {
)
do_cmd "$_ilm_cmd"
else
_ilm_msg=$(printf "error: %s%s%s" \
"Unsupported Linux distribution. " \
"Try downloading the tar.gz file from " \
_ilm_msg=$(printf "error: %s%s%s" \
"Unsupported Linux distribution. " \
"Try downloading the tar.gz file from " \
"https://github.com/unikraft/kraftkit or switch to manual mode" \
)
err "$_ilm_msg"
Expand Down Expand Up @@ -1187,20 +1188,20 @@ install_linux_manual() {
"[y/N]: " \
)

if prompt_user_yes_no "$_ill_prompt_msg" "n"; then
if prompt_yes_no "$_ill_prompt_msg" "n"; then
PREFIX="$($DIRNAME "$_ill_kraft_path")"
else
err "fatal: kraft binary already installed."
fi
else

if prompt_user_yes_no "change the install prefix? [$PREFIX] [y/N]: " "n"; then
if prompt_yes_no "change the install prefix? [$PREFIX] [y/N]: " "n"; then
get_user_response "what should the prefix be? [$PREFIX]: " "$PREFIX"
PREFIX="$_RETVAL"
fi

if [ ! -d "$PREFIX" ]; then
if prompt_user_yes_no "prefix does not exist, create? [y/N]: " "n"; then
if prompt_yes_no "prefix does not exist, create? [y/N]: " "n"; then
do_cmd "$MKDIR -p $PREFIX"
else
err "fatal: prefix does not exist."
Expand Down Expand Up @@ -1274,19 +1275,19 @@ install_darwin_manual() {
"[y/N]: " \
)

if prompt_user_yes_no "$_idr_prompt_msg" "n"; then
if prompt_yes_no "$_idr_prompt_msg" "n"; then
PREFIX="$($DIRNAME "$_idr_kraft_path")"
else
err "fatal: kraft binary already installed."
fi
else
if prompt_user_yes_no "change the install prefix? [$PREFIX] [y/N]: " "n"; then
if prompt_yes_no "change the install prefix? [$PREFIX] [y/N]: " "n"; then
get_user_response "what should the prefix be? [$PREFIX]: " "$PREFIX"
PREFIX="$_RETVAL"
fi

if [ ! -d "$PREFIX" ]; then
if prompt_user_yes_no "prefix does not exist, create? [y/N]: " "n"; then
if prompt_yes_no "prefix does not exist, create? [y/N]: " "n"; then
do_cmd "$MKDIR -p $PREFIX"
else
err "fatal: prefix does not exist."
Expand Down Expand Up @@ -1429,7 +1430,7 @@ install_dependencies_gnu() {
say_debug "Installing dependencies: $_idd_list"

_idd_recommended=""
if prompt_user_yes_no "install recommended dependencies? [y/N]: " "n"; then
if prompt_yes_no "install recommended dependencies? [y/N]: " "n"; then
_idd_recommended="--no-install-recommends"
else
_idd_recommended="--install-recommends"
Expand Down Expand Up @@ -1517,7 +1518,8 @@ install_completions() {

_inc_arch="$1"

if ! prompt_user_yes_no "Do you want to install command completions? [Y/n]: " "y"; then
if ! prompt_yes_no \
"Do you want to install command completions? [Y/n]: " "y"; then
return 0
fi

Expand Down Expand Up @@ -1553,12 +1555,14 @@ install_completions() {
elif [ -z "$_inc_answer" ]; then
printf "No shell provided. Please try again or exit with Ctrl+C\n"
else
printf "Shell %s not supported. Please try again or exit with Ctrl+C\n" "$_inc_answer"
printf "Shell %s not supported. " \
"Please try again or exit with Ctrl+C\n" "$_inc_answer"
fi
done

if [ -f "$_inc_kraft_config_file" ]; then
if ! prompt_user_yes_no "kraft completions already exist, overwrite? [Y/n]: " "y"; then
if ! prompt_yes_no \
"kraft completions already exist, overwrite? [Y/n]: " "y"; then
return 0
fi
fi
Expand Down Expand Up @@ -1632,7 +1636,7 @@ arg_parse() {
check_autoinstall() {
_cai_auto_install=""

if prompt_user_yes_no "install kraftkit using package manager? [Y/n]: " "y"; then
if prompt_yes_no "install kraftkit using package manager? [Y/n]: " "y"; then
say "installing kraftkit via package manager..."
else
_cai_auto_install="n"
Expand Down

0 comments on commit 4bd702c

Please sign in to comment.