Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/cmd_add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
source "$(dirname "${BASH_SOURCE[0]}")/profile.sh"
source "$(dirname "${BASH_SOURCE[0]}")/ssh_writer.sh"

validate_ssh_key() {
local key_path="$1"
if [[ ! -f "$key_path" ]]; then
log_error "Error: SSH key file '$key_path' does not exist."
return 1
fi
local perms
perms=$(stat -c "%a" "$key_path" 2>/dev/null || stat -f "%Lp" "$key_path")
if [[ "$perms" != "600" ]]; then
log_error "Error: SSH key file '$key_path' must have 600 permissions."
return 1
fi
return 0
}

cmd_add() {
local name="$1"

Expand All @@ -15,8 +30,13 @@ cmd_add() {
echo "Creating profile: ${name}"

read -p "SSH key path (~/.ssh/): " ssh_key
ssh_key="${ssh_key/#\~/$HOME}"
ssh_key="${ssh_key:-$HOME/.ssh/id_rsa}"

if ! validate_ssh_key "$ssh_key"; then
exit 1
fi

read -p "Git name: " git_name
read -p "Git email: " git_email
read -p "GitHub username: " github_user
Expand Down