updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / acpi-eeepc-generic-svn / acpi-eeepc-generic-functions.sh
bloba0c4f1483e0867e81adacbc7454cc6b0b8e3655a
1 #!/bin/bash
3 CONSOLE_NUMBER=$(fgconsole)
5 # Get username
6 if [ -S /tmp/.X11-unix/X0 ]; then
7 export DISPLAY=:0
8 user=$(who | sed -n '/ (:0[\.0]*)$\| :0 /{s/ .*//p;q}')
9 # If autodetection fails, fallback to default user
10 # set in /etc/conf.d/acpi-eeepc-generic.conf
11 [ "x$user" == "x" ] && user=$XUSER
12 home=$(getent passwd $user | cut -d: -f6)
13 XAUTHORITY=$home/.Xauthority
14 if [[ -f $XAUTHORITY ]]; then
15 export XAUTHORITY
19 function eeepc_notify {
20 /bin/su $XUSER --login -c "/usr/bin/notify-send -i $2 -t 1500 \"EeePC $EEEPC_MODEL\" \"$1\""
21 #/usr/bin/notify-send -i $2 -t 1500 "EeePC $EEEPC_MODEL" "$1"
22 logger "EeePC $EEEPC_MODEL: $1 ($2)"
25 function execute_commands() {
26 cmds=( "$@" )
27 cmds_num=${#cmds[@]}
28 logger "execute_commands = $cmds ($cmds_num)"
29 for ((i=0;i<${cmds_num};i++)); do
30 c=${cmds[${i}]}
31 logger "execute_commands #$i: $c"
32 echo "execute_commands #$i: $c"
33 ${c} &
34 done
36 function execute_commands_as_user() {
37 cmds=( "$@" )
38 cmds_num=${#cmds[@]}
39 logger "execute_commands_as_user = $cmds ($cmds_num)"
40 for ((i=0;i<${cmds_num};i++)); do
41 c=${cmds[${i}]}
42 logger "execute_commands_as_user #$i: $c"
43 echo "execute_commands_as_user #$i: $c"
44 su $XUSER --login -c "${c} &"
45 done
48 function volume_is_mute() {
49 # 0 is true, 1 is false
50 on_off=`amixer get iSpeaker | grep -A 1 -e Mono | grep Playback | awk '{print ""$4""}'`
51 is_muted=1
52 [ "$on_off" == "[off]" ] && is_muted=0
53 return $is_muted
56 function get_volume() {
57 echo `amixer get PCM | grep -A 1 -e Mono | grep Playback | awk '{print ""$5""}' | sed -e "s|\[||g" -e "s|]||g" -e "s|\%||g"`
60 function get_model() {
61 (grep EEEPC_MODEL /etc/conf.d/acpi-eeepc-generic.conf >/dev/null 2>&1) || echo "EEEPC_MODEL=$(dmidecode -s system-product-name)" >> /etc/conf.d/acpi-eeepc-generic.conf
62 (grep EEEPC_CPU /etc/conf.d/acpi-eeepc-generic.conf >/dev/null 2>&1) || echo "EEEPC_CPU=`((grep Celeron /proc/cpuinfo >/dev/null 2>&1) && echo Celeron) || echo Atom`" >> /etc/conf.d/acpi-eeepc-generic.conf
65 function brightness_get_percentage() {
66 actual_brightness=`cat /sys/class/backlight/eeepc/actual_brightness`
67 maximum_brightness=`cat /sys/class/backlight/eeepc/max_brightness`
68 echo $((10000*$actual_brightness / (100*$maximum_brightness) ))
71 function brightness_find_direction() {
72 actual_brightness=`cat /sys/class/backlight/eeepc/actual_brightness`
73 previous_brightness=`cat /var/eeepc/brightness_saved`
74 [ "x$previous_brightness" == "x" ] && previous_brightness=$actual_brightness
75 to_return="up"
76 [ $actual_brightness -lt $previous_brightness ] && to_return="down"
77 echo $actual_brightness > /var/eeepc/brightness_saved
78 echo $to_return