5
0
Fork 0
mirror of https://codeberg.org/Computertruhe/Setup-Skripte.git synced 2025-06-28 03:16:21 +02:00

V2 Anfänge

This commit is contained in:
Robert 2024-10-22 22:03:22 +02:00
parent 74a9a97ca4
commit 9d2efcd48f
7 changed files with 247 additions and 22 deletions

View file

@ -0,0 +1,78 @@
#!/bin/bash
source sub_install
while true;
do
dialog --clear
# select filename using dialog
IMG=$(dialog --title "Image-Datei wählen. Mit *Leertaste* selektieren" --stdout --dselect ./ 14 88)
GG=$(lsblk -r -p -n -o NAME,TYPE |grep disk | cut -f1 -d' ')
echo $GG
Devs=()
for dev in $GG; do
Devs+=($dev)
Devs+=("")
done
DEV=`dialog --menu "Festplattengerät wählen" 0 0 0 \
"${Devs[@]}" 3>&1 1>&2 2>&3`
dialog --clear
dialog --yesno "Bestätigen Sie Ihre Auswahl: $DEV <- $IMG" 0 0
# Get exit status
# 0 means user hit [yes] button.
# 1 means user hit [no] button.
# 255 means user hit [Esc] key.
response=$?
case $response in
0) echo "Bestätigt"; break;;
1) echo "Sicherheitshalber beendet"; exit 1;;
255) echo "[ESC], Sicherheitshalber beendet"; exit 1;;
esac
done
#---------
if [ -z "$(command -v growpart)" ]; then
echo "growpart fehlt! Installiere cloud-guest-utils..."
sudo apt update
sudo apt install -y cloud-guest-utils
fi
if [ -z "$IMG" ] ; then
echo "Image-File angeben!"
exit 1
fi
if [ -z "$DEV" ] ; then
echo "HDD dev angeben! z. B. /dev/hdc"
exit 1
fi
echo "Warte 2 Sekunden vor dem löschen, abbrechen mit strg + c..."
sleep 2
echo "Achtung - vorbei, ich mache jetzt alles platt auf" "${DEV}"
NVME_PARTITION_SUFFIX=''
if [[ "$DEV" == *"nvme"* ]]; then
echo "$DEV is NVME device"
NVME_PARTITION_SUFFIX='p'
fi
case "$IMG" in
*.bz2)
sudo dd if="$IMG" bs=1M status=progress | bzip2 -d > "$DEV"
;;
*)
sudo dd if="$IMG" of=$DEV bs=1M status=progress
;;
esac
sync
sudo growpart $DEV 3
sudo mount ${DEV}${NVME_PARTITION_SUFFIX}3 /mnt
sudo btrfs filesystem resize max /mnt
sudo umount /mnt
sync

View file

@ -1,17 +1,6 @@
#!/bin/bash
if [[ -z "$(command -v growpart)" || -z "$(command -v btrfs)" ]]; then
echo "growpart oder btrfs fehlt! Installiere cloud-guest-utils und btrfs-progs..."
sudo apt update
sudo apt install -y cloud-guest-utils btrfs-progs
fi
if [ -z "$(command -v dialog)" ]; then
echo "dialog fehlt! Installiere dialog..."
sudo apt update
sudo apt install -y dialog
fi
source sub_install
while true;
do

View file

@ -1,10 +1,7 @@
#!/bin/bash
if [ -z "$(command -v dialog)" ]; then
echo "dialog fehlt! Installiere dialog..."
sudo apt update
sudo apt install -y dialog btrfs-progs
fi
source sub_install
GG=$(lsblk -r -p -n -o NAME,TYPE |grep disk | cut -f1 -d' ')

View file

