Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding recoverargo_ssh.sh scripts for ssh via bastion and recoverargo… #33

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions scripts/recoverargo_oc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Check the current project
CURRENT_PROJECT=$(oc project --short=false)
if [ $? -ne 0 ]; then
echo "Failed to get the current project."
exit 1
fi

echo "You are currently in the project: $CURRENT_PROJECT"

# Ask the user if they want to continue
read -p "Would you like to continue and delete resources in the current project? (yes/no): " CONTINUE

if [ "$CONTINUE" != "yes" ]; then
echo "Operation cancelled."
exit 0
fi

oc delete argocd --all -n openshift-gitops
if [ $? -ne 0 ]; then
echo "Failed to delete argocd."
exit 1
fi

oc delete pods --all -n openshift-gitops-operator
if [ $? -ne 0 ]; then
echo "Failed to delete pods."
exit 1
fi

if [ $? -eq 0 ]; then
echo "Commands executed successfully."
else
echo "Failed to execute commands on the remote server."
exit 1
fi

echo "rerun ./bootstrap.sh "
36 changes: 36 additions & 0 deletions scripts/recoverargo_ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Check if the correct number of parameters is passed
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 <ssh_key> <hostname_or_ip> [ssh_port]"
exit 1
fi

SSH_KEY=$1
HOST=$2
SSH_PORT=${3:-22}

# Ask the user if the ssh key needs to be copied
read -p "Do you need to copy the SSH key to the host? (yes/no): " COPY_KEY

if [ "$COPY_KEY" = "yes" ]; then
ssh-copy-id -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -i "$SSH_KEY" -p "$SSH_PORT" "$HOST"
if [ $? -ne 0 ]; then
echo "Failed to copy SSH key."
exit 1
fi
fi

# Run the remote commands
ssh -i "$SSH_KEY" -p "$SSH_PORT" "$HOST" << EOF
oc delete argocd --all -n openshift-gitops
oc delete pods --all -n openshift-gitops-operator
EOF

# Check if the remote commands executed successfully
if [ $? -eq 0 ]; then
echo "Commands executed successfully. \n rerun ./bootstrap.sh"
else
echo "Failed to execute commands on the remote host."
exit 1
fi