summaryrefslogtreecommitdiff
path: root/src/initrd/samizdat-eject.sh
blob: da56d74c10fac2bd4178b641c7a755217c0b316a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
[ "$(id -u)" = 0 ] || exec sudo $0 "$@"

get()
{
    btrfs filesystem show / |
        sed -Ene 's?^\t*devid +([^ ]+) .* path ([^ ]+)?\1 \2?p'
}

go()
{
    set --
    found=
    while read id path
    do
        case "$path" in
            /dev/ram*) return ;;
            /dev/mapper/samizdatcrypt) found=y; continue ;;
            *) set -- "$@" "$id"
        esac
    done
    [ $# = 0 ] && return
    [ ! "$found" ] && return
    btrfs device remove "$@" /
}

get | go