@ -0,0 +1,130 @@
#!/bin/bash
# Das ist die Version 2 von Platte einlesen.
# Hier wird mit einem anderen tool als dd ein image erstellt. Mit partclone
# daher muss das Layout der Installation strikt eingehalten werden
# P0=Efi(vfat) P1=swap P2=homeroot(Btrfs)
source sub_install
GG=$(lsblk -r -p -n -o NAME,TYPE |grep disk | cut -f1 -d' ')
echo $GG
Devs=()
for dev in $GG; do
Devs+=($dev)
Devs+=("")
done
while true
do
dev=`dialog --menu "Platte einlesen. Festplattengerät wählen" 0 0 0 \
"${Devs[@]}" 3>&1 1>&2 2>&3`
dialog --clear
dialog --yesno "Bestätigen Sie Ihre Auswahl: $dev" 0 0
# Get exit status
# 0 means user hit [yes] button.
# 1 means user hit [no] button.
# 255 means user hit [Esc] key.
response=$?
case $response in
0) echo "Bestätigt"; break;;
1) echo "Neu wählen";;
255) echo "[ESC]"; exit 1;;
esac
done
# in $dev steht jetzt das Basisdevice
while true
do
dialog --clear
# show an inputbox
FILENM=$(dialog --title "Imagedateiverzeichnis" --inputbox "Verzeichnisname " 8 60 3>&1 1>&2 2>&3 3>&- )
# get respose
respose=$?
case $response in
1) exit 2 ;;
255) echo "[ESC]"; exit 1;;
esac
dialog --clear
dialog --yesno "Gewählter Name: $FILENM" 0 0
# Get exit status
# 0 means user hit [yes] button.
# 1 means user hit [no] button.
# 255 means user hit [Esc] key.
response=$?
case $response in
0) echo "Bestätigt"; break;;
1) echo "Neu wählen";;
255) echo "[ESC]"; exit 1;;
esac
done
# ------- eigentliche Aktion ---------
# Partitionen ermitteln und checken
echo "Habe folgende Partitionen entdeckt:"
# Typen,fstyp und pfad auf normale partitionen beschränkt ermitteln
DSK=$(lsblk -l -oPATH,FSTYPE,TYPE -p "$dev" |grep 'part')
Pp=()
Pt=()
IFS=$'\n' #newline ist separator (=ws wird mitgenommen)
pat='^([^ ]*) +([^ ]+) +.*$' # Bash regex mit Leerzeichen nutzen = Variable nehmen
for line in $DSK; do
echo $line
if [[ $line =~ $pat ]]; then
#li=${BASH_REMATCH[1]}${BASH_REMATCH[2]};
pp=${BASH_REMATCH[1]}
fs=${BASH_REMATCH[2]}
#echo " pp $pp - fs $fs"
Pp+=($pp)
Pt+=($fs)
# Pp+=("")
fi
done
# jetzt sind in den arrays Pt und Pp die Partitionstypen und Pfade drin
echo "Prüfe layout, ob es unserem Modus passt"
if [ "${Pt[0]}" != "vfat" ]; then
echo "Erwarte bei ${Pp[0]} eine EFI-Partition mit vfat. Nicht gefunden"
exit 1
fi
if [ "${Pt[1]}" != "swap" ]; then
echo "Erwarte bei ${Pp[1]} eine Swap-Partition. Nicht gefunden"
exit 1
fi
if [ "${Pt[2]}" != "btrfs" ]; then
echo "Erwarte bei ${Pp[2]} eine root/home Partition mit BTRFS. Nicht gefunden"
exit 1
fi
echo "Layout passt so. Beginne den Einlesevorgang"
DIRECTORY="$FILENM"
if [ -d "$DIRECTORY" ]; then
echo "$DIRECTORY existiert bereits. Beende."
exit 2
fi
mkdir "$DIRECTORY"
echo "Bearbeite jetzt ${Pt[2]}"
partclone.vfat -c -s "${Pt[0]}" -o "$DIRECTORY/p0"
partclone.btrfs -c -s "${Pt[2]}" -o "$DIRECTORY/p2"
echo "Fertig. In $DIRECTORY befinden sich nun die Abbilder der Partitionen"

View file

@ -3,11 +3,7 @@
IMG="$1"
DEV="$2"
if [[ -z "$(command -v growpart)" || -z "$(command -v btrfs)" ]]; then
echo "growpart oder btrfs fehlt! Installiere cloud-guest-utils und btrfs-progs..."
sudo apt update
sudo apt install -y cloud-guest-utils btrfs-progs
fi
source sub_install
if [ -z "$IMG" ] ; then
echo "Image-File angeben!"

9
installstick/sub_install Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
# Das ist das include um Dinge nachzuinstalliere
if [ -z "$(command -v dialog)" ]; then
echo "dialog fehlt! Installiere dialog, partclone cloud-guest-utils, und btrfs-progs..."
sudo apt update
sudo apt install -y dialog btrfs-progs partclone cloud-guest-utils
fi

26
installstick/test.sh Normal file
View file

@ -0,0 +1,26 @@
DSK=$(lsblk -l -oPATH,FSTYPE,TYPE -p /dev/sda |grep 'part')
Pp=()
Pt=()
IFS=$'\n' #newline ist separator (=ws wird mitgenommen)
pat='^([^ ]*) +([^ ]+) +.*$'
for line in $DSK; do
echo $line
if [[ $line =~ $pat ]]; then
#li=${BASH_REMATCH[1]}${BASH_REMATCH[2]};
pp=${BASH_REMATCH[1]}
fs=${BASH_REMATCH[2]}
#echo " pp $pp - fs $fs"
Pp+=($pp)
Pt+=($fs)
# Pp+=("")
fi
done
if [ "${Pt[0]}" != "vfdat" ]; then
echo "OK1"
fi
if [ "${Pt[1]}" == "btrdfs" ]; then
echo "OK2"
fi