diff options
author | Xiao Pan <xyz@flylightning.xyz> | 2025-07-25 16:44:29 +0800 |
---|---|---|
committer | Xiao Pan <xyz@flylightning.xyz> | 2025-07-25 16:47:02 +0800 |
commit | 3de60655d66eb67d1f9e49ee51b69aab84767af2 (patch) | |
tree | cb7a9b3cd2a15578160252ebc5eed3693ace43dd | |
parent | 54fad638ff48f093a0063e72b53163df5ca53349 (diff) |
upd use udisksctl instead of cryptsetup so no sudo
-rwxr-xr-x | sh/upd | 34 |
1 files changed, 27 insertions, 7 deletions
@@ -88,14 +88,29 @@ backup () { # backup pp rsync -avP --delete "$HOME/backup/pp/" "/run/media/xyz/bd0/pp" - # busybox df if filesystem name too long, it will put the filesystem - # name in a separate line which nornally is in the second line and - # there's total three lines. So I use df -P option which seems busybox - # will also not put filesystem name in a separate line and behave same - # as gnu df. - bd0_fs_name="$(df -P /run/media/xyz/bd0 | awk 'END{print $1}')" + # bd0 is the label name of the unlocked ext4 fs, maybe was configured + # with sth. like `sudo e2label /dev/mapper/luks-... bd0`. ebd0 is the + # label name of the locked crypto_LUKS fs, maybe was configured with + # `sudo cryptsetup config /dev/sdx --label ebd0`. + # + # Another way to represent disk is using uuid. ebd0 locked crypto_LUKS + # fs uuid is cf91dfaa-35dc-4ce4-b333-df15966f34a2, so I can use + # /dev/disk/by-uuid/cf91dfaa-35dc-4ce4-b333-df15966f34a2 to represent + # it. bd0 unlocked ext4 fs uuid is + # 93670fb4-af1d-43aa-a8cc-b7ac5c05e766, so I can use + # /dev/disk/by-uuid/93670fb4-af1d-43aa-a8cc-b7ac5c05e766 for it, I can + # also use /dev/mapper/luks-cf91dfaa-35dc-4ce4-b333-df15966f34a2 for + # bd0, note here cf91dfaa-35dc-4ce4-b333-df15966f34a2 is the ebd0 + # locked crypto_LUKS fs uuid. However, udisksctl does not recognize + # /dev/mapper/luks-..., but recognize /dev/disk/...; cryptosetup close + # and umount recognize both. More ways see dirs in /dev/disk, and see + # output of press tab after `udiskiectl info -b`. + # + # Note `udisksctl lock` need ebd0 locked crypto_LUKS fs, but `sudo + # cryptsetup close` need bd0 unlocked ext4 fs. umount /run/media/xyz/bd0 - sudo cryptsetup close "$bd0_fs_name" + udisksctl lock -b /dev/disk/by-label/ebd0 + udisksctl power-off -b /dev/disk/by-label/ebd0 alarm 0 'Unplug external HDD' # duplicity backup to ib @@ -345,6 +360,11 @@ monthly_misc () { # need to be after `wait`, because checksum need to be at ventoy dir cd || exit + # busybox df if filesystem name too long, it will put the filesystem + # name in a separate line which nornally is in the second line and + # there's total three lines. So I use df -P option which seems busybox + # will also not put filesystem name in a separate line and behave same + # as gnu df. disk="$(df -P /run/media/xyz/Ventoy/ | awk 'END{sub(/[[:digit:]]+$/,"",$1);print $1}')" sudo ventoy -l "$disk" | awk '/Ventoy:/{a=$2} /Ventoy Version in Disk:/{b=$NF;exit} END{exit((a==b)?1:0)}' && echo y | sudo ventoy -u "$disk" umount /run/media/xyz/Ventoy /run/media/xyz/FAT32DIR |