-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
204 lines (168 loc) · 6.06 KB
/
install.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
SERVER = 'https://mobileid.oc.edu'
# INSTALLER SCRIPT FOR MOBIL-ID Reader
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
clear
echo "This script installs software for the"
echo "MOBIL-ID Reader on the Raspberry Pi."
echo "This includes:"
echo "- Creating a new hostname & password"
echo "- Updating the package index files (apt-get update)"
echo "- Installing prerequisite software"
echo "- Installing MOBIL-ID software and examples"
echo "- Configuring boot options"
echo "Run time ~20 minutes. Reboot recommended after install."
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo
echo -n "CONTINUE? [Y/n] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
clear
# FEATURE PROMPTS ----------------------------------------------------------
echo "To setup a new MOBIL-ID Reader we will need to"
echo "first reset the default hostname and password."
echo
echo "We want to set the hostname to MOBIL-ID-Reader-XXX"
echo "where XXX is a unique identifier for the device."
echo
echo -n "Enter a unique identifier for this device: "
read ID
echo
echo "Hostname will be changed to MOBIL-ID-Reader-"$ID
echo
echo "Now lets change the default password (raspberry)."
sudo passwd pi
echo
echo "Done."
echo
read -n 1 -s -r -p "Press any key to continue."
clear
# START INSTALL ------------------------------------------------------------
echo "Starting installation..."
echo "Updating package index files..."
sudo apt-get update -y
echo "Downloading prerequisites..."
sudo apt install git-all -y
sudo apt-get install python3-pip -y
sudo apt-get install python3-venv -y
echo "Downloading MOBIL-ID Reader software..."
if [ ! -d "/home/pi/MOBIL-ID-Reader" ]
then
sudo rm -r /home/pi/MOBIL-ID-Reader
fi
cd /home/pi
git clone https://github.com/andrewsiemer/MOBIL-ID-Reader
echo "Setting up virtual environment..."
python3 -m venv /home/pi/MOBIL-ID-Reader
cd /home/pi/MOBIL-ID-Reader
source bin/activate
echo "Downloading dependencies..."
pip3 install -r requirements.txt
# CONFIG -------------------------------------------------------------------
echo "Configuring MOBIL-ID software..."
touch /home/pi/MOBIL-ID-Reader/config.py
sudo sed -i '/SERIAL_NUMBER/d' /home/pi/MOBIL-ID-Reader/config.py
echo "SERIAL_NUMBER = '"$ID"'" | sudo tee -a /home/pi/MOBIL-ID-Reader/config.py
echo "Configuring system..."
sudo sed -i 's+ init=/bin/systemd++' /boot/cmdline.txt
sudo sed -i 's+$+ init=/bin/systemd+' /boot/cmdline.txt
echo "Setting up USB Gadget..."
sudo sed -i '/dtoverlay=dwc2/d' /boot/config.txt
sudo sed -i '/dwc2/d' /etc/modules
sudo sed -i '/libcomposite/d' /etc/modules
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "dwc2" | sudo tee -a /etc/modules
sudo echo "libcomposite" | sudo tee -a /etc/modules
echo "Creating USB Keyboard Service..."
sudo touch /usr/bin/mobil_id_usb
sudo chmod +x /usr/bin/mobil_id_usb
sudo sed -i '/mobil_id_usb/d' /etc/rc.local
sudo sed -i '19 a /usr/bin/mobil_id_usb # libcomposite configuration' /etc/rc.local
sudo tee -a /usr/bin/mobil_id_usb > /dev/null << EOT
#!/bin/bash
cd /sys/kernel/config/usb_gadget/
mkdir -p mobil_id
cd mobil_id
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "$ID" > strings/0x409/serialnumber
echo "Oklahoma Christian University" > strings/0x409/manufacturer
echo "MOBIL-ID Reader" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
# Add functions here
mkdir -p functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
echo -ne \\\x05\\\x01\\\x09\\\x06\\\xa1\\\x01\\\x05\\\x07\\\x19\\\xe0\\\x29\\\xe7\\\x15\\\x00\\\x25\\\x01\\\x75\\\x01\\\x95\\\x08\\\x81\\\x02\\\x95\\\x01\\\x75\\\x08\\\x81\\\x03\\\x95\\\x05\\\x75\\\x01\\\x05\\\x08\\\x19\\\x01\\\x29\\\x05\\\x91\\\x02\\\x95\\\x01\\\x75\\\x03\\\x91\\\x03\\\x95\\\x06\\\x75\\\x08\\\x15\\\x00\\\x25\\\x65\\\x05\\\x07\\\x19\\\x00\\\x29\\\x65\\\x81\\\x00\\\xc0 > functions/hid.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1/
# End functions
ls /sys/class/udc > UDC
EOT
echo "Creating MOBIL-ID Reader Startup Service..."
if test -f "/lib/systemd/system/mobil-id.service"; then
sudo rm /lib/systemd/system/mobil-id.service
fi
sudo tee -a /lib/systemd/system/mobil-id.service > /dev/null << EOT
[Unit]
Description=MOBIL-ID Reader
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/sudo /home/pi/MOBIL-ID-Reader/bin/python3 /home/pi/MOBIL-ID-Reader/main.py > /home/pi/system.log 2>&1
[Install]
WantedBy=multi-user.target
EOT
touch /home/pi/system.log
sudo chmod +x /home/pi/system.log
sudo chmod 644 /lib/systemd/system/mobil-id.service
sudo systemctl daemon-reload
sudo systemctl enable mobil-id.service
echo "Starting MOBIL-ID Reader service..."
sudo systemctl start mobil-id.service
echo "Enabling UART..."
sudo sed -i '/enable_uart/d' /boot/config.txt
echo "enable_uart=1" | sudo tee -a /boot/config.txt
sudo sed -i 's+console=serial0,115200 ++' /boot/cmdline.txt
sudo sed -i 's+ console=tty1++' /boot/cmdline.txt
sudo sed -i '/raspberrypi/d' /etc/hostname
sudo sed -i '/MOBIL-ID-Reader-/d' /etc/hostname
sudo sed -i '/raspberrypi/d' /etc/hosts
sudo sed -i '/MOBIL-ID-Reader-/d' /etc/hosts
echo "MOBIL-ID-Reader-"$ID | sudo tee -a /etc/hostname
echo "127.0.1.1 MOBIL-ID-Reader-"$ID | sudo tee -a /etc/hosts
# PROMPT FOR REBOOT --------------------------------------------------------
echo
echo "Done."
echo
echo "Install will take effect on next boot."
echo
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo "Upon reboot, ssh into the Raspberry Pi using:"
echo
echo "ssh pi@MOBIL-ID-Reader-"$ID".local"
echo
echo "...and your new password."
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo
echo -n "REBOOT NOW? [Y/n] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Exiting without reboot."
exit 0
fi
echo "Reboot started..."
reboot
sleep infinity