From b5c71b3933216f5ec17404e92a0cce91251ba6ad Mon Sep 17 00:00:00 2001 From: Peng Li Date: Fri, 22 Jun 2018 16:45:38 +0800 Subject: [PATCH] Add script to add new user debug for remote debugging --- add-user.sh | 17 +++++++++++++++++ mqtt-client.py | 2 +- suanzi-support | 3 +-- suanzi-support.service | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100755 add-user.sh diff --git a/add-user.sh b/add-user.sh new file mode 100755 index 0000000..f140ec5 --- /dev/null +++ b/add-user.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Add a new user named debug, with password hard2guess for remote debug +# the suanzi-support daemon will be running as this user +# run : sudo ./add-user.sh + +USER="debug" +PASS="hard2guess" + +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/mqtt-client.py b/mqtt-client.py index 59eff28..8a053d0 100644 --- a/mqtt-client.py +++ b/mqtt-client.py @@ -23,7 +23,7 @@ if __name__ == '__main__': if msg.topic == id + '-response': port = msg.payload print 'port is', str(port) - print 'run ssh user@autossh.suanzi.ai -p ' + str(port) + ' to connect to ' + id + ' device' + print 'run ssh debug@autossh.suanzi.ai -p ' + str(port) + ' to connect to ' + id + ' device' client = mqtt.Client() client.on_connect = on_connect diff --git a/suanzi-support b/suanzi-support index d016b06..678853d 100755 --- a/suanzi-support +++ b/suanzi-support @@ -7,7 +7,6 @@ from subprocess import call, Popen, PIPE, STDOUT import paho.mqtt.client as mqtt import shlex -import os import random from uuid import getnode as get_mac @@ -67,7 +66,7 @@ class MyClient(mqtt.Client): if __name__ == '__main__': mac = hex(get_mac()) - id = os.getenv('USER') + '-' + '{:0>12}'.format(mac[2:-1]) + id = '{:0>12}'.format(mac[2:-1]) print 'id is: ' , id client = MyClient(id) client.connect(MQTT_SERVER, MQTT_PORT, 60) diff --git a/suanzi-support.service b/suanzi-support.service index 87f0081..dbf7a11 100644 --- a/suanzi-support.service +++ b/suanzi-support.service @@ -3,7 +3,7 @@ Description= suanzi support daemon After=network-online.target [Service] -User=debian +User=debug Type=simple ExecStart=/usr/local/bin/suanzi-support ExecStop=/usr/bin/pkill -P $MAINPID -- 2.11.0