Skip to content

Commit

Permalink
Updated installation and USB Listener scripts to remove hard-coded pa…
Browse files Browse the repository at this point in the history
…ths. Added correct calls to /login and /logout in handleUserDeviceEvent.sh. Updated sample user token to correspond with our test preferences profile.
  • Loading branch information
colinbdclark authored and bsheytanov committed Apr 9, 2012
1 parent 59d322a commit 729ccc9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
29 changes: 28 additions & 1 deletion build.sh
Expand Up @@ -3,9 +3,12 @@
node_modules="../node_modules"
universal="../node_modules/universal"
repoURL="git://github.com/GPII/universal.git"
usbListenerDir="./usbDriveListener"
gpiiInstallDir="/usr/local/gpii"
gpiiStateDir="/var/lib/gpii"

# Clone the necessary GPII framework dependencies from Git.

# TODO: Deal with cut and pastage for directory creation logic.
if [ -d $node_modules ]; then
echo "$node_modules already exists"
else
Expand All @@ -24,3 +27,27 @@ fi
# Compile the GSettings C++ Bridge
cd node_modules/gsettingsBridge/nodegsettings
node-waf configure build


# Create standard directory structure for GPII.
# Note: everything below here must be run as root, since we're installing ourselves centrally.
if [ -d $gpiiInstallDir ]; then
echo "$gpiiInstallDir already exists"
else
echo "$gpiiInstallDir does not exist"
echo "creating $gpiiInstallDir"
mkdir -p "$gpiiInstallDir"
fi

if [ -d $gpiiStateDir ]; then
echo "$gpiiStateDir already exists"
else
echo "$gpiiStateDir does not exist"
echo "creating $gpiiStateDir"
mkdir -p "$gpiiStateDir"
fi

# Install the USB Drive User Listener
# TODO: We should install the entire GPII in /usr/local/gpii, not just the USB Listener
cp -r "$usbListenerDir/bin" "$gpiiInstallDir/bin"
cp "$usbListenerDir/80-local.rules" /etc/udev/rules.d/
4 changes: 2 additions & 2 deletions usbDriveListener/80-local.rules
@@ -1,2 +1,2 @@
KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/home/boyan/repos/gpiistack/usb_auth/trigger.sh 1 /dev/%k"
KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="/home/boyan/repos/gpiistack/usb_auth/trigger.sh 0 /dev/%k"
KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/usr/local/gpii/bin/trigger.sh 1 /dev/%k"
KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="/usr/local/gpii/bin/trigger.sh 0 /dev/%k"
13 changes: 8 additions & 5 deletions usbDriveListener/bin/handleUserDeviceEvent.sh
@@ -1,4 +1,6 @@
#!/bin/sh
usersFilePath="/var/lib/gpii/users.txt"

if [ $1 -eq 1 ]; then
# USB disk drive is added.
retries=0
Expand All @@ -9,13 +11,14 @@ if [ $1 -eq 1 ]; then
done

mountLocation=`mount | grep $2 |cut -d " " -f 3`
token=`cat $mountLocation/token.txt`
token=`cat $mountLocation/.gpii-user-token.txt`
echo "User logged in on device $2 with token ${token}." >> log.txt
echo $2:$token >> users.txt # Keep the location and token in a users file.
curl http://localhost:3000/user/$token
echo $2:$token >> "$usersFilePath" # Keep the location and token in a users file.
curl http://localhost:3000/user/$token/login
else
# USB disk drive is removed.
token=`grep $2 < users.txt | cut -d ":" -f 2`
sed -ie "\|^$2|d" users.txt # Remove entry from the users file
curl http://localhost:3000/user/$token/logout
token=`grep $2 < "$usersFilePath" | cut -d ":" -f 2`
sed -ie "\|^$2|d" "$usersFilePath" # Remove entry from the users file
echo "User logged out from device $2 with token ${token}." >> log.txt
fi
6 changes: 4 additions & 2 deletions usbDriveListener/bin/trigger.sh
@@ -1,5 +1,7 @@
#!/bin/sh
# This is a workaround for correct udev script execution.
# There should be a way to avoid using a intermediate file.
cd /home/boyan/repos/gpiistack/usb_auth
./usb_test.sh $1 $2 & exit

gpiiBinPath="/usr/local/gpii/bin"

"$gpiiBinPath/handleUserDeviceEvent.sh" $1 $2 & exit
2 changes: 1 addition & 1 deletion usbDriveListener/tests/.gpii-user-token.txt
@@ -1 +1 @@
intergalacticSheepherder
123

0 comments on commit 729ccc9

Please sign in to comment.