v4l2-settings-restore.sh: don't use "echo -n"
[v4l2-persistent-settings.git] / v4l2-settings-restore.sh
1 #!/bin/sh
2 #
3 # v4l2-settings-restore.sh - restore v4l2 device settings
4 #
5 # Copyright (C) 2018  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 # NOTE: this script is meant to be called by an udev rule.
14
15 [ "$DEBUG" = "true" ] && set -x
16 set -e
17
18 SETTINGS_DIR="/tmp"
19 [ -f /etc/default/v4l2-persistent-settings ] && . /etc/default/v4l2-persistent-settings
20
21 SETTINGS_FILE="${SETTINGS_DIR}/${ID_V4L_PRODUCT}.conf"
22
23 if [ "$ACTION" = "add" ] && [ -f "$SETTINGS_FILE" ];
24 then
25   while read -r setting;
26   do
27     CTRL=$(echo "$setting" | tr -d '\n' | cut -d ' ' -f 1)
28     VAL=$(echo "$setting" | tr -d '\n' | cut -d ' ' -f 2)
29     v4l2-ctl -d "$DEVNAME" --set-ctrl "${CTRL}=${VAL}"
30   done < "$SETTINGS_FILE"
31 fi