From a566c6c405483a79f9d2b84718b7d1c3737bb8d8 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Tue, 7 Nov 2017 22:20:50 +0800 Subject: [PATCH] openwrt: add a simple luci app for ttyd --- .gitignore | 3 +-- openwrt/README.md | 1 - openwrt/luci-app-terminal/Makefile | 17 ++++++++++++ .../luasrc/controller/terminal.lua | 9 +++++++ .../luasrc/view/terminal.htm | 9 +++++++ .../luci-app-terminal/po/zh-cn/terminal.po | 5 ++++ .../luci-app-terminal/root/etc/init.d/ttyd | 26 +++++++++++++++++++ openwrt/{ => ttyd}/Makefile | 0 8 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 openwrt/luci-app-terminal/Makefile create mode 100644 openwrt/luci-app-terminal/luasrc/controller/terminal.lua create mode 100644 openwrt/luci-app-terminal/luasrc/view/terminal.htm create mode 100644 openwrt/luci-app-terminal/po/zh-cn/terminal.po create mode 100755 openwrt/luci-app-terminal/root/etc/init.d/ttyd rename openwrt/{ => ttyd}/Makefile (100%) diff --git a/.gitignore b/.gitignore index dc14281..1ccef53 100644 --- a/.gitignore +++ b/.gitignore @@ -39,7 +39,6 @@ CMakeCache.txt CMakeFiles CMakeScripts -Makefile cmake_install.cmake install_manifest.txt CTestTestfile.cmake @@ -50,4 +49,4 @@ build # Project files html.h -!openwrt/Makefile \ No newline at end of file +!init.d diff --git a/openwrt/README.md b/openwrt/README.md index 7e1cf4a..2eac22b 100644 --- a/openwrt/README.md +++ b/openwrt/README.md @@ -8,7 +8,6 @@ curl -sLo- https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/l cd lede-sdk-ar71xx-generic_gcc-5.4.0_musl-1.1.15.Linux-x86_64 ./scripts/feeds update -a ./scripts/feeds install -a -sed -i 's/$(eval $(call BuildPackage,libwebsockets-cyassl))/#\0/' package/feeds/packages/libwebsockets/Makefile make defconfig make package/feeds/packages/ttyd/compile V=99 ``` diff --git a/openwrt/luci-app-terminal/Makefile b/openwrt/luci-app-terminal/Makefile new file mode 100644 index 0000000..301a3b8 --- /dev/null +++ b/openwrt/luci-app-terminal/Makefile @@ -0,0 +1,17 @@ +# Copyright (C) 2016 Openwrt.org +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for ttyd +LUCI_DEPENDS:=+ttyd +LUCI_PKGARCH:=all +PKG_VERSION:=1.0 +PKG_RELEASE:=1 + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/openwrt/luci-app-terminal/luasrc/controller/terminal.lua b/openwrt/luci-app-terminal/luasrc/controller/terminal.lua new file mode 100644 index 0000000..ab95f46 --- /dev/null +++ b/openwrt/luci-app-terminal/luasrc/controller/terminal.lua @@ -0,0 +1,9 @@ +module("luci.controller.terminal", package.seeall) + +function index() + if not (luci.sys.call("pidof ttyd > /dev/null") == 0) then + return + end + + entry({"admin", "system", "terminal"}, template("terminal"), _("Terminal"), 10).leaf = true +end \ No newline at end of file diff --git a/openwrt/luci-app-terminal/luasrc/view/terminal.htm b/openwrt/luci-app-terminal/luasrc/view/terminal.htm new file mode 100644 index 0000000..db9b46c --- /dev/null +++ b/openwrt/luci-app-terminal/luasrc/view/terminal.htm @@ -0,0 +1,9 @@ +<%+header%> +
+

<%=translate("Terminal")%>

+ +
+ +<%+footer%> \ No newline at end of file diff --git a/openwrt/luci-app-terminal/po/zh-cn/terminal.po b/openwrt/luci-app-terminal/po/zh-cn/terminal.po new file mode 100644 index 0000000..9fb0596 --- /dev/null +++ b/openwrt/luci-app-terminal/po/zh-cn/terminal.po @@ -0,0 +1,5 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "Terminal" +msgstr "终端" diff --git a/openwrt/luci-app-terminal/root/etc/init.d/ttyd b/openwrt/luci-app-terminal/root/etc/init.d/ttyd new file mode 100755 index 0000000..8721665 --- /dev/null +++ b/openwrt/luci-app-terminal/root/etc/init.d/ttyd @@ -0,0 +1,26 @@ +#!/bin/sh /etc/rc.common + +START=99 +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +start() { + logger -t TTYD 'Starting ttyd service' + service_start /usr/bin/ttyd -i br-lan /bin/login + return 0 +} + +stop() { + if [ -n "`pidof ttyd`" ]; then + logger -t TTYD 'Shutting down ttyd service' + service_stop /usr/bin/ttyd + fi + return 0 +} + +restart() { + logger -t TTYD 'Restarting ttyd service' + stop + sleep 2 + start +} diff --git a/openwrt/Makefile b/openwrt/ttyd/Makefile similarity index 100% rename from openwrt/Makefile rename to openwrt/ttyd/Makefile -- 2.43.4