Browse Source

ix: better account handling

DanielFGray 2 years ago
parent
commit
902e8e1ccd
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      ix

+ 9
- 4
ix View File

@@ -19,10 +19,11 @@ HELP
19 19
 }
20 20
 
21 21
 err() {
22
-  printf "${c_red}%s${c_reset}\n" "$*" >&2
22
+  printf "${c_red}%s${c_reset}\n" "$@" >&2
23 23
 }
24 24
 
25 25
 die() {
26
+  err "$@"
26 27
   exit 1
27 28
 }
28 29
 
@@ -60,7 +61,7 @@ select_from() {
60 61
 }
61 62
 
62 63
 has_account() {
63
-  grep -qF 'ix.io' ~/.netrc
64
+  [[ -r ~/.netrc ]] && grep -qF 'ix.io' ~/.netrc
64 65
 }
65 66
 
66 67
 create_account() {
@@ -69,9 +70,13 @@ create_account() {
69 70
   read -rs -p 'enter a password (this will be hashed with sha256sum): ' password
70 71
   password=$(sha256sum <<< "$password" | awk '{print $1}')
71 72
   echo ''
72
-  tee -a  ~/.netrc <<< "machine ix.io login $username password $password"
73
+  echo "machine ix.io login $username password $password" >> ~/.netrc
73 74
   chmod 600 ~/.netrc
74
-  echo "$username"
75
+  if has_account; then
76
+    echo 'success!'
77
+  else
78
+    die 'could not create account!'
79
+  fi
75 80
 }
76 81
 
77 82
 get_user_name() {

Loading…
Cancel
Save