Fix the ssh command

This commit is contained in:
2021-05-01 13:32:52 +01:00
parent 7bf4f21d92
commit 2d25e61e34
3 changed files with 18 additions and 11 deletions

View File

@@ -9,13 +9,15 @@ SSHPATH="$HOME/.ssh/id_ed25519" # The path to the SSH key file
TITLE="$USER@$(cat /etc/hostname)" # The title for the SSH key
# Generate the SSH key if it does not exist
if [ ! -f $SSHPATH ] && ssh-keygen -t ed25519 -f "$SSHPATH" -N "" -q
[ ! -f $SSHPATH ] && ssh-keygen -t ed25519 -f "$SSHPATH" -N "" -q
KEY=$(cat "$SSHPATH.pub")
# A method to generate the parameters for creating an SSH key on gitea
generate_post_data() {
cat <<EOF
{
"key": "$(cat "$SSHPATH.pub")",
"key": "$KEY",
"read_only": false,
"title": "$TITLE"
}
@@ -23,14 +25,14 @@ EOF
}
CREDENTIALS="$LABSUN:$LABSPW" # The credentials to pass to the API
KEYS_URL="https://$CREDENTIALS@labs.scarif.space/api/v1/users/keys"
KEYS_URL="https://$CREDENTIALS@labs.scarif.space/api/v1/user/keys"
# Get all the existing keys
KEYS=$(curl -X GET -s --url "$KEYS_URL")
KEY_EXISTS=$(echo $KEYS | jq --arg KEY "$(cat "$SSHPATH.pub")" 'contains({ key: $KEY })')
KEY_EXISTS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(.title)|contains([$TITLE])')
if [[ $KEY_EXISTS != true ]]; do
if [[ $KEY_EXISTS != true ]]; then
# Extract the ids of the keys with the same title as this machine
IDS=$(echo $KEYS | jq --arg TITLE "$TITLE" 'map(select(.title == $TITLE))[].id')
@@ -65,6 +67,6 @@ for dir in $(ls "$HOME/.local/src"); do
fi
done
DOTFILES_SSH_URL=$(git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" get-url origin | sed "$HTTP_REPLACE")
git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" set-url origin "$DOTFILES_SSH_URL"
DOTFILES_SSH_URL=$(git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" remote get-url origin | sed "$HTTP_REPLACE")
git --git-dir "$HOME/.config/dotfiles/.git" --work-tree="$HOME" remote set-url origin "$DOTFILES_SSH_URL"