Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm adduser via bash

Tags:

I want to automate the npm login process via a bash script.

I tried it with this snippet:

/usr/bin/expect -f - <<EOD spawn npm adduser expect "Username:" send "myUserName\n" expect "mail: (this IS public)" send "[email protected]\n" EOD 

But without luck.

Note: I will change the strings with env variables

like image 381
ke_wa Avatar asked Jun 10 '14 14:06

ke_wa


Video Answer


2 Answers

@Aurélien Thieriot: thanks for the hint.

I have two solutions for my problem:

Solution 1

export NPM_AUTH_TOKEN=myToken export NPM_EMAIL=myEmail 

create/override ~/.npmrc by following shell script:

echo "_auth = $NPM_AUTH_TOKEN" > ~/.npmrc echo "email = $NPM_EMAIL" >> ~/.npmrc 

Solution 2

export NPM_USERNAME=myUsername export NPM_PASSWORD=myPassword export NPM_EMAIL=myEmail 

I know the order of the questions. So I can do the following:

npm adduser <<! $NPM_USERNAME $NPM_PASSWORD $NPM_EMAIL ! 

Note: solution 2 works only when the user isn't added yet
Otherwise the $NPM_PASSWORD is not necessary

like image 89
ke_wa Avatar answered Oct 03 '22 23:10

ke_wa


This way works and with a more elegant expect:

/usr/bin/expect <<EOD spawn npm adduser expect {   "Username:" {send "$USERNAME\r"; exp_continue}   "Password:" {send "$PASSWORD\r"; exp_continue}   "Email: (this IS public)" {send "$EMAIL\r"; exp_continue} } EOD 
like image 22
Seralto Avatar answered Oct 03 '22 22:10

Seralto