-
Notifications
You must be signed in to change notification settings - Fork 0
/
sebpi-setup.sh
130 lines (104 loc) · 4.38 KB
/
sebpi-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
#!/bin/bash
function confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure?} [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
return 0
;;
*)
return 1
;;
esac
}
function force_fix_dns() {
until ping -c1 www.google.com
do
sudo sh -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf' # temp fix if DNS fails because of previous commands
sleep 1
done
}
function install_log2ram() {
if [ -e "/usr/local/bin/uninstall-log2ram.sh" ]; then
chmod +x /usr/local/bin/uninstall-log2ram.sh && sudo /usr/local/bin/uninstall-log2ram.sh
fi
curl -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz
tar xf log2ram.tar.gz
cd log2ram-master
chmod +x install.sh && sudo ./install.sh
cd ..
rm -r log2ram-master
sudo rm log2ram.tar.gz
}
function install_speedtest() {
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest-cli
sudo mv -f speedtest-cli /usr/local/bin/
}
function install_pihole() {
sudo mkdir -p /etc/pihole
sudo rm -f /etc/pihole/setupVars.conf
sudo touch /etc/pihole/setupVars.conf
sudo sh -c 'echo "PIHOLE_INTERFACE=eth0" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "IPV4_ADDRESS=192.168.1.2/24" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "IPV6_ADDRESS=" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "PIHOLE_DNS_1=1.1.1.1" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "PIHOLE_DNS_2=1.0.0.1" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "QUERY_LOGGING=true" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "INSTALL_WEB_SERVER=true" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "INSTALL_WEB_INTERFACE=true" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "LIGHTTPD_ENABLED=true" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "BLOCKING_ENABLED=true" >> /etc/pihole/setupVars.conf'
sudo sh -c 'echo "WEBPASSWORD=" >> /etc/pihole/setupVars.conf'
cd /home/pi
curl -sSL https://install.pi-hole.net > install_pihole.sh
chmod +x install_pihole.sh
sudo sh -c './install_pihole.sh --unattended'
force_fix_dns
sudo sh -c './install_pihole.sh --unattended' # run script twice because it fails at every first install and succeeds at 2nd - don't know why yet
rm install_pihole.sh
echo | pihole -a -p
sudo sh -c 'echo "DBINTERVAL=60" >> /etc/pihole/pihole-FTL.conf'
sudo sh -c 'echo "MAXDBDAYS=7" >> /etc/pihole/pihole-FTL.conf'
}
PUSHBULLET_API_KEY="$1"
if [ -z "$PUSHBULLET_API_KEY" ]; then
confirm "No PushBullet API key was provided in parameter. Continue?" || exit 1
fi
SEBPI_UPDATE_SCRIPT=/boot/sebpi-update.sh
SEBPI_INSTALLED_FILE=/boot/sebpi.installed
SEBPI_LOCALE_GEN_FILE=/boot/sebpi.locale.gen
if [ ! -e "$SEBPI_LOCALE_GEN_FILE" ]; then
# Fix locale issues on Debian
sudo sed -i 's/^AcceptEnv.*/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config
local SEBPI_LOCALE="en_GB.UTF-8"
export LANGUAGE=$SEBPI_LOCALE
sudo locale-gen "$SEBPI_LOCALE"
sudo update-locale LC_ALL=$SEBPI_LOCALE LANG=$SEBPI_LOCALE
sudo touch "$SEBPI_LOCALE_GEN_FILE"
fi
force_fix_dns
if [ -n "$PUSHBULLET_API_KEY" ]; then
if ! grep -q "$PUSHBULLET_API_KEY" "/etc/rc.local"; then
# send a pushbullet notification on login
sudo sed -i '$i'"$(echo "curl -s -u $PUSHBULLET_API_KEY: https://api.pushbullet.com/v2/pushes -d type=note -d title=Raspberry\\\ Pi -d body=Raspberry\\\ Pi\\\ is\\\ up! > /dev/null")" /etc/rc.local
curl -s -u $PUSHBULLET_API_KEY: https://api.pushbullet.com/v2/pushes -d type=note -d title="Raspberry Pi" -d body="PushBullet enabled!" > /dev/null
# TODO - use PushBullet to send healthcheck warnings: low free space / high CPU / internet lost
fi
fi
if [ ! -e "$SEBPI_INSTALLED_FILE" ]; then
install_log2ram
# disable physical board LEDs on login
sudo sed -i '$i'"$(echo "sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'")" /etc/rc.local
sudo sed -i '$i'"$(echo "sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'")" /etc/rc.local
sudo sh -c "$SEBPI_UPDATE_SCRIPT"
install_speedtest
sudo touch "$SEBPI_INSTALLED_FILE"
fi
install_pihole
# disable physical board LEDs immediately
sudo sh -c 'echo 0 > /sys/class/leds/led0/brightness'
sudo sh -c 'echo 0 > /sys/class/leds/led1/brightness'
if [ -n "$PUSHBULLET_API_KEY" ]; then
curl -s -u $PUSHBULLET_API_KEY: https://api.pushbullet.com/v2/pushes -d type=note -d title="Raspberry Pi" -d body="sebpi setup finished!" > /dev/null
fi