This commit is contained in:
Jan 2025-02-11 23:09:50 +01:00
commit 4326c715f5
6 changed files with 283 additions and 0 deletions

BIN
BOOT/1-Boot-NoEmul.img Executable file

Binary file not shown.

BIN
BOOT/2-Boot-NoEmul.img Executable file

Binary file not shown.

14
build.sh Executable file
View file

@ -0,0 +1,14 @@
cd source-files
xorriso -as mkisofs \
-o ../debian-angestoepselt.iso \
-c isolinux/boot.cat \
-b isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e boot/grub/efi.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
.

103
preseed.cfg Executable file
View file

@ -0,0 +1,103 @@
### 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
# Grub wird automatisch auf den MBR installiert, wenn kein anderes OS vorhanden ist (sicher)
d-i grub-installer/only_debian boolean true
# MBR installation ebenfalls wenn andere OS vorhanden sind (koennte dazu fuehren, dass diese nicht mehr booten)
#d-i grub-installer/with_other_os boolean true
# Verhindert, dass grub alternativ fragt, wo er installiert werden soll
d-i grub-installer/bootdev string /dev/sda
# Fuer die vollautomatische Partitionierung (falls unten aktiv) - Beispiel Lenovo Tiny mit NVMe-SSD
# VirtualBox -> /dev/sda, KVM -> /dev/vda
#d-i partman-auto/disk string /dev/nvme0n1
# Fuer lvm 'lvmcfg/vgdelete_confirm', 'partman-lvm/confirm' und 'partman-lvm/confirm_nooverwrite' setzen
# Siehe https://www.debian.org/releases/stable/s390x/apbs04.de.html Abschnitt B.4.7.1.
d-i partman-auto/method string regular
# Alle Daten auf einer Partition (mit 'home' wird das Home-Verzeichnis auf eine eigene Partition gelegt)
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
### 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, gnome-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
### 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 \
wget -P /tmp/ http://10.0.2.2:8000/script.sh;

166
scriipts/post_hardware.sh Executable file
View file

