Skip to content

Latest commit

 

History

History
102 lines (79 loc) · 2.61 KB

TODO.ASCIINEMA.md

File metadata and controls

102 lines (79 loc) · 2.61 KB

Here's a shell script to automate the process of starting a recording, running specified commands, ending the recording, and optionally uploading it to Asciinema.org. The script will prompt for login if you choose to upload.

Shell Script: record_cdactl.sh

#!/bin/bash

# Check if asciinema is installed
if ! command -v asciinema &> /dev/null
then
    echo "asciinema could not be found, please install it first."
    exit
fi

# Function to start recording
start_recording() {
    echo "Starting asciinema recording..."
    asciinema rec demo.cast -c "$@"
}

# Function to end recording
end_recording() {
    echo "Recording stopped."
}

# Function to upload recording
upload_recording() {
    read -p "Do you want to upload the recording to Asciinema.org? (y/n): " upload
    if [ "$upload" == "y" ]; then
        echo "Uploading recording..."
        asciinema auth
        asciinema upload demo.cast
    else
        echo "Recording saved locally as demo.cast"
    fi
}

# Commands to run
COMMANDS=$(cat << EOF
cdactl network status
cdactl ssh <hostname>
cdactl update
cdactl backup create
cdactl monitor
cdactl dotfiles init
cdactl dotfiles add .zshrc
cdactl cred store git cdaprod
cdactl cred retrieve
EOF
)

# Start recording
start_recording "$COMMANDS"

# Wait for user input to end recording
read -p "Press any key to stop recording..." -n1 -s

# End recording
end_recording

# Upload recording
upload_recording

Usage

  1. Save the script: Save the above script as record_cdactl.sh.

  2. Make the script executable:

    chmod +x record_cdactl.sh
  3. Run the script:

    ./record_cdactl.sh

Steps Explained

  1. Check for Asciinema: The script first checks if Asciinema is installed. If not, it prompts the user to install it.

  2. Define Functions:

    • start_recording(): Starts the Asciinema recording.
    • end_recording(): Ends the recording.
    • upload_recording(): Prompts the user if they want to upload the recording to Asciinema.org. If yes, it authenticates (if not already) and uploads the recording.
  3. Commands to Run: A list of cdactl commands to record.

  4. Start Recording: The script starts recording and runs the specified commands.

  5. End Recording: The user is prompted to press any key to stop the recording.

  6. Upload Recording: The script asks if the user wants to upload the recording to Asciinema.org. If the user agrees, it handles the upload process.

This script automates the entire process of recording terminal sessions with cdactl, ensuring that the recording and subsequent handling are as seamless as possible.