Skip to content

Instantly share code, notes, and snippets.

@jspiro
Last active May 13, 2020 06:22

Revisions

  1. jspiro revised this gist May 13, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions login-to-artifactory.sh
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    scope=company-name
    any_scoped_package_name=secret_package
    url=artifactory.company.com
    repo=npm

    cd "$(dirname "$0")" || exit
    echo Please enter your email address:
    @@ -13,9 +14,9 @@ read -r token
    echo
    echo Generating .npmrc, keep this in "$(pwd -P)"
    echo
    echo registry=https://$url/artifactory/api/npm/npm/ >.npmrc
    curl -u"$email:$token" https://$url/artifactory/api/npm/auth >>.npmrc 2>/dev/null
    curl -u"$email:$token" https://$url/artifactory/api/npm/npm/auth/$scope >>.npmrc 2>/dev/null
    echo registry=https://$url/artifactory/api/npm/$repo/ >.npmrc
    curl -u"$email:$token" https://$url/artifactory/api/$repo/auth >>.npmrc 2>/dev/null
    curl -u"$email:$token" https://$url/artifactory/api/npm/$repo/auth/$scope >>.npmrc 2>/dev/null
    sed -i '' -e "s!ENTER_YOUR_EMAIL_HERE!$email!" .npmrc
    echo Testing...
    echo
  2. jspiro created this gist May 13, 2020.
    40 changes: 40 additions & 0 deletions login-to-artifactory.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/bin/sh

    scope=company-name
    any_scoped_package_name=secret_package
    url=artifactory.company.com

    cd "$(dirname "$0")" || exit
    echo Please enter your email address:
    read -r email
    echo
    echo Please enter your Artifactory API token:
    read -r token
    echo
    echo Generating .npmrc, keep this in "$(pwd -P)"
    echo
    echo registry=https://$url/artifactory/api/npm/npm/ >.npmrc
    curl -u"$email:$token" https://$url/artifactory/api/npm/auth >>.npmrc 2>/dev/null
    curl -u"$email:$token" https://$url/artifactory/api/npm/npm/auth/$scope >>.npmrc 2>/dev/null
    sed -i '' -e "s!ENTER_YOUR_EMAIL_HERE!$email!" .npmrc
    echo Testing...
    echo
    if ! npm info @$scope/$any_scoped_package_name; then
    echo =====================================
    echo Check your credentials and try again.
    exit
    fi

    echo
    echo ====================================================
    echo Do you want to overwrite your user ~/.npmrc as well?
    echo
    echo You may get faster and more reliable package installation, but you will no longer
    echo be able to publish packages to the original NPM Private Registry, only to Artifactory.
    echo
    echo Do you want to use Artifactory instead of NPM Private Registry?
    echo \(Only 'yes' will be accepted\)
    read -r x
    [ "$x" = "yes" ] && cp .npmrc ~/.npmrc

    echo Done.