forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.lunar
106 lines (93 loc) · 3.38 KB
/
kernel.lunar
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
############################################################
# #
# kernel.lunar functions for managing kernel installation #
# and bootloaders #
# #
############################################################
# #
# Parts Copyright Terry Chan 2002 GPLv2 #
# Parts Copyright Niki Guldbrand 2003 GPLv2 #
# Parts Copyright FW Systems llc 2003 GPLv2 #
# Parts Copyright Auke Kok 2005 GPLv2 #
# Parts Copyright Stefan Wold 2010 GPLv2 #
# #
############################################################
# Description : This function makes backups of the kernels and modules
# Arg 1 : Filename of the kernel to backup (With or without full path)
# With the format $VERSION_$EXTRAVERSION
backup_mods_krnl() {
local ARCH=$(arch)
debug_msg "backup_mods_krnl ($@)"
devoke_installwatch
if [ -f /boot/vmlinuz-$1-$ARCH ]; then
verbose_msg "copying vmlinuz-$1.$ARCH"
cp -p /boot/vmlinuz-$1-$ARCH{,.old}
fi
if [ -d /lib/modules/$1 ]; then
rm -rf /lib/modules/$1.old
cp -a /lib/modules/$1{,.old}
fi
if [ -f /boot/config-${1}-$ARCH.gz ]; then
verbose_msg "copying config-$1.$ARCH.gz"
cp -p /boot/config-${1}-$ARCH{,.old}.gz
fi
if [ -f /boot/System.map-${1}-$ARCH ]; then
verbose_msg "copying System.map-$1-$ARCH"
cp -p /boot/System.map-${1}-$ARCH{,.old}
fi
invoke_installwatch
}
update_bootloader() {
plugin_call KERNEL_UPDATEBOOTLOADER $1 $2
}
# function: kernel_config_exists
# usage: kernel_config_exists
# purpose: Verify that a readable kernel config is available
# returns: Config file path, (0) if successful, (1) if config not found
kernel_config_exists() {
if [ -e /proc/config.gz ]; then
echo "/proc/config.gz"
elif [ -e /lib/modules/$(uname -r)/source/.config ]; then
echo "/lib/modules/$(uname -r)/source/.config"
elif [ -e /boot/config-$(uname -r)-$(arch).gz ]; then
echo "/boot/config-$(uname -r)-$(arch).gz"
elif [ -e /usr/src/linux/.config ]; then
echo "/usr/src/linux/.config"
elif [ -e $CONFIG_CACHE/.config.current ]; then
echo "$CONFIG_CACHE/.config.current"
elif [ -e $CONFIG_CACHE/.config.2.6.stable ]; then
echo "$CONFIG_CACHE/.config.2.6.stable"
else
return 1
fi
return 0
}
# function: kernel_option_present
# usage: kernel_option_present config_option
# purpose: Check if a kernel option is configured
# returns: (0) if option is found and enabled, (1) if option is not found or disabled, (255) if kernel config not found
kernel_option_present() {
local KERNEL_CONFIG KERNEL_OPTION KERNEL_VALUE CAT
KERNEL_CONFIG=$(kernel_config_exists) || return 255
KERNEL_OPTION=$1
KERNEL_VALUE=$2
case $KERNEL_CONFIG in
*.gz)
CAT=zcat
;;
*)
CAT=cat
;;
esac
if [ -n "$KERNEL_VALUE" ]; then
if $CAT "$KERNEL_CONFIG" | grep -Eq "^$KERNEL_OPTION=\"$KERNEL_VALUE\""; then
return 0
fi
else
if $CAT "$KERNEL_CONFIG" | grep -Eq "^$KERNEL_OPTION=(y|m)$"; then
return 0
fi
fi
return 1
}