{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3b7cae68-dcab-4520-b1bd-309c71b1b27a",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "remove-cell",
     "remove_cell"
    ]
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<>:126: SyntaxWarning: invalid escape sequence '\\;'\n",
      "<>:126: SyntaxWarning: invalid escape sequence '\\;'\n",
      "/tmp/ipykernel_302572/1479612387.py:126: SyntaxWarning: invalid escape sequence '\\;'\n",
      "  find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n"
     ]
    }
   ],
   "source": [
    "my_notebook_text = \"\"\"\n",
    "# Summer 2026 Midterm exam Q-and-A.\n",
    "\n",
    "June 22 2026. Time 6:00 p.m. -- 9:00 p.m.\n",
    "\n",
    "Number of exercises:4. Each exercise has a maximum score. \n",
    "\n",
    "In home directory of user hostadm, you need to create a new subdirectory, ```MIDTERM``` and a file within it, ```answers.txt```, where you will be writing answers to the exam exercises.\n",
    "\n",
    "In the file, first, put your name, then proceed with answering to the questions below.\n",
    "\n",
    "\n",
    "\n",
    "***\n",
    "##  1. VM deployment in KVM (max score 5)\n",
    "\n",
    "A) Create a new VMs, vmm26, by cloning kvm1.\n",
    "\n",
    "B) Set hostname to IP address resolution for vmm26 on your virtual desktop (VD).\n",
    "   \n",
    "   Make sure you can ```ping vmm26``` from the desktop.\n",
    "   \n",
    "C) Enable SSH service on vmm26. Make sure you can SSH from the ```VD``` to ```vmm26```.\n",
    "\n",
    "D) Set SSH public/private key authentication for SSH connection from the ```VD``` to ```vmm26``` with empty passphrase.\n",
    "\n",
    "Verify you can ssh to vmm26 without password.\n",
    "\n",
    "***Answers***\n",
    "\n",
    "- A.\n",
    "\n",
    "```bash\n",
    "virt-clone -o kvm1 -n vmm26 -f KVM/vmm26.qcow2\n",
    "virsh start vmm26\n",
    "virsh console vmm26\n",
    "```\n",
    "\n",
    "- B.\n",
    "```bash\n",
    "virsh domfiaddr vmm26\n",
    "\n",
    "nano /etc/hosts # add \"192.168.122.165 vmm26\"\n",
    "\n",
    "ping -c 3 vmm26\n",
    "```\n",
    "\n",
    "- C.\n",
    "```bash\n",
    "sudo rm /etc/ssh//sshd_config.d/60-cloudimg-settings.conf\n",
    "sudo ssh-keygen -A\n",
    "sudo systemctl restart sshd\n",
    "\n",
    "mkdir .ssh\n",
    "```\n",
    "\n",
    "- D.\n",
    "```bash\n",
    "ssh-keygen -t rsa\n",
    "scp .ssh/id_rsa.pub  hostadm@vmm26:.ssh/authorized_keys\n",
    "```\n",
    "\n",
    "***\n",
    "## 2. Command apt and dpkg (max score 3)\n",
    "\n",
    "A) Download package ```qt6-networkauth-dev``` into directory MIDTERM on the VD. \n",
    "\n",
    "B) Extract the package content into new directory ```DEB```.\n",
    "\n",
    "***Answers***\n",
    "\n",
    "- A.\n",
    "```bash\n",
    "apt download qt6-networkauth-dev\n",
    "```\n",
    "\n",
    "- B.\n",
    "```bash\n",
    "dpkg -X qt6-networkauth-dev_6.4.2-1_amd64.deb DEB\n",
    "```\n",
    "\n",
    "***\n",
    "## 3. Command ```find``` (max score 5)\n",
    "\n",
    "In directory ```DEB```,\n",
    "\n",
    "A) Find all files with extension ```.json```\n",
    "\n",
    "B) Find the largest file in directory DEB.\n",
    "\n",
    "C) Find all files of sizes between 2000 bytes and 3000 bytes.\n",
    "\n",
    "D) In directory MIDTERM, create new directory HED.\n",
    "\n",
    "  By using command ```find``` with ```-exec``` option, copy all the files with extension ```.h``` from all subdirectories in DEB into directory HED.\n",
    "\n",
    "***Answers***\n",
    "- A.\n",
    "```bash\n",
    "find DEB -name \"*.json\"\n",
    "```\n",
    "\n",
    "    DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
    "    DEB/usr/share/qt6/modules/NetworkAuth.json\n",
    "\n",
    "- B.\n",
    "```bash\n",
    "find DEB -size +100k\n",
    "find DEB -size +10k -ls\n",
    "```\n",
    "\n",
    "    1703682 44 -rw-r--r--   1 hostadm  hostadm  41053 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
    "\n",
    "- C.\n",
    "```bash\n",
    "find DEB -size +2000c -size -3000c -ls\n",
    "```\n",
    "    1703673      4 -rw-r--r--   1 hostadm  hostadm      2461 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthAdditionalTargetInfo.cmake\n",
    "    1703675      4 -rw-r--r--   1 hostadm  hostadm      2853 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthConfigVersion.cmake\n",
    "    1703666      4 -rw-r--r--   1 hostadm  hostadm      2507 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth1signature.h\n",
    "    1703667      4 -rw-r--r--   1 hostadm  hostadm      2412 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth2authorizationcodeflow.h\n",
    "\n",
    "- D.\n",
    "```bash\n",
    "mkdir HED\n",
    "find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
    "```\n",
    "\n",
    "\n",
    "***\n",
    "## 4. Commands ```tar```, ```scp``` and shell scripts (max score 7)\n",
    "\n",
    "A) Archive directory HED with ```tar/gzip``` into file ```HED.tgz```.\n",
    "\n",
    "B) Copy the archive onto vmm26 by using command ```scp``` into hostadm home directory.\n",
    "\n",
    "C) Extract the archive on vmm26 by using SSH command. Note, with SSH bublic key authentication, there is no need for password to run command ```tar``` remotely via SSH to vmm26.\n",
    "\n",
    "D) In directory MIDTERM, create shell script with name ```find_archive_1.sh``` that completes exercises 3D, 4A, 4B, and 4C above.\n",
    "\n",
    "E) Create a modified version of the script, ```find_archive_2.sh```, that \n",
    "- takes file names as an input prameter in the command line,\n",
    "- if directory HED already exists, it removes the directory before creating it.\n",
    "- Run ```find_archive_2.sh``` for files ```*.json```.\n",
    "\n",
    "***Answers***\n",
    "\n",
    "- A.\n",
    "```bash\n",
    "tar -zcvf HED.tgz HED\n",
    "```\n",
    "\n",
    "- B.\n",
    "```bash\n",
    "scp HED.tgz vmm26:\n",
    "```\n",
    "\n",
    "- C.\n",
    "```bash\n",
    "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n",
    "\n",
    "- D\n",
    "```c\n",
    "   #!/bin/bash\n",
    "\n",
    "   mkdir DEB\n",
    "   \n",
    "   find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
    "   tar -zcvf HED.tgz HED\n",
    "   scp HED.tgz vmm26:\n",
    "   ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n",
    "\n",
    "- E.\n",
    "```c\n",
    "   #!/bin/bash\n",
    "\n",
    "   [ -d HED ] && rm -rf HED\n",
    "   mkdir HED\n",
    "\n",
    "   find DEB/ -name \"$1\" -exec cp '{}' HED \\;\n",
    "   tar -zcvf HED.tgz HED\n",
    "   scp HED.tgz vmm26:\n",
    "   ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d96018e1-241a-4e60-8fd0-a14e799d9875",
   "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": [
      "# Summer 2026 Midterm Exam Q&A\n",
      "\n",
      "**Date:** June 22, 2026  \n",
      "**Time:** 6:00 p.m. -- 9:00 p.m.  \n",
      "**Number of Exercises:** 4 (Each exercise has a maximum score indicated)\n",
      "\n",
      "In the home directory of user `hostadm`, you need to create a new subdirectory named `MIDTERM` and a file within it named `answers.txt`, where you will write your answers to the exam exercises.\n",
      "\n",
      "In the file, first put your name, then proceed with answering the questions below.\n",
      "\n",
      "***\n",
      "\n",
      "## 1. VM Deployment in KVM (Max Score: 5)\n",
      "\n",
      "A) Create a new virtual machine, `vmm26`, by cloning `kvm1`.\n",
      "\n",
      "B) Set up hostname-to-IP-address resolution for `vmm26` on your virtual desktop (VD). Make sure you can `ping vmm26` from the desktop.\n",
      "\n",
      "C) Enable the SSH service on `vmm26`. Make sure you can establish an SSH connection from the `VD` to `vmm26`.\n",
      "\n",
      "D) Set up SSH public/private key authentication for the connection from the `VD` to `vmm26` with an empty passphrase. Verify that you can connect via `ssh` to `vmm26` without a password.\n",
      "\n",
      "### Answers\n",
      "\n",
      "- **A.**\n",
      "```bash\n",
      "virt-clone -o kvm1 -n vmm26 -f KVM/vmm26.qcow2\n",
      "virsh start vmm26\n",
      "virsh console vmm26\n",
      "```\n",
      "\n",
      "- **B.**\n",
      "```bash\n",
      "virsh domifaddr vmm26\n",
      "\n",
      "sudo nano /etc/hosts # add \"192.168.122.165 vmm26\"\n",
      "\n",
      "ping -c 3 vmm26\n",
      "```\n",
      "\n",
      "- **C.**\n",
      "```bash\n",
      "sudo rm /etc/ssh/sshd_config.d/60-cloudimg-settings.conf\n",
      "sudo ssh-keygen -A\n",
      "sudo systemctl restart sshd\n",
      "\n",
      "mkdir ~/.ssh\n",
      "```\n",
      "\n",
      "- **D.**\n",
      "```bash\n",
      "ssh-keygen -t rsa\n",
      "scp ~/.ssh/id_rsa.pub hostadm@vmm26:.ssh/authorized_keys\n",
      "```\n",
      "\n",
      "***\n",
      "\n",
      "## 2. Apt and Dpkg Commands (Max Score: 3)\n",
      "\n",
      "A) Download the package `qt6-networkauth-dev` into the `MIDTERM` directory on the VD. \n",
      "\n",
      "B) Extract the package contents into a new directory named `DEB`.\n",
      "\n",
      "### Answers\n",
      "\n",
      "- **A.**\n",
      "```bash\n",
      "apt download qt6-networkauth-dev\n",
      "```\n",
      "\n",
      "- **B.**\n",
      "```bash\n",
      "dpkg -X qt6-networkauth-dev_6.4.2-1_amd64.deb DEB\n",
      "```\n",
      "\n",
      "***\n",
      "\n",
      "## 3. The `find` Command (Max Score: 5)\n",
      "\n",
      "Inside the `DEB` directory:\n",
      "\n",
      "A) Find all files with the extension `.json`.\n",
      "\n",
      "B) Find the largest file in the `DEB` directory.\n",
      "\n",
      "C) Find all files with sizes between 2000 bytes and 3000 bytes.\n",
      "\n",
      "D) In the `MIDTERM` directory, create a new directory named `HED`. Using the `find` command with the `-exec` option, copy all files with the `.h` extension from all subdirectories inside `DEB` into the `HED` directory.\n",
      "\n",
      "### Answers\n",
      "\n",
      "- **A.**\n",
      "```bash\n",
      "find DEB -name \"*.json\"\n",
      "```\n",
      "```text\n",
      "DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
      "DEB/usr/share/qt6/modules/NetworkAuth.json\n",
      "```\n",
      "\n",
      "- **B.**\n",
      "```bash\n",
      "find DEB -size +100k\n",
      "find DEB -size +10k -ls\n",
      "```\n",
      "```text\n",
      "1703682 44 -rw-r--r--   1 hostadm  hostadm  41053 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
      "```\n",
      "\n",
      "- **C.**\n",
      "```bash\n",
      "find DEB -size +2000c -size -3000c -ls\n",
      "```\n",
      "```text\n",
      "1703673      4 -rw-r--r--   1 hostadm  hostadm      2461 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthAdditionalTargetInfo.cmake\n",
      "1703675      4 -rw-r--r--   1 hostadm  hostadm      2853 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthConfigVersion.cmake\n",
      "1703666      4 -rw-r--r--   1 hostadm  hostadm      2507 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth1signature.h\n",
      "1703667      4 -rw-r--r--   1 hostadm  hostadm      2412 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth2authorizationcodeflow.h\n",
      "```\n",
      "\n",
      "- **D.**\n",
      "```bash\n",
      "mkdir HED\n",
      "find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
      "```\n",
      "\n",
      "***\n",
      "\n",
      "## 4. Commands `tar`, `scp`, and Shell Scripts (Max Score: 7)\n",
      "\n",
      "A) Archive the `HED` directory using `tar`/`gzip` into a file named `HED.tgz`.\n",
      "\n",
      "B) Copy the archive onto `vmm26` using the `scp` command into the `hostadm` home directory.\n",
      "\n",
      "C) Extract the archive on `vmm26` using an SSH command. Note: With SSH public key authentication, no password is required to run the `tar` command remotely via SSH on `vmm26`.\n",
      "\n",
      "D) In the `MIDTERM` directory, create a shell script named `find_archive_1.sh` that completes exercises 3D, 4A, 4B, and 4C above.\n",
      "\n",
      "E) Create a modified version of the script, `find_archive_2.sh`, that:\n",
      "- Takes file names as an input parameter from the command line.\n",
      "- If the `HED` directory already exists, removes it before creating a new one.\n",
      "- Runs `find_archive_2.sh` for `*.json` files.\n",
      "\n",
      "### Answers\n",
      "\n",
      "- **A.**\n",
      "```bash\n",
      "tar -zcvf HED.tgz HED\n",
      "```\n",
      "\n",
      "- **B.**\n",
      "```bash\n",
      "scp HED.tgz vmm26:\n",
      "```\n",
      "\n",
      "- **C.**\n",
      "```bash\n",
      "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
      "```\n",
      "\n",
      "- **D.**\n",
      "```bash\n",
      "#!/bin/bash\n",
      "\n",
      "mkdir DEB\n",
      "\n",
      "find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
      "tar -zcvf HED.tgz HED\n",
      "scp HED.tgz vmm26:\n",
      "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
      "```\n",
      "\n",
      "- **E.**\n",
      "```bash\n",
      "#!/bin/bash\n",
      "\n",
      "[ -d HED ] && rm -rf HED\n",
      "mkdir HED\n",
      "\n",
      "find DEB/ -name \"$1\" -exec cp '{}' HED \\;\n",
      "tar -zcvf HED.tgz HED\n",
      "scp HED.tgz vmm26:\n",
      "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
      "```\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": "0c912b6e-effe-445a-8775-7ad667678f2d",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Summer 2026 Midterm Exam Q&A\n",
    "\n",
    "**Date:** June 22, 2026  \n",
    "**Time:** 6:00 p.m. -- 9:00 p.m.  \n",
    "**Number of Exercises:** 4 (Each exercise has a maximum score indicated)\n",
    "\n",
    "In the home directory of user `hostadm`, you need to create a new subdirectory named `MIDTERM` and a file within it named `answers.txt`, where you will write your answers to the exam exercises.\n",
    "\n",
    "In the file, first put your name, then proceed with answering the questions below.\n",
    "\n",
    "***\n",
    "\n",
    "## 1. VM Deployment in KVM (Max Score: 5)\n",
    "\n",
    "A) Create a new virtual machine, `vmm26`, by cloning `kvm1`.\n",
    "\n",
    "B) Set up hostname-to-IP-address resolution for `vmm26` on your virtual desktop (VD). Make sure you can `ping vmm26` from the desktop.\n",
    "\n",
    "C) Enable the SSH service on `vmm26`. Make sure you can establish an SSH connection from the `VD` to `vmm26`.\n",
    "\n",
    "D) Set up SSH public/private key authentication for the connection from the `VD` to `vmm26` with an empty passphrase. Verify that you can connect via `ssh` to `vmm26` without a password.\n",
    "\n",
    "### Answers\n",
    "\n",
    "- **A.**\n",
    "```bash\n",
    "virt-clone -o kvm1 -n vmm26 -f KVM/vmm26.qcow2\n",
    "virsh start vmm26\n",
    "virsh console vmm26\n",
    "```\n",
    "\n",
    "- **B.**\n",
    "```bash\n",
    "virsh domifaddr vmm26\n",
    "\n",
    "sudo nano /etc/hosts # add \"192.168.122.165 vmm26\"\n",
    "\n",
    "ping -c 3 vmm26\n",
    "```\n",
    "\n",
    "- **C.**\n",
    "```bash\n",
    "sudo rm /etc/ssh/sshd_config.d/60-cloudimg-settings.conf\n",
    "sudo ssh-keygen -A\n",
    "sudo systemctl restart sshd\n",
    "\n",
    "mkdir ~/.ssh\n",
    "```\n",
    "\n",
    "- **D.**\n",
    "```bash\n",
    "ssh-keygen -t rsa\n",
    "scp ~/.ssh/id_rsa.pub hostadm@vmm26:.ssh/authorized_keys\n",
    "```\n",
    "\n",
    "***\n",
    "\n",
    "## 2. Apt and Dpkg Commands (Max Score: 3)\n",
    "\n",
    "A) Download the package `qt6-networkauth-dev` into the `MIDTERM` directory on the VD. \n",
    "\n",
    "B) Extract the package contents into a new directory named `DEB`.\n",
    "\n",
    "### Answers\n",
    "\n",
    "- **A.**\n",
    "```bash\n",
    "apt download qt6-networkauth-dev\n",
    "```\n",
    "\n",
    "- **B.**\n",
    "```bash\n",
    "dpkg -X qt6-networkauth-dev_6.4.2-1_amd64.deb DEB\n",
    "```\n",
    "\n",
    "***\n",
    "\n",
    "## 3. The `find` Command (Max Score: 5)\n",
    "\n",
    "Inside the `DEB` directory:\n",
    "\n",
    "A) Find all files with the extension `.json`.\n",
    "\n",
    "B) Find the largest file in the `DEB` directory.\n",
    "\n",
    "C) Find all files with sizes between 2000 bytes and 3000 bytes.\n",
    "\n",
    "D) In the `MIDTERM` directory, create a new directory named `HED`. Using the `find` command with the `-exec` option, copy all files with the `.h` extension from all subdirectories inside `DEB` into the `HED` directory.\n",
    "\n",
    "### Answers\n",
    "\n",
    "- **A.**\n",
    "```bash\n",
    "find DEB -name \"*.json\"\n",
    "```\n",
    "```text\n",
    "DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
    "DEB/usr/share/qt6/modules/NetworkAuth.json\n",
    "```\n",
    "\n",
    "- **B.**\n",
    "```bash\n",
    "find DEB -size +100k\n",
    "find DEB -size +10k -ls\n",
    "```\n",
    "```text\n",
    "1703682 44 -rw-r--r--   1 hostadm  hostadm  41053 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/metatypes/qt6networkauth_none_metatypes.json\n",
    "```\n",
    "\n",
    "- **C.**\n",
    "```bash\n",
    "find DEB -size +2000c -size -3000c -ls\n",
    "```\n",
    "```text\n",
    "1703673      4 -rw-r--r--   1 hostadm  hostadm      2461 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthAdditionalTargetInfo.cmake\n",
    "1703675      4 -rw-r--r--   1 hostadm  hostadm      2853 Jan 26  2023 DEB/usr/lib/x86_64-linux-gnu/cmake/Qt6NetworkAuth/Qt6NetworkAuthConfigVersion.cmake\n",
    "1703666      4 -rw-r--r--   1 hostadm  hostadm      2507 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth1signature.h\n",
    "1703667      4 -rw-r--r--   1 hostadm  hostadm      2412 Dec 12  2022 DEB/usr/include/x86_64-linux-gnu/qt6/QtNetworkAuth/qoauth2authorizationcodeflow.h\n",
    "```\n",
    "\n",
    "- **D.**\n",
    "```bash\n",
    "mkdir HED\n",
    "find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
    "```\n",
    "\n",
    "***\n",
    "\n",
    "## 4. Commands `tar`, `scp`, and Shell Scripts (Max Score: 7)\n",
    "\n",
    "A) Archive the `HED` directory using `tar`/`gzip` into a file named `HED.tgz`.\n",
    "\n",
    "B) Copy the archive onto `vmm26` using the `scp` command into the `hostadm` home directory.\n",
    "\n",
    "C) Extract the archive on `vmm26` using an SSH command. Note: With SSH public key authentication, no password is required to run the `tar` command remotely via SSH on `vmm26`.\n",
    "\n",
    "D) In the `MIDTERM` directory, create a shell script named `find_archive_1.sh` that completes exercises 3D, 4A, 4B, and 4C above.\n",
    "\n",
    "E) Create a modified version of the script, `find_archive_2.sh`, that:\n",
    "- Takes file names as an input parameter from the command line.\n",
    "- If the `HED` directory already exists, removes it before creating a new one.\n",
    "- Runs `find_archive_2.sh` for `*.json` files.\n",
    "\n",
    "### Answers\n",
    "\n",
    "- **A.**\n",
    "```bash\n",
    "tar -zcvf HED.tgz HED\n",
    "```\n",
    "\n",
    "- **B.**\n",
    "```bash\n",
    "scp HED.tgz vmm26:\n",
    "```\n",
    "\n",
    "- **C.**\n",
    "```bash\n",
    "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n",
    "\n",
    "- **D.**\n",
    "```bash\n",
    "#!/bin/bash\n",
    "\n",
    "mkdir DEB\n",
    "\n",
    "find DEB/ -name \"*.h\" -exec cp '{}' HED \\;\n",
    "tar -zcvf HED.tgz HED\n",
    "scp HED.tgz vmm26:\n",
    "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n",
    "\n",
    "- **E.**\n",
    "```bash\n",
    "#!/bin/bash\n",
    "\n",
    "[ -d HED ] && rm -rf HED\n",
    "mkdir HED\n",
    "\n",
    "find DEB/ -name \"$1\" -exec cp '{}' HED \\;\n",
    "tar -zcvf HED.tgz HED\n",
    "scp HED.tgz vmm26:\n",
    "ssh vmm26 \"tar -zxvf HED.tgz\"\n",
    "```\n"
   ]
  }
 ],
 "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
}
