-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcws-setup.sh
More file actions
109 lines (96 loc) · 4.25 KB
/
cws-setup.sh
File metadata and controls
109 lines (96 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# ScriptVault — Chrome Web Store Credential Setup
# Interactive wizard to configure .env for CWS publishing.
#
# Run once: bash cws-setup.sh
# Re-run anytime to update credentials.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.env"
echo "========================================"
echo " ScriptVault — CWS Publish Setup"
echo "========================================"
echo ""
echo "This wizard will create a .env file with your Chrome Web Store credentials."
echo "You need 4 values. Follow the steps below to get them."
echo ""
# ── Step 1: Extension ID ─────────────────────────────────────────────────────
echo "--- STEP 1: Extension ID ---"
echo "Find it at: https://chrome.google.com/webstore/devconsole"
echo "Click your extension -> the 32-character ID is in the URL."
echo ""
read -p "Extension ID: " EXTENSION_ID
echo ""
# ── Step 2: OAuth Client ID & Secret ─────────────────────────────────────────
echo "--- STEP 2: Google OAuth2 Credentials ---"
echo "1. Go to https://console.cloud.google.com/"
echo "2. Create a project (or select existing)"
echo "3. Enable the 'Chrome Web Store API':"
echo " https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com"
echo "4. Go to Credentials -> Create Credentials -> OAuth client ID"
echo "5. Application type: 'Desktop app'"
echo "6. Copy the Client ID and Client Secret"
echo ""
read -p "Client ID: " CLIENT_ID
read -p "Client Secret: " CLIENT_SECRET
echo ""
# ── Step 3: Get Refresh Token ─────────────────────────────────────────────────
echo "--- STEP 3: Authorization & Refresh Token ---"
echo ""
echo "Open this URL in your browser and authorize the app:"
echo ""
echo " https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/chromewebstore&client_id=${CLIENT_ID}&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
echo ""
echo "After authorizing, Google will show you an authorization code."
echo "(If you see a redirect to localhost, copy the 'code' parameter from the URL.)"
echo ""
read -p "Authorization code: " AUTH_CODE
echo ""
echo "Exchanging authorization code for refresh token..."
RESPONSE=$(curl -s -X POST "https://oauth2.googleapis.com/token" \
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" \
-d "code=${AUTH_CODE}" \
-d "grant_type=authorization_code" \
-d "redirect_uri=urn:ietf:wg:oauth:2.0:oob")
# Try to extract refresh_token
REFRESH_TOKEN=$(echo "$RESPONSE" | grep -o '"refresh_token": *"[^"]*"' | cut -d'"' -f4)
if [ -z "$REFRESH_TOKEN" ]; then
echo ""
echo "WARNING: Could not automatically extract refresh token."
echo "API response:"
echo "$RESPONSE"
echo ""
echo "If the response contains a refresh_token, paste it below."
echo "If it shows an error, re-run this script with correct credentials."
echo ""
read -p "Refresh Token (paste manually): " REFRESH_TOKEN
fi
if [ -z "$REFRESH_TOKEN" ]; then
echo "ERROR: No refresh token obtained. Setup incomplete."
exit 1
fi
# ── Write .env ────────────────────────────────────────────────────────────────
cat > "$ENV_FILE" <<EOL
# ScriptVault — Chrome Web Store Credentials
# Generated by cws-setup.sh on $(date -Iseconds 2>/dev/null || date)
# DO NOT commit this file (it's in .gitignore)
EXTENSION_ID=${EXTENSION_ID}
CLIENT_ID=${CLIENT_ID}
CLIENT_SECRET=${CLIENT_SECRET}
REFRESH_TOKEN=${REFRESH_TOKEN}
EOL
echo ""
echo "========================================"
echo " Setup complete!"
echo "========================================"
echo ""
echo "Credentials saved to: .env"
echo ""
echo "To publish to the Chrome Web Store:"
echo " bash publish.sh # Upload + auto-publish"
echo " bash publish.sh --draft # Upload only (review first)"
echo ""
echo "To add an npm shortcut:"
echo " npm run publish # Same as bash publish.sh"
echo " npm run publish:draft # Same as bash publish.sh --draft"