diff --git a/tools/python_utils/Dockerfile b/tools/python_utils/Dockerfile new file mode 100644 index 0000000..557f259 --- /dev/null +++ b/tools/python_utils/Dockerfile @@ -0,0 +1,24 @@ +# Use an official Python runtime as a base image +FROM python:3.12-bookworm + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Set work directory +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +RUN apt install cups + +# Copy the project files +COPY . . + +# Expose the port Gunicorn will run on +EXPOSE 5000 + +# Run the app using Gunicorn +CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"] + diff --git a/tools/python_utils/app.py b/tools/python_utils/app.py index 2378d5f..1e3b4bd 100644 --- a/tools/python_utils/app.py +++ b/tools/python_utils/app.py @@ -2,7 +2,6 @@ from flask import Flask, send_from_directory, abort, request import json import requests import os -import logging import label app = Flask(__name__) @@ -23,9 +22,13 @@ def pretty_print_POST(req): )) FILES_DIR = os.path.join(os.path.dirname(__file__), "files") +@app.route('/') +def index(): + return("↑ ↑ ↓ ↓ ← → ← → B A") @app.route('/snipe_api') def home(): - return "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiMmU3YmJhZTEwZjM1NThhNTQ2MzZmNTRiYjhiNzQ1NmRhNDRiZDAyNWJlZTNmZjFkZTAxZTI3NzZiNjEwODQ5MDRkNGRkYjE3Njg5ZDYyMjYiLCJpYXQiOjE3MzA1NTQxMzguMTAwMzAyLCJuYmYiOjE3MzA1NTQxMzguMTAwMzE0LCJleHAiOjIzNjE3MDYxMzcuOTkwMzQ0LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.rFVnJo5E-UHW-Z4fQ639xBXq9zroAGmPQSkm1Z6iVir-8NAm-AJy-_UZLH32IG9_aT9CGJZc6_hyCRisEhm2PIAvQ0ejUzZb8atNfD3bhMEp4DwjNZtsonO6xP8Mi4YXuscWuyxNAlg7svm53bAl3mop_S2jeOEQ5DM_RhjpYxy1VMvs3diiN7W6U-WDgznMl9FLQ7TFHQ8w8g3zCbIrI5PEeKn05525sQcvgonlo1hjEe5L2gcUCV5dvXnZHnyCaZcrCcuhmZM0Xy4_ZiK5EtFvKKm4BFprnis1pT9xEdv5QzRk-IJYrFkIcAZzha7sVGShln8HzyhTE27oq1wsUgBKY4J_VQhyc4343_n3eofAOrTSRbnsMNjZE0Vy7wUVw8snOVoz56T_AYa7IKtBuv0CBGS2XLVNERer-rkJtPLTVGPC9Ck0vKfO202klRlkPgfl_HeYMIDxBwDwY6dZSoNPPG1hPSTFFv74zkSz3AsxyKmD5QOp90tuclvpINTxghRhbpHSBl1TV4XRY9rbmQ9Wo40A7XRsSUGrh-SDErLp6J5Taa9rXrxaIVs5oFZA8ehaRcZlZRm-uiJXbgd7gHhWSNdqnZ1kbPGJwsXvGI8JTAL04LSd3moWyx3TCoP2yCLAdAqPoOe35RK76IWSpZ1Et-yKzYwPMHlsKiYLjCA" + api_key = os.environ['API_KEY'] + return api_key @app.route('/download_late_command') def download_file(): diff --git a/tools/python_utils/files/late_test.sh b/tools/python_utils/files/late_test.sh new file mode 100644 index 0000000..cebc64a --- /dev/null +++ b/tools/python_utils/files/late_test.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +touch "/home/computerspende/test.txt" + diff --git a/tools/python_utils/files/preseed.cfg b/tools/python_utils/files/preseed.cfg index a653b24..77736df 100755 --- a/tools/python_utils/files/preseed.cfg +++ b/tools/python_utils/files/preseed.cfg @@ -100,4 +100,7 @@ d-i netcfg/choose_interface select auto d-i netcfg/hostname string computerspende d-i preseed/late_command string \ - in-target --pass-stdout bash -c "echo 'computerspende ALL=NOPASSWD:ALL' > /etc/sudoers.d/computerspende"; + in-target --pass-stdout bash -c "echo 'computerspende ALL=NOPASSWD:ALL' > /etc/sudoers.d/computerspende"; \ + in-target wget -O /home/computerspende/late_command.sh http://10.0.2.4:8888/download_late_command; \ + in-target chmod +x /home/computerspende/late_command.sh; \ + in-target /root/late_command.sh; diff --git a/tools/python_utils/files/preseed.new.cfg b/tools/python_utils/files/preseed.new.cfg new file mode 100644 index 0000000..320677b --- /dev/null +++ b/tools/python_utils/files/preseed.new.cfg @@ -0,0 +1,100 @@ +### Allgemeines +# Verhindert weniger wichtige Nachfragen +# https://www.debian.org/releases/sarge/s390/ch05s02.html.en +# https://preseed.debian.net/debian-preseed/bullseye/amd64-main-full.txt +d-i debconf/priority string critical +# Deaktiviert die Meldung am Ende, dass die Installation abgeschlossen wurde und man neu starten kann +d-i finish-install/reboot_in_progress note + +# Gibt an, ob Infos zum Nutzungsverhalten (installierte/verwendete Software) an Debian gesendet werden +popularity-contest popularity-contest/participate boolean false +# Proprietaere Firmware laden (falls es zu Hardwareproblemen kommt) +#d-i hw-detect/load_firmware boolean true + +### Lokalisierung +d-i debian-installer/locale string de_DE +# Keymap setzen reicht nicht, layout/variantcode hilft ebenfalls nicht: https://groups.google.com/g/linux.debian.bugs.dist/c/XYcrRjLwpQM +d-i keyboard-configuration/variant select Deutschland +d-i keyboard-configuration/xkb-keymap select de + +d-i clock-setup/utc boolean true +d-i tzdata/Areas select Europe +tzdata/Zones/Europe select Berlin +d-i time/zone string Europe/Berlin + +### Partitionierung +# UEFI-spezifische Einstellungen +d-i partman-efi/non_efi_system boolean false +d-i partman/efi_boot_mountpoint string /boot/efi + +# Automatisches Partitionieren mit einem einzelnen Root-Dateisystem +# Grub wird automatisch auf die EFI-Partition installiert, wenn UEFI aktiv ist +d-i partman-auto/method string regular +d-i partman-auto/choose_recipe select atomic + +# Komplett automatisiert ohne Bestaetigung fuer alle Partitionierungsmethoden (Mit Vorsicht verwenden!) +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman-md/confirm boolean true +d-i partman-md/deleteverify boolean true +d-i lvmcfg/vgdelete_confirm boolean true +d-i partman-lvm/vgdelete_confirm boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true + +### GRUB Bootloader +d-i grub-installer/only_debian boolean true +# Nicht noetig für UEFI – kann zu Konflikten fuehren +#d-i grub-installer/with_other_os boolean true +d-i grub-installer/bootdev string /dev/sda + +### Software +d-i mirror/country string manual +d-i mirror/http/hostname string ftp2.de.debian.org +d-i mirror/http/directory string /debian +d-i mirror/http/proxy string + +# Aktiviert Spiegelserver abseits der Sicherheitsupdates per Netzwerk statt Image +d-i apt-setup/use_mirror boolean true +d-i apt-setup/disable-cdrom-entries boolean true +# Aktiviert offizielle, aber unfreie Repositorys: https://wiki.debian.org/SourcesList +d-i apt-setup/non-free boolean true +d-i apt-setup/contrib boolean true + +# Vorinstallierte Software +# Programmgruppe kann festlegen, ob z.B. Headless oder eine bestimmte Desktopumgebung (xfce-desktop, kde-desktop usw) vorinstalliert werden soll (siehe B.4.10) +tasksel tasksel/first multiselect standard, cinnamon-desktop + +d-i pkgsel/install-language-support boolean true +d-i pkgsel/update-policy select Install security updates automatically +# Alle Pakete automatisch aktualisieren +d-i pkgsel/upgrade select full-upgrade +d-i pkgsel/include string git vim htop curl jq +# Stdout Weiterleitungen funktionieren in in-target nicht ohne --pass-stdout +# Siehe https://askubuntu.com/a/1248987/650986 und https://serverfault.com/questions/390122/how-do-i-pipe-commands-together-in-a-debian-preseed-file + +### Benutzerkonten +d-i passwd/username string computerspende +d-i passwd/user-fullname string computerspende +d-i passwd/user-uid string 1000 +d-i passwd/user-password password csw +d-i passwd/user-password-again password csw +# root +d-i passwd/root-password password csw +d-i passwd/root-password-again password csw + +# Fuer Testsysteme kann die Policy strikter PWs abgeschaltet werden +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +d-i user-setup/enable sudo boolean true +### Netzwerk +d-i netcfg/enable boolean true +d-i netcfg/choose_interface select auto +d-i netcfg/hostname string computerspende + +d-i preseed/late_command string \ + in-target --pass-stdout bash -c "echo 'computerspende ALL=NOPASSWD:ALL' > /etc/sudoers.d/computerspende"; \ + in-target --pass-stdout bash -c "curl -s 10.200.4.12:8888/download_late_command | bash -s"; diff --git a/tools/python_utils/python.sh b/tools/python_utils/python.sh index 719cebd..78dec81 100644 --- a/tools/python_utils/python.sh +++ b/tools/python_utils/python.sh @@ -13,6 +13,6 @@ print_data() { EOF } -curl -X POST http://localhost:5000/label \ +curl -X POST http://10.200.4.12:5000/label \ -H "Content-Type: application/json" \ -d "$(print_data)" diff --git a/tools/python_utils/requirements.txt b/tools/python_utils/requirements.txt new file mode 100644 index 0000000..8fd64b8 --- /dev/null +++ b/tools/python_utils/requirements.txt @@ -0,0 +1,4 @@ +flask +requests +typst +gunicorn