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