Skip to content

Commit 43ecb5b

Browse files
Split the install script into three parts
1 parent fb675b8 commit 43ecb5b

4 files changed

Lines changed: 318 additions & 260 deletions

File tree

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Publish Install Script to R2
1+
name: Publish Install Scripts to R2
22

33
on:
44
push:
55
branches:
66
- main
77
paths:
8-
- 'install.sh'
8+
- 'install/*.sh'
99
workflow_dispatch:
1010

1111
jobs:
@@ -16,15 +16,24 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818

19-
- name: Upload install.sh to R2
19+
- name: Upload install scripts to R2
2020
env:
2121
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
2222
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
2323
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
2424
R2_BUCKET: ${{ secrets.R2_BUCKET }}
2525
run: |
26-
aws s3 cp install.sh s3://${R2_BUCKET}/install/install.sh \
26+
aws s3 cp install/install.sh s3://${R2_BUCKET}/install.sh \
2727
--endpoint-url "${R2_ENDPOINT}" \
2828
--content-type "text/plain"
29-
3029
echo "✓ install.sh uploaded to R2"
30+
31+
aws s3 cp install/walkthrough.sh s3://${R2_BUCKET}/walkthrough.sh \
32+
--endpoint-url "${R2_ENDPOINT}" \
33+
--content-type "text/plain"
34+
echo "✓ walkthrough.sh uploaded to R2"
35+
36+
aws s3 cp install/examples.sh s3://${R2_BUCKET}/examples.sh \
37+
--endpoint-url "${R2_ENDPOINT}" \
38+
--content-type "text/plain"
39+
echo "✓ examples.sh uploaded to R2"

install/examples.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Brand Colors (use exported colors if available, otherwise define them)
6+
YELLOW="${YELLOW:-\033[38;2;224;255;110m}"
7+
GREEN="${GREEN:-\033[38;2;121;252;150m}"
8+
RED="${RED:-\033[38;2;239;68;68m}"
9+
GRAY="${GRAY:-\033[38;2;128;128;128m}"
10+
BOLD="${BOLD:-\033[1m}"
11+
NC="${NC:-\033[0m}"
12+
13+
# Download examples step
14+
clear
15+
echo ""
16+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
17+
echo -e " ${YELLOW}${BOLD}Example Projects${NC}"
18+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
19+
echo ""
20+
echo -e " we've prepared some example Plain projects for you"
21+
echo -e " to explore and experiment with."
22+
echo ""
23+
echo -e " would you like to download them?"
24+
echo ""
25+
read -p " [Y/n]: " DOWNLOAD_EXAMPLES </dev/tty
26+
echo ""
27+
28+
if [[ ! "${DOWNLOAD_EXAMPLES:-}" =~ ^[Nn]$ ]]; then
29+
# Show current directory and ask for extraction path
30+
CURRENT_DIR=$(pwd)
31+
echo -e " current folder: ${YELLOW}${CURRENT_DIR}${NC}"
32+
echo ""
33+
echo -e " extract examples here, or enter a different path:"
34+
echo ""
35+
read -p " [Enter for current, or type path]: " EXTRACT_PATH </dev/tty
36+
echo ""
37+
38+
# Use current directory if empty
39+
if [ -z "${EXTRACT_PATH:-}" ]; then
40+
EXTRACT_PATH="$CURRENT_DIR"
41+
fi
42+
43+
# Expand ~ to home directory
44+
EXTRACT_PATH="${EXTRACT_PATH/#\~/$HOME}"
45+
46+
# Check if directory exists, create if not
47+
if [ ! -d "$EXTRACT_PATH" ]; then
48+
echo -e " ${GRAY}creating directory...${NC}"
49+
mkdir -p "$EXTRACT_PATH" 2>/dev/null
50+
if [ $? -ne 0 ]; then
51+
echo -e " ${RED}${NC} failed to create directory: ${EXTRACT_PATH}"
52+
echo -e " ${GRAY}skipping example download.${NC}"
53+
DOWNLOAD_EXAMPLES="n"
54+
fi
55+
fi
56+
57+
if [[ ! "${DOWNLOAD_EXAMPLES:-}" =~ ^[Nn]$ ]]; then
58+
echo -e " ${GRAY}downloading examples...${NC}"
59+
60+
# Download the zip file
61+
TEMP_ZIP=$(mktemp)
62+
curl -L -s -o "$TEMP_ZIP" "https://github.com/Codeplain-ai/plainlang-examples/archive/refs/tags/0.1.zip"
63+
64+
if [ $? -eq 0 ] && [ -s "$TEMP_ZIP" ]; then
65+
echo -e " ${GRAY}extracting to ${EXTRACT_PATH}...${NC}"
66+
67+
# Extract the zip file
68+
unzip -q -o "$TEMP_ZIP" -d "$EXTRACT_PATH" 2>/dev/null
69+
70+
if [ $? -eq 0 ]; then
71+
# Remove the .gitignore file from the root of the extracted directory
72+
EXTRACTED_DIR="${EXTRACT_PATH}/plainlang-examples-0.1"
73+
if [ -f "${EXTRACTED_DIR}/.gitignore" ]; then
74+
rm -f "${EXTRACTED_DIR}/.gitignore"
75+
fi
76+
77+
echo ""
78+
echo -e " ${GREEN}${NC} examples downloaded successfully!"
79+
echo ""
80+
echo -e " examples are in: ${YELLOW}${EXTRACTED_DIR}${NC}"
81+
echo ""
82+
else
83+
echo -e " ${RED}${NC} failed to extract examples."
84+
fi
85+
86+
# Clean up temp file
87+
rm -f "$TEMP_ZIP"
88+
else
89+
echo -e " ${RED}${NC} failed to download examples."
90+
rm -f "$TEMP_ZIP"
91+
fi
92+
93+
echo ""
94+
read -p " press [Enter] to continue..." </dev/tty
95+
fi
96+
fi

