diff --git a/installstick/dlg_platte_bespielen2_btrfs.sh b/installstick/dlg_platte_bespielen2_btrfs.sh new file mode 100644 index 0000000..a60811a --- /dev/null +++ b/installstick/dlg_platte_bespielen2_btrfs.sh @@ -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 diff --git a/installstick/dlg_platte_bespielen_btrfs.sh b/installstick/dlg_platte_bespielen_btrfs.sh index a0c0c07..22ba859 100755 --- a/installstick/dlg_platte_bespielen_btrfs.sh +++ b/installstick/dlg_platte_bespielen_btrfs.sh @@ -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 diff --git a/installstick/dlg_platte_einlesen.sh b/installstick/dlg_platte_einlesen.sh index 8543d42..01328d5 100755 --- a/installstick/dlg_platte_einlesen.sh +++ b/installstick/dlg_platte_einlesen.sh @@ -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' ') diff --git a/installstick/dlg_platte_einlesenv2.sh b/installstick/dlg_platte_einlesenv2.sh new file mode 100755 index 0000000..ca78361 --- /dev/null +++ b/installstick/dlg_platte_einlesenv2.sh @@ -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" diff --git a/installstick/platte_bespielen_btrfs.sh b/installstick/platte_bespielen_btrfs.sh index 4af2525..513bd1c 100755 --- a/installstick/platte_bespielen_btrfs.sh +++ b/installstick/platte_bespielen_btrfs.sh @@ -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!" diff --git a/installstick/sub_install b/installstick/sub_install new file mode 100755 index 0000000..172f216 --- /dev/null +++ b/installstick/sub_install @@ -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 diff --git a/installstick/test.sh b/installstick/test.sh new file mode 100644 index 0000000..b8323fa --- /dev/null +++ b/installstick/test.sh @@ -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 \ No newline at end of file