summarylogtreecommitdiffstats
path: root/zfs.install
blob: 6cba9a63700629016635e5d09e3ebc1ac377fe5b (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
post_install() {
    dkms add zfs/${1%%[-_]*}
    cat << EOF
==> To build and install your modules run: dkms install zfs/${1%%[_-]*} -k [KERNEL]
==> To do this automatically at startup run: systemctl enable dkms.service

EOF
    check_hook
}

pre_upgrade() {
    if [ "${1%%[-_]*}" != "${2%%[-_]*}" ]; then
        pre_remove "$2"
    fi
}

post_upgrade() {
    if [ "${1%%[-_]*}" != "${2%%[-_]*}" ]; then
        post_install "$1"
    fi
}

pre_remove() {
    [ -n "${1%%[-_]*}" ] && dkms remove zfs/${1%%[-_]*} --all -q || true
}

post_remove() {
    check_hook remove
}

check_hook() {
    ZFSHOOKFILES=()

    for preset in /etc/mkinitcpio.d/*.preset; do
        source $preset
        CONF_FILE=()

        if [ -n "${ALL_config}" ]; then
            CONF_FILE+=("${ALL_config}")
            unset ALL_config
        fi

        for prefix in ${PRESETS[@]}; do
            varname="${prefix}_config"
            if [ -n "$(eval echo \$$varname)" ]; then
                eval CONF_FILE+=("$(eval echo \$$varname)")
                unset $varname
            fi
        done

        i=0
        unset ZFSHOOKPRESENCE
        while [ $i -lt ${#CONF_FILE[@]} ]; do
            if [ -e "${CONF_FILE[$i]}" ] && [ $(grep -q "zfs" ${CONF_FILE[$i]} && echo -n "1") ]; then
                ZFSHOOKPRESENCE=1
                if [ "$1" == "remove" ] && [ $(echo -n "${ZFSHOOKFILES[@]}" | grep -q "${CONF_FILE[$i]}" || echo -n "1") ]; then
                    ZFSHOOKFILES+=("${CONF_FILE[$i]}")
                fi
            fi
            i+=1
        done

        if [ ${ZFSHOOKPRESENCE} ]; then
            if [ "$1" != "remove" ]; then
                echo "==> Generating initial ramdisk for $(basename "$preset" .preset), using mkinitcpio. Please wait..."
                mkinitcpio -p $(basename "$preset" .preset)
            fi
        fi
    done

    if [ "$1" == "remove" ] && [ ${#ZFSHOOKFILES[@]} -gt 0 ]; then
        echo "==> zfs-dkms package has been removed but \"zfs\" is still in the hooks list of:"
        for file in ${ZFSHOOKFILES[@]}; do
            echo "  -> ${file}"
        done
        echo "==> Remove \"zfs\" and generate a new initrd."
    fi
}