-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup-system.sh
175 lines (148 loc) · 5.59 KB
/
setup-system.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
# 2020/02/13 version modified by JLC for Raspbian buster & RPi4
#
# use $(hrpi-version) to do conditional process for rpi-3, rpi-4 and buster
# install_custom_raspiconfig() only for RPi3
username=$1
password=$2
creature=$3
git_branch=${4:-"master"}
install_custom_raspiconfig()
{
echo -e "\e[33m install_custom_raspiconfig \e[0m"
wget https://raw.githubusercontent.com/poppy-project/raspi-config/master/raspi-config
chmod +x raspi-config
sudo chown root:root raspi-config
sudo mv raspi-config /usr/bin/
}
setup_user()
{
username=$1
password=$2
echo -e "\e[33m Create a user \e[4m$username\e[0m"
pass=$(perl -e 'print crypt($ARGV[0], "password")' "$password")
sudo useradd -m -p "$pass" -s /bin/bash "$username"
# copy groups from pi user
user_groups=$(id -Gn pi)
user_groups=${user_groups// /,}
sudo usermod -a -G "$user_groups" "$username"
echo "$username ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/011_poppy-nopasswd
}
system_setup()
{
# Change password for pi user
echo -e "\e[33m Change password for pi user \e[0m"
sudo usermod -p "$(mkpasswd --method=sha-512 raspoppy)" pi
#enable ssh
echo -e "\e[33m Enable ssh communication \e[0m"
sudo systemctl enable ssh
# Add more langs (GB, US, FR)
sudo sed -i 's/^#\s*\(en_GB.UTF-8 UTF-8\)/\1/g' /etc/locale.gen
sudo sed -i 's/^#\s*\(en_US.UTF-8 UTF-8\)/\1/g' /etc/locale.gen
sudo sed -i 's/^#\s*\(fr_FR.UTF-8 UTF-8\)/\1/g' /etc/locale.gen
sudo locale-gen
echo -e "\e[33m Start X11 at boot \e[0m"
echo "start_x=1" | sudo tee --append /boot/config.txt
echo -e "\e[33m Enable camera \e[0m"
echo "bcm2835-v4l2" | sudo tee /etc/modules-load.d/bcm2835-v4l2.conf
if [ "$creature" = "poppy-ergo-jr" ]; then
echo -e "\e[33m Setup serial communication \e[0m"
sudo raspi-config --disable-serial-log
sudo tee --append /boot/config.txt > /dev/null <<EOF
init_uart_clock=16000000
dtoverlay=pi3-miniuart-bt
EOF
fi
}
install_additional_packages()
{
echo -e "\e[33m upgrade_system \e[0m"
sudo apt-get update -q && sudo apt upgrade -q -y && sudo apt autoremove -q -y
# added python3-venev & libatalas-base-dev for RaspBian buster:
# removed samba* & dhcpcd, added libhdf5-dev libhdf5-serial-dev libjasper-dev for opencv
echo -e "\e[33m install_additional_packages \e[0m"
sudo apt-get install -q -y \
build-essential unzip whois \
network-manager git avahi-autoipd avahi-utils \
libxslt-dev python3-venv libatlas-base-dev \
libhdf5-dev libhdf5-serial-dev libjasper-dev libqtgui4 libqt4-test
# board version utility
# hrpi-version compatible with rpi-3 & rpi-4 is replaced by the new version included in the depository
echo -e "\e[33m board_version_utility \e[0m"
wget https://raw.githubusercontent.com/poppy-project/raspoppy/${git_branch}/hrpi-version.sh -O hrpi-version.sh
sudo cp hrpi-version.sh /usr/bin/hrpi-version
sudo chmod +x /usr/bin/hrpi-version
}
setup_network_tools()
{
echo -e "\e[33m setup_network_tools \e[0m"
# avahi services
sudo tee /etc/avahi/services/ssh.service <<EOF
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">SSH on %h</name>
<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>
<service>
<type>_sftp-ssh._tcp</type>
<port>22</port>
</service>
</service-group>
EOF
sudo tee /etc/avahi/services/poppy.service <<EOF
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">poppy on %h</name>
<service>
<type>_poppy-robot._tcp</type>
<port>9</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
</service>
</service-group>
EOF
}
setup_desktop()
{
username=$1
git_branch=$2
echo -e "\e[33m setup_desktop \e[0m"
# Disable some verbose logs at boot
sudo tee --append /boot/config.txt >/dev/null <<< "disable_splash=1"
sudo sed -i 's/console=tty1/console=tty3 logo.nologo vt.global_cursor_default=0/g' /boot/cmdline.txt
# Put some Poppy images
wget https://raw.githubusercontent.com/poppy-project/raspoppy/$git_branch/splash.png -O "/tmp/splash.png"
wget https://raw.githubusercontent.com/poppy-project/raspoppy/$git_branch/wallpaper.jpg -O "/tmp/wallpaper.jpg"
wget https://raw.githubusercontent.com/poppy-project/raspoppy/$git_branch/icon.png -O "/tmp/icon.png"
sudo mv /tmp/splash.png /usr/share/plymouth/themes/pix/splash.png
sudo mv /tmp/wallpaper.jpg /usr/share/rpd-wallpaper/temple.jpg
sudo mv /tmp/icon.png /usr/share/icons/poppy.png
# Desktop autologin with username
sudo sed -i "s/autologin-user=pi/autologin-user=$username/g" /etc/lightdm/lightdm.conf
sudo sed -i "s/autologin pi/autologin $username/g" /etc/systemd/system/[email protected]/autologin.conf
echo 'alias ll="ls -l"' >> ~/.bash_aliases
# # Setup a Poppy Manager desktop entry
# sudo -u "$username" mkdir -p "/home/$username/.local/share/applications/"
# sudo -u "$username" tee "/home/$username/.local/share/applications/poppy.desktop" > /dev/null <<EOF
#[Desktop Entry]
#Encoding=UTF-8
#Name=Poppy Manager
#Icon=/usr/share/icons/poppy.png
#Type=Application
#Categories=Office;
#Exec=xdg-open http://poppy.local/
#EOF
}
# install_additional_packages is run first to make hrpi-version available:
install_additional_packages
install_custom_raspiconfig
setup_user "$username" "$password"
setup_desktop "$username" "$git_branch"
system_setup
setup_network_tools