summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-system/lh_restart_needed.sh
blob: 2db8a2de6daa25a5b0d46eae083a51dab189aa3e (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
#!/bin/bash

get_boot_kernel() {
    local get_version=0
    for field in $(file /boot/vmlinuz*); do
        if [[ $get_version -eq 1 ]]; then
            echo $field
            return
        elif [[ $field == version ]]; then
            # the next field contains the version
            get_version=1
        fi
    done
}

rc=1

libs=$(lsof -n +c 0 2> /dev/null | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u)
if [[ -n $libs ]]; then
    cat <<< $libs
    echo "# LIBS: reboot required"
    rc=0
fi

active_kernel=$(uname -r)
current_kernel=$(get_boot_kernel)
#echo $active_kernel
#echo $current_kernel

if [[ $active_kernel != $current_kernel ]]; then
    echo "$active_kernel < $current_kernel"
    echo "# KERNEL: reboot required"
    rc=0
fi

if [[ $rc == 1 ]]; then
    echo "No reboot needed."
fi
exit $rc