File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,21 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
44source " $( dirname " ${BASH_SOURCE[0]} " ) /profile.sh"
55source " $( dirname " ${BASH_SOURCE[0]} " ) /ssh_writer.sh"
66
7+ validate_ssh_key () {
8+ local key_path=" $1 "
9+ if [[ ! -f " $key_path " ]]; then
10+ log_error " Error: SSH key file '$key_path ' does not exist."
11+ return 1
12+ fi
13+ local perms
14+ perms=$( stat -c " %a" " $key_path " 2> /dev/null || stat -f " %Lp" " $key_path " )
15+ if [[ " $perms " != " 600" ]]; then
16+ log_error " Error: SSH key file '$key_path ' must have 600 permissions."
17+ return 1
18+ fi
19+ return 0
20+ }
21+
722cmd_add () {
823 local name=" $1 "
924
@@ -15,8 +30,13 @@ cmd_add() {
1530 echo " Creating profile: ${name} "
1631
1732 read -p " SSH key path (~/.ssh/): " ssh_key
33+ ssh_key=" ${ssh_key/# \~ / $HOME } "
1834 ssh_key=" ${ssh_key:- $HOME / .ssh/ id_rsa} "
1935
36+ if ! validate_ssh_key " $ssh_key " ; then
37+ exit 1
38+ fi
39+
2040 read -p " Git name: " git_name
2141 read -p " Git email: " git_email
2242 read -p " GitHub username: " github_user
You can’t perform that action at this time.
0 commit comments