This commit is contained in:
teldra 2022-02-13 09:51:10 +01:00
parent 3d62ae51e9
commit d48eaaa173
2 changed files with 51 additions and 61 deletions

View File

@ -66,7 +66,7 @@ if [ "$ENC" == "1" ]; then
echo "echo \"Disk pw is '${PASS}'\"" > /etc/runit/core-services/99-changepwdisk.sh echo "echo \"Disk pw is '${PASS}'\"" > /etc/runit/core-services/99-changepwdisk.sh
echo "read -p \"Change PW for disk? y/n \" answer" >> /etc/runit/core-services/99-changepwdisk.sh echo "read -p \"Change PW for disk? y/n \" answer" >> /etc/runit/core-services/99-changepwdisk.sh
echo "if [ \"\${answer}\" = \"y\" ]; then" >> /etc/runit/core-services/99-changepwdisk.sh echo "if [ \"\${answer}\" = \"y\" ]; then" >> /etc/runit/core-services/99-changepwdisk.sh
echo " while ! cryptsetup luksChangeKey /dev/disk/by-uuid/${cfg[partuuid]}; do" >> /etc/runit/core-services/99-changepwdisk.sh echo " while ! cryptsetup luksChangeKey /dev/disk/by-id/${TARGET_PHY_ID}-part${TARGET_PART}; do" >> /etc/runit/core-services/99-changepwdisk.sh
echo " echo \"Again, please\"" >> /etc/runit/core-services/99-changepwdisk.sh echo " echo \"Again, please\"" >> /etc/runit/core-services/99-changepwdisk.sh
echo " done" >> /etc/runit/core-services/99-changepwdisk.sh echo " done" >> /etc/runit/core-services/99-changepwdisk.sh
echo " rm -rf /etc/runit/core-services/99-changepwdisk.sh" >> /etc/runit/core-services/99-changepwdisk.sh echo " rm -rf /etc/runit/core-services/99-changepwdisk.sh" >> /etc/runit/core-services/99-changepwdisk.sh

View File

@ -6,72 +6,62 @@ if [ $UID -ne 0 ]; then
exit 1 exit 1
fi fi
#test -f "${backupcfg}" && echo "${backupcfg} existiert" && exit 1 input() {
output=""
echo "${1}"
read -r -p "[${2}]: " output
test -z "${output}" && output="${2}"
return 0
}
# find all disks multiplechoice() {
declare -A disk_tmp=() output=""
declare -A disk=() local done=""
index=0 local input=("${@}")
for i in $(find /dev/disk/by-id/ -type l -printf "%P\n" | grep usb | grep -v part | tac ); do #for i in $(seq 1 "$(( ${#input[@]} - 1 ))"); do
name="$(readlink -f /dev/disk/by-id/"${i}")" for i in $(seq 0 "$(( ${#input[@]} - 1 ))"); do
if [[ "${name}" =~ *"^[0-9]+$"* ]]; then if [[ "${i}" == "0" ]]; then
continue choices="${input[$i]}"
fi use="${input[$i]}"
if [[ "${name}" == *"dm"* ]]; then
continue
fi
if [[ "${name}" == *"/dev/sr"* ]]; then
continue
fi
if blkid "${name}"|grep -q UUID; then
size="$(fdisk -l "${name}" | head -n1 | awk '{print $3}')"
else else
continue choices="${choices}|${input[$i]}"
fi use+=" ${input[$i]}"
size=$(awk "BEGIN { printf(\"%.0f\n\", ${size}); }")
uuid=$(blkid -o value -s UUID ${name})
index=$(( index + 1 ))
disk_tmp+=( [${index}.id]="${i}" [${index}.name]="${name}" [${index}.uuid]="${uuid}" [${index}.size]="${size}" )
done
disk_tmp+=( [count]="${index}" )
if [[ "${disk_tmp[count]}" -eq 0 ]]; then
echo "No Disk attached."
exit 1
fi
# show devices
echo "Devices:"
for i in $(seq 1 "${disk_tmp[count]}"); do
echo "${disk_tmp[${i}.id]}"
echo " - uuid: ${disk_tmp[${i}.uuid]}"
echo " - name: ${disk_tmp[${i}.name]}"
echo " - size: ${disk_tmp[${i}.size]}"
done
# choose device
found=
while read -p "Which Device? [${disk_tmp[1.uuid]}]: " output; do
test -z "${output}" && output="${disk_tmp[1.uuid]}"
for i in $(seq 1 "${disk_tmp[count]}"); do
if [[ "${disk_tmp[${i}.id]}" == "${output}" ]] || [[ "${disk_tmp[${i}.name]}" == "${output}" ]] || [[ "${disk_tmp[${i}.uuid]}" == "${output}" ]]; then
found=1
id="${disk_tmp[${i}.id]}"
break
fi fi
done done
[[ "${found}" ]] && break while input "[${choices}]: " "${input[0]}"; do
echo "${output} not found" for i in $(seq 0 "${#input[@]}"); do
done 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
echo "g done
n }
1
echo "Bitte Backupgerät noch nicht anschliessen!"
read
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL|grep disk)
echo "${DISKS_DETAILS}"
echo ""
echo "Nun das Gerät anschliessen und das neue in der Liste auswaehlen"
read
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL|grep disk)
echo "${DISKS_DETAILS}"
multiplechoice $(echo "${DISKS_DETAILS}"|awk '{print $1}')
TARGET_PHY_DISK="${output}"
w parted "${TARGET_PHY_ID}" -s -- mklabel gpt
q" | fdisk "/dev/disk/by-id/${id}" parted "${TARGET_PHY_ID}" unit mib -s -- mkpart root btrfs 1 100%
UUID=$(blkid -o value -s UUID "/dev/disk/by-id/${id}-part1") UUID=$(blkid -o value -s UUID "/dev/${TARGET_PHY_ID}1")
if ! cryptsetup luksFormat UUID="${UUID}"; then if ! cryptsetup luksFormat UUID="${UUID}"; then
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln." echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."