Hi all,

in the forum we often tell the users to add several options to /etc/modprobe.d/*
and modules to /etc/modules. what about doing this setup automatically?
i recently wrote a script to do so. what do you think about installing this 
script
by a package and calling it in the package's post-install script?

before doing so, please have a look and comment on it. you can call the attached
script with:
sudo mactel-modules-config --test
or:
sudo mactel-modules-config --test MacBookPro4,1
to check its intended configuration.

not using --test causes the script to output to 
/etc/modprobe.d/mactel-modules-config,
as well as to update /etc/modules.

finally, before i think it is useful, i'd like to ask a few questions:
1. Does the 5th generation models really need the model option for 
snd_hda_intel?
   Is snd_hda_intel loaded on those machines?
2. Is appleir really deprecated? Right now, i'm blacklisting this module.

by the way: since it is quite confusing to install the necessary packages from 
the
PPA - not all machines need all packages on all releases - what about adding 
meta-packages,
e.g., mactel-support-macbookpro4 that installs the other packages through its 
dependency?

ciao,
Mario

-- 
 Wo das Chaos auf die Ordnung trifft, gewinnt meist das Chaos,
 weil es besser organisiert ist.
     - Friedrich Nietzsche -

--
    _____    ________
   /     \  /   ____/  Mario Schwalbe
  /  \ /  \ \____  \
 /    Y    \/       \  eMail: [email protected],
 \____|__  /______  /         [email protected]
         \/       \/

          key ID: 7DA9 DAFF
      public key: https://www1.inf.tu-dresden.de/~s4700588/key.asc
 key fingerprint: 2979 AA20 4A93 B527 90CC  45E5 4B28 511A 7DA9 DAFF

#!/bin/bash

NAME=${0##*/}
MODPROBE_OPTIONS_FILE="/etc/modprobe.d/$NAME"

. /etc/lsb-release

#
# general functions
#
jaunty_or_newer()
{
        if [ "$DISTRIB_CODENAME" = "jaunty" ] ; then
                return 0
        fi
        return 1
}

add_to_etc_modules()
{
        # never add in test-only mode
        if [ -z "$TEST_ONLY" ] ; then
                for m in "$@" ; do
                        # the regex also applies to commented modules, allowing
                        # to make the script ignore a module
                        if ! grep -qE "^([[:space:]]|#)*$m" /etc/modules ; then
                                echo "# added by $NAME" >> /etc/modules
                                echo "$m" >> /etc/modules
                        fi
                done
        fi
}

#
# general options
#
general_options()
{
        cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# enable autosuspend of USB subsystem
options usbcore autosuspend=1

## function keys control hardware functions
#options hid pb_fnmode=2

# obsolete module: use LIRC instead
blacklist appleir

EOF
}

#
# model specific options
#
apple_smc()
{
        # no need to check whether then dkms package is installed
        # the upstream module should work as well
        add_to_etc_modules applesmc
}

broadcom_wlan()
{
        cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# blacklist conflicting modules for wl/ndiswrapper to work
blacklist ssb
blacklist b43
blacklist b43legacy

EOF
}

intel_sound()
{
        cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# fix sound for SantaRosa (Intel chipset) Macs
options snd_hda_intel model=$1

EOF
}

nvidia_graphics()
{
        cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# unnecessary modules: the nvidia driver handles AGP as well
blacklist intel_agp
blacklist agpgart

EOF
}

nvidia_backlight()
{
        m="$1"

        # check whether nvidia_bl is installed if to be used
        # (mbp_nvidia_bl is available upstream)
        if [ "$m" = "nvidia_bl" ] && ! dpkg -L nvidia-bl-dkms > /dev/null ; then
                m="mbp_nvidia_bl"
        fi

        # blacklisting is necessary for jaunty because module auto-loading
        # finally works as it should have in earlier versions
        if [ "$m" = "nvidia_bl" ] ; then
                # only intrepid: add the shift option to avoid
                # brightness level overflows in g-p-m
                if ! jaunty_or_newer ; then
                        cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# fix brightness level overflow with nvidia_bl
options nvidia_bl shift=2
EOF
                fi

                cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# blacklist mbp_nvidia_bl in order to use nvidia_bl
blacklist mbp_nvidia_bl

EOF
        elif [ "$m" = "mbp_nvidia_bl" ] ; then
                cat <<EOF >> "$MODPROBE_OPTIONS_FILE"
# blacklist nvidia_bl in order to use mbp_nvidia_bl
blacklist nvidia_bl

EOF
        fi

        # now add the module to /etc/modules
        add_to_etc_modules "$m"
}

#
# get --test option
#
if [ "$1" = "--test" ] || [ "$1" = "--show-only" ] || [ "$1" = "--dry-run" ] ; 
then
        MODPROBE_OPTIONS_FILE="/dev/stdout"
        TEST_ONLY=1
        shift
fi

#
# get vendor and model string if not provided via command line
#
if [ ! -z "$1" ] ; then
        VENDOR="Apple Inc."
        MODEL="$1"
else
        VENDOR=$(dmidecode --string system-manufacturer)
        if [ $? -ne 0 ] ; then
                echo "$NAME: Failed to run dmidecode. Are you root?" > 
/dev/stderr
                exit 1
        fi

        MODEL=$(dmidecode --string system-product-name)
        if [ $? -ne 0 ] ; then
                echo "$NAME: Failed to run dmidecode. Are you root?" > 
/dev/stderr
                exit 1
        fi
fi

#
# check vendor string
#
if [ "$VENDOR" != "Apple Inc." ] ; then
        echo "$NAME: No Apple machine detected." > /dev/stderr
        exit 1
fi

#
# truncate file & print header
#
cat <<EOF > "$MODPROBE_OPTIONS_FILE"
#
# This file has been automatically created by $NAME. Do not edit.
# Don't forget to run \`update-initramfs -k all -u\` after updating this file.
#
# detected machine:
#     vendor: $VENDOR
#     model:  $MODEL
#

EOF

#
# print general options
#
general_options

#
# print model specific options
#
case "$MODEL" in
        MacBookAir1,1|MacBook4,1)
                apple_smc
                broadcom_wlan
                intel_sound mbp3
        ;;

        MacBookPro3,1|MacBookPro3,2|MacBookPro4,1)
                apple_smc
                broadcom_wlan
                intel_sound mbp3
                nvidia_graphics
                # nvidia_bl works better than mbp_nvidia_bl on those models
                nvidia_backlight nvidia_bl
        ;;

        MacBookAir2,1|MacBook5,1)
                apple_smc
                broadcom_wlan
                # is this necessary?
                intel_sound mbp3
                nvidia_graphics
                # nvidia_bl works better than mbp_nvidia_bl on those models
                nvidia_backlight nvidia_bl
        ;;

        MacBookPro5,1)
                apple_smc
                broadcom_wlan
                # is this necessary?
                intel_sound mbp3
                nvidia_graphics
                # same as above but nvidia_bl does not work on MacBookPro5
                nvidia_backlight mbp_nvidia_bl
        ;;

#
# still incomplete - help appreciated
#
#       iMac4,1|iMac4,2|iMac5,1|iMac6,1|iMac7,1|iMac8,1)
#               apple_smc
#               intel_sound imac24
#       ;;

        *)
                echo "# Unsupported model. No more options available."
        ;;
esac

# ***** end of source *****

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mailing list: https://launchpad.net/~mactel-support
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~mactel-support
More help   : https://help.launchpad.net/ListHelp

Reply via email to