vinstaller/files/bin/void-createbackupcontainer

94 lines
2.6 KiB
Plaintext
Raw Normal View History

2022-02-08 20:41:09 +01:00
#!/bin/bash
backupcfg="/etc/backup.cfg"
if [ $UID -ne 0 ]; then
echo "Keine Rootrechte."
exit 1
fi
2022-02-13 09:51:10 +01:00
input() {
output=""
echo "${1}"
read -r -p "[${2}]: " output
test -z "${output}" && output="${2}"
return 0
}
2022-02-08 20:41:09 +01:00
2022-02-13 09:51:10 +01:00
multiplechoice() {
output=""
local done=""
local input=("${@}")
#for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do
for i in $(seq 0 "$(( ${#input[@]} - 1 ))"); do
if [[ "${i}" == "0" ]]; then
choices="${input[$i]}"
use="${input[$i]}"
else
choices="${choices}|${input[$i]}"
use+=" ${input[$i]}"
fi
done
while input "[${choices}]: " "${input[0]}"; do
for i in $(seq 0 "${#input[@]}"); do
if [[ "${output}" == "${input[$i]}" ]] || [[ "${output}" == "${input[$i]:0:2}" ]]; then
output="${input[$i]}"
done=1
fi
done
if [[ -z "${done}" ]]; then
echo wronginput "${output}"
echo use these: "${use}"
else
break
fi
2022-02-08 20:41:09 +01:00
2022-02-13 09:51:10 +01:00
done
}
2022-02-08 20:41:09 +01:00
2022-02-13 09:59:26 +01:00
clear
echo "Bitte Backupgerät noch nicht anschliessen oder wieder entfernen!"
echo "Dücke Enter"
2022-02-13 09:51:10 +01:00
read
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL|grep disk)
echo "${DISKS_DETAILS}"
echo ""
2022-02-13 09:59:26 +01:00
echo "Nun das Gerät anschliessen"
echo "Vergleiche diese Ausgabe mit der folgenden"
echo "Drücke Enter"
2022-02-13 09:51:10 +01:00
read
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL|grep disk)
echo "${DISKS_DETAILS}"
2022-02-13 09:59:26 +01:00
echo ""
echo "Welches kam neu hinzu?"
DIFF=$(diff <(echo "$a") <(echo "$b")|tail -n-1|awk '{print $2}')
echo "Vermutlich '${DIFF}'"
2022-02-13 09:51:10 +01:00
multiplechoice $(echo "${DISKS_DETAILS}"|awk '{print $1}')
TARGET_PHY_DISK="${output}"
2022-02-08 20:41:09 +01:00
2022-02-13 09:51:10 +01:00
parted "${TARGET_PHY_ID}" -s -- mklabel gpt
parted "${TARGET_PHY_ID}" unit mib -s -- mkpart root btrfs 1 100%
2022-02-08 20:41:09 +01:00
2022-02-13 09:51:10 +01:00
UUID=$(blkid -o value -s UUID "/dev/${TARGET_PHY_ID}1")
2022-02-08 20:41:09 +01:00
if ! cryptsetup luksFormat UUID="${UUID}"; then
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."
exit 1
else
if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."
exit 1
fi
fi
if ! mkfs.btrfs -f "/dev/mapper/luks-${UUID}"; then
echo "Konnte /dev/mapper/luks-${UUID} nicht formatieren"
exit 1
fi
cryptsetup close "luks-${UUID}"
echo "UUID=\"${UUID}\"" > "${backupcfg}"
echo "Erstellen des Containers fertig."