Skip to content

Commit e69a3e9

Browse files
Copilothydraxman
andcommitted
Fix shell script: use $'\\033' for ANSI colors and read from /dev/tty for piped execution
Co-authored-by: hydraxman <8344245+hydraxman@users.noreply.github.com>
1 parent 37ae4d2 commit e69a3e9

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

deepstudio/private-install-v2.sh

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ DEFAULT_REGISTRY_B64="aHR0cHM6Ly9taWNyb3NvZnQucGtncy52aXN1YWxzdHVkaW8uY29tL09TL1
1818
# ---------------------------
1919
# Color helpers
2020
# ---------------------------
21-
RED='\033[0;31m'
22-
YELLOW='\033[0;33m'
23-
GREEN='\033[0;32m'
24-
CYAN='\033[0;36m'
25-
MAGENTA='\033[0;35m'
26-
BLUE='\033[0;34m'
27-
DIM='\033[0;90m'
28-
WHITE='\033[1;37m'
29-
NC='\033[0m' # No Color
30-
31-
info() { printf " ${CYAN}%s${NC}\n" "$*"; }
32-
warn() { printf " ${YELLOW}⚠ %s${NC}\n" "$*"; }
33-
fail() { printf " ${RED}✖ %s${NC}\n" "$*"; }
34-
success() { printf " ${GREEN}✔ %s${NC}\n" "$*"; }
35-
dim() { printf " ${DIM}%s${NC}\n" "$*"; }
21+
# Use $'...' syntax so escape sequences become real ANSI bytes
22+
RED=$'\033[0;31m'
23+
YELLOW=$'\033[0;33m'
24+
GREEN=$'\033[0;32m'
25+
CYAN=$'\033[0;36m'
26+
MAGENTA=$'\033[0;35m'
27+
BLUE=$'\033[0;34m'
28+
DIM=$'\033[0;90m'
29+
WHITE=$'\033[1;37m'
30+
NC=$'\033[0m' # No Color
31+
32+
info() { printf " %s%s%s\n" "$CYAN" "$*" "$NC"; }
33+
warn() { printf " %s⚠ %s%s\n" "$YELLOW" "$*" "$NC"; }
34+
fail() { printf " %s✖ %s%s\n" "$RED" "$*" "$NC"; }
35+
success() { printf " %s✔ %s%s\n" "$GREEN" "$*" "$NC"; }
36+
dim() { printf " %s%s%s\n" "$DIM" "$*" "$NC"; }
3637

