Tuesday, July 21, 2009

bil - change the brightness of an iMac


#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.7).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh02580
# Made on 2009-07-21 09:19 GMTDT by .
# Source directory was `/cygdrive/c/Users/mcarter/docs'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1959 -rwx------ bil/bil.c
# 70 -rwx------ bil/bil.txt
# 118 -rwx------ bil/Makefile
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir ;;
esac
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and'
${echo} 'installing GNU `touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir}
then : ; else ${echo} 'lock directory '${lock_dir}' exists'
exit 1
fi
if mkdir ${lock_dir}
then ${echo} 'x - created lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to create lock directory `'${lock_dir}\''.'
exit 1
fi
# ============= bil/bil.c ==============
if test ! -d 'bil'; then
mkdir 'bil'
if test $? -eq 0
then ${echo} 'x - created directory `bil'\''.'
else ${echo} 'x - failed to create directory `bil'\''.'
exit 1
fi
fi
if test -f 'bil/bil.c' && test "$first_param" != -c; then
${echo} 'x -SKIPPING bil/bil.c (file already exists)'
else
${echo} 'x - extracting bil/bil.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'bil/bil.c' &&
/* http://www.felipe-alfaro.org/blog/2006/09/11/basic-backlight-support-for-macbook-pro/ */
/*
X * Apple Macbook Pro LCD backlight control
X *
X * Copyright (C) 2006 Nicolas Boichat
X * Copyright (C) 2006 Felipe Alfaro Solana
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 2 of the License, or
X * (at your option) any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X */
X
#include
#include
#include
X
void init()
{
X if (ioperm(0xB2, 0xB3, 1) < 0)
X {
X perror("ioperm failed (you should be root).");
X exit(2);
X }
}
X
int get_current_value()
{
X outb(0x03, 0xB3);
X outb(0xBF, 0xB2);
X char t = inb(0xB3) >> 4;
X return t;
}
X
int calculate_new_value(const char *arg)
{
X int val, new = atoi(arg);
X
X if (arg[0] == '+' || arg[0] == '-')
X val = new + get_current_value();
X else
X val = new;
X
X if (val > 15)
X val = 15;
X else if (val < 1)
X val = 1;
X
X return val;
}
X
int main(int argc, char** argv)
{
X if (argc > 2)
X {
X printf("Usage:\n");
X printf("%s : read current value\n", argv[0]);
X printf("%s value : write value [0-15]\n", argv[0]);
X exit(1);
X }
X
X init();
X
X if (argc < 2)
X {
X printf("Current value : %d\n", get_current_value());
X exit(0);
X }
X
X if (argc == 2)
X {
X int value = calculate_new_value(argv[1]);
X outb(0x04 | (value << 4), 0xB3);
X outb(0xBF, 0xB2);
X printf("new value: %d\n", value);
X }
X
X return 0;
}
SHAR_EOF
(set 20 09 04 03 20 16 15 'bil/bil.c'; eval "$shar_touch") &&
chmod 0700 'bil/bil.c'
if test $? -ne 0
then ${echo} 'restore of bil/bil.c failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'bil/bil.c: MD5 check failed'
) << \SHAR_EOF
1929d6231118d4138e2594c4b42cb0d2 bil/bil.c
SHAR_EOF
else
test `LC_ALL=C wc -c < 'bil/bil.c'` -ne 1959 && \
${echo} 'restoration warning: size of bil/bil.c is not 1959'
fi
fi
# ============= bil/bil.txt ==============
if test ! -d 'bil'; then
mkdir 'bil'
if test $? -eq 0
then ${echo} 'x - created directory `bil'\''.'
else ${echo} 'x - failed to create directory `bil'\''.'
exit 1
fi
fi
if test -f 'bil/bil.txt' && test "$first_param" != -c; then
${echo} 'x -SKIPPING bil/bil.txt (file already exists)'
else
${echo} 'x - extracting bil/bil.txt (text)'
sed 's/^X//' << 'SHAR_EOF' > 'bil/bil.txt' &&
bil - changes the brightness settings on iMacs
X
Created: 04-Apr-2009
SHAR_EOF
(set 20 09 04 04 18 53 49 'bil/bil.txt'; eval "$shar_touch") &&
chmod 0700 'bil/bil.txt'
if test $? -ne 0
then ${echo} 'restore of bil/bil.txt failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'bil/bil.txt: MD5 check failed'
) << \SHAR_EOF
91e3afb8c696acc63777a70a0fbe1ac1 bil/bil.txt
SHAR_EOF
else
test `LC_ALL=C wc -c < 'bil/bil.txt'` -ne 70 && \
${echo} 'restoration warning: size of bil/bil.txt is not 70'
fi
fi
# ============= bil/Makefile ==============
if test -f 'bil/Makefile' && test "$first_param" != -c; then
${echo} 'x -SKIPPING bil/Makefile (file already exists)'
else
${echo} 'x - extracting bil/Makefile (text)'
sed 's/^X//' << 'SHAR_EOF' > 'bil/Makefile' &&
DEST=/usr/local/bin
X
bil : bil.c
X gcc bil.c bil
X
clean :
X rm -f bil
X
install :
X cp bil ${DEST}
X chmod a+s ${DEST}/bil
SHAR_EOF
(set 20 09 04 26 13 01 15 'bil/Makefile'; eval "$shar_touch") &&
chmod 0700 'bil/Makefile'
if test $? -ne 0
then ${echo} 'restore of bil/Makefile failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'bil/Makefile: MD5 check failed'
) << \SHAR_EOF
46661b10d9f20e7fe682f3573e835663 bil/Makefile
SHAR_EOF
else
test `LC_ALL=C wc -c < 'bil/Makefile'` -ne 118 && \
${echo} 'restoration warning: size of bil/Makefile is not 118'
fi
fi
if rm -fr ${lock_dir}
then ${echo} 'x - removed lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to remove lock directory `'${lock_dir}\''.'
exit 1
fi
exit 0

No comments: