|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +PKG="${DEEPSTUDIO_PKG:-deepstudio-server}" |
| 5 | + |
| 6 | +require_npm() { |
| 7 | + if ! command -v npm >/dev/null 2>&1; then |
| 8 | + echo "" |
| 9 | + echo "❌ Node.js / npm not found." |
| 10 | + echo "Please install Node.js first:" |
| 11 | + echo "https://nodejs.org/en/download" |
| 12 | + echo "" |
| 13 | + exit 1 |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +b64() { |
| 18 | + if command -v openssl >/dev/null 2>&1; then |
| 19 | + printf '%s' "$1" | openssl base64 -A |
| 20 | + else |
| 21 | + printf '%s' "$1" | base64 |
| 22 | + fi |
| 23 | +} |
| 24 | + |
| 25 | +cleanup() { |
| 26 | + npm config delete --global registry >/dev/null 2>&1 || true |
| 27 | + npm config delete --global "${AUTH_PREFIX}:username" >/dev/null 2>&1 || true |
| 28 | + npm config delete --global "${AUTH_PREFIX}:_password" >/dev/null 2>&1 || true |
| 29 | + npm config delete --global "${AUTH_PREFIX}:email" >/dev/null 2>&1 || true |
| 30 | + echo "✅ Cleanup complete." |
| 31 | +} |
| 32 | + |
| 33 | +require_npm |
| 34 | + |
| 35 | +read -r -p "Enter npm registry URL (for ex: https://xxx.pkgs.xxx.com/xxx/_packaging/xxx/npm/registry/): " REGISTRY |
| 36 | +REGISTRY="${REGISTRY%/}" |
| 37 | + |
| 38 | +if [ -z "$REGISTRY" ]; then |
| 39 | + echo "Registry URL is required." |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# derive auth prefix |
| 44 | +URI_NO_PROTO="${REGISTRY#https://}" |
| 45 | +URI_NO_PROTO="${URI_NO_PROTO#http://}" |
| 46 | +AUTH_PREFIX="//${URI_NO_PROTO}/" |
| 47 | + |
| 48 | +trap cleanup EXIT |
| 49 | + |
| 50 | +printf "Enter Azure DevOps PAT (Packaging:Read): " |
| 51 | +stty -echo |
| 52 | +read -r PAT |
| 53 | +stty echo |
| 54 | +printf "\n" |
| 55 | + |
| 56 | +if [ -z "$PAT" ]; then |
| 57 | + echo "PAT is empty." |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | + |
| 61 | +PAT_B64="$(b64 "$PAT")" |
| 62 | +unset PAT |
| 63 | + |
| 64 | +npm config set --global registry "${REGISTRY}/" >/dev/null |
| 65 | +npm config set --global "${AUTH_PREFIX}:username" microsoft >/dev/null |
| 66 | +npm config set --global "${AUTH_PREFIX}:_password" "${PAT_B64}" >/dev/null |
| 67 | +npm config set --global "${AUTH_PREFIX}:email" npm@example.com >/dev/null |
| 68 | + |
| 69 | +npm install -g "${PKG}@latest" --registry "${REGISTRY}/" |
| 70 | + |
| 71 | +echo "" |
| 72 | +echo "✅ Installed ${PKG}@latest successfully." |
| 73 | +echo "You can now run ${PKG} to launch it." |
0 commit comments