3738
show_banner() {
3839
local lines=(
@@ -210,13 +211,13 @@ upgrade_node() {
210211
require_node() {
211212
if ! command -v node >/dev/null 2>&1; then
212213
echo ""
213-
printf " ${YELLOW}┌─────────────────────────────────────────────────────┐${NC}\n"
214-
printf " ${YELLOW}│ ⚙️ Node.js is not installed │${NC}\n"
215-
printf " ${YELLOW}│ Node.js >= %s is required to continue. │${NC}\n" "$MIN_NODE_VERSION"
216-
printf " ${YELLOW}└─────────────────────────────────────────────────────┘${NC}\n"
214+
printf " %b┌─────────────────────────────────────────────────────┐%b\n" "$YELLOW" "$NC"
215+
printf " %b│ ⚙️ Node.js is not installed │%b\n" "$YELLOW" "$NC"
216+
printf " %b│ Node.js >= %s is required to continue. │%b\n" "$YELLOW" "$NC" "$MIN_NODE_VERSION"
217+
printf " %b└─────────────────────────────────────────────────────┘%b\n" "$YELLOW" "$NC"
217218
echo ""
218-
printf " ${CYAN}📥 ${NC}"
219-
read -r -p "Install Node.js now? [Y/n] " install_choice
219+
printf " %b📥 %b" "$CYAN" "$NC"
220+
read -r -p "Install Node.js now? [Y/n] " install_choice < /dev/tty
220221
if [ -z "$install_choice" ] || echo "$install_choice" | grep -qi '^y'; then
221222
install_node
222223
if ! command -v node >/dev/null 2>&1; then
@@ -239,14 +240,14 @@ require_node() {
239240

240241
if [ "$major" -lt "$MIN_NODE_VERSION" ] 2>/dev/null; then
241242
echo ""
242-
printf " ${YELLOW}┌─────────────────────────────────────────────────────┐${NC}\n"
243-
printf " ${YELLOW}│ ⬆️ Node.js upgrade required │${NC}\n"
244-
printf " ${YELLOW}│ Current: v%-40s│${NC}\n" "$version_str"
245-
printf " ${YELLOW}│ Required: >= v%s.0.0 │${NC}\n" "$MIN_NODE_VERSION"
246-
printf " ${YELLOW}└─────────────────────────────────────────────────────┘${NC}\n"
243+
printf " %b┌─────────────────────────────────────────────────────┐%b\n" "$YELLOW" "$NC"
244+
printf " %b│ ⬆️ Node.js upgrade required │%b\n" "$YELLOW" "$NC"
245+
printf " %b│ Current: v%-40s│%b\n" "$YELLOW" "$NC" "$version_str"
246+
printf " %b│ Required: >= v%s.0.0 │%b\n" "$YELLOW" "$NC" "$MIN_NODE_VERSION"
247+
printf " %b└─────────────────────────────────────────────────────┘%b\n" "$YELLOW" "$NC"
247248
echo ""
248-
printf " ${CYAN}⬆️ ${NC}"
249-
read -r -p "Upgrade Node.js to >= v${MIN_NODE_VERSION}? [Y/n] " upgrade_choice
249+
printf " %b⬆️ %b" "$CYAN" "$NC"
250+
read -r -p "Upgrade Node.js to >= v${MIN_NODE_VERSION}? [Y/n] " upgrade_choice < /dev/tty
250251
if [ -z "$upgrade_choice" ] || echo "$upgrade_choice" | grep -qi '^y'; then
251252
upgrade_node
252253
version_str=$(node --version 2>/dev/null | sed 's/^v//')
@@ -322,13 +323,13 @@ get_az_access_token() {
322323

323324
if [ "$az_available" = false ]; then
324325
echo ""
325-
printf " ${YELLOW}┌─────────────────────────────────────────────────────┐${NC}\n"
326-
printf " ${YELLOW}│ 🔧 Azure CLI (az) is not installed │${NC}\n"
327-
printf " ${YELLOW}│ It is recommended for automatic token auth. │${NC}\n"
328-
printf " ${YELLOW}└─────────────────────────────────────────────────────┘${NC}\n"
326+
printf " %b┌─────────────────────────────────────────────────────┐%b\n" "$YELLOW" "$NC"
327+
printf " %b│ 🔧 Azure CLI (az) is not installed │%b\n" "$YELLOW" "$NC"
328+
printf " %b│ It is recommended for automatic token auth. │%b\n" "$YELLOW" "$NC"
329+
printf " %b└─────────────────────────────────────────────────────┘%b\n" "$YELLOW" "$NC"
329330
echo ""
330-
printf " ${CYAN}📥 ${NC}"
331-
read -r -p "Install Azure CLI now? [Y/n] " install_choice
331+
printf " %b📥 %b" "$CYAN" "$NC"
332+
read -r -p "Install Azure CLI now? [Y/n] " install_choice < /dev/tty
332333
if [ -z "$install_choice" ] || echo "$install_choice" | grep -qi '^y'; then
333334
if install_az_cli; then
334335
az_available=true
@@ -463,8 +464,8 @@ echo ""
463464
DEFAULT_REGISTRY=$(b64_decode "$DEFAULT_REGISTRY_B64")
464465
REGISTRY_INPUT="$REGISTRY_FROM_ENV"
465466
if [ -z "$REGISTRY_INPUT" ]; then
466-
printf " ${CYAN}🏢 ${NC}"
467-
read -r -p "Enter ADO org name [microsoft] " ado_org
467+
printf " %b🏢 %b" "$CYAN" "$NC"
468+
read -r -p "Enter ADO org name [microsoft] " ado_org < /dev/tty
468469
if [ -z "$ado_org" ]; then ado_org="microsoft"; fi
469470
REGISTRY_INPUT=$(echo "$DEFAULT_REGISTRY" | sed "s/microsoft\.pkgs/${ado_org}.pkgs/")
470471
dim "Using org: $ado_org"
@@ -493,16 +494,16 @@ if get_az_access_token; then
493494
success "Using temporary token from Azure CLI (no PAT creation needed)."
494495
else
495496
echo ""
496-
printf " ${YELLOW}┌─────────────────────────────────────────────────────┐${NC}\n"
497-
printf " ${YELLOW}│ 🔑 Manual PAT required │${NC}\n"
498-
printf " ${YELLOW}│ Create one at: │${NC}\n"
499-
printf " ${YELLOW}│ https://dev.azure.com/ > User Settings > PATs │${NC}\n"
500-
printf " ${YELLOW}│ Scope: Packaging > Read │${NC}\n"
501-
printf " ${YELLOW}└─────────────────────────────────────────────────────┘${NC}\n"
497+
printf " %b┌─────────────────────────────────────────────────────┐%b\n" "$YELLOW" "$NC"
498+
printf " %b│ 🔑 Manual PAT required │%b\n" "$YELLOW" "$NC"
499+
printf " %b│ Create one at: │%b\n" "$YELLOW" "$NC"
500+
printf " %b│ https://dev.azure.com/ > User Settings > PATs │%b\n" "$YELLOW" "$NC"
501+
printf " %b│ Scope: Packaging > Read │%b\n" "$YELLOW" "$NC"
502+
printf " %b└─────────────────────────────────────────────────────┘%b\n" "$YELLOW" "$NC"
502503
echo ""
503504
printf " 🔑 Enter Azure DevOps PAT (Packaging:Read): "
504505
stty -echo 2>/dev/null || true
505-
read -r PAT
506+
read -r PAT < /dev/tty
506507
stty echo 2>/dev/null || true
507508
printf "\n"
508509

@@ -559,7 +560,7 @@ echo ""
559560

560561
# Ask user whether to start
561562
printf " ${MAGENTA}🚀 ${NC}"
562-
read -r -p "Start ${PKG} now? [Y/n] " start_choice
563+
read -r -p "Start ${PKG} now? [Y/n] " start_choice < /dev/tty
563564
if [ -z "$start_choice" ] || echo "$start_choice" | grep -qi '^y'; then
564565
echo ""
565566
printf " ${MAGENTA}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"

0 commit comments

Comments
 (0)