-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·115 lines (99 loc) · 3.7 KB
/
install
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
#!/bin/bash
set -e
# Adapted from raspi-config source
# 1: variable name
# 2: new variable value
# 3: config file to update
set_config_var() {
tmp="/tmp/set_config_var$3.bak"
tmpdir=$(dirname "${tmp}")
mkdir -p $tmpdir
sudo lua - "$1" "$2" "$3" <<EOF > "$tmp"
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
sudo mv "$tmp" "$3"
}
# There must be a password supplied to the script as an environment variable.
if [ -z "$LOGBOX_PASSWORD" ]
then
echo "Password must be set to install"
exit 1
fi
# Set hostname to default, indicating setup is required.
default_hostname="LogBox-new"
echo "$default_hostname" | sudo tee /etc/hostname
# If there's a bigger SD card, use it all.
sudo raspi-config --expand-rootfs
# Disable terminal over serial, allowing programmable serial connection.
serial_device="serial0"
sudo systemctl stop serial-getty@$serial_device.service
sudo systemctl disable serial-getty@$serial_device.service
set_config_var enable_uart 1 /boot/config.txt
sudo sed -i /boot/cmdline.txt -e "s/console=ttyAMA0,[0-9]\+ //"
sudo sed -i /boot/cmdline.txt -e "s/console=serial0,[0-9]\+ //"
# Install necessary software.
sudo apt update
sudo apt upgrade -y
sudo apt install -y bc avrdude arduino-core arduino-mk gdb-avr git python-dev python-rpi.gpio minicom unzip fail2ban nginx php7.0-cli php7.0-fpm php7.0-curl php7.0-json php7.0-xml
sudo git clone https://github.com/neu-rah/PCINT.git /usr/share/arduino/libraries/pcint
# Configure users.
logbox_home=/home/logbox
sudo useradd --home-dir "$logbox_home" --create-home --groups adm,dialout,netdev,gpio,users,i2c,sudo logbox
echo "logbox:$LOGBOX_PASSWORD" | sudo chpasswd
echo "PermitRootLogin no" | sudo tee -a /etc/ssh/sshd_config
echo "AllowUsers logbox" | sudo tee -a /etc/ssh/sshd_config
echo "logbox ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/010_logbox-nopasswd
sudo chsh -s /bin/bash logbox
sudo passwd pi -d
# Download required scripts.
cd "$logbox_home"
sudo git clone https://github.com/BrightFlair/logbox-avr avr
sudo git clone https://github.com/BrightFlair/logbox-hat.git hat
sudo git clone https://github.com/BrightFlair/logbox-hat-update.git hat-update
sudo git clone https://github.com/BrightFlair/logbox-os.git os
sudo chown -R logbox:logbox "$logbox_home"
# Install OS scripts.
sudo cp "$logbox_home/os/nginx.d"/* /etc/nginx/conf.d
sudo crontab -u logbox "$logbox_home/os/cron.conf"
sudo rm /etc/nginx/sites-enabled/*
sudo rm -rf /var/www
sudo ln -s "$logbox_home/os/www" /var/www
sudo touch "$logbox_home/os/www/logbox/cfg.dat"
sudo chown logbox:logbox "$logbox_home/os/www/logbox/cfg.dat"
sudo chmod g+w,o+w "$logbox_home/os/www/logbox/cfg.dat"
# Link scripts in place for execution.
sudo ln -s "$logbox_home"/avr/autoreset /usr/bin/autoreset
sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
sudo ln -s "$logbox_home"/avr/avrdude-autoreset /usr/bin/avrdude
sudo ln -s "$logbox_home"/hat-update/logbox-hat-update /usr/bin/logbox-hat-update
sudo mkdir $logbox_home/serial
sudo chown -R logbox:logbox "$logbox_home/serial"
# Disable swap
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove
sudo mkdir -p "$logbox_home/.ssh"
sudo ssh-keygen -b 4096 -t rsa -f "$logbox_home/.ssh/id_logbox" -q -N ""
sudo chown -R logbox:logbox "$logbox_home/.ssh"
echo
sudo cat "$logbox_home/.ssh/id_logbox.pub"
echo
# All done!
echo "Complete."
echo "Power off the pi now if you wish to save the pre-configured image, otherwise..."
read -p "Press enter to reboot"
sudo reboot