Skip to content

Instantly share code, notes, and snippets.

@1st8
Last active November 16, 2025 15:43
Show Gist options
  • Select an option

  • Save 1st8/df56362f3044e97b7db14a84db0c2202 to your computer and use it in GitHub Desktop.

Select an option

Save 1st8/df56362f3044e97b7db14a84db0c2202 to your computer and use it in GitHub Desktop.
{
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/setup_env2.sh"
}
]
}
]
}
}
#!/bin/bash
set -e
if [ "$CLAUDE_CODE_REMOTE" != "true" ]; then
exit 0
fi
echo "==> Setting up Elixir environment"
echo ""
# Check if Elixir is already installed
if command -v elixir &> /dev/null; then
echo "✓ Elixir already installed ($(elixir --version 2>&1 | grep 'Elixir' | awk '{print $2}'))"
else
echo "Installing Elixir 1.19.2 with OTP 28.1..."
curl -fsSO https://elixir-lang.org/install.sh
sh install.sh [email protected] [email protected] > /dev/null 2>&1
rm install.sh
echo "✓ Elixir installed"
fi
# Set up environment variables
export PATH=$HOME/.elixir-install/installs/otp/28.1/bin:$PATH
export PATH=$HOME/.elixir-install/installs/elixir/1.19.2-otp-28/bin:$PATH
# Set locale to UTF-8
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
if [ -n "$CLAUDE_ENV_FILE" ]; then
echo 'export PATH=$HOME/.elixir-install/installs/otp/28.1/bin:$PATH' >> "$CLAUDE_ENV_FILE"
echo 'export PATH=$HOME/.elixir-install/installs/elixir/1.19.2-otp-28/bin:$PATH' >> "$CLAUDE_ENV_FILE"
echo 'export LC_ALL=C.UTF-8' >> "$CLAUDE_ENV_FILE"
echo 'export LANG=C.UTF-8' >> "$CLAUDE_ENV_FILE"
echo 'export LANGUAGE=C.UTF-8' >> "$CLAUDE_ENV_FILE"
echo "✓ Added to $CLAUDE_ENV_FILE"
fi
# Install Hex package manager
if mix hex.info &> /dev/null; then
echo "✓ Hex already installed"
else
echo "Installing Hex package manager..."
mix local.hex --force > /dev/null 2>&1
echo "✓ Hex installed"
fi
# Install Rebar (Erlang build tool)
if mix local.rebar --force &> /dev/null; then
echo "✓ Rebar installed"
fi
# Configure Hex to use system CA certificates
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
mix hex.config cacerts_path /etc/ssl/certs/ca-certificates.crt > /dev/null 2>&1
echo "✓ Hex SSL certificates configured"
fi
# Install project dependencies
echo ""
echo "==> Installing project dependencies"
if [ -f mix.exs ]; then
mix deps.get
echo "✓ Dependencies installed"
echo "Compiling project..."
mix compile
echo "✓ Project compiled"
else
echo "⚠ No mix.exs found in current directory"
fi
# Set up PostgreSQL
echo ""
echo "==> Setting up PostgreSQL"
# Check if PostgreSQL is already running
if pg_isready &> /dev/null; then
echo "✓ PostgreSQL already running"
else
# Ensure PostgreSQL is installed
if ! command -v psql &> /dev/null && [ ! -x /usr/lib/postgresql/16/bin/postgres ]; then
echo "✗ PostgreSQL not installed. Please install PostgreSQL 16 or later."
exit 1
fi
# Check if SSL needs to be disabled in config
if [ -f /etc/postgresql/16/main/postgresql.conf ]; then
if grep -q "^ssl = on" /etc/postgresql/16/main/postgresql.conf; then
echo "Disabling SSL for development..."
sed -i "s/^ssl = on/ssl = off/" /etc/postgresql/16/main/postgresql.conf
fi
fi
# Fix pg_hba.conf for local development (trust auth)
if [ -f /etc/postgresql/16/main/pg_hba.conf ]; then
if grep -q "peer" /etc/postgresql/16/main/pg_hba.conf; then
echo "Configuring PostgreSQL authentication..."
# Backup original config
cp /etc/postgresql/16/main/pg_hba.conf /etc/postgresql/16/main/pg_hba.conf.bak 2>/dev/null || true
# Change peer to trust for local connections, scram-sha-256 to md5 for TCP
sed -i 's/^\(local.*\)peer$/\1trust/' /etc/postgresql/16/main/pg_hba.conf
sed -i 's/^\(host.*127\.0\.0\.1.*\)scram-sha-256$/\1md5/' /etc/postgresql/16/main/pg_hba.conf
fi
# Ensure correct permissions
chown claude:ubuntu /etc/postgresql/16/main/pg_hba.conf 2>/dev/null || true
chmod 640 /etc/postgresql/16/main/pg_hba.conf 2>/dev/null || true
fi
# Start PostgreSQL as claude user
echo "Starting PostgreSQL..."
if su - claude -c "/usr/lib/postgresql/16/bin/pg_ctl -D /var/lib/postgresql/16/main -o '-c config_file=/etc/postgresql/16/main/postgresql.conf' -l /tmp/postgresql.log start" &> /dev/null; then
# Wait for PostgreSQL to be ready
for i in {1..10}; do
if pg_isready &> /dev/null; then
echo "✓ PostgreSQL started"
break
fi
sleep 1
done
else
echo "✗ Failed to start PostgreSQL. Check /tmp/postgresql.log for details."
exit 1
fi
fi
# Ensure postgres user exists with correct password
if pg_isready &> /dev/null; then
su - claude -c "psql -U postgres -c \"SELECT 1\" &> /dev/null" || \
su - claude -c "psql -U postgres -c \"ALTER USER postgres WITH PASSWORD 'password';\" &> /dev/null" || true
echo "✓ PostgreSQL configured for development"
fi
echo ""
echo "==> Setup complete!"
echo "Elixir version: $(elixir --version 2>&1 | grep 'Elixir' | awk '{print $2}')"
echo "Erlang/OTP version: $(erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell 2>&1)"
echo "PostgreSQL version: $(psql --version | awk '{print $3}')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment