From 5c1ef4d9e7cc0395bf6c56709dfe4b662a10ec5f Mon Sep 17 00:00:00 2001 From: Niels Geens Date: Mon, 17 Mar 2025 10:38:36 +0100 Subject: [PATCH] More improvements to bootstrap --- scripts/bootstrap.sh | 13 +++++++++++-- scripts/github_keys.sh | 40 +++++++++++++++++++++++++++++++++------- scripts/install.sh | 13 +++++++++++++ scripts/restart.sh | 17 +---------------- 4 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 scripts/install.sh diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index dc55bf8..a1f43fa 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,8 +1,13 @@ #!/bin/bash -# bootstrap.sh - Initialize SIA (Self-Improving Agent) environment for cloud deployment set -eo pipefail # Exit on any error, pipe failures +# Check if required environment variables are set +if [ -z "$SIA_REPO_URL" ]; then + echo "Error: SIA_REPO_URL environment variable is not set" + exit 1 +fi + # Create directory structure echo "Creating directory structure..." mkdir -p "/root/data/iterations" @@ -29,10 +34,14 @@ npm install npm run build ln -s "/root/sia/web/dist" "/root/static" +# Install SIA dependencies +echo "Installing SIA dependencies..." +"/root/sia/scripts/install.sh" + # Finetune model echo "Finetuning model..." train # Start SIA using restart script -echo "Start restart script..." +echo "Run restart script..." "/root/sia/scripts/restart.sh" \ No newline at end of file diff --git a/scripts/github_keys.sh b/scripts/github_keys.sh index 2598e58..07469f0 100644 --- a/scripts/github_keys.sh +++ b/scripts/github_keys.sh @@ -7,14 +7,9 @@ if [ -z "$SIA_GITHUB_API_KEY" ]; then exit 1 fi -if [ -z "$SIA_REPO_URL" ]; then - echo "Error: SIA_REPO_URL environment variable is not set" - exit 1 -fi - # Install dependencies apt-get update -apt-get install -y jq +apt-get install -y jq openssh-client git # Create SSH directory if it doesn't exist mkdir -p ~/.ssh @@ -26,6 +21,10 @@ if [ ! -f ~/.ssh/sia_repo ]; then ssh-keygen -t ed25519 -f ~/.ssh/sia_repo -N "" fi +# Ensure proper permissions on SSH keys +chmod 600 ~/.ssh/sia_repo +chmod 644 ~/.ssh/sia_repo.pub + # Get the public key SSH_PUBLIC_KEY=$(cat ~/.ssh/sia_repo.pub) @@ -53,4 +52,31 @@ curl -X POST "https://api.github.com/user/keys" \ -H "Accept: application/vnd.github+json" \ -H "Content-Type: application/json" \ -H "Authorization: token $SIA_GITHUB_API_KEY" \ - -d "{\"title\":\"sia\", \"key\":\"$SSH_PUBLIC_KEY\"}" \ No newline at end of file + -d "{\"title\":\"sia\", \"key\":\"$SSH_PUBLIC_KEY\"}" + +# Create SSH config file to specify which key to use for GitHub +echo "Configuring SSH to use the correct key for GitHub..." +cat > ~/.ssh/config << EOF +Host github.com + HostName github.com + User git + IdentityFile ~/.ssh/sia_repo + IdentitiesOnly yes +EOF + +chmod 600 ~/.ssh/config + +# Start SSH agent and add the key +eval $(ssh-agent -s) +ssh-add ~/.ssh/sia_repo + +# Ensure git is configured with a name and email +if ! git config --global user.email > /dev/null; then + echo "Configuring default git user email..." + git config --global user.email "niels.geens@gmail.com" +fi + +if ! git config --global user.name > /dev/null; then + echo "Configuring default git user name..." + git config --global user.name "Niels Geens" +fi \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..5661ce3 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +echo "Installing ITB tool..." +python3 -m venv "/root/venvs/itb" +/root/venvs/itb/bin/pip install -e /root/sia/tools/itb/ + +echo "Installing Train tool..." +python3 -m venv "/root/venvs/train" +/root/venvs/train/bin/pip install -e /root/sia/tools/train/ + +echo "Installing SIA core..." +python3 -m venv "/root/venvs/sia" +/root/venvs/sia/bin/pip install -e /root/sia/ \ No newline at end of file diff --git a/scripts/restart.sh b/scripts/restart.sh index cd95738..341a5a2 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -2,24 +2,9 @@ set -e -echo "=== Preparing SIA environment ===" - -echo "Installing ITB tool..." -python3 -m venv "/root/venvs/itb" -/root/venvs/itb/bin/pip install -e /root/sia/tools/itb/ - -echo "Installing Train tool..." -python3 -m venv "/root/venvs/train" -/root/venvs/train/bin/pip install -e /root/sia/tools/train/ - -echo "Installing SIA core..." -python3 -m venv "/root/venvs/sia" -/root/venvs/sia/bin/pip install -e /root/sia/ - -echo "=== Starting SIA ===" - cd "/root/desktop" while true; do + "/root/sia/scripts/init.sh" sia EXIT_CODE=$?