Add some configs from generic Ubuntu

This commit is contained in:
2020-05-11 05:16:27 -04:00
parent f32c1048d1
commit 754f64f135
16037 changed files with 205635 additions and 137 deletions

View File

@@ -0,0 +1,245 @@
#!/bin/bash
# cpufreqctl - This script can configure the pstate driver of your intel CPU.
#
# Copyright (C) 2015-2020
# Martin Koppehel <psl.kontakt@gmail.com>,
# Fin Christensen <christensen.fin@gmail.com>,
#
# This file is part of the gnome-shell extension cpupower.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
VERSION="9.0.1"
log ()
{
echo "$@" >&2 || true
}
show_usage ()
{
log "usage: cpufreqctl [-h] [turbo {get,0,1}] [min {get,check,VALUE}] [max {get,VALUE}]"
log "version $VERSION"
}
show_help ()
{
log "usage: cpufreqctl [-h] ACTION PARAMETER"
log
log "This script can configure the pstate driver of your intel CPU."
log
help_arguments
help_actions
help_turbo
help_min
help_max
help_examples
help_copyright
}
help_arguments ()
{
log "optional arguments:"
log " -h, --help show this help message and exit"
log
}
help_actions ()
{
log "available actions:"
log " turbo control or read the turbo boost state of your cpu"
log " min get or set the minimum cpu frequency (in %, [0;100])"
log " or get the smallest allowed value"
log " max get or set the maximum cpu frequency (in %, [0;100])"
log
}
help_turbo ()
{
log "turbo parameters:"
log " get get the current turbo boost state"
log " 0 turn turbo boost off"
log " 1 turn turbo boost on"
log
}
help_min ()
{
log "min parameters:"
log " get get the current set minimum frequency (in %, [0;100])"
log " check get the smallest allowed minimum frequency for your cpu model"
log " VALUE set the current minimum frequency to a value in [0;100]"
log " the values is automatically clamped to the minimum allowed cpu"
log " frequency"
log
}
help_max ()
{
log "max parameters:"
log " get get the current set maximum frequency (in %, [0;100])"
log " VALUE set the current maximum frequency to a value in [0;100]"
log
}
help_examples ()
{
log "examples:"
log " Set the maximum frequency to 50%"
log " cpufreqctl max 50"
log
log " Get the turbo boost state"
log " cpufreqctl turbo get"
log
log " Get smallest allowed minimum cpu frequency for your model"
log " cpufreqctl min check"
log
}
help_copyright ()
{
log "cpufreqctl $VERSION Copyright (c) 2020 Martin Koppehel, Fin Christensen"
}
if [ $# -lt 1 ]
then
show_usage
log "error: you must specify an action!"
exit
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
show_help
exit
fi
if [ "$1" = "turbo" ]
then
if [ -z "$2" ]
then
log "usage: cpufreqctl turbo {get,0,1}"
log
help_turbo
help_copyright
exit
fi
if [ "$2" = "get" ]
then
value=$(<"/sys/devices/system/cpu/intel_pstate/no_turbo")
if [ "${value}" -eq 0 ]
then
echo 1
else
echo 0
fi
exit
fi
if [ "$2" -lt 0 ] || [ "$2" -gt 1 ];
then
log "usage: cpufreqctl turbo {get,0,1}"
log "error: VALUE must be 0 or 1"
exit
fi
if [ "$2" -eq 1 ]
then
echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo
else
echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo
fi
exit
fi
if [ "$1" = "max" ]
then
if [ -z "$2" ]
then
log "usage: cpufreqctl max {get,VALUE}"
log
help_max
help_copyright
exit
fi
if [ "$2" = "get" ]
then
value=$(</sys/devices/system/cpu/intel_pstate/max_perf_pct)
echo "${value}"
exit
fi
if [ "$2" = "check" ]
then
preValue=$(</sys/devices/system/cpu/intel_pstate/max_perf_pct)
echo 100 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
postValue=$(</sys/devices/system/cpu/intel_pstate/max_perf_pct)
echo "${preValue}" > /sys/devices/system/cpu/intel_pstate/max_perf_pct
echo "${postValue}"
exit
fi
if [ "$2" -lt 0 ] || [ "$2" -gt 100 ];
then
log "usage: cpufreqctl max {get,VALUE}"
log "error: VALUE must be between 0 and 100"
exit
fi
echo "$2" > /sys/devices/system/cpu/intel_pstate/max_perf_pct
exit
fi
if [ "$1" = "min" ]
then
if [ -z "$2" ]
then
log "usage: cpufreqctl mini {get,check,VALUE}"
log
help_min
help_copyright
exit
fi
if [ "$2" = "get" ]
then
value=$(</sys/devices/system/cpu/intel_pstate/min_perf_pct)
echo "${value}"
exit
fi
if [ "$2" = "check" ]
then
preValue=$(</sys/devices/system/cpu/intel_pstate/min_perf_pct)
echo 0 > /sys/devices/system/cpu/intel_pstate/min_perf_pct
postValue=$(</sys/devices/system/cpu/intel_pstate/min_perf_pct)
echo "${preValue}" > /sys/devices/system/cpu/intel_pstate/min_perf_pct
echo "${postValue}"
exit
fi
if [ "$2" -lt 0 ] || [ "$2" -gt 100 ];
then
log "usage: cpufreqctl min {get,check,VALUE}"
log "error: VALUE must be between 0 and 100"
exit
fi
echo "$2" > /sys/devices/system/cpu/intel_pstate/min_perf_pct
exit
fi
show_usage
log "error: unknown action $*"
exit 1

View File

@@ -0,0 +1,241 @@
#!/bin/bash
# installer.sh - This script installs a policykit action for the cpu power gnome-shell extension.
#
# Copyright (C) 2017-2020
# Martin Koppehel <psl.kontakt@gmail.com>,
# Fin Christensen <christensen.fin@gmail.com>,
#
# This file is part of the gnome-shell extension cpupower.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
EXIT_SUCCESS=0
EXIT_INVALID_ARG=1
EXIT_FAILED=2
EXIT_NEEDS_UPDATE=3
EXIT_NEEDS_SECURITY_UPDATE=4
EXIT_NOT_INSTALLED=5
EXIT_MUST_BE_ROOT=6
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #stackoverflow 59895
PREFIX="/usr" # default install prefix is /usr
function usage() {
echo "Usage: installer.sh [options] {supported,install,check,update,uninstall}"
echo
echo "Available options:"
echo " --prefix PREFIX Set the install prefix (default: /usr)"
echo " --tool-suffix SUFFIX Set the tool name suffix (default: <empty>)"
echo
exit ${EXIT_INVALID_ARG}
}
if [ $# -lt 1 ]
then
usage
fi
ACTION=""
while [[ $# -gt 0 ]]
do
key="$1"
# we have to use command line arguments here as pkexec does not support
# setting environment variables
case $key in
--prefix)
PREFIX="$2"
shift
shift
;;
--tool-suffix)
TOOL_SUFFIX="$2"
shift
shift
;;
supported|install|check|update|uninstall)
if [ -z "$ACTION" ]
then
ACTION="$1"
else
echo "Too many actions specified. Please give at most 1."
usage
fi
shift
;;
*)
echo "Unknown argument $key"
usage
;;
esac
done
ACTION_IN="${DIR}/../data/mko.cpupower.policy.in"
ACTION_DIR="${PREFIX}/share/polkit-1/actions"
RULE_IN="${DIR}/../data/10-mko.cpupower.setcpufreq.rules"
RULE_DIR="${PREFIX}/share/polkit-1/rules.d"
RULE_OUT="${RULE_DIR}/10-mko.cpupower.setcpufreq.rules"
CFC_IN="${DIR}/cpufreqctl"
# if TOOL_SUFFIX is provided, install to .../local/bin
# see https://github.com/martin31821/cpupower/issues/102
# the TOOL_SUFFIX enables per-user installations on a multi-user system
# see https://github.com/martin31821/cpupower/issues/84
if [ -z "${TOOL_SUFFIX}" ]
then
CFC_DIR="${PREFIX}/bin"
CFC_OUT="${CFC_DIR}/cpufreqctl"
ACTION_ID="mko.cpupower.setcpufreq"
ACTION_OUT="${ACTION_DIR}/${ACTION_ID}.policy"
else
CFC_DIR="${PREFIX}/local/bin"
CFC_OUT="${CFC_DIR}/cpufreqctl-${TOOL_SUFFIX}"
ACTION_ID="mko.cpupower.setcpufreq.${TOOL_SUFFIX}"
ACTION_OUT="${ACTION_DIR}/${ACTION_ID}.policy"
fi
V7_LEGACY_OUT="/usr/share/polkit-1/actions/mko.cpupower.policy"
V8_LEGACY_OUT="/usr/share/polkit-1/actions/mko.cpupower.setcpufreq.policy"
if [ "$ACTION" = "supported" ]
then
if [ -d /sys/devices/system/cpu/intel_pstate ]
then
echo "Supported"
exit ${EXIT_SUCCESS}
else
echo "Unsupported"
exit ${EXIT_FAILED}
fi
fi
if [ "$ACTION" = "check" ]
then
# pre v9 policy rules have security issues
# cpufreqctl should always be located in /usr/local/bin or /usr/bin as of
# https://github.com/martin31821/cpupower/issues/102
# therefore check for occurence of prefix
if [ -f "${V8_LEGACY_OUT}" ] && ! grep -sq "${PREFIX}" "${V8_LEGACY_OUT}" || \
[ -f "${V7_LEGACY_OUT}" ]
then
echo "Your cpupower installation needs updating!"
echo "Warning: Security issues were found with your installation! Update immediately!"
exit ${EXIT_NEEDS_SECURITY_UPDATE}
fi
if ! sed -e "s:{{PATH}}:${CFC_OUT}:g" \
-e "s:{{ID}}:${ACTION_ID}:g" "${ACTION_IN}" | \
cmp --silent "${ACTION_OUT}"
then
if [ -f "${ACTION_OUT}" ]
then
echo "Your cpupower installation needs updating!"
exit ${EXIT_NEEDS_UPDATE}
else
echo "Not installed"
exit ${EXIT_NOT_INSTALLED}
fi
fi
echo "Installed"
exit ${EXIT_SUCCESS}
fi
if [ "$ACTION" = "install" ]
then
if [ "${EUID}" -ne 0 ]; then
echo "The install action must be run as root for security reasons!"
echo "Please have a look at https://github.com/martin31821/cpupower/issues/102"
echo "for further details."
exit ${EXIT_MUST_BE_ROOT}
fi
echo -n "Installing cpufreqctl tool... "
mkdir -p "${CFC_DIR}"
install "${CFC_IN}" "${CFC_OUT}" || (echo "Failed" && exit ${EXIT_FAILED})
echo "Success"
echo -n "Installing policykit action... "
mkdir -p "${ACTION_DIR}"
sed -e "s:{{PATH}}:${CFC_OUT}:g" \
-e "s:{{ID}}:${ACTION_ID}:g" "${ACTION_IN}" > "${ACTION_OUT}" 2>/dev/null || \
(echo "Failed" && exit ${EXIT_FAILED})
echo "Success"
echo -n "Installing policykit rule... "
mkdir -p "${RULE_DIR}"
install -m 0644 "${RULE_IN}" "${RULE_OUT}" || (echo "Failed" && exit ${EXIT_FAILED})
echo "Success"
exit ${EXIT_SUCCESS}
fi
if [ "$ACTION" = "update" ]
then
if [ -f "V7_LEGACY_OUT" ]
then
echo -n "Uninstalling legacy v7 polkit rule... "
rm "${V7_LEGACY_OUT}" || \
(echo "Failed - cannot remove ${V7_LEGACY_OUT}" && exit ${EXIT_FAILED})
echo "Success"
fi
if [ -f "${V8_LEGACY_OUT}" ] && ! grep -sq "${PREFIX}" "${V8_LEGACY_OUT}"
then
echo -n "Uninstalling legacy v8 polkit rule... "
rm "${V8_LEGACY_OUT}" || \
(echo "Failed - cannot remove ${V8_LEGACY_OUT}" && exit ${EXIT_FAILED})
echo "Success"
fi
"${BASH_SOURCE[0]}" --prefix "${PREFIX}" --tool-suffix "${TOOL_SUFFIX}" uninstall || exit $?
"${BASH_SOURCE[0]}" --prefix "${PREFIX}" --tool-suffix "${TOOL_SUFFIX}" install || exit $?
exit ${EXIT_SUCCESS}
fi
if [ "$ACTION" = "uninstall" ]
then
echo -n "Uninstalling cpufreqctl tool... "
if [ -f "${CFC_OUT}" ]
then
rm "${CFC_OUT}" || (echo "Failed - cannot remove ${CFC_OUT}" && exit ${EXIT_FAILED}) && echo "Success"
else
echo "tool not installed at ${CFC_OUT}"
fi
echo -n "Uninstalling policykit action... "
if [ -f "${ACTION_OUT}" ]
then
rm "${ACTION_OUT}" || (echo "Failed - cannot remove ${ACTION_OUT}" && exit ${EXIT_FAILED}) && echo "Success"
else
echo "policy action not installed at ${ACTION_OUT}"
fi
echo -n "Uninstalling policykit rule... "
if [ -f "${RULE_OUT}" ]
then
rm "${RULE_OUT}" || (echo "Failed - cannot remove ${RULE_OUT}" && exit ${EXIT_FAILED}) && echo "Success"
else
echo "policy rule not installed at ${RULE_OUT}"
fi
exit ${EXIT_SUCCESS}
fi
echo "Unknown parameter."
usage