Skip to content

Instantly share code, notes, and snippets.

@eknowles
Created July 21, 2023 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eknowles/6b9b0b9899846d4345936d7923938f7f to your computer and use it in GitHub Desktop.
Save eknowles/6b9b0b9899846d4345936d7923938f7f to your computer and use it in GitHub Desktop.
#!/bin/bash
write_npm_token() {
local username=$1
local password=$2
local rc="${HOME}/.zshrc"
# Use sed to remove lines starting with "export NPM_TOKEN="
sed -i '/^export NPM_TOKEN=/d' "$rc"
new_token=$(echo -n "${username}:${password}" | openssl base64 -A)
# write token to rc file
echo "export NPM_TOKEN=$new_token" >> "$rc"
# tell user it's done
echo "New NPM_TOKEN has been updated in $rc"
}
read -pr "Enter your email (artifactory username):" email
read -spr "Paste your artifactory reference token (press Enter when done):" reftoken
write_npm_token "$email" "$reftoken"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment