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 "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 " 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 " 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

View File

@ -6,72 +6,62 @@ if [ $UID -ne 0 ]; then
exit 1
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
declare -A disk_tmp=()
declare -A disk=()
index=0
for i in $(find /dev/disk/by-id/ -type l -printf "%P\n" | grep usb | grep -v part | tac ); do
name="$(readlink -f /dev/disk/by-id/"${i}")"
if [[ "${name}" =~ *"^[0-9]+$"* ]]; then
continue
fi
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
continue
fi
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}" )
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
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
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
done
[[ "${found}" ]] && break
echo "${output} not found"
done
echo "g
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
q" | fdisk "/dev/disk/by-id/${id}"
parted "${TARGET_PHY_ID}" -s -- mklabel gpt
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
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."