Skip to content

Commit

Permalink
imp
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdaSeremet committed Jul 17, 2020
1 parent c01a83b commit a4b7aa3
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const systemFolder = path.join(__dirname, 'sys');
const systemLogsFile = path.join(__dirname, 'static/logs.txt');
const nodeName = execSync('uname -n').toString().replace('\n', '');

//const availablePins = ['11','12','68','15','16','17','55','54','56','65','64','69','74','73','71','57','76','72','77','78','79','80','75','70']; // For RockPiS
//const availablePins = ['1','2','3','4','5','6','7','8','9','10','12','13','14','15','16','17','18','19']; // For NanoPiNEO-LTS
const availablePins = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','30']; // For Orange Pi Zero
const availableTaskTypes = ['turnOn', 'turnOff', 'unlink', 'linkToInput', 'setMonostable', 'setBistable', 'removePin', 'renamePin', 'renameBoard'];

let ioData = {};
Expand Down Expand Up @@ -155,12 +152,19 @@ app.get('/index.htm', (req, res) => {
if(command >= 200) {
let pinNumber = command - 200;
if(pinNumber in ioData.controllable_pins) {
setMonostable(pinNumber, "5000", success => {
changeState(pinNumber, '1', success => {
if(success != true) {
res.write('An error occured');
res.end();
return;
}
setTimeout(() => {
changeState(pinNumber, '0', success => {
if(success != true) {
return;
}
});
}, 3000);
res.write('Success');
res.end();
});
Expand Down
98 changes: 98 additions & 0 deletions scripts/install_from_scratch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

trap ctrl_c INT
function ctrl_c() {
echo 'Program interrupted! Exiting...'
exit 1
}

echo 'Please specify the port number for SSH Tunneling: '
read tunnelPort
echo '----'

echo 'Updating package repos ==> '
sudo apt-get update
echo '----'

echo 'Installing Curl, AutoSSH and Git ==> '
sudo apt-get install curl git autossh -y
echo '----'

echo 'Going to home directory ==> '
cd ~
echo '----'

echo 'Installing NodeJS Version 10'
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
sudo chmod +x ./nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo rm nodesource_setup.sh
sudo apt-get install nodejs -y
echo '----'

echo 'Getting project files from Github'
cd ~
git clone https://github.com/ArdaSeremet/SBC-RealTimeIO.git
cd SBC-RealTimeIO
npm install
echo '----'

echo 'Setting MAC address for security file.'
macAddress=$(cat /sys/class/net/eth0/address)
macAddress=${macAddress: -5}
sudo touch security.txt
echo $macAddress >> security.txt
echo '----'

echo 'Setting systemd daemon for system bootup'
sudo rm /etc/systemd/system/gpioctrl.service
cat >> /etc/systemd/system/gpioctrl.service <<EOF
[Unit]
Description=Realtime GPIO Controller for OPiZero, NanoPiNEO-LTS and RockPiS
[Service]
User=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/SBC-RealTimeIO/
ExecStart=/root/SBC-RealTimeIO/app.js
[Install]
WantedBy=multi-user.target
EOF
echo '----'

echo 'Setting systemd daemon for SSH tunneling'
sudo rm /etc/systemd/system/tunnel-do.service
cat >> /etc/systemd/system/tunnel-do.service <<EOF
[Unit]
Description=AutoSSH tunnel service for reverse tunneling
After=network-online.target
[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -N -o UserKnownHostsFile=/dev/null -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=no -R $(echo "$tunnelPort"):localhost:80 [email protected] -p 22
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable gpioctrl
sudo systemctl enable tunnel-do
echo '----'

echo 'Generating a brand-new SSH key'
ssh-keygen -t rsa -b 4096 -C "[email protected]" -N "" -f /root/.ssh/id_rsa
echo '----'

echo 'Copying SSH key to remote machine'
ssh-copy-id [email protected]
echo '----'

echo 'Running the server and SSH Tunnel services'
sudo systemctl start gpioctrl
sudo systemctl start tunnel-do
echo '----'

echo 'Done installing the script! Have a nice day!'

0 comments on commit a4b7aa3

Please sign in to comment.