Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 329 lines (301 sloc) 9.94 KB
#!/bin/bash
# lightum-indicator helper script
# (c)2012 Pau Oliva Fora
# License: GPLv2+
# load include file
source /usr/share/lightum-indicator/lightum-indicator-include
# make sure zenity is installed
which zenity 2>&1 >/dev/null
if [ $? != 0 ]; then
echo "Missing dependancy: this indicator needs zenity installed to work"
exit 1
fi
# make sure lightum is installed
which lightum 2>&1 >/dev/null
if [ $? != 0 ]; then
${ZEN} --no-wrap --error --text "Missing dependancy: this indicator needs lightum installed to work"
exit 1
fi
# conf dir must exist
if [ ! -d "${CONFDIR}" ]; then
mkdir -p "${CONFDIR}"
fi
# conf file must exist
touch "${CONFIG}"
#### proced with the actions
s="$*"
case "$s" in
"Mode:Auto")
${ZEN} --no-wrap --question --text="Reload lightum in auto mode?"
if [ $? == 0 ]; then
manualmode=`cat ${CONFIG} |grep "^manualmode="`
if [ -z "$manualmode" ]; then
echo "manualmode=0" >> ${CONFIG}
else
sed -i "s/^manualmode=.*/manualmode=0/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
;;
"Mode:Manual")
${ZEN} --no-wrap --question --text="Reload lightum in manual mode?"
if [ $? == 0 ]; then
manualmode=`cat ${CONFIG} |grep "^manualmode="`
if [ -z "$manualmode" ]; then
echo "manualmode=1" >> ${CONFIG}
else
sed -i "s/^manualmode=.*/manualmode=1/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
;;
"Manage:Screen Only")
${ZEN} --no-wrap --question --text="Manage only screen backlight?"
if [ $? == 0 ]; then
workmode=`cat ${CONFIG} |grep "^workmode="`
if [ -z "$workmode" ]; then
echo "workmode=2" >> ${CONFIG}
else
sed -i "s/^workmode=.*/workmode=2/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
;;
"Manage:Keyboard Only")
${ZEN} --no-wrap --question --text="Manage only keyboard brightness?"
if [ $? == 0 ]; then
workmode=`cat ${CONFIG} |grep "^workmode="`
if [ -z "$workmode" ]; then
echo "workmode=1" >> ${CONFIG}
else
sed -i "s/^workmode=.*/workmode=1/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
;;
"Manage:Screen + Keyboard")
${ZEN} --no-wrap --question --text="Manage both keyboard brightness and screen backlight?"
if [ $? == 0 ]; then
workmode=`cat ${CONFIG} |grep "^workmode="`
if [ -z "$workmode" ]; then
echo "workmode=3" >> ${CONFIG}
else
sed -i "s/^workmode=.*/workmode=3/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
;;
"Keyboard Options:Max Brightness")
cv=`cat ${CONFIG} |grep "^maxbrightness=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=255 ; fi
ans=`${ZEN} --forms --add-entry="maximum keyboard brightness value (between 4 and 255)" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 255 ] && [ ${ans} -ge 4 ]; then
maxbrightness=`cat ${CONFIG} |grep "^maxbrightness="`
if [ -z "$maxbrightness" ]; then
echo "maxbrightness=${ans}" >> ${CONFIG}
else
sed -i "s/^maxbrightness=.*/maxbrightness=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "max keyboard brightness should be a value between 4 and 255."
fi
fi
;;
"Keyboard Options:Min Brightness")
cv=`cat ${CONFIG} |grep "^minbrightness=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=0 ; fi
ans=`${ZEN} --forms --add-entry="minimum keyboard brightness value (between 0 and 3)" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 3 ] && [ ${ans} -ge 0 ]; then
minbrightness=`cat ${CONFIG} |grep "^minbrightness="`
if [ -z "$minbrightness" ]; then
echo "minbrightness=${ans}" >> ${CONFIG}
else
sed -i "s/^minbrightness=.*/minbrightness=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "min keyboard brightness should be a value between 0 and 3"
fi
fi
;;
"Keyboard Options:Dim on idle time")
cv=`cat ${CONFIG} |grep "^idleoff=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=5 ; fi
ans=`${ZEN} --forms --add-entry="Dim keyboard brightness if computer unused for X seconds" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
idleoff=`cat ${CONFIG} |grep "^idleoff="`
if [ -z "$idleoff" ]; then
echo "idleoff=${ans}" >> ${CONFIG}
else
sed -i "s/^idleoff=.*/idleoff=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
fi
fi
;;
"Screen Options:Max Backlight")
cv=`cat ${CONFIG} |grep "^maxbacklight=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=15 ; fi
ans=`${ZEN} --forms --add-entry="maximum screen backlight value (between 7 and 15)" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 15 ] && [ ${ans} -ge 7 ]; then
maxbacklight=`cat ${CONFIG} |grep "^maxbacklight="`
if [ -z "$maxbacklight" ]; then
echo "maxbacklight=${ans}" >> ${CONFIG}
else
sed -i "s/^maxbacklight=.*/maxbacklight=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "max screen backlight should be a value between 7 and 15"
fi
fi
;;
"Screen Options:Min Backlight")
cv=`cat ${CONFIG} |grep "^minbacklight=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=0 ; fi
ans=`${ZEN} --forms --add-entry="minimum screen backlight value (between 1 and 6)" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 6 ] && [ ${ans} -ge 1 ]; then
minbacklight=`cat ${CONFIG} |grep "^minbacklight="`
if [ -z "$minbacklight" ]; then
echo "minbacklight=${ans}" >> ${CONFIG}
else
sed -i "s/^minbacklight=.*/minbacklight=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "min screen backlight should be a value between 1 and 6"
fi
fi
;;
"Screen Options:Dim on idle time")
cv=`cat ${CONFIG} |grep "^screenidle=" |cut -f 2 -d "="`
if [ -z "$cv" ]; then cv=30 ; fi
ans=`${ZEN} --forms --add-entry="Dim screen backlight if computer unused for X seconds" --text="current value: $cv"`
if [ $? == 0 ]; then
if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
screenidle=`cat ${CONFIG} |grep "^screenidle="`
if [ -z "$screenidle" ]; then
echo "screenidle=${ans}" >> ${CONFIG}
else
sed -i "s/^screenidle=.*/screenidle=${ans}/" ${CONFIG}
fi
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
else
${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
fi
fi
;;
"About")
${ZEN} --no-wrap --info --text "lightum-indicator version ${VERSION}\n(c)2012 Pau Oliva Fora\nLicensed under GPL"
;;
"Profile:Refresh")
updatemenu
;;
*)
# handle profiles here
echo "$s" |grep "Profile:.*:Save As..." >/dev/null
if [ $? == 0 ]; then
ans=`${ZEN} --forms --add-entry="Profile name (max 16 chars, no spaces)" --text="Enter the new profile name"`
profile=$(echo `echo "${ans}" |grep -oi "[a-z]"` |sed -e "s/ //g" |cut -c "1-16")
write="yes"
if [ -z "${profile}" ]; then
${ZEN} --no-wrap --error --text "Invalid profile name."
else
if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
write="no"
${ZEN} --no-wrap --question --text="a profile named '${profile}' already exists. Overwrite?"
if [ $? == 0 ]; then
write="yes"
fi
fi
if [ "${write}" == "yes" ]; then
cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
grep "^#PROFILE: " "${CONFDIR}/lightum-${profile}.conf" >/dev/null
if [ $? == 0 ]; then
sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" "${CONFDIR}/lightum-${profile}.conf"
else
echo "#PROFILE: ${profile}" >> "${CONFDIR}/lightum-${profile}.conf"
fi
${ZEN} --no-wrap --question --text "Profile '${profile}' successfully saved.\nDo you want to load it now?"
if [ $? == 0 ]; then
cp "${CONFDIR}/lightum-${profile}.conf" "${CONFIG}"
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
fi
updatemenu
fi
fi
fi
echo "$s" |grep "Profile:.*:Save$" >/dev/null
if [ $? == 0 ]; then
profile=`echo $s |cut -f 2 -d ":"`
if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
write="no"
${ZEN} --no-wrap --question --text="Overwrite profile '${profile}' with current settings?"
if [ $? == 0 ]; then
write="yes"
fi
fi
if [ "${write}" == "yes" ]; then
grep "^#PROFILE: " ${CONFIG} >/dev/null
if [ $? == 0 ]; then
sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" ${CONFIG}
else
echo "#PROFILE: ${profile}" >> ${CONFIG}
fi
cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
${ZEN} --no-wrap --info --text "Profile '${profile}' successfully saved."
fi
fi
echo "$s" |grep "Profile:.*:View" >/dev/null
if [ $? == 0 ]; then
profile=`echo $s |cut -f 2 -d ":"`
if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
cat "${CONFDIR}/lightum-${profile}.conf" |grep -v "^$" |grep -v "#" |${ZEN} --text-info --title="lightum profile ${profile}"
else
${ZEN} --no-wrap --error --text "Could not view profile, sorry."
fi
fi
echo "$s" |grep "Profile:.*:Load" >/dev/null
if [ $? == 0 ]; then
profile=`echo $s |cut -f 2 -d ":"`
if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
${ZEN} --no-wrap --question --text="Load profile '${profile}'?"
if [ $? == 0 ]; then
cp "${CONFDIR}/lightum-${profile}.conf" "${CONFIG}"
kill -USR1 $(pidof lightum) 2>/dev/null || lightum
updatemenu
fi
else
${ZEN} --no-wrap --error --text "Could not load profile, sorry."
fi
fi
echo "$s" |grep "Profile:.*:Delete" >/dev/null
if [ $? == 0 ]; then
profile=`echo $s |cut -f 2 -d ":"`
if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
${ZEN} --no-wrap --question --text="Really delete profile '${profile}'?"
if [ $? == 0 ]; then
rm -f "${CONFDIR}/lightum-${profile}.conf"
updatemenu
fi
else
${ZEN} --no-wrap --error --text "Could not delete profile, sorry."
fi
fi
;;
esac
# make sure lightum is running, otherwise start it
pidof lightum 2>&1 >/dev/null || lightum