More improvements to bootstrap

This commit is contained in:
Niels Geens
2025-03-17 10:38:36 +01:00
parent 2d655781c8
commit 5c1ef4d9e7
4 changed files with 58 additions and 25 deletions

View File

@@ -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\"}"
-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