1- #! /bin/bash -e
2-
3- SCRIPT_DIR=` pwd` /` dirname $0 `
4-
5- INSTALL_LIB=/usr/lib
6- INSTALL_BIN=/usr/bin
7- INSTALL_ETC=/usr/etc/primesense
8- INSTALL_RULES=/etc/udev/rules.d
9-
10- if [ " ` uname -s` " == " Darwin" ]; then
1+ #! /bin/sh -e
2+
3+ usage="
4+ Usage: $0 [OPTIONS]
5+ Installs PrimeSense Sensor Driver to current machine.
6+
7+ -i,--install
8+ Installs PrimeSense Sensor Driver (default mode)
9+ -u,--uninstall
10+ Uninstalls PrimeSense Sensor Driver.
11+ -c,--cross-compile-rootfs <path>
12+ Used for cross-compiling. Installs PrimeSense Sensor Driver to <path> instead of '/'.
13+ -h,--help
14+ Shows this help screen.
15+ "
16+
17+ OS_NAME=` uname -s`
18+
19+ case $OS_NAME in
20+ Darwin)
1121 MODULES=" libXnDeviceSensorV2.dylib libXnDeviceFile.dylib"
12- else
22+ ;;
23+ * )
1324 MODULES=" libXnDeviceSensorV2.so libXnDeviceFile.so"
14- fi
25+ ;;
26+ esac
1527
1628RULES_FILE=" 55-primesense-usb.rules"
1729
18- # read arguments
19- INSTALL= " 1 "
30+ # create file list
31+ SCRIPT_DIR= ` pwd ` / ` dirname $0 `
2032
21- while (( "$# " )) ; do
22- case " $1 " in
23- " -i" )
24- INSTALL=" 1"
33+ LIB_FILES=` ls $SCRIPT_DIR /Lib/* `
34+ BIN_FILES=` ls $SCRIPT_DIR /Bin/* `
35+
36+ rootfs=
37+
38+ # parse command line
39+ while [ " $1 " ]; do
40+ case $1 in
41+ -i|--install)
42+ install=yes
43+ ;;
44+ -u|--uninstall)
45+ uninstall=yes
46+ ;;
47+ -c|--cross-staging-dir)
48+ shift
49+ rootfs=$1
2550 ;;
26- " -u" )
27- INSTALL=" 0"
51+ -h|--help)
52+ echo " $usage "
53+ exit 0
2854 ;;
2955 * )
30- echo " Usage: $0 [options]"
31- echo " Available options:"
32- printf " \t-i\tInstall (default)\n"
33- printf " \t-u\tUninstall\n"
56+ echo " Unrecognized option $1 "
3457 exit 1
35- ;;
3658 esac
3759 shift
3860done
3961
40- # create file list
41- LIB_FILES=` ls $SCRIPT_DIR /Lib/* `
42- BIN_FILES=` ls $SCRIPT_DIR /Bin/* `
62+ # default mode is install
63+ if [ ! " $install " = yes ] && [ ! " $uninstall " = yes ]; then
64+ install=yes
65+ fi
66+
67+ # validity check
68+ if [ " $install " = yes ] && [ " $uninstall " = yes ]; then
69+ echo " -i and -u flags cannot be used together!"
70+ exit 1
71+ fi
4372
44- if [ " $INSTALL " == " 1" ]; then
73+ INSTALL_LIB=$rootfs /usr/lib
74+ INSTALL_BIN=$rootfs /usr/bin
75+ INSTALL_ETC=$rootfs /usr/etc/primesense
76+ INSTALL_RULES=$rootfs /etc/udev/rules.d
77+ SERVER_LOGS_DIR=$rootfs /var/log/primesense/XnSensorServer
4578
79+ # make all calls into OpenNI run in this filesystem
80+ export OPEN_NI_INSTALL_PATH=$rootfs
81+ # make sure the staging dir OpenNI is the one being run
82+ export LD_LIBRARY_PATH=$INSTALL_LIB
83+
84+ if [ " $install " = yes ]; then
85+ printf " Installing PrimeSense Sensor\n"
86+ printf " ****************************\n\n"
87+
4688 # create config dir
4789 printf " creating config dir $INSTALL_ETC ..."
4890 mkdir -p $INSTALL_ETC
@@ -61,7 +103,7 @@ if [ "$INSTALL" == "1" ]; then
61103 # register modules
62104 for module in $MODULES ; do
63105 printf " registering module '$module ' with OpenNI..."
64- niReg -r $INSTALL_LIB /$module $INSTALL_ETC
106+ $INSTALL_BIN / niReg -r $INSTALL_LIB /$module $INSTALL_ETC
65107 printf " OK\n"
66108 done
67109
@@ -78,9 +120,9 @@ if [ "$INSTALL" == "1" ]; then
78120
79121 # create server log dir
80122 printf " creating server logs dir..."
81- mkdir -p /var/log/primesense/XnSensorServer
123+ mkdir -p $SERVER_LOGS_DIR
82124 # make this dir readable and writable by all (we allow anyone to delete logs)
83- chmod a+w /var/log/primesense/XnSensorServer
125+ chmod a+w $SERVER_LOGS_DIR
84126 printf " OK\n"
85127
86128 if [ " ` uname -s` " != " Darwin" ]; then
@@ -90,12 +132,17 @@ if [ "$INSTALL" == "1" ]; then
90132 printf " OK\n"
91133 fi
92134
93- else # uninstall
135+ printf " \n*** DONE ***\n\n"
136+
137+ elif [ " $uninstall " = yes ]; then
138+
139+ printf " Uninstalling PrimeSense Sensor\n"
140+ printf " ******************************\n\n"
94141
95142 # unregister modules
96143 for module in $MODULES ; do
97144 printf " unregistering module '$module ' from OpenNI..."
98- if niReg -u $INSTALL_LIB /$module ; then
145+ if $INSTALL_BIN / niReg -u $INSTALL_LIB /$module ; then
99146 printf " OK\n"
100147 fi
101148 done
@@ -126,6 +173,6 @@ else #uninstall
126173 printf " OK\n"
127174 fi
128175
129- fi
176+ printf " \n*** DONE ***\n\n "
130177
131- printf " \n*** DONE ***\n\n "
178+ fi
0 commit comments