Browse Source

增加一键安装脚本
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
271c39ddd0
6 changed files with 116 additions and 5 deletions
  1. 1 0
      .gitignore
  2. 2 4
      index.js
  3. 68 0
      install.sh
  4. BIN
      lib/node
  5. 44 0
      lib/npm
  6. 1 1
      package.json

+ 1 - 0
.gitignore

@@ -28,3 +28,4 @@ build/Release
 # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
 node_modules
 
+package-lock.json

+ 2 - 4
index.js

@@ -12,7 +12,7 @@ class ContrlServer {
   // socket 服务
   initSoketHttp() {
     const app = express();
-    app.use(express.static("./web"));
+    app.use(express.static("/root/control/web"));
     const httpServer = createServer(app);    
     const io = new Server(httpServer,{
       cors: {
@@ -59,13 +59,11 @@ class ContrlServer {
   }
   // 控制服务
   initContrl() {
-    this.Contrl = fork('./lib/contrl.js')
+    this.Contrl = fork('/root/control/lib/contrl.js')
     this.Contrl.on('message', (msg) => {
       if (this.socket && this.socket.connected) {
-        console.log('用户连接可发送', msg);
         this.socket.emit('msg',JSON.parse(msg))
       }
-      console.log('contrl message: ' , msg);
     })
   }
 }

+ 68 - 0
install.sh

@@ -0,0 +1,68 @@
+sudo rm -rf /root/control/
+sudo systemctl stop control.service
+sudo rm /lib/systemd/system/control.service
+sudo mkdir /root/control/
+echo "下载安装包..."
+if sudo wget -O /root/control/control.zip https://cloud.caner.top/api/v3/file/get/4668/control.zip?sign=YGgyQqNbmQgOYHVYAYPWkFgaGRftZOaWRmdN5P99lyE%3D%3A0; then
+    echo ''
+else
+    echo '下载失败,请重试!'
+    exit 1
+fi
+
+if unzip -o /root/control/control.zip -d /root/control/;then
+    rm /root/control/control.zip
+    sudo chmod 744 /root/control/index.js
+    sudo chmod 744 /root/control/lib/node
+    echo ''
+else
+    echo '解压失败,请重试'
+    exit
+fi
+
+
+if echo "@chromium-browser --start-fullscreen /root/control/web/index.html" >> /etc/xdg/lxsession/LXDE-pi/autostart;then
+    echo ''
+else
+    echo '全屏自动设置失败,请稍后手动设置!'
+fi
+
+if echo "[Unit]
+Description=control-server
+After=network.target
+
+[Service]
+Type=simple
+User=root
+ExecStart=/root/control/lib/node /root/control/index.js &
+Restart=always
+RestartSec=3s
+
+[Install]
+WantedBy=multi-user.target" >> /lib/systemd/system/control.service;then
+    echo ''
+else
+    echo '自动设置开机启动失败,请稍后手动添加!'
+fi
+
+sudo systemctl daemon-reload
+if sudo systemctl enable control.service;then
+    echo '开机启动设置成功'
+else
+    echo '开机添加失败,请重试!'
+    exit 
+fi
+
+if sudo systemctl start control.service;then
+    echo ''
+else
+    echo '车端服务启动失败,请重试!'
+    exit 
+fi   
+if ip=`ifconfig wlan0 | awk 'NR==2{print $2}'`;then
+    echo "当前服务地址:ws://${ip}:7896"
+else 
+    echo '请检查网卡是否是wlan0,请手动重启服务!'
+    exit
+fi
+exit

BIN
lib/node


+ 44 - 0
lib/npm

@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
+
+basedir=`dirname "$0"`
+
+case `uname` in
+  *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+esac
+
+NODE_EXE="$basedir/node.exe"
+if ! [ -x "$NODE_EXE" ]; then
+  NODE_EXE="$basedir/node"
+fi
+if ! [ -x "$NODE_EXE" ]; then
+  NODE_EXE=node
+fi
+
+# this path is passed to node.exe, so it needs to match whatever
+# kind of paths Node.js thinks it's using, typically win32 paths.
+CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
+NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
+
+NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
+if [ $? -ne 0 ]; then
+  # if this didn't work, then everything else below will fail
+  echo "Could not determine Node.js install directory" >&2
+  exit 1
+fi
+NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
+
+# a path that will fail -f test on any posix bash
+NPM_WSL_PATH="/.."
+
+# WSL can run Windows binaries, so we have to give it the win32 path
+# however, WSL bash tests against posix paths, so we need to construct that
+# to know if npm is installed globally.
+if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
+  NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
+fi
+if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
+  NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
+fi
+
+"$NODE_EXE" "$NPM_CLI_JS" "$@"

+ 1 - 1
package.json

@@ -9,7 +9,7 @@
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },
-  "author": "",
+  "author": "Caner",
   "license": "ISC",
   "dependencies": {
     "express": "^4.18.1",