{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "458d90bc",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "remove-cell",
     "remove_cell"
    ]
   },
   "outputs": [],
   "source": [
    "my_notebook_text = \"\"\"\n",
    "##  Homework 5: ssh, scp, rsync\n",
    "\n",
    "Due Date: Tuesday, October 6, 2026\n",
    "\n",
    "1. Log into your Virtual Desktop (VD).\n",
    "2. Create a working directory named `HW_5`:\n",
    "   ```bash\n",
    "   mkdir HW_5\n",
    "   cd HW_5\n",
    "   ```\n",
    "3. Inside the `HW_5` directory, create a file named `README`.\n",
    "4. Document all commands used to complete the following exercises inside your `README` file.\n",
    "\n",
    "#### Make SSH service working on both `master` and `n01`:\n",
    "\n",
    "Remove the SSH password authentication restriction configuration file:\n",
    "```bash\n",
    "sudo rm /etc/ssh/sshd_config.d/60-cloudimg-settings.conf\n",
    "```\n",
    "\n",
    "Restart SSH service:\n",
    "```bash\n",
    "sudo systemctl restart sshd\n",
    "```\n",
    "\n",
    "#### Using SSH, scp and rsync\n",
    "- Set private/public SSH key authentication for user hostadm to SSH between ```master``` and ```n01```.\n",
    "\n",
    "- Have user hostadm to download deb package ```vim``` on ```master```.\n",
    "\n",
    "Extract the deb file content into new directory VIM.\n",
    "\n",
    "- By using recursive ```scp``` (option ```-r```), copy subdirectory ```doc``` from VIM/usr/share to the home directory of user hostadm on ```n01```.\n",
    "\n",
    "- By using ```rsync```, copy the subdirectory ```doc``` to /tmp directory on ```n01```.\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d859f328-3b8b-478d-a4fe-d36d1d83de1e",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "remove-cell",
     "remove_cell"
    ]
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## Homework 5: ssh, scp, rsync\n",
      "\n",
      "Due Date: Tuesday, October 6, 2026\n",
      "\n",
      "```text\n",
      "[Web access to Ravada portal with authentication] ===> [Start VM] ===> [Access VM via SSH with provided port]\n",
      "```\n",
      "\n",
      "1. Log into your Virtual Desktop (VD).\n",
      "2. Create a working directory named `HW_5`:\n",
      "   ```bash\n",
      "   mkdir HW_5\n",
      "   cd HW_5\n",
      "   ```\n",
      "3. Inside the `HW_5` directory, create a file named `README`.\n",
      "4. Document all commands used to complete the following exercises inside your `README` file.\n",
      "\n",
      "### Make SSH service working on both `master` and `n01`\n",
      "\n",
      "Remove the SSH password authentication restriction configuration file:\n",
      "```bash\n",
      "sudo rm /etc/ssh/sshd_config.d/60-cloudimg-settings.conf\n",
      "```\n",
      "\n",
      "Restart the SSH service:\n",
      "```bash\n",
      "sudo systemctl restart sshd\n",
      "```\n",
      "\n",
      "### Using SSH, scp, and rsync\n",
      "\n",
      "- Set private/public SSH key authentication for user `hostadm` to enable SSH access between `master` and `n01`.\n",
      "- Have user `hostadm` download the `vim` `.deb` package on `master`.\n",
      "- Extract the `.deb` file contents into a new directory named `VIM`.\n",
      "- Using recursive `scp` (with the `-r` option), copy the subdirectory `doc` from `VIM/usr/share` to the home directory of user `hostadm` on `n01`.\n",
      "- Using `rsync`, copy the subdirectory `doc` to the `/tmp` directory on `n01`.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import time\n",
    "import base64 \n",
    "from google import genai\n",
    "from google.genai.errors import APIError\n",
    "\n",
    "os.environ[\"GEMINI_API_KEY\"] = \"AQ.Ab8RN6K9G5S-h6IWgpUgfmHbIk7b8iZlWTuYptMFqOT4Ph6FnQ\"\n",
    "client = genai.Client()\n",
    "\n",
    "# Use triple quotes \"\" \" so you can paste long paragraphs easily!\n",
    "\n",
    "prompt_instructions_simple = f\"Rewrite this text for a university course. Make it clear and write WCAG 2.1 AA compliant alt text descriptions for any charts mentioned: {my_notebook_text}\"\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "prompt_instructions_detailed5 = (\n",
    "    \"You are processing raw course text meant for Jupyter Notebook markdown cells.\\n\\n\"\n",
    "    \n",
    "    \"CRITICAL RULE: Do NOT delete, alter, or remove any original image links, image paths, \"\n",
    "    \"or image tags (e.g., lines starting with `![...](...)` or containing `<img ...>`). \"\n",
    "    \"Leave them exactly where they are in the original text sequence.\\n\\n\"\n",
    "    \n",
    "    \"INSTRUCTION:\\n\"\n",
    "    \"Rewrite the text to make it clear and university-appropriate.Make it clear and write WCAG 2.1 AA compliant. Use the following strict sequence \"\n",
    "    \"when dealing with image placements:\\n\\n\"\n",
    "    \n",
    "    \"1. First, insert the NEW Text-Based Structured Alternative ABOVE the image:\\n\"\n",
    "    \"   - For numerical data charts or grid plots: Provide a clean Markdown Data Table.\\n\"\n",
    "    \"   - For hardware architecture, network layouts, or OS Process lifecycles (like fork(), process states, execution threads): \"\n",
    "    \"Provide a high-level text flowchart inside a preformatted ```text code block.\\n\"\n",
    "    \"   - For Terminal Commands or Pipelines (like stdin/stdout piping, shell interactions): \"\n",
    "    \"Provide a vertical box-and-arrow sequence map illustrating data flow from one utility to the next.\\n\"\n",
    "    \"   - Keep diagram characters perfectly aligned and compatible with static HTML page exports.\\n\\n\"\n",
    "    \"   - CRITICAL RULE FOR VIRTUAL DESKTOP LOGIN CONTEXT:\\n\"\n",
    "    \"     If the text or diagram is about logging into the Virtual Desktop or using Ravada, \"\n",
    "    \"the text diagram sequence MUST start exactly with this workflow path:\\n\"\n",
    "    \"     [Web access to Ravada portal with authentication] ===> [Start VM] ===> [Access VM via SSH with provided port]\\n\\n\"\n",
    "    \n",
    "    \"2. Second, place the ORIGINAL untouched image link exactly as it was.\\n\\n\"\n",
    "    \n",
    "    \"3. Third, immediately BELOW the original image link, add the Comprehensive Detailed Description:\\n\"\n",
    "    \"Inside this caption block, you MUST start with the exact text '**Accessible Image Description:**'. Place it always under the image.\"\n",
    "    \"   - Overview: One sentence describing what the visual shows at a high level.\\n\"\n",
    "    \"   - Setup: Explain the primary components, labels, axes, or code pathways without hyper-granular specs.\\n\"\n",
    "    \"   - Key Takeaways: Core conceptual trends or execution results shown.\\n\\n\"\n",
    "\n",
    "    f\"Course Text:\\n{my_notebook_text}\"\n",
    ")\n",
    "prompt_instructions = prompt_instructions_detailed5\n",
    "\n",
    "# Trying the 2.5-flash model which often has lower server congestion\n",
    "try:\n",
    "    response = client.models.generate_content(\n",
    "        model='models/gemini-3.5-flash-lite',\n",
    "        contents= prompt_instructions,\n",
    "        )\n",
    "\n",
    "    #print(response.text)\n",
    "\n",
    "    output_text = response.text\n",
    "    print(output_text)\n",
    "    \n",
    "    # --- THE MAGIC TRICK ---\n",
    "    # This forces Jupyter to create a new cell below and paste the AI response inside it!\n",
    "    #get_ipython().set_next_input(response.text)\n",
    "    \n",
    "except APIError as e:\n",
    "    if e.code == 503:\n",
    "        print(\"Servers are still busy. Waiting 5 seconds before a quick automatic retry...\")\n",
    "        time.sleep(5)\n",
    "        # Automatic second attempt\n",
    "        response = client.models.generate_content(\n",
    "            model='models/gemini-3.5-flash-lite',\n",
    "            contents= prompt_instructions,\n",
    "            )\n",
    "        print(response.text)\n",
    "        # --- THE MAGIC TRICK ---\n",
    "        # This forces Jupyter to create a new cell below and paste the AI response inside it!\n",
    "        #get_ipython().set_next_input(response.text)\n",
    "    else:\n",
    "        raise e\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0a52933-2fec-44c2-850c-f4904f3ec06f",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## Homework 5: ssh, scp, rsync\n",
    "\n",
    "Due Date: Tuesday, October 6, 2026\n",
    "\n",
    "```text\n",
    "[Web access to Ravada portal with authentication] ===> [Start VM] ===> [Access VM via SSH with provided port]\n",
    "```\n",
    "\n",
    "1. Log into your Virtual Desktop (VD).\n",
    "2. Create a working directory named `HW_5`:\n",
    "   ```bash\n",
    "   mkdir HW_5\n",
    "   cd HW_5\n",
    "   ```\n",
    "3. Inside the `HW_5` directory, create a file named `README`.\n",
    "4. Document all commands used to complete the following exercises inside your `README` file.\n",
    "\n",
    "### Make SSH service working on both `master` and `n01`\n",
    "\n",
    "Remove the SSH password authentication restriction configuration file:\n",
    "```bash\n",
    "sudo rm /etc/ssh/sshd_config.d/60-cloudimg-settings.conf\n",
    "```\n",
    "\n",
    "Restart the SSH service:\n",
    "```bash\n",
    "sudo systemctl restart sshd\n",
    "```\n",
    "\n",
    "### Using SSH, scp, and rsync\n",
    "\n",
    "- Set private/public SSH key authentication for user `hostadm` to enable SSH access between `master` and `n01`.\n",
    "- Have user `hostadm` download the `vim` `.deb` package on `master`.\n",
    "- Extract the `.deb` file contents into a new directory named `VIM`.\n",
    "- Using recursive `scp` (with the `-r` option), copy the subdirectory `doc` from `VIM/usr/share` to the home directory of user `hostadm` on `n01`.\n",
    "- Using `rsync`, copy the subdirectory `doc` to the `/tmp` directory on `n01`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a29ec403-ff7e-42a6-8d74-54b0473ae24e",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
