Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation prompt for k3s-killall.sh and k3s-uninstall.sh #10585

Open
James4Ever0 opened this issue Jul 27, 2024 · 2 comments
Open

Add confirmation prompt for k3s-killall.sh and k3s-uninstall.sh #10585

James4Ever0 opened this issue Jul 27, 2024 · 2 comments

Comments

@James4Ever0
Copy link

James4Ever0 commented Jul 27, 2024

Is your feature request related to a problem? Please describe.

These two scripts have no confirmation and it is like having rm -rf /* over the user's fingertips.

Describe the solution you'd like

Add an overridable prompt which will prevent most human errors and allow headless operation to run smoothly by passing an environment variable.

#!/bin/bash

# Check if NO_CONFIRMATION environment variable is set
if [ -z "$NO_CONFIRMATION" ]; then
  # Prompt user for confirmation
  read -p "Are you sure you want to perform this operation? [y/N] " confirm
  if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
    echo "Operation cancelled."
    exit 1
  fi
fi

# Perform operation here
echo "Performing operation..."

Describe alternatives you've considered

Commandline argument -y will do the same as the environment variable, and more convenient.

#!/bin/bash

# Check if either -y option or NO_CONFIRMATION environment variable is set
if [[ $1 == "-y" || ! -z "$NO_CONFIRMATION" ]]; then
  # Skip confirmation
  echo "Skipping confirmation."
else
  # Prompt user for confirmation
  read -p "Are you sure you want to perform this operation? [y/N] " confirm
  if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
    echo "Operation cancelled."
    exit 1
  fi
fi

# Perform operation here
echo "Performing operation..."

Additional context

Help message can be added:

#!/bin/bash

# Function to display help message
display_help() {
  echo "Usage: <script_name>.sh [OPTIONS]"
  echo "Options:"
  echo "  -y             Skip confirmation"
  echo "  -h             Display this help message"
  echo "Environment Variable:"
  echo "  NO_CONFIRMATION   Set this variable to skip confirmation"
  exit 0
}

# Check if -h flag is present
if [[ $1 == "-h" ]]; then
  display_help
fi

The scripts within install.sh are using /bin/sh instead of /bin/bash so some rewrites are necessary if the example code does not work as intended.

Copy link
Contributor

This repository uses a bot to automatically label issues which have not had any activity (commit/comment/label) for 45 days. This helps us manage the community issues better. If the issue is still relevant, please add a comment to the issue so the bot can remove the label and we know it is still valid. If it is no longer relevant (or possibly fixed in the latest release), the bot will automatically close the issue in 14 days. Thank you for your contributions.

@James4Ever0
Copy link
Author

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

No branches or pull requests

1 participant