diff options
author | Joe <bousset.rudy@gmail.com> | 2023-10-31 02:14:13 +0100 |
---|---|---|
committer | Joe <bousset.rudy@gmail.com> | 2023-10-31 02:14:13 +0100 |
commit | 5f43b704980023fe4e2b76d7888559e87c2ebef2 (patch) | |
tree | d4d4f6364a6091f3b2bb1cedc639c5a45c8c40f6 /.local | |
parent | up (diff) | |
download | dotfiles-bsd-5f43b704980023fe4e2b76d7888559e87c2ebef2.tar.gz dotfiles-bsd-5f43b704980023fe4e2b76d7888559e87c2ebef2.tar.bz2 dotfiles-bsd-5f43b704980023fe4e2b76d7888559e87c2ebef2.tar.xz dotfiles-bsd-5f43b704980023fe4e2b76d7888559e87c2ebef2.tar.zst dotfiles-bsd-5f43b704980023fe4e2b76d7888559e87c2ebef2.zip |
up
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/hddmnt | 62 | ||||
-rwxr-xr-x | .local/bin/hddumnt | 39 |
2 files changed, 71 insertions, 30 deletions
diff --git a/.local/bin/hddmnt b/.local/bin/hddmnt index e2df789..33d0ebf 100755 --- a/.local/bin/hddmnt +++ b/.local/bin/hddmnt @@ -1,21 +1,45 @@ #!/bin/sh -e -if ! diskinfo da0 >/dev/null; then - notify-send -u critical 'fathdd' ' HDD not detected' - exit 1 -fi -if mount | grep -F /dev/da0p1; then - notify-send -u critical \ - 'fathdd' \ - " HDD already mounted to \ -<b>$(mount | grep -F '/dev/da0p1' | awk '{print $3}')</b>" - exit 1 -fi -if ! dmenu -m 0 -p 'Enter password: ' -P | - geli attach -k /root/geli_keys/fathdd_ext.key -j - da0p1; then - notify-send -u critical 'fathdd' ' Failed to mount HDD' - exit 1 -fi -mkdir -p "$HOME"/hdd -mount /dev/da0p1.eli "$HOME"/hdd -notify-send -t 5000 'fathdd' ' HDD mounted to <b>~/hdd</b>' +devname="exthdd" +mountpoint="$HOME/$devname" + +case "$(hostname -s)" in + mother|po-rbo) + dev=$(find /dev/sd* -type b -exec bash -c 'doas cryptsetup isLuks {} && echo {}' \; | head -n1) + if [ -z "$dev" ]; then + notify-send -u critical 'exthdd' ' crypt dev not detected' + exit 1 + fi + if ! doas cryptsetup open "$dev" "$devname"; then + notify-send -u critical 'exthdd' " failed to uncrypt dev $dev" + exit 1 + fi + mkdir -p "$mountpoint" + if ! doas mount /dev/mapper/"$devname" "$mountpoint"; then + notify-send -u critical 'exthdd' " failed to mount dev $dev" + exit 1 + fi + notify-send -t 5000 'exthdd' " crypt dev mounted to $mountpoint" + ;; + mars) + if ! diskinfo da0 >/dev/null; then + notify-send -u critical 'fathdd' ' HDD not detected' + exit 1 + fi + if mount | grep -F /dev/da0p1; then + notify-send -u critical \ + 'fathdd' \ + " HDD already mounted to \ + <b>$(mount | grep -F '/dev/da0p1' | awk '{print $3}')</b>" + exit 1 + fi + if ! dmenu -m 0 -p 'Enter password: ' -P | + geli attach -k /root/geli_keys/fathdd_ext.key -j - da0p1; then + notify-send -u critical 'fathdd' ' Failed to mount HDD' + exit 1 + fi + mkdir -p "$HOME"/hdd + mount /dev/da0p1.eli "$HOME"/hdd + notify-send -t 5000 'fathdd' ' HDD mounted to <b>~/hdd</b>' + ;; +esac diff --git a/.local/bin/hddumnt b/.local/bin/hddumnt index 4a883f7..75c6570 100755 --- a/.local/bin/hddumnt +++ b/.local/bin/hddumnt @@ -1,13 +1,30 @@ #!/bin/sh -e -if ! mount | grep -F /dev/da0p1; then - notify-send -u critical 'fathdd' ' HDD not mounted' - exit 1 -fi -if ! umount /dev/da0p1.eli; then - notify-send -u critical 'fathdd' ' Failed to dismount HDD' - exit 1 -fi -geli detach da0p1.eli -rmdir "$HOME"/hdd -notify-send -t 5000 'fathdd' ' HDD dismounted from <b>~/hdd</b>' +devname="exthdd" +mountpoint="$HOME/$devname" + +case "$(hostname -s)" in + mother|po-rbo) + if ! doas umount "$mountpoint"; then + notify-send -u critical 'exthdd' " failed to dismount $mountpoint" + fi + if ! doas cryptsetup close "$devname"; then + notify-send -u critical 'exthdd' " failed to close crypt dev $devname" + fi + rmdir "$mountpoint" + notify-send -t 5000 'exthdd' " crypt dev dismounted from $mountpoint" + ;; + mars) + if ! mount | grep -F /dev/da0p1; then + notify-send -u critical 'fathdd' ' HDD not mounted' + exit 1 + fi + if ! umount /dev/da0p1.eli; then + notify-send -u critical 'fathdd' ' Failed to dismount HDD' + exit 1 + fi + geli detach da0p1.eli + rmdir "$HOME"/hdd + notify-send -t 5000 'fathdd' ' HDD dismounted from <b>~/hdd</b>' + ;; +esac |