aboutsummarylogtreecommitdiffstats
path: root/post-hook
blob: 479bc5c156d0874e3cc4ffd66d32839363086f6f (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
#!/usr/bin/env bash

# set -o xtrace
set -o errexit -o nounset -o pipefail -o errtrace
IFS=$'\n\t'

cd /usr/lib/modules/saved-kernel-modules

running_kernel=$(uname -r)

if [ -e modules/"$running_kernel" ] ; then
    if [ -L /usr/lib/modules/"$running_kernel" ] ; then
        # symlink already there, do nothing
        exit 0
    elif [ -d /usr/lib/modules/"$running_kernel" ] ; then
        # leftover for some reason, make a backup
        suffix="bck-$(date -u +%FT%T)"
        mv /usr/lib/modules/"$running_kernel" \
           /usr/lib/modules/"$running_kernel-${suffix}"
        echo "This directory was backed up by saved-kernel-modules, it's probably safe to delete." \
             >  /usr/lib/modules/"$running_kernel-${suffix}"/DELETE_THIS_DIR
    fi

    ln -s $PWD/modules/"$running_kernel" /usr/lib/modules/"$running_kernel"
fi