-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstallRPi.sh
executable file
·181 lines (149 loc) · 5.32 KB
/
installRPi.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
176
177
178
179
180
181
#!/bin/bash
[[ $EUID -ne 0 ]] && echo "This script must be run as root." && exit 1
heading ()
{
echo -e "\n\n+- $1\n"
}
echo -e '\n\n\n\n####################\n#'
echo -e '# This will install MilwaukeeMakerspacePiFobReader on this system'
echo -e '#\n####################\n'
mkdir -p /opt/MmsPiW26Interface
mkdir -p /opt/MmsPiFobReader
# Set Reader Id
if [ ! -f /opt/MmsPiFobReader/readerid.txt ]
then
while ! [[ $READERID =~ ^-?[0-9]+$ ]]
do
heading 'Type the Reader Id you wish to set and press [ENTER]:'
read READERID
done
echo $READERID > /opt/MmsPiFobReader/readerid.txt
fi
# Set Server
if [ ! -f /opt/MmsPiFobReader/server.txt ]
then
heading '[Optional] If you wish you can hardcode the address of your API Server by typing it and pressing [ENTER]:\n+- If you wish to use SSDP just press [ENTER] without typing anything:'
read SERVER
if [[ -n "${SERVER/[ ]*\n/}" ]]
then
echo $SERVER > /opt/MmsPiFobReader/server.txt
fi
fi
# Work out of root user home
cd /root
# Disable serial console, we need the interface for fob reader.
heading 'Disabling serial console'
systemctl stop serial-getty@ttyAMA0
systemctl disable serial-getty@ttyAMA0
# Remove unneeded libraries
heading 'Removing Libraries'
apt-get -y purge anacron unattended-upgrades logrotate dphys-swapfile rsyslog apt-listchanges wiringpi
apt-get -y autoremove
# Update the OS
heading 'Updating Operating System'
apt-get -y update
apt-get -y dist-upgrade
# Install needed libraries
heading 'Installing Libraries'
apt-get -y install git libunwind8 busybox-syslogd ntp libgpiod-dev gpiod
# Install SSH Key
heading 'Installing SSH Key'
mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAvaHWKFt0zD0HAiv/PrTT/Qx0g4RxRAnbCrxO2C9oqPifXtcuKTW0aWNp0NyQMEQz/KFLZtzyRJi3A7rjEOH/6qotuhV7T5KJT39OgCL4A4vK1e4R+h8ZmitgIPGR5HYzW8X+1ODhGhO04nLh7LELHdYxy9gZWaMFNC3F1hlkCJF3WepkMClFoqt4pv8UHA4yWjS8eaudvcdPnoSdO2bAAuoCao/tB78dJomkxV8laDENb5wgwqNv/1p3yxTK+y1srxRcJyr6dFS6us9puVEfbpWFuMrW9v/NxylcCa1TOp1F3iKCkg8WQQPNbTC7drIh9J8Ntma/1wFPsFHfQcQ0oqgz0QDK/z8F1w1PQmh+exlK5gk0769Zt4EaTUJ8xDFf++fBIFVgGE8FnLjHRmaNfGWe3Uw0Kd9pzbXfOmcqMxvKCapTKG0c/j7fOJUIXE4BIYFB00FezEQs4e5d+rZ5Pc6SW3ue/4fB3+JoI4Kh1C2lx7SreODhgkc+uLYK31W/Z/jtJ3CwYSLz2EIdwJXLGHyPavhTxLi6mhEUpFNI85NUIOBxc2Fhx34kDEbrGPL7tiLiJo4ZfIVEog8ghgcBnxVuDFlMi/poAU8cLO2USAx0XCkF2kkyeuiBHuze/qzjO0YEXxeEapgbJnDIO0kJHONiLmjAV0DysZ1sNV8EBhs= MmsPiFobReader' > ~/.ssh/authorized_keys
# Install MmsPiW26Interface
heading 'Installing MmsPiW26Interface'
cd /opt/MmsPiW26Interface
rm -rfv *
wget https://raw.githubusercontent.com/DanDude0/MilwaukeeMakerspacePiFobReader/master/MmsPiW26Interface/MmsPiW26Interface.cpp
wget https://raw.githubusercontent.com/DanDude0/MilwaukeeMakerspacePiFobReader/master/MmsPiW26Interface/build.sh
sed -i 's/d0Line = 199;/d0Line = 21;/g' MmsPiW26Interface.cpp
sed -i 's/d1Line = 198;/d1Line = 20;/g' MmsPiW26Interface.cpp
chmod +x build.sh
./build.sh
# Install MmsPiFobReader
heading 'Installer MmsPiFobReader'
cd /tmp
mv /opt/MmsPiFobReader/readerid.txt /tmp/
mv /opt/MmsPiFobReader/server.txt /tmp/
rm -rfv /opt/MmsPiFobReader/*
curl -s https://api.github.com/repos/DanDude0/MilwaukeeMakerspacePiFobReader/releases/latest | grep -P "(?<=browser_download_url\": \")https://.*zip" -o | wget -i -
unzip -o MmsPiFobReader.zip -d /opt/MmsPiFobReader
rm -f MmsPiFobReader.zip
chmod +x /opt/MmsPiFobReader/MmsPiFobReader
mv /tmp/readerid.txt /opt/MmsPiFobReader/
mv /tmp/server.txt /opt/MmsPiFobReader/
# Install Systemd Unit
heading 'Installing Systemd Units'
cat > /etc/systemd/system/MmsPiFobReader.service << 'END'
[Unit]
Description=Milwaukee Makerspace Pi Fob Reader Client
After=network.target
[Service]
WorkingDirectory=/opt/MmsPiFobReader
ExecStart=/opt/MmsPiFobReader/MmsPiFobReader
KillMode=process
Restart=always
User=root
CPUAffinity=0 1 2
[Install]
WantedBy=multi-user.target
END
cat > /etc/systemd/system/MmsPiW26Interface.service << 'END'
[Unit]
Description=Milwaukee Makerspace Pi W26 Interface
After=network.target
[Service]
WorkingDirectory=/opt/MmsPiW26Interface
ExecStart=/opt/MmsPiW26Interface/MmsPiW26Interface
KillMode=process
Restart=always
User=root
CPUAffinity=3
Nice=-1
[Install]
WantedBy=multi-user.target
END
systemctl enable MmsPiFobReader MmsPiW26Interface
# Improve readability of tiny console
heading 'Setting Console Font'
cat > /etc/default/console-setup << 'END'
# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="UTF-8"
CODESET="guess"
FONTFACE="Terminus"
FONTSIZE="6x12"
VIDEOMODE=
# The following is an example how to use a braille font
# FONT='lat9w-08.psf.gz brl-8x8.psf'
END
# Disable LEDs
heading 'Disabling LEDs'
cat > /etc/rc.local << 'END'
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
echo none >/sys/class/leds/led0/trigger
echo none >/sys/class/leds/led1/trigger
echo 0 >/sys/class/leds/led0/brightness
echo 0 >/sys/class/leds/led1/brightness
exit 0
END
echo 'Install completed, rebooting to start reader';
reboot