Linus Walleij | bce7cca | 2007-09-01 18:52:00 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2 | |
| 3 | INSTALL="@INSTALL@" |
| 4 | HOTPLUGPATH=/etc/hotplug |
| 5 | SCRIPTNAME=libmtp.sh |
| 6 | USERMAP=libmtp.usermap |
| 7 | UDEVPATH=/etc/udev/rules.d |
| 8 | UDEVRULES=libmtp.rules |
jefferai | e3f1bba | 2007-05-24 23:27:13 +0000 | [diff] [blame] | 9 | HALBASEPATH=/usr/share/hal/fdi/information |
| 10 | HALPATH=/usr/share/hal/fdi/information/20thirdparty |
| 11 | HALRULES=libmtp.fdi |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 12 | |
| 13 | # See if the parameter script ($2), device ($3) and productid ($4) |
| 14 | # are already defined in the usermap ($1) |
| 15 | function inmap { |
| 16 | while read LINE; do |
| 17 | if [ "x${LINE}" != "x" ]; then |
| 18 | firstword=`echo ${LINE} | awk '{ print $1 }'` |
| 19 | if [ ${firstword} != "#" ]; then |
| 20 | # This is a device line entry |
| 21 | script=${firstword} |
| 22 | manid=`echo ${LINE} | awk '{ print $3 }'` |
| 23 | productid=`echo ${LINE} | awk '{ print $4 }'` |
| 24 | # Skip blank products... |
| 25 | if [ "x${script}" = "x$2" ]; then |
| 26 | if [ "x${manid}" = "x$3" ]; then |
| 27 | if [ "x${productid}" = "x$4" ]; then |
| 28 | echo "yes" |
| 29 | return 0 |
| 30 | fi |
| 31 | fi |
| 32 | fi |
| 33 | fi |
| 34 | fi |
| 35 | done < $1 |
| 36 | echo "no" |
| 37 | return 0 |
| 38 | } |
| 39 | |
| 40 | # Scan the usermap $2 for all devices in $1 to see if they are already |
| 41 | # there, else patch the usermap. |
| 42 | function patchusermap { |
| 43 | # Nullify comment |
| 44 | comment="" |
| 45 | while read LINE; do |
| 46 | if [ "x$LINE" != "x" ]; then |
| 47 | firstword=`echo ${LINE} | awk '{ print $1 }'` |
| 48 | if [ ${firstword} = "#" ]; then |
| 49 | # This is a comment line, save it. |
| 50 | comment=${LINE} |
| 51 | else |
| 52 | # This is a device line entry |
| 53 | script=${firstword} |
| 54 | manid=`echo ${LINE} | awk '{ print $3 }'` |
| 55 | productid=`echo ${LINE} | awk '{ print $4 }'` |
| 56 | # Skip blank products... |
| 57 | if [ "x${manid}" != "x" ]; then |
| 58 | # See if this product is already in the usermap |
| 59 | echo "Checking for product ${productid} in $2..." |
| 60 | if [ `inmap $2 ${script} ${manid} ${productid}` = "no" ]; then |
| 61 | echo "Not present, adding to hotplug map." |
| 62 | echo ${comment} >> $2 |
| 63 | echo ${LINE} >> $2 |
| 64 | comment="" |
| 65 | else |
| 66 | echo "Already installed." |
| 67 | fi |
| 68 | fi |
| 69 | fi |
| 70 | fi |
| 71 | done < $1 |
| 72 | } |
| 73 | |
| 74 | # Check for udev first |
| 75 | if test -d ${UDEVPATH} ; then |
| 76 | echo "You seem to have udev on your system. Installing udev rules..." |
| 77 | ${INSTALL} ${UDEVRULES} ${UDEVPATH} |
| 78 | echo "You may need additional setup to get correct permissions on your device." |
| 79 | echo "See the INSTALL file for information." |
jefferai | e3f1bba | 2007-05-24 23:27:13 +0000 | [diff] [blame] | 80 | echo "Do you also want to install HAL support or the old hotplug support (y/n)?" |
| 81 | read IN |
| 82 | if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then |
| 83 | echo "Continuing..." |
| 84 | else |
| 85 | exit 0 |
| 86 | fi |
| 87 | fi |
| 88 | |
| 89 | # Check for HAL next |
| 90 | if test -d ${HALBASEPATH} ; then |
| 91 | echo "You seem to have HAL on your system. Installing HAL rules..." |
| 92 | mkdir -p ${HALPATH} |
| 93 | ${INSTALL} ${HALRULES} ${HALPATH} |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 94 | echo "Do you also want to install the old hotplug support (y/n)?" |
| 95 | read IN |
| 96 | if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then |
| 97 | echo "Continuing..." |
| 98 | else |
| 99 | exit 0 |
| 100 | fi |
| 101 | fi |
| 102 | |
| 103 | |
| 104 | # Check prerequisites |
| 105 | COMMAND=`which grep 2> /dev/null` |
| 106 | if [ "x${COMMAND}" = "x" ]; |
| 107 | then |
| 108 | echo "Missing grep program. Fatal error." |
| 109 | exit 1 |
| 110 | fi |
| 111 | COMMAND=`which awk 2> /dev/null` |
| 112 | if [ "x${COMMAND}" = "x" ]; |
| 113 | then |
| 114 | echo "Missing awk program. Fatal error." |
| 115 | exit 1 |
| 116 | fi |
| 117 | |
| 118 | # This script locates the hotplug distribution on a certain host |
| 119 | # and sets up userland hotplugging scripts according to rules. |
| 120 | # The in-parameters are the hotplug directory and the name of a |
| 121 | # file of hotplug device entries and a script to be executed for |
| 122 | # these deviced. |
| 123 | |
| 124 | if test -d ${HOTPLUGPATH} |
| 125 | then |
| 126 | echo "Hotplug in ${HOTPLUGPATH}" |
| 127 | else |
| 128 | echo "Hotplug missing on this system. Cannot install." |
| 129 | exit 1 |
| 130 | fi |
| 131 | |
| 132 | if test -d ${HOTPLUGPATH}/usb |
| 133 | then |
| 134 | echo "Has usb subdirectory." |
| 135 | else |
| 136 | mkdir ${HOTPLUGPATH}/usb |
| 137 | fi |
| 138 | |
| 139 | echo "Installing script." |
| 140 | ${INSTALL} nomadjukebox ${HOTPLUGPATH}/usb |
| 141 | echo "Installing usermap." |
| 142 | ${INSTALL} -m 644 ${USERMAP} ${HOTPLUGPATH}/usb |
| 143 | # If we find a usb.usermap file, and we see that this distribution |
| 144 | # of hotplug does not support private usermaps, then we need to |
| 145 | # patch the usb.usermap file. |
| 146 | # |
| 147 | # Create a merged file, diff the files to each other, and if there |
| 148 | # were mismatches, then patch the installed file. |
| 149 | echo "Checking hotplugging CVS version..." |
| 150 | echo "/etc/hotplug/usb/*.usermap support was added in august 2002" |
| 151 | EDITMAP="yes" |
| 152 | CVSTAG=`grep '\$Id:' /etc/hotplug/usb.agent` |
| 153 | if [ "x${CVSTAG}" != "x" ]; then |
| 154 | DATE=`echo ${CVSTAG} | awk '{ print $5 }'` |
| 155 | echo "Hotplug version seems to be from ${DATE}" |
| 156 | YEAR=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $1; }'` |
| 157 | MONTH=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $2; }'` |
| 158 | DAY=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $3; }'` |
| 159 | if [ "${YEAR}" -gt "2002" ]; then |
| 160 | EDITMAP="no" |
| 161 | else |
| 162 | if [ "${YEAR}" -eq "2002" ]; then |
| 163 | if [ "${MONTH}" -ge "08" ]; then |
| 164 | EDITMAP="no" |
| 165 | fi |
| 166 | fi |
| 167 | fi |
| 168 | fi |
| 169 | if [ "x${EDITMAP}" == "xyes" ]; then |
| 170 | echo "We need to edit the ${HOTPLUGPATH}/usb.usermap if it exists..." |
| 171 | if test -f ${HOTPLUGPATH}/usb.usermap |
| 172 | then |
| 173 | echo "We have a usb.usermap..." |
| 174 | patchusermap ${USERMAP} /etc/hotplug/usb.usermap |
| 175 | fi |
| 176 | fi |
| 177 | |
| 178 | echo "Hotplugging successfully installed." |
| 179 | |
| 180 | exit 0 |
| 181 | |