install/install.sh

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Base URL for additional scripts
6+
CODEPLAIN_SCRIPTS_BASE_URL="${CODEPLAIN_SCRIPTS_BASE_URL:-https://codeplain.ai}"
7+
8+
# Brand Colors (True Color / 24-bit)
9+
YELLOW='\033[38;2;224;255;110m' # #E0FF6E
10+
GREEN='\033[38;2;121;252;150m' # #79FC96
11+
GREEN_LIGHT='\033[38;2;197;220;217m' # #C5DCD9
12+
GREEN_DARK='\033[38;2;34;57;54m' # #223936
13+
BLUE='\033[38;2;10;31;212m' # #0A1FD4
14+
BLACK='\033[38;2;26;26;26m' # #1A1A1A
15+
WHITE='\033[38;2;255;255;255m' # #FFFFFF
16+
RED='\033[38;2;239;68;68m' # #EF4444
17+
GRAY='\033[38;2;128;128;128m' # #808080
18+
GRAY_LIGHT='\033[38;2;211;211;211m' # #D3D3D3
19+
BOLD='\033[1m'
20+
NC='\033[0m' # No Color / Reset
21+
22+
# Export colors for child scripts
23+
export YELLOW GREEN GREEN_LIGHT GREEN_DARK BLUE BLACK WHITE RED GRAY GRAY_LIGHT BOLD NC
24+
25+
clear
26+
echo -e "started ${YELLOW}${BOLD}*codeplain CLI${NC} installation..."
27+
28+
# Install uv if not present
29+
install_uv() {
30+
echo -e "installing uv package manager..."
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
# Add uv to PATH for this session
33+
export PATH="$HOME/.local/bin:$PATH"
34+
}
35+
36+
# Check if uv is installed
37+
if ! command -v uv &> /dev/null; then
38+
echo -e "${GRAY}uv is not installed.${NC}"
39+
install_uv
40+
echo -e "${GREEN}${NC} uv installed successfully"
41+
echo -e ""
42+
fi
43+
44+
echo -e "${GREEN}${NC} uv detected"
45+
echo -e ""
46+
47+
# Install or upgrade codeplain using uv tool
48+
if uv tool list 2>/dev/null | grep -q "^codeplain"; then
49+
CURRENT_VERSION=$(uv tool list 2>/dev/null | grep "^codeplain" | sed 's/codeplain v//')
50+
echo -e "${GRAY}codeplain ${CURRENT_VERSION} is already installed.${NC}"
51+
echo -e "upgrading to latest version..."
52+
echo -e ""
53+
uv tool upgrade codeplain &> /dev/null
54+
NEW_VERSION=$(uv tool list 2>/dev/null | grep "^codeplain" | sed 's/codeplain v//')
55+
if [ "$CURRENT_VERSION" = "$NEW_VERSION" ]; then
56+
echo -e "${GREEN}${NC} codeplain is already up to date (${NEW_VERSION})"
57+
else
58+
echo -e "${GREEN}${NC} codeplain upgraded from ${CURRENT_VERSION} to ${NEW_VERSION}!"
59+
fi
60+
else
61+
echo -e "installing codeplain...${NC}"
62+
echo -e ""
63+
uv tool install codeplain
64+
clear
65+
echo -e "${GREEN}✓ codeplain installed successfully!${NC}"
66+
fi
67+
68+
# Check if API key already exists
69+
SKIP_API_KEY_SETUP=false
70+
if [ -n "${CODEPLAIN_API_KEY:-}" ]; then
71+
echo -e " you already have an API key configured."
72+
echo ""
73+
echo -e " would you like to log in and get a new one?"
74+
echo ""
75+
read -p " [y/N]: " GET_NEW_KEY </dev/tty
76+
echo ""
77+
78+
if [[ ! "$GET_NEW_KEY" =~ ^[Yy]$ ]]; then
79+
echo -e "${GREEN}${NC} using existing API key."
80+
SKIP_API_KEY_SETUP=true
81+
fi
82+
fi
83+
84+
if [ "$SKIP_API_KEY_SETUP" = false ]; then
85+
echo -e "go to ${YELLOW}https://platform.codeplain.ai${NC} and sign up to get your API key."
86+
echo ""
87+
read -r -p "paste your API key here: " API_KEY < /dev/tty
88+
echo ""
89+
fi
90+
91+
if [ "$SKIP_API_KEY_SETUP" = true ]; then
92+
: # API key already set, nothing to do
93+
elif [ -z "${API_KEY:-}" ]; then
94+
echo -e "${GRAY}no API key provided. you can set it later with:${NC}"
95+
echo -e " export CODEPLAIN_API_KEY=\"your_api_key\""
96+
else
97+
# Export for current session
98+
export CODEPLAIN_API_KEY="$API_KEY"
99+
100+
# Detect user's default shell from $SHELL (works even when script runs in different shell)
101+
case "$SHELL" in
102+
*/zsh)
103+
SHELL_RC="$HOME/.zshrc"
104+
;;
105+
*/bash)
106+
SHELL_RC="$HOME/.bashrc"
107+
;;
108+
*)
109+
SHELL_RC="$HOME/.profile"
110+
;;
111+
esac
112+
113+
# Create the file if it doesn't exist
114+
touch "$SHELL_RC"
115+
116+
# Add to shell config if not already present
117+
if ! grep -q "CODEPLAIN_API_KEY" "$SHELL_RC" 2>/dev/null; then
118+
echo "" >> "$SHELL_RC"
119+
echo "# codeplain API Key" >> "$SHELL_RC"
120+
echo "export CODEPLAIN_API_KEY=\"$API_KEY\"" >> "$SHELL_RC"
121+
echo -e "${GREEN}✓ API key saved to ${SHELL_RC}${NC}"
122+
else
123+
# Update existing key (different sed syntax for macOS vs Linux)
124+
if [[ "$OSTYPE" == "darwin"* ]]; then
125+
sed -i '' "s|export CODEPLAIN_API_KEY=.*|export CODEPLAIN_API_KEY=\"$API_KEY\"|" "$SHELL_RC"
126+
else
127+
sed -i "s|export CODEPLAIN_API_KEY=.*|export CODEPLAIN_API_KEY=\"$API_KEY\"|" "$SHELL_RC"
128+
fi
129+
fi
130+
fi
131+
132+
# ASCII Art Welcome
133+
clear
134+
echo ""
135+
echo -e "${NC}"
136+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
137+
echo -e ""
138+
cat << 'EOF'
139+
_ _ _
140+
___ ___ __| | ___ _ __ | | __ _(_)_ __
141+
/ __/ _ \ / _` |/ _ \ '_ \| |/ _` | | '_ \
142+
| (_| (_) | (_| | __/ |_) | | (_| | | | | |
143+
\___\___/ \__,_|\___| .__/|_|\__,_|_|_| |_|
144+
|_|
145+
EOF
146+
echo ""
147+
echo -e "${GREEN}${NC} Sign in successful."
148+
echo ""
149+
echo -e " ${YELLOW}welcome to *codeplain!${NC}"
150+
echo ""
151+
echo -e " spec-driven, production-ready code generation"
152+
echo ""
153+
echo ""
154+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
155+
echo ""
156+
echo -e " would you like to get a quick intro to ***plain specification language?"
157+
echo ""
158+
read -p " [Y/n]: " WALKTHROUGH_CHOICE </dev/tty
159+
echo ""
160+
161+
# Determine script directory for local execution
162+
SCRIPT_DIR=""
163+
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
164+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
165+
fi
166+
167+
# Helper function to run a script (local or remote)
168+
run_script() {
169+
local script_name="$1"
170+
if [ -n "$SCRIPT_DIR" ] && [ -f "${SCRIPT_DIR}/${script_name}" ]; then
171+
# Run locally
172+
bash "${SCRIPT_DIR}/${script_name}"
173+
else
174+
# Download and run
175+
bash <(curl -fsSL "${CODEPLAIN_SCRIPTS_BASE_URL}/${script_name}")
176+
fi
177+
}
178+
179+
# Run walkthrough if user agrees
180+
if [[ ! "$WALKTHROUGH_CHOICE" =~ ^[Nn]$ ]]; then
181+
run_script "walkthrough.sh"
182+
fi
183+
184+
# Run examples download
185+
run_script "examples.sh"
186+
187+
# Final message
188+
clear
189+
echo ""
190+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
191+
echo -e " ${YELLOW}${BOLD}You're all set!${NC}"
192+
echo -e "${GRAY}────────────────────────────────────────────${NC}"
193+
echo ""
194+
echo -e " thank you for using *codeplain!"
195+
echo ""
196+
echo ""
197+
echo -e " learn more at ${YELLOW}https://plainlang.org/${NC}"
198+
echo ""
199+
echo -e " ${GREEN}happy development!${NC} 🚀"
200+
echo ""

0 commit comments

Comments
 (0)