-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_pifacecad_lirc.sh
executable file
·133 lines (117 loc) · 3.82 KB
/
setup_pifacecad_lirc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#: Description: Configures Raspberry Pi for the IR Recevier on
#: PiFace Control and Display.
MODULES_FILE="/etc/modules"
HARDWARECONF_FILE="/etc/lirc/hardware.conf"
LIRCD_FILE="/etc/lirc/lircd.conf"
#=======================================================================
# NAME: issue_warning
# DESCRIPTION: Issues a warning about running this script.
#=======================================================================
issue_warning() {
echo "This script will overwrite the following files:"
echo $MODULES_FILE
echo $HARDWARECONF_FILE
echo "Do you wish to continue?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
}
#=======================================================================
# NAME: backup_file
# DESCRIPTION: Creates a backup of a file.
#=======================================================================
backup_file() {
echo "Backing up $1."
cp $1 $1.setup_pifacecad_lirc.backup
}
#=======================================================================
# NAME: install_lirc
# DESCRIPTION: Install LIRC.
#=======================================================================
install_lirc() {
echo "Installing LIRC."
apt-get install --assume-yes lirc || \
{ echo 'Installing LIRC failed.' ; exit 1; }
}
#=======================================================================
# NAME: setup_modules
# DESCRIPTION: Add appropriate kernel modules.
#=======================================================================
setup_modules() {
echo "Configuring modules."
backup_file $MODULES_FILE
# add "lirc_dev" and "lirc_rpi gpio_in_pin=23" to $MODULES_FILE
for line in "lirc_dev" "lirc_rpi gpio_in_pin=23"; do
if ! grep -q "$line" $MODULES_FILE; then
echo "$line" >> $MODULES_FILE
fi
done
}
#=======================================================================
# NAME: setup_hardwareconf
# DESCRIPTION: Copies hardware conf
#=======================================================================
setup_hardwareconf() {
echo "Configuring hardware."
backup_file $HARDWARECONF_FILE
# write to the hardware conf
cat << EOF > $HARDWARECONF_FILE
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"
#
#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false
#
#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false
#
#Try to load appropriate kernel modules
LOAD_MODULES=true
#
# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
#
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
EOF
}
#=======================================================================
# NAME: final_message
# DESCRIPTION: Install
#=======================================================================
final_message() {
printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Now you must create an $LIRCD_FILE for your remote control.
Either download one from here:
http://lirc.sourceforge.net/remotes/
Or generate one yourself with the following command:
sudo irrecord -f -d /dev/lirc0 /etc/lirc/lircd.conf
For more information go to:
http://piface.github.io/pifacecad/lirc.html#configuring-lirc
You will need to reboot.
"
}
#=======================================================================
# MAIN
#=======================================================================
# check if the script is being run as root
if [[ $EUID -ne 0 ]]
then
printf 'This script must be run as root.\nExiting..\n'
exit 1
fi
issue_warning
install_lirc
setup_modules
setup_hardwareconf
final_message