@ -0,0 +1,166 @@
#!/bin/bash
# Script for hardware post on snipeIT and print label by angestöpselt e.V.
# v0.4
export $(curl --silent 10.200.4.10/.env | xargs)
echo '#####################################'
echo '####### exec post_hardware.sh #######'
echo '#####################################'
echo "looking for anydesk source list" >> ${LOG}
if [ -f etc/apt/sources.list.d/anydesk-stable.list ] ; then
echo "Anydesk source.list besteht" >> ${LOG}
else
sudo wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | apt-key add -
sudo echo "deb http://deb.anydesk.com/ all main" > /etc/apt/sources.list.d/anydesk-stable.list
fi
echo "update apt cache" >> ${LOG}
sudo apt-get update -qq
echo "install dependencies" >> ${LOG}
sudo apt-get install -y -qq jq curl wkhtmltopdf zenity anydesk
# prepare for publishing computer to snipe-IT
category=`hostnamectl | grep Chassis | cut -c 21-`
#hdd=`cat "/sys/class/block/sda/size" | awk '{print $1 / 1024 / 1024 }' | awk -F "." '{print $1}'`
hdd=$(lsblk -dno SIZE --fs /dev/sda | awk -F "," '{print $1}')
memory=`(grep MemTotal /proc/meminfo | awk '{print int($2 / 1000000 + 0.5)}')`
os=`hostname | awk -F- '{print $1}'`
version=`cat /etc/os-release | grep VERSION_ID | grep -oP '(?<=").*(?=")'`
cpu=`cat /proc/cpuinfo | grep 'model name' | uniq | cut -c14-39 | sed -e 's/([^()]*)//g' | tr -d ' ' | cut -c -12`
mac=`ip link | sed -n "/BROADCAST.*state UP/{n;p}" | tail -1 | tr -s " " | cut -d" " -f3`
anydeskid=`anydesk --get-id`
serialno=`sudo dmidecode -s system-serial-number`
# name is for a nice label with some data
name=`echo $os/$version/$cpu/$memory/$hdd`
# Check the category for required field: model_id and fill laptop variables
if [[ $category = "laptop" || $category = "notebook" ]]; then
model=2
battery=`acpi -V | grep '^Battery.*%$' | tail -c 4`
display=`xrandr | awk '/ connected/{print sqrt( ($(NF-2)/10)^2 + ($NF/10)^2 )/2.54}' | cut -c -2 | head -n 1`
else
model=1
fi
# Check if an optical drive is available
if [[ $(lsblk | grep sr0) ]]; then
odd=ja
else
odd=nein
fi
# check, based on mac address
curl --request GET \
--url 'https://orga.z31.it/api/v1/hardware?limit=5&search='$mac'' \
--header 'accept: application/json' \
--header 'authorization: Bearer '$API_KEY'' \
--header 'content-type: application/x-www-form-urlencoded' > $HOME/check_result.json
# look for asset tag in payload
asset_tag=$(jq -j .rows[].asset_tag $HOME/check_result.json)
if [ ! -z ${asset_tag} ]
then
zenity --info --text "Der Rechner ist ist bereits eingetragen RE${asset_tag}" --width=500 --height=200
#echo " Der Rechner ist bereits eingetragen RE${asset_tag}"
exit 0
else
echo "preparing asset data in json"
post_data()
{
cat <<EOF
{
"status_id": "2",
"name": "$name",
"model_id": "$model",
"serial": "$serialno",
"_snipeit_mac_address_1": "$mac",
"_snipeit_betriebssystem_2": "$os$version",
"_snipeit_festplatte_4": "$hddGB",
"_snipeit_prozessor_5": "$cpu",
"_snipeit_arbeitsspeicher_6": "$memory",
"_snipeit_optisches_laufwerk_7": "$odd",
"_snipeit_display_8": "$display",
"_snipeit_akku_9": "$battery",
"_snipeit_anydeskid_10": "$anydeskid"
}
EOF
}
echo "do curl request to snipe-IT"
curl --request POST \
--url https://orga.z31.it/api/v1/hardware \
--header 'accept: application/json' \
--header 'authorization: Bearer '$API_KEY'' \
--header 'Content-Type: application/json' \
--data "$(post_data)" > $HOME/result.json
# get missing information from payload
asset_tag=$(cat $HOME/result.json | jq -r '.payload.asset_tag')
result_jq=$(cat $HOME/result.json | jq -r '.status')
erstellt_am=$(cat $HOME/result.json | jq -r '.payload.created_at')
echo "checking if the asset has been created and display an error from the snipeIT api" >> ${LOG}
for result in $result_jq
do
case $result in
success)
echo "${category} RE${asset_tag}, erstellt am ${erstellt_am}" >> ${LOG}
echo "MAC-Adresse ${mac} | Anydesk-ID ${anydeskid}" >> ${LOG}
touch "/home/computerspende/RE${asset_tag}"
echo "erstellt am: ${erstellt_am}" >> /home/computerspende/RE${asset_tag}
## This part is creating a file with html content for the printer
cat >/tmp/rechner.html <<EOL
<div>
<p style="float: left;"><img src="http://${PXESERVER_IP}/angestoepselt.png" height="80px" width="80px"></p>
</div>
<div>
<p style="font-size:15px">angestoepselt e.V.<br>Passwort: csw</p>
<b> <p style="font-size:23px"><b>RE${asset_tag}</p></b>
<p style="margin-left:5%; font-size:12px;">${name}</p>
</div>
EOL
exec 2>/dev/null # vernichtet nervige Fehlermeldungen
zenity --question --title "Label drucken" --text "\nEs wurde folgender PC eingetragen: \n\nRechnernr: $asset_tag \nTyp: $category \nOS: $os $version \nCPU: $cpu \nRAM: $memory GB \n\nWillst du jetzt das Label drucken?" --no-wrap --ok-label "Ja" --cancel-label "Nein"
if [ "$?" -eq "0" ]; then
## wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
# parsing the variables into html file and make a nice looking pdf for printing
# page-heigt and page-width are 99012 Large Adress Labels, you can set this by default in cups Print Options with "Media Size"
wkhtmltopdf --page-height 36mm --page-width 89mm /tmp/rechner.html /tmp/rechner.pdf
echo 'Label drucken' >> ${LOG}
## change the ip of the printer host
# -P is the printer name of cups -> https://CUPS_SERVER_IP:631/printers/
lpr -H ${PRINTER_IP}:631 -P DYMO -o landscape /tmp/rechner.pdf
zenity --info --text="<big>Das ist der Rechner\n\n<big>RE$asset_tag</big></big>" --width=500 --height=200
echo 'Label wurde gedruckt' >> ${LOG}
else
echo "es wurde nichts gedruckt" >> ${LOG}
fi
;;
null)
zenity --info --text "Das hat nicht geklappt bitte führe das Script von Hand aus.\nBenutze bitte im Terminal:\n\ncurl -sSL pxe.z31.it/post_hardware.sh | bash" --width=500 --height=200
zenity --error --text "Fehlermeldung: \n\n$(cat $HOME/result.json | jq -r '.error')" --width=500 --height=200
;;
esac
done
fi
echo '#####################################'
echo '##### finished post_hardware.sh #####' >> ${LOG}
echo '#####################################'

0
scriipts/setup.sh Executable file
View file