NEWS: release v0.5
[kinect-audio-setup.git] / kinect_patch_udev_rules
1 #!/bin/sh
2 #
3 # kinect_patch_udev_rules - Patch contrib/ udev rules file to load UACFirmware
4 #
5 # Copyright (C) 2016  Antonio Ospite <ao2@ao2.it>
6 #
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
12
13 set -e
14
15 [ $# -lt 3 ] && { echo "usage: $(basename "$0") <firmware path> <kinect_upload_fw path> <55-kinect_audio.rules path>" 1>&2; exit 1; }
16 FIRMWARE_PATH="$1"
17 LOADER_PATH="$2"
18 UDEV_RULES_PATH="$3"
19
20 [ "x$FIRMWARE_PATH" != "x" ] || { echo "Empty FIRMWARE_PATH" 1>&2; exit 1;}
21 [ "x$LOADER_PATH" != "x" ] || { echo "Empty LOADER_PATH" 1>&2; exit 1;}
22
23 # The udev rules file must exist the other files may not exist just yet: they
24 # may be under a prefixed path different from the final one, like in the case
25 # when this is called at package creation time.
26 [ -f "$UDEV_RULES_PATH" ] || { echo "Cannot find the udev rules file: $UDEV_RULES_PATH" 1>&2; exit 1; }
27
28 if grep -q "@LOADER_PATH@ @FIRMWARE_PATH@" "$UDEV_RULES_PATH";
29 then
30   sed -e "s|@LOADER_PATH@|${LOADER_PATH}|g" \
31       -e "s|@FIRMWARE_PATH@|${FIRMWARE_PATH}|g" \
32       -i "$UDEV_RULES_PATH"
33 else
34   echo "$UDEV_RULES_PATH does not contain the expected placeholders." 2>&1
35   exit 1
36 fi