You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-2.2-builder/data/calculate-builder

90 lines
1.9 KiB

#!/sbin/runscript
depend() {
need modules
before cpufrequtils
}
KERNEL_VERSION=`uname -r`
KERNEL_VERSION_CONF=${KERNEL_VERSION//./_}
KERNEL_VERSION_CONF="modules_3"
MODULES_PATH="/lib/modules/${KERNEL_VERSION}"
CONF_FILE="/etc/conf.d/modules"
# get variable value from cl-install
variable_value()
{
local varname=$1
cl-install -v --filter $varname |
awk "{ if (\$1 == \"$varname\") print \$3 }"
}
# detect modules for cpu freq
get_cpufreq_modules(){
MODULES_STRING=""
# find all cpufreq modules
for path in $(find $MODULES_PATH -name cpufreq)
do
# load each module and chech it
for module_path in $(find $path -name *.ko | sort)
do
module_name=${module_path##\/*\/}
module_name=${module_name%.ko}
if modprobe $module_name &>/dev/null;
then
if [[ ${MODULES_STRING} ]];
then
MODULES_STRING="${MODULES_STRING} $module_name"
else
MODULES_STRING=$module_name
fi
fi
done
done
}
# find cpu freq modules autoload string
find_string_modules(){
find_string=$(awk "/^\s*[^#]*\s*${KERNEL_VERSION_CONF}/ {print}" < ${CONF_FILE})
if [[ -n $find_string ]];
then
return 0
fi
return 1
}
# add cpu freq modules to modules autoload file
add_autoload_modules(){
# get root type
local roottype=`variable_value os_root_type`
# if modules have not added yet
if ! find_string_modules;
then
ebegin "Added rules for cpu frequency"
# detect cpufreq modules
get_cpufreq_modules
# if root type is hdd
if [[ $roottype == "hdd" ]]
then
# append config string to conf file
echo ${KERNEL_VERSION_CONF}=\"${MODULES_STRING}\" >> ${CONF_FILE}
fi
else
ebegin "Cpu frequency modules already detected"
fi
}
start() {
add_autoload_modules
eend
}
stop() {
# remove calculate-builder from autorun
local roottype=`variable_value os_root_type`
if [[ $roottype == "hdd" ]] && rc-config list boot | grep -q calculate-builder
then
rc-update del calculate-builder boot
fi
}