-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
init.sh
49 lines (43 loc) · 1.11 KB
/
init.sh
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
declare -rl PARAM1=${1-null}
# shellcheck disable=SC2155
declare -rl SCRIPT_NAME=$(basename "${0}")
# shellcheck disable=SC2155
declare -rl DIR_NAME=$(dirname "${0}")
# shellcheck disable=SC2155
declare -r CURDIR=$(pwd)
# shellcheck disable=SC2155
declare -r WHOAMI=$(whoami)
usage() {
echo "${SCRIPT_NAME} usage:"
echo ""
echo "${SCRIPT_NAME} [-h|--help]"
echo ""
echo "-h: Display this usage"
echo "--help: Display this usage"
echo ""
echo "This script change group ownership and rights of the powercap"
echo "special files. So you can run scaphandre as a regular user and"
echo "access power data."
exit 1
}
check_parameters() {
if [[ ${PARAM1} == '-h' ]] || [[ ${PARAM1} == '--help' ]]; then
usage
fi
}
change_power_sf_group_owner_and_rights() {
while IFS= read -r -d '' file; do
sudo chown root:"${WHOAMI}" "${file}"
sudo chmod g+r -R "${file}"
done < <(find /sys/devices/virtual/powercap -name energy_uj -print0)
}
main() {
cd "${DIR_NAME}"
check_parameters
change_power_sf_group_owner_and_rights
cd "${CURDIR}"
}
main