forked from DanDude0/MilwaukeeMakerspacePiFobReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallOPi.sh
More file actions
executable file
·135 lines (114 loc) · 4.66 KB
/
installOPi.sh
File metadata and controls
executable file
·135 lines (114 loc) · 4.66 KB
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
#!/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
# Remove unneeded libraries
heading 'Removing Libraries'
apt-get -y purge anacron unattended-upgrades logrotate dphys-swapfile rsyslog apt-listchanges
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
# Setup Screen Hardware
heading 'Setting Up Screen Hardware'
if [ -f "/boot/armbianEnv.txt.bak" ]
then
cp -f /boot/armbianEnv.txt.bak /boot/armbianEnv.txt
fi
sed -i.bak 's/rootfstype=ext4/rootfstype=ext4\noverlays=spi-spidev spi-add-cs1 uart3\nparam_spidev_spi_bus=0\nparam_spidev_spi_cs=1\nextraargs=consoleblank=0 vt.global_cursor_default=0/g' /boot/armbianEnv.txt
echo -e 'fbtft\nfbtft_device' > /etc/modules-load.d/fbtft.conf
echo 'options fbtft_device rotate=270 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768' > /etc/modprobe.d/fbtft.conf
# 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 = 21;/d0Line = 199;/g' MmsPiW26Interface.cpp
sed -i 's/d1Line = 20;/d1Line = 198;/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
echo 'Install completed, rebooting to start reader';
reboot