relocate the files
authorPeng Li <seudut@gmail.com>
Thu, 5 Jul 2018 02:11:07 +0000 (10:11 +0800)
committerPeng Li <seudut@gmail.com>
Thu, 5 Jul 2018 02:11:07 +0000 (10:11 +0800)
add-user.sh [deleted file]
board/add-user.sh [new file with mode: 0755]
board/install.sh [new file with mode: 0755]
board/suanzi-support [new file with mode: 0755]
board/suanzi-support.service [new file with mode: 0644]
install.sh [deleted file]
suanzi-support [deleted file]
suanzi-support.service [deleted file]

diff --git a/add-user.sh b/add-user.sh
deleted file mode 100755 (executable)
index aaff13f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-# Add a new user named debug, with password suanzikeji for remote debug
-# the suanzi-support daemon will be running as this user
-# run : sudo ./add-user.sh
-
-USER="debug"
-PASS="suanzikeji"
-
-echo "Create $USER user"
-useradd -m "${USER}" || exit 1
-
-echo "set the password of $USER"
-echo -e "${PASS}\n${PASS}" | passwd "$USER"  || exit 1
-
-echo "Done"
-
diff --git a/board/add-user.sh b/board/add-user.sh
new file mode 100755 (executable)
index 0000000..aaff13f
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Add a new user named debug, with password suanzikeji for remote debug
+# the suanzi-support daemon will be running as this user
+# run : sudo ./add-user.sh
+
+USER="debug"
+PASS="suanzikeji"
+
+echo "Create $USER user"
+useradd -m "${USER}" || exit 1
+
+echo "set the password of $USER"
+echo -e "${PASS}\n${PASS}" | passwd "$USER"  || exit 1
+
+echo "Done"
+
diff --git a/board/install.sh b/board/install.sh
new file mode 100755 (executable)
index 0000000..9c4f7ff
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+SERVICE='suanzi-support.service'
+
+echo 'Install dependencies'
+apt install sshpass || exit 1
+pip install paho-mqtt || exit 1
+
+echo 'Install suanzi-support'
+cp suanzi-support /usr/local/bin/ || exit 1
+
+echo "Install ${SERVICE}"
+
+cp ${SERVICE} /lib/systemd/system || exit 1
+systemctl enable ${SERVICE} || exit 1
+
+echo "Start ${SERVICE}"
+systemctl start ${SERVICE} || exit 1
+
+echo "Done"
+
+
+
diff --git a/board/suanzi-support b/board/suanzi-support
new file mode 100755 (executable)
index 0000000..eca6e9b
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python2
+
+from subprocess import call, Popen, PIPE, STDOUT
+import paho.mqtt.client as mqtt
+import shlex
+import random
+from uuid import getnode as get_mac
+import ast
+import sys
+
+MQTT_SERVER = 'mqtt.suanzi.ai'
+MQTT_PORT = 1883
+
+# The alive time new ssh session exist. It means if no client connect to this device through ssh tunnel in 5 minutes,
+# this new sessin will terminate.
+ALIVE_TIME = 60 * 5
+
+SSH_SERVER = 'autossh.suanzi.ai'
+PORT_RANGE = (20000, 40000)
+USER = 'autossh'
+PASSWORD = 'hard2guess'
+
+def getAvailablePort(host, ports):
+    while True:
+        port = random.randint(ports[0], ports[1])
+        command = 'nc -z -v -w3 ' + host + ' ' + str(port)
+        p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
+        pout = p.communicate()[0].strip()
+        if p.returncode == 0:
+            continue
+        if 'Connection refused' in pout:
+            return port
+        else:
+            print pout
+
+def get_mac_str():
+    mac = hex(get_mac())
+    return '{:0>12}'.format(mac[2:-1])
+
+def exec_ssh(port):
+    if port == None:
+        raise Exception('Port not avaliable')
+    command = 'sshpass -p' + PASSWORD + ' ssh -o "StrictHostKeyChecking=no"  -o "UserKnownHostsFile /dev/null" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fCR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER + ' sleep ' + str(ALIVE_TIME)
+    print command
+    return call(shlex.split(command), shell=False)
+
+
+def on_connect(client, userdata, flags, rc):
+    client.subscribe(userdata['id'])
+    client.subscribe('all')
+    print("Connected with result code "+str(rc))
+
+def on_message(client, userdata, msg):
+    print('Receive topic:' + msg.topic + ' payload: ' +str(msg.payload))
+    payload = ast.literal_eval(str(msg.payload))
+    from_id = payload['from']
+    if payload['type'] == 'request':
+        if payload['command'] == 'ssh':
+            port = getAvailablePort(SSH_SERVER, PORT_RANGE)
+            if exec_ssh(port) == 0:
+                response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data':port}
+                client.publish(payload['from'], str(response))
+            else:
+                raise Exception ('run ssh failed')
+        if payload['command'] == 'list':
+            response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data':'OK'}
+            client.publish(payload['from'], str(response))
+
+
+
+if __name__ == '__main__':
+    id = get_mac_str()
+    print 'Mac: ', id
+    client = mqtt.Client(userdata={'id':id})
+    client.on_connect = on_connect
+    client.on_message = on_message
+    client.connect(MQTT_SERVER, MQTT_PORT, 60)
+    client.loop_forever()
diff --git a/board/suanzi-support.service b/board/suanzi-support.service
new file mode 100644 (file)
index 0000000..dbf7a11
--- /dev/null
@@ -0,0 +1,16 @@
+[Unit]
+Description= suanzi support daemon
+After=network-online.target
+
+[Service]
+User=debug
+Type=simple
+ExecStart=/usr/local/bin/suanzi-support
+ExecStop=/usr/bin/pkill -P $MAINPID
+KillMode=process
+Restart=always
+RestartSec=60
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/install.sh b/install.sh
deleted file mode 100755 (executable)
index 9c4f7ff..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-SERVICE='suanzi-support.service'
-
-echo 'Install dependencies'
-apt install sshpass || exit 1
-pip install paho-mqtt || exit 1
-
-echo 'Install suanzi-support'
-cp suanzi-support /usr/local/bin/ || exit 1
-
-echo "Install ${SERVICE}"
-
-cp ${SERVICE} /lib/systemd/system || exit 1
-systemctl enable ${SERVICE} || exit 1
-
-echo "Start ${SERVICE}"
-systemctl start ${SERVICE} || exit 1
-
-echo "Done"
-
-
-
diff --git a/suanzi-support b/suanzi-support
deleted file mode 100755 (executable)
index eca6e9b..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env python2
-
-from subprocess import call, Popen, PIPE, STDOUT
-import paho.mqtt.client as mqtt
-import shlex
-import random
-from uuid import getnode as get_mac
-import ast
-import sys
-
-MQTT_SERVER = 'mqtt.suanzi.ai'
-MQTT_PORT = 1883
-
-# The alive time new ssh session exist. It means if no client connect to this device through ssh tunnel in 5 minutes,
-# this new sessin will terminate.
-ALIVE_TIME = 60 * 5
-
-SSH_SERVER = 'autossh.suanzi.ai'
-PORT_RANGE = (20000, 40000)
-USER = 'autossh'
-PASSWORD = 'hard2guess'
-
-def getAvailablePort(host, ports):
-    while True:
-        port = random.randint(ports[0], ports[1])
-        command = 'nc -z -v -w3 ' + host + ' ' + str(port)
-        p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
-        pout = p.communicate()[0].strip()
-        if p.returncode == 0:
-            continue
-        if 'Connection refused' in pout:
-            return port
-        else:
-            print pout
-
-def get_mac_str():
-    mac = hex(get_mac())
-    return '{:0>12}'.format(mac[2:-1])
-
-def exec_ssh(port):
-    if port == None:
-        raise Exception('Port not avaliable')
-    command = 'sshpass -p' + PASSWORD + ' ssh -o "StrictHostKeyChecking=no"  -o "UserKnownHostsFile /dev/null" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fCR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER + ' sleep ' + str(ALIVE_TIME)
-    print command
-    return call(shlex.split(command), shell=False)
-
-
-def on_connect(client, userdata, flags, rc):
-    client.subscribe(userdata['id'])
-    client.subscribe('all')
-    print("Connected with result code "+str(rc))
-
-def on_message(client, userdata, msg):
-    print('Receive topic:' + msg.topic + ' payload: ' +str(msg.payload))
-    payload = ast.literal_eval(str(msg.payload))
-    from_id = payload['from']
-    if payload['type'] == 'request':
-        if payload['command'] == 'ssh':
-            port = getAvailablePort(SSH_SERVER, PORT_RANGE)
-            if exec_ssh(port) == 0:
-                response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data':port}
-                client.publish(payload['from'], str(response))
-            else:
-                raise Exception ('run ssh failed')
-        if payload['command'] == 'list':
-            response = {'from': userdata['id'], 'type':'response', 'command':payload['command'], 'data':'OK'}
-            client.publish(payload['from'], str(response))
-
-
-
-if __name__ == '__main__':
-    id = get_mac_str()
-    print 'Mac: ', id
-    client = mqtt.Client(userdata={'id':id})
-    client.on_connect = on_connect
-    client.on_message = on_message
-    client.connect(MQTT_SERVER, MQTT_PORT, 60)
-    client.loop_forever()
diff --git a/suanzi-support.service b/suanzi-support.service
deleted file mode 100644 (file)
index dbf7a11..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-[Unit]
-Description= suanzi support daemon
-After=network-online.target
-
-[Service]
-User=debug
-Type=simple
-ExecStart=/usr/local/bin/suanzi-support
-ExecStop=/usr/bin/pkill -P $MAINPID
-KillMode=process
-Restart=always
-RestartSec=60
-
-[Install]
-WantedBy=multi-user.target
-