-
Notifications
You must be signed in to change notification settings - Fork 253
/
hardware_setup.sh
executable file
·135 lines (113 loc) · 3.87 KB
/
hardware_setup.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
134
135
#!/bin/bash
set -e
##################################################################################################################################
# Настройка интерфейсов
##################################################################################################################################
# вот так все в принципе должно включиться
# /usr/bin/raspi-config nonint do_i2c 0
# /usr/bin/raspi-config nonint do_spi 0
# /usr/bin/raspi-config nonint do_camera 0
# /usr/bin/raspi-config nonint do_rgpio 0
# /usr/bin/raspi-config nonint do_ssh 0
# по идеи эти настройки должны проводиться до по другому как сделано в prepare_image.sh
set_config_var() {
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
if line:match("^#?%s*"..key.."=.*$") then
line=key.."="..value
made_change=true
end
print(line)
end
if not made_change then
print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
CONFIG=/boot/config.txt
# 2. Изменить необходимые настройки
# 2.1. Включить sshd
echo -e "\033[0;31m\033[1m$(date) | #1 Turn on sshd\033[0m\033[0m"
touch /boot/ssh
# 2.2. Включить GPIO
# Включено по умолчанию
# 2.3. Включить I2C
echo -e "\033[0;31m\033[1m$(date) | #2 Turn on I2C\033[0m\033[0m"
set_config_var dtparam=i2c_arm on $CONFIG &&
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/"
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/"
if ! grep -q "^i2c[-_]dev" /etc/modules; then
printf "i2c-dev\n" >> /etc/modules
fi
# 2.4. Включить SPI
echo -e "\033[0;31m\033[1m$(date) | #3 Turn on SPI\033[0m\033[0m"
set_config_var dtparam=spi on $CONFIG &&
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*spi[-_]bcm2708\)/#\1/"
# 2.5. Включить raspicam
echo -e "\033[0;31m\033[1m$(date) | #4 Turn on raspicam\033[0m\033[0m"
get_config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
local found=false
for line in file:lines() do
local val = line:match("^%s*"..key.."=(.*)$")
if (val ~= nil) then
print(val)
found=true
break
end
end
if not found then
print(0)
end
EOF
}
# тут уже немного иначе, но по сути одно и тоже
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config#L1136
# $1 is 0 to disable camera, 1 to enable it
set_camera() {
# Stop if /boot is not a mountpoint
#if ! mountpoint -q /boot; then
# return 1
#fi
[ -e $CONFIG ] || touch $CONFIG
if [ "$1" -eq 0 ]; then # disable camera
set_config_var start_x 0 $CONFIG
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^start_file/#start_file/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
else # enable camera
set_config_var start_x 1 $CONFIG
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
set_config_var gpu_mem 128 $CONFIG
fi
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
fi
}
if [ ! -e /boot/start_x.elf ];
then echo "Your firmware appears to be out of date (no start_x.elf). Please update"
else set_camera 1
fi
# Включение V4L драйвера http://robocraft.ru/blog/electronics/3158.html
#echo "bcm2835-v4l2" >> /etc/modules
if ! grep -q "^bcm2835-v4l2" /etc/modules; then
printf "bcm2835-v4l2\n" >> /etc/modules
fi
echo -e "\033[0;31m\033[1m$(date) | #5 End of configuring interfaces\033[0m\033[0m"