Skip to content

feat: added input validation in installer#26

Open
Ayush4958 wants to merge 1 commit into
TheCodeVerseHub:mainfrom
Ayush4958:input-validation-installer
Open

feat: added input validation in installer#26
Ayush4958 wants to merge 1 commit into
TheCodeVerseHub:mainfrom
Ayush4958:input-validation-installer

Conversation

@Ayush4958
Copy link
Copy Markdown

Summary

I had added input validation and safety checks in installation process which will prevent user to enter invalid input during installlation.

Changes

  • Validate Disk Selection
  • Prevent an accidental formatting , check if the disk is mounted or not , checks for disk labels (archiso/cvh/codeverse)
  • Safer Hostname & Username Input , re-try had been limited upto 3 attempt at single run

Related Issue

Fix #16

Checklist

  • Scope is focused (no unrelated changes)
  • Docs updated (if needed)
  • Scripts/configs changed were tested

Signed-off-by: Ayush <bhandariayush935@gmail.com>
Copy link
Copy Markdown
Contributor

@youngcoder45 youngcoder45 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh looks good to me just want a review from @sinisterMage

Comment thread scripts/install.sh
log_warn "Invalid username '$USERNAME'. (Attempt $attempt/$max_attempts)"
echo -e " ${DIM}Usernames must start with a letter or underscore,${NC}"
echo -e " ${DIM}and contain only lowercase letters, digits, - or _.${NC}"
echo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds additional input validation and safety checks to the interactive installer flow to reduce the risk of destructive actions (e.g., wiping the wrong disk) due to invalid user input.

Changes:

  • Adds live-boot medium detection and excludes it from install targets (including --disk preselection).
  • Improves disk selection UX with detailed disk info and a confirmation prompt; adds retry limits for invalid selections.
  • Adds retry-limited validation loops for hostname and username prompts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/install.sh
Comment on lines +107 to +115
# Block partitions ,only allow whole disks
if [[ "$2" =~ [0-9]$ ]] && [[ -n "$(lsblk -dno PKNAME "$2" 2>/dev/null)" ]]; then
echo -e "${RED}[ERROR]${NC} '$2' appears to be a partition, not a whole disk."
echo -e " Please specify the parent disk instead (e.g. /dev/sda, /dev/nvme0n1)."
echo -e " Available disks :-"
lsblk -dno NAME,SIZE,MODEL | grep -vE "^(loop|sr|rom|fd|zram)" | \
awk '{printf " /dev/%-10s %s\n", $1, $2}'
exit 1
fi
Comment thread scripts/install.sh
Comment on lines +118 to +120
echo -e "${RED}[ERROR]${NC} '$2' is the live boot medium! You cannot install to it."
echo -e "-Select a different disk."
exit 1
Comment thread scripts/install.sh
Comment on lines +305 to +307
# Check if the disk holds the archiso label
if lsblk -no LABEL "$dev" 2>/dev/null | grep -qiE "(archiso|cvh|codeverse)"; then
return 0
Comment thread scripts/install.sh
Comment on lines +107 to +115
# Block partitions ,only allow whole disks
if [[ "$2" =~ [0-9]$ ]] && [[ -n "$(lsblk -dno PKNAME "$2" 2>/dev/null)" ]]; then
echo -e "${RED}[ERROR]${NC} '$2' appears to be a partition, not a whole disk."
echo -e " Please specify the parent disk instead (e.g. /dev/sda, /dev/nvme0n1)."
echo -e " Available disks :-"
lsblk -dno NAME,SIZE,MODEL | grep -vE "^(loop|sr|rom|fd|zram)" | \
awk '{printf " /dev/%-10s %s\n", $1, $2}'
exit 1
fi
Comment thread scripts/install.sh
Comment on lines +118 to +120
echo -e "${RED}[ERROR]${NC} '$2' is the live boot medium! You cannot install to it."
echo -e "-Select a different disk."
exit 1
Comment thread scripts/install.sh
Comment on lines +305 to +307
# Check if the disk holds the archiso label
if lsblk -no LABEL "$dev" 2>/dev/null | grep -qiE "(archiso|cvh|codeverse)"; then
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add input validation to installer

3 participants