{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9682669f-46d2-44b0-bcc6-db65e411b302",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "remove_cell",
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "my_notebook_text = \"\"\"\n",
    "# Homework 3: Linux package management\n",
    "\n",
    "Make sure, you have completed the exercises in Lectures 2 and 3, and have ```kvm3``` and ```rocky10-1``` VMs available. \n",
    "\n",
    "On your VD, create directory ```HW_3```. In the directory, create file README where you put the commands to complete the exercises below.\n",
    "\n",
    "The exercises below assume you already have deployed ```kvm3``` and ```rocky10-1``` on your VD.\n",
    "\n",
    "### Command ```apt```\n",
    "\n",
    "On ```kvm3```:\n",
    "\n",
    "- install package ```lua5.4```\n",
    "- dowload package ```lua5.3```\n",
    "\n",
    "### Command ```dpkg```\n",
    "\n",
    "On ```kvm3```:\n",
    "\n",
    "- List the files contained in package ```lua5.4```\n",
    "- Delete file  /usr/share/doc/lua5.4/changelog.Debian.gz.\n",
    "  Verify installed package ```lua5.4``` for consistency.\n",
    "- Extract the content of ```lua5.3``` package file into new directory LUA.\n",
    "- Uninstall package ```lua5.4```.\n",
    "\n",
    "### Command ```dnf```\n",
    "\n",
    "On ```rocky10-1```:\n",
    "\n",
    "- Install package ```lua```\n",
    "- Download package ```lua```\n",
    "\n",
    "### Command ```rpm```\n",
    "\n",
    "On ```rocky10-1```:\n",
    "\n",
    "- List the files contained in package ```lua```\n",
    "- Delete file /usr/share/man/man1/lua.1.gz.\n",
    "  Verify installed package ```lua``` for consistency.\n",
    "- Uninstall package ```lua```.\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "38d2771b-198c-4070-95e9-dcbe45a21ede",
   "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 3: Linux Package Management\n",
      "\n",
      "## Environment Setup and Prerequisites\n",
      "\n",
      "Before starting this assignment, ensure you have completed the exercises in Lectures 2 and 3 and that your virtual machines (`kvm3` and `rocky10-1`) are deployed and running.\n",
      "\n",
      "### Virtual Desktop Workflow Map\n",
      "\n",
      "```text\n",
      "[Web access to Ravada portal with authentication] ===> [Start VM] ===> [Access VM via SSH with provided port]\n",
      "```\n",
      "\n",
      "### Setup Instructions\n",
      "\n",
      "1. Log into your Virtual Desktop (VD).\n",
      "2. Create a working directory named `HW_3`:\n",
      "   ```bash\n",
      "   mkdir HW_3\n",
      "   cd HW_3\n",
      "   ```\n",
      "3. Inside the `HW_3` directory, create a file named `README`.\n",
      "4. Document all commands used to complete the following exercises inside your `README` file.\n",
      "\n",
      "---\n",
      "\n",
      "## Part 1: Debian Package Management (`kvm3`)\n",
      "\n",
      "Perform the following operations on the **`kvm3`** virtual machine.\n",
      "\n",
      "### Task 1.1: High-Level Management with `apt`\n",
      "* **Install Package:** Install the package `lua5.4`.\n",
      "* **Download Package:** Download the package archive for `lua5.3` without installing it.\n",
      "\n",
      "### Task 1.2: Low-Level Management with `dpkg`\n",
      "* **List Files:** List all files installed and managed by the `lua5.4` package.\n",
      "* **Integrity Check:**\n",
      "  1. Manually delete the file `/usr/share/doc/lua5.4/changelog.Debian.gz`.\n",
      "  2. Verify the installed `lua5.4` package to detect missing or altered files.\n",
      "* **Archive Extraction:** Extract the contents of the downloaded `lua5.3` package file into a new directory named `LUA`.\n",
      "* **Remove Package:** Uninstall the `lua5.4` package.\n",
      "\n",
      "---\n",
      "\n",
      "## Part 2: RPM Package Management (`rocky10-1`)\n",
      "\n",
      "Perform the following operations on the **`rocky10-1`** virtual machine.\n",
      "\n",
      "### Task 2.1: High-Level Management with `dnf`\n",
      "* **Install Package:** Install the package `lua`.\n",
      "* **Download Package:** Download the package archive for `lua` without installing it.\n",
      "\n",
      "### Task 2.2: Low-Level Management with `rpm`\n",
      "* **List Files:** List all files contained in the installed `lua` package.\n",
      "* **Integrity Check:**\n",
      "  1. Manually delete the file `/usr/share/man/man1/lua.1.gz`.\n",
      "  2. Verify the installed `lua` package for consistency to identify missing files.\n",
      "* **Remove Package:** Uninstall the `lua` package.\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",
    "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",
    "try:\n",
    "    response = client.models.generate_content(\n",
    "        model='models/gemini-3.6-flash',\n",
    "        contents= prompt_instructions,\n",
    "        )\n",
    "\n",
    "    #print(response.text)\n",
    "\n",
    "    output_text = response.text\n",
    "    print(output_text)\n",
    "    \n",
    "except APIError as e:\n",
    "    raise e"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a33e450d-6e3a-40b7-96a3-735d2b56e906",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Homework 3: Linux Package Management\n",
    "\n",
    "**Due Date:** Tuesday, September 22, 2026\n",
    "\n",
    "## Environment Setup and Prerequisites\n",
    "\n",
    "Before starting this assignment, ensure you have completed the exercises in Lectures 2 and 3 and that your virtual machines (`kvm3` and `rocky10-1`) are deployed and running.\n",
    "\n",
    "### Virtual Desktop Workflow Map\n",
    "\n",
    "```text\n",
    "[Web access to Ravada portal with authentication] ===> [Start VM] ===> [Access VM via SSH with provided port]\n",
    "```\n",
    "\n",
    "### Setup Instructions\n",
    "\n",
    "1. Log into your Virtual Desktop (VD).\n",
    "2. Create a working directory named `HW_3`:\n",
    "   ```bash\n",
    "   mkdir HW_3\n",
    "   cd HW_3\n",
    "   ```\n",
    "3. Inside the `HW_3` directory, create a file named `README`.\n",
    "4. Document all commands used to complete the following exercises inside your `README` file.\n",
    "\n",
    "---\n",
    "\n",
    "## Part 1: Debian Package Management (`kvm3`)\n",
    "\n",
    "Perform the following operations on the **`kvm3`** virtual machine.\n",
    "\n",
    "### Task 1.1: High-Level Management with `apt`\n",
    "* **Install Package:** Install the package `lua5.4`.\n",
    "* **Download Package:** Download the package archive for `lua5.3` without installing it.\n",
    "\n",
    "### Task 1.2: Low-Level Management with `dpkg`\n",
    "* **List Files:** List all files installed and managed by the `lua5.4` package.\n",
    "* **Integrity Check:**\n",
    "  1. Manually delete the file `/usr/share/doc/lua5.4/changelog.Debian.gz`.\n",
    "  2. Verify the installed `lua5.4` package to detect missing or altered files.\n",
    "* **Archive Extraction:** Extract the contents of the downloaded `lua5.3` package file into a new directory named `LUA`.\n",
    "* **Remove Package:** Uninstall the `lua5.4` package.\n",
    "\n",
    "---\n",
    "\n",
    "## Part 2: RPM Package Management (`rocky10-1`)\n",
    "\n",
    "Perform the following operations on the **`rocky10-1`** virtual machine.\n",
    "\n",
    "### Task 2.1: High-Level Management with `dnf`\n",
    "* **Install Package:** Install the package `lua`.\n",
    "* **Download Package:** Download the package archive for `lua` without installing it.\n",
    "\n",
    "### Task 2.2: Low-Level Management with `rpm`\n",
    "* **List Files:** List all files contained in the installed `lua` package.\n",
    "* **Integrity Check:**\n",
    "  1. Manually delete the file `/usr/share/man/man1/lua.1.gz`.\n",
    "  2. Verify the installed `lua` package for consistency to identify missing files.\n",
    "* **Remove Package:** Uninstall the `lua` package."
   ]
  }
 ],
 "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
}
