55# curl -fsSL https://raw.githubusercontent.com/flexion/opencode/flex/install-flex | bash
66#
77# What this does:
8- # 1. Checks prerequisites (git, bun, aws-cli v2 )
9- # 2. Prompts: clone directory, AWS account ID, preferred AWS region
8+ # 1. Checks prerequisites (git, bun)
9+ # 2. Prompts: clone directory
1010# 3. Clones git@github.com:flexion/opencode.git (flex branch) — skipped if already present
1111# 4. Installs dependencies and builds the native binary
12- # 5. Writes [profile ClaudeCodeAccess] to ~/.aws/config
13- # 6. Writes ~/.config/opencode/opencode.json (Bedrock + model config)
14- # 7. Appends opencode-work() launcher function to ~/.zshrc or ~/.bashrc
12+ # 5. Appends opencode-work() launcher function to ~/.zshrc or ~/.bashrc
13+ #
14+ # AWS credentials and opencode configuration are managed by flexcamp-ai:
15+ # https://github.com/flexion/flexcamp-ai
16+ # Run flexcamp-ai setup before or after this installer.
1517#
1618# Existing files are never overwritten; each step is skipped with a warning
1719# if the output already exists.
2729fi
2830
2931# ── constants ─────────────────────────────────────────────────────────────────
30- SSO_START_URL=" https://identitycenter.amazonaws.com/ssoins-6684680a9b285ea2"
31- SSO_REGION=" us-east-2"
32- SSO_ROLE_NAME=" ClaudeCodeAccess"
33- AWS_PROFILE=" ClaudeCodeAccess"
3432REPO_URL=" git@github.com:flexion/opencode.git"
3533BRANCH=" flex"
3634
@@ -46,12 +44,6 @@ check_prereqs() {
4644 local missing=()
4745 command -v git > /dev/null 2>&1 || missing+=(" git" )
4846 command -v bun > /dev/null 2>&1 || missing+=(" bun (https://bun.sh)" )
49- if command -v aws > /dev/null 2>&1 ; then
50- aws --version 2>&1 | grep -q ' ^aws-cli/2\.' \
51- || missing+=(" aws-cli v2 (found v1 — upgrade: https://aws.amazon.com/cli/)" )
52- else
53- missing+=(" aws-cli v2 (https://aws.amazon.com/cli/)" )
54- fi
5547 if [ ${# missing[@]} -gt 0 ]; then
5648 die " Missing prerequisites:$( printf ' \n • %s' " ${missing[@]} " ) "
5749 fi
@@ -78,22 +70,6 @@ gather_inputs() {
7870 if [[ " $CLONE_DIR " =~ [[:cntrl:]] ]]; then
7971 die " Invalid clone directory — control characters are not allowed"
8072 fi
81-
82- while true ; do
83- printf ' AWS account ID: ' > /dev/tty
84- IFS= read -r ACCOUNT_ID < /dev/tty
85- [ -n " ${ACCOUNT_ID:- } " ] || { warn " AWS account ID is required." ; continue ; }
86- # AWS account IDs are exactly 12 digits
87- [[ " $ACCOUNT_ID " =~ ^[0-9]{12}$ ]] || { warn " AWS account ID must be exactly 12 digits." ; continue ; }
88- break
89- done
90-
91- printf ' Preferred AWS region [us-east-1]: ' > /dev/tty
92- IFS= read -r AWS_REGION < /dev/tty
93- AWS_REGION=" ${AWS_REGION:- us-east-1} "
94- # AWS regions match the pattern: two-or-more-letters, dash, letters, dash, digit(s)
95- [[ " $AWS_REGION " =~ ^[a-z]{2,}-[a-z]+-[0-9]+$ ]] \
96- || die " Invalid AWS region format (expected e.g. us-east-1, eu-west-2)"
9773 echo
9874}
9975
@@ -135,96 +111,7 @@ clone_and_build() {
135111 success " Binary built"
136112}
137113
138- # ── step 4: AWS SSO config ────────────────────────────────────────────────────
139- write_aws_config () {
140- mkdir -p " $HOME /.aws"
141- # Use aws configure set for atomic, structured writes — avoids raw cat >> which can
142- # corrupt ~/.aws/config if a concurrent write leaves an unterminated section header.
143- # aws configure get doubles as an idempotency check without relying on fragile grep.
144- if aws configure get sso_start_url --profile " $AWS_PROFILE " > /dev/null 2>&1 ; then
145- warn " AWS profile [$AWS_PROFILE ] already configured — skipping"
146- return
147- fi
148-
149- info " Writing AWS SSO profile via aws configure set..."
150- aws configure set sso_start_url " $SSO_START_URL " --profile " $AWS_PROFILE "
151- aws configure set sso_region " $SSO_REGION " --profile " $AWS_PROFILE "
152- aws configure set sso_account_id " $ACCOUNT_ID " --profile " $AWS_PROFILE "
153- aws configure set sso_role_name " $SSO_ROLE_NAME " --profile " $AWS_PROFILE "
154- aws configure set region " $AWS_REGION " --profile " $AWS_PROFILE "
155- success " AWS profile [$AWS_PROFILE ] written"
156- }
157-
158- # ── step 5: opencode provider config ─────────────────────────────────────────
159- write_opencode_config () {
160- local config_dir=" $HOME /.config/opencode"
161- local config_file=" $config_dir /opencode.json"
162- mkdir -p " $config_dir "
163-
164- if [ -f " $config_file " ]; then
165- warn " opencode config already exists at $config_file — skipping"
166- return
167- fi
168-
169- info " Writing opencode config to $config_file ..."
170- cat > " $config_file " << EOF
171- {
172- "\$ schema": "https://opencode.ai/config.json",
173- "autoupdate": false,
174- "model": "amazon-bedrock/us.anthropic.claude-sonnet-4-6",
175- "enabled_providers": ["amazon-bedrock"],
176- "plugin": [],
177- "provider": {
178- "amazon-bedrock": {
179- "options": {
180- "region": "$AWS_REGION "
181- },
182- "models": {
183- "writer.palmyra-x4-v1:0": {
184- "name": "Writer Palmyra X4",
185- "tool_call": false,
186- "limit": { "context": 128000, "output": 8192 }
187- },
188- "writer.palmyra-x5-v1:0": {
189- "name": "Writer Palmyra X5",
190- "tool_call": false,
191- "limit": { "context": 1000000, "output": 8192 }
192- },
193- "deepseek.r1-v1:0": {
194- "name": "DeepSeek R1 (A)",
195- "tool_call": false,
196- "reasoning": false,
197- "limit": { "context": 64000, "output": 32768 }
198- },
199- "mistral.pixtral-large-2502-v1:0": {
200- "name": "Mistral Pixtral Large",
201- "tool_call": false,
202- "limit": { "context": 128000, "output": 8192 }
203- },
204- "meta.llama4-maverick-17b-instruct-v1:0": {
205- "name": "Meta Llama 4 Maverick 17B",
206- "tool_call": false,
207- "limit": { "context": 1000000, "output": 8192 }
208- },
209- "meta.llama4-scout-17b-instruct-v1:0": {
210- "name": "Meta Llama 4 Scout 17B",
211- "tool_call": false,
212- "limit": { "context": 10000000, "output": 8192 }
213- },
214- "amazon.nova-2-lite-v1:0": {
215- "name": "Amazon Nova 2 Lite",
216- "limit": { "context": 300000, "output": 5120 }
217- }
218- }
219- }
220- }
221- }
222- EOF
223- chmod 600 " $config_file "
224- success " opencode config written"
225- }
226-
227- # ── step 6: shell launcher function ──────────────────────────────────────────
114+ # ── step 4: shell launcher function ──────────────────────────────────────────
228115write_shell_alias () {
229116 local rc_file
230117 case " $( basename " ${SHELL:- bash} " ) " in
@@ -252,22 +139,14 @@ write_shell_alias() {
252139 cat >> " $rc_file " << SHELL_EOF
253140
254141# ── Flexion opencode launcher ─────────────────────────────────────────────────
142+ # AWS credentials are managed by flexcamp-ai (github.com/flexion/flexcamp-ai).
255143opencode-work() {
256- local profile="ClaudeCodeAccess"
257144 local clone_dir=$clone_dir_q
258145 local arch os
259146 case "\$ (uname -m)" in arm64|aarch64) arch="arm64" ;; *) arch="x64" ;; esac
260147 case "\$ (uname -s)" in Darwin) os="darwin" ;; Linux) os="linux" ;; *)
261148 echo "Unsupported OS: \$ (uname -s)" && return 1 ;; esac
262- echo "Logging in to AWS SSO (\$ profile)..."
263- aws sso login --profile "\$ profile" || return 1
264- # Subshell confines exported credentials to the opencode process — they do not
265- # persist in the interactive shell environment after opencode exits.
266- (
267- eval "\$ (aws configure export-credentials --profile "\$ profile" --format env)"
268- export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
269- "\$ {clone_dir}/packages/opencode/dist/opencode-\$ {os}-\$ {arch}/bin/opencode" "\$ @"
270- )
149+ "\$ {clone_dir}/packages/opencode/dist/opencode-\$ {os}-\$ {arch}/bin/opencode" "\$ @"
271150}
272151# ─────────────────────────────────────────────────────────────────────────────
273152SHELL_EOF
@@ -280,8 +159,6 @@ main() {
280159 check_prereqs
281160 gather_inputs
282161 clone_and_build
283- write_aws_config
284- write_opencode_config
285162 write_shell_alias
286163
287164 local rc_file
@@ -293,11 +170,11 @@ main() {
293170 printf ' \n%s%sInstallation complete!%s\n' " $GREEN " " $BOLD " " $NC "
294171 printf ' ────────────────────────────────────────────\n'
295172 printf ' Binary: %s/packages/opencode/dist/opencode-*/bin/opencode\n' " $CLONE_DIR "
296- printf ' AWS: profile=%s account=%s region=%s\n' " $AWS_PROFILE " " $ACCOUNT_ID " " $AWS_REGION "
297- printf ' Config: %s/.config/opencode/opencode.json\n' " $HOME "
298173 printf ' \n Next steps:\n'
299- printf ' 1. source %s\n' " $rc_file "
300- printf ' 2. opencode-work\n\n'
174+ printf ' 1. Set up AWS credentials via flexcamp-ai:\n'
175+ printf ' https://github.com/flexion/flexcamp-ai\n'
176+ printf ' 2. source %s\n' " $rc_file "
177+ printf ' 3. opencode-work\n\n'
301178}
302179
303180main
0 commit comments