Audit fixes for command injection risks in helper scripts: - moonarch-cpugov: eval for quoted COMMANDS expansion (pkexec context) - moonarch-btnote: while+read with process substitution, quoted vars - moonarch-vpn: -- guard before connection name in nmcli calls - post-install.sh: else-logging when USER_DEFAULTS dir missing
71 lines
1.6 KiB
Bash
Executable File
71 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ABOUTME: Walker-dmenu CPU governor switcher using auto-cpufreq.
|
|
# ABOUTME: Allows switching between performance, powersave, and reset modes.
|
|
|
|
declare -A LABELS
|
|
declare -A COMMANDS
|
|
|
|
###
|
|
# List of defined 'bangs'
|
|
|
|
COMMANDS[""]="pkexec auto-cpufreq --force=performance"
|
|
LABELS[""]="Performance"
|
|
|
|
COMMANDS[""]='pkexec auto-cpufreq --force=powersave'
|
|
LABELS[""]="Powersave"
|
|
|
|
COMMANDS[""]='pkexec auto-cpufreq --force=reset'
|
|
LABELS[""]="Reset"
|
|
|
|
|
|
################################################################################
|
|
# do not edit below
|
|
################################################################################
|
|
##
|
|
# Generate menu
|
|
##
|
|
function print_menu()
|
|
{
|
|
for key in ${!LABELS[@]}
|
|
do
|
|
# echo "$key ${LABELS}"
|
|
echo "$key ${LABELS[$key]}"
|
|
# my top version just shows the first field in labels row, not two words side by side
|
|
done
|
|
}
|
|
##
|
|
# Show rofi.
|
|
##
|
|
function start()
|
|
{
|
|
print_menu | sort | walker -d -p " CPU Mode"
|
|
}
|
|
|
|
|
|
# Run it
|
|
value="$(start)"
|
|
|
|
# Split input.
|
|
# grab upto first space.
|
|
choice=${value%%\ *}
|
|
|
|
##
|
|
# Cancelled? bail out
|
|
##
|
|
if test -z "${choice}"
|
|
then
|
|
exit
|
|
fi
|
|
|
|
# check if choice exists
|
|
if test "${COMMANDS[$choice]+isset}"
|
|
then
|
|
# Execute the choice — eval required because COMMANDS values contain
|
|
# multi-word strings that must be interpreted as full commands.
|
|
eval "${COMMANDS[$choice]}"
|
|
|
|
notify-send -h string:x-canonical-private-synchronous:cpugov -i cpu "CPU Mode" "Set to $choice ${LABELS[$choice]}"
|
|
else
|
|
notify-send -u critical "CPU Governor" "Unknown command: ${choice}"
|
|
fi
|