-
Notifications
You must be signed in to change notification settings - Fork 0
/
Raspberry-Pi-after-installation-script
166 lines (135 loc) · 6.57 KB
/
Raspberry-Pi-after-installation-script
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
#!/bin/bash
# This script can be run by executing the following:
# curl -sL https://git.io/JfJBl | bash
# and should be run as root
### Test if dialog is installed
if ! [ -x "$(command -v dialog)" ]
then
printf "Installieren Sie dialog (pacman -S dialog)\n"
exit
fi
### Check if user is root, exit if not
if [[ $EUID -ne 0 ]]; then
printf "\n######################################\n## This skript must be run as root ##\n######################################\n"
exit 1
fi
### Ask Questions
modell=$(dialog --stdout --inputbox "Welches Raspberry Pi Modell (nur Nummer)?" 0 0) || exit 1
clear
: ${modell:?"You have to answer!"}
hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1
clear
: ${hostname:?"hostname cannot be empty."}
avahi=$(dialog --stdout --inputbox "Soll Avahi aktiviert und systemd-resolved deactiviert werden?" 0 0) || exit 1
clear
: ${avahi:?"You have to answer!"}
if [ $avahi == "yes" ] || [ $avahi == "ja" ];
then
nameserver=$(dialog --stdout --inputbox "Wie lautet die IP des DHCP (für /etc/resolv.conf)?" 0 0) || exit 1
clear
: ${nameserver:?"You have to answer!"}
fi
snapclient=$(dialog --stdout --inputbox "Compile Snapclient (answer 'yes' or 'no')?" 0 0) || exit 1
clear
: ${snapclient:?"You have to answer with yes or no."}
if [ $snapclient == "no" ]
then
snapclientinst=$(dialog --stdout --inputbox "Install Snapclient (answer 'yes' or 'no')?" 0 0) || exit 1
clear
: ${snapclient:?"You have to answer with yes or no."}
fi
roomass=$(dialog --stdout --inputbox "Soll Room-Assistant installiert werden?" 0 0) || exit 1
clear
: ${roomass:?"You have to answer!"}
pythongpio=$(dialog --stdout --inputbox "Soll das Python-Modul für GPIO installiert werden?" 0 0) || exit 1
clear
: ${pythongpio:?"You have to answer!"}
### Initialize pacman, update and install packages
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syu --noconfirm --needed base-devel htop unzip zip tar man dialog git neofetch wget linux-raspberrypi-headers bluez nss-mdns alsa-utils python python-pip pacman-contrib
### Allow group wheel for sudo
sed -i '/^#.*wheel ALL=(ALL) ALL/s/^# //' /etc/sudoers
gpasswd -a alarm wheel
printf "\nalarm ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
### Install AUR-helper yay
su - alarm -c 'git clone https://aur.archlinux.org/yay.git;cd /home/alarm/yay;makepkg -si --noconfirm --needed;cd'
rm -r /home/alarm/yay
### Install Python GPIO Modul
if [ $pythongpio == "yes" ]
then
CFLAGS="-fcommon" pip install rpi.gpio systemd
fi
### Install AUR packages
su - alarm -c 'yay -S --noconfirm pi-bluetooth python-devtools'
### Localisation
printf "${hostname}" > /etc/hostname
timedatectl set-timezone Europe/Berlin
localectl set-locale LANG=de_DE.UTF-8
## SSH configuration
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/g' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 22222/g' /etc/ssh/sshd_config
cat <<\EOF >> /etc/ssh/sshd_config
KexAlgorithms [email protected],diffie-hellman-group16-sha512,diffie-hellman-group14-sha256,diffie-hellman-group18-sha512
HostKeyAlgorithms ssh-rsa,rsa-sha2-256,rsa-sha2-512
EOF
### Aliase Festlegen
printf "\n\n###Alias\nalias nano='nano -l'\nalias ls='ls -Alh --group-directories-first --color=auto'\nalias ip='ip -c=auto'\nalias update='yay -Syu --noconfirm; echo; echo Cleaning Orphans; sudo pacman -Rns $(pacman -Qtdq) --noconfirm; echo; echo Pacman-Cache bereinigen; sudo paccache -rk 2; echo yay-Cache bereinigen; yay -Sc --noconfirm; echo; echo ----------------; echo Update Finished;'" >> /etc/bash.bashrc
### Neofetch configuration
mkdir -p /home/alarm/.config/neofetch
curl -sL https://git.io/JeV8r > /home/alarm/.config/neofetch/config
chown alarm:alarm -R /home/alarm/.config/
printf "\n\n### Neofetch Aufruf\nneofetch" >> /etc/bash.bashrc
### Systemd activieren
systemctl enable systemd-timesyncd.service
### Avahi
if [ $avahi == "yes" ] || [ $avahi == "ja" ];
then
sed -i 's/hosts: files mymachines myhostname resolve [!UNAVAIL=return] dns/hosts: files mymachines myhostname mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns/g' /etc/nsswitch.conf
systemctl enable avahi-daemon
systemctl disable systemd-resolved
rm /etc/resolv.conf
cat <<\EOF >> /etc/resolv.conf
search home
nameserver $nameserver
EOF
fi
### Snapclient
if [ $snapclient == "yes" ] || [ $snapclient == "ja" ];
then
su - alarm -c 'git clone https://github.com/badaix/snapcast.git && cd snapcast/externals && git submodule update --init --recursive && aurman -S boost avahi opus && cd && cd snapcast/client && make && sudo make install'
fi
if [ $snapclientinst == "yes" ] || [ $snapclientinst == "ja" ];
then
su - alarm -c 'yay -S --noconfirm snapcast'
fi
### Room-Assistant
if [ $roomass == "yes" ] || [ $roomass == "ja" ];
then
su - alarm -c 'yay -S --noconfirm bluez bluez-utils-compat nodejs-lts-fermium npm'
su - alarm -c 'sudo npm i --global --unsafe-perm room-assistant'
printf "[Unit]\nDescription=room-assistant service\n\n[Service]\nType=notify\nExecStart=/usr/bin/room-assistant\nWorkingDirectory=/home/alarm/room-assistant\nTimeoutStartSec=120\nTimeoutStopSec=30\nRestart=always\nRestartSec=10\nWatchdogSec=60\nUser=alarm\n\n[Install]\nWantedBy=multi-user.target" >> /etc/systemd/system/room-assistant.service
su - alarm -c 'mkdir -p room-assistant/config'
usermod -aG lp alarm
systemctl enable bluetooth.service
sed -i 's/#AutoEnable=true/AutoEnable=true/g' /etc/bluetooth/main.conf
fi
if [ $modell == "3" ] || [ $modell == "2" ] || [ $modell == "1" ] || [ $modell == "zero" ];
then
## For Audio
printf "\n### Audio\ndtparam=audio=on\n\n### Bluetooth\ndtparam=krnbt=on\nenable_uart=0" >> /boot/config.txt
### Wifi-Bluetooth-Coexistence
printf "\nbtc_mode=1\nbtc_params8=0x4e20\nbtc_params1=0x7530" >> /usr/lib/firmware/updates/brcm/brcmfmac43430-sdio.txt
printf "\nbtc_mode=1\nbtc_params8=0x4e20\nbtc_params1=0x7530" >> /usr/lib/firmware/updates/brcm/brcmfmac43455-sdio.txt
fi
if [ $modell == "4" ]
then
## For Audio from kodi
printf "\n\n### For Audio\ndtoverlay=rpivid-v4l2" >> /boot/config.txt
fi
### Cleanup
sed -n '$d' /etc/sudoers
printf "########################\n Fertig ########################"
printf "########################\nAll entrys with ttyAMA0 have to be removed in /boot/cmdline.txt!!!########################"
printf "########################\nAdd ipv6 adrress of nameserver in /etc/resolv.conf. ########################"