From 32620d83f1a89865961e9c7fc46b2c4127c5bfae Mon Sep 17 00:00:00 2001 From: qiurui Date: Mon, 8 Apr 2024 19:41:36 +0800 Subject: [PATCH] add debian folder --- .../keyboard-hook/installed-by-dh_install | 3 + .../keyboard-hook/installed-by-dh_installdocs | 0 .../generated/keyboard-hook/postinst.service | 30 ++++ .../generated/keyboard-hook/prerm.service | 5 + debian/changelog | 5 + debian/control | 16 ++ debian/copyright | 39 ++++ debian/install | 2 + debian/keyboard-hook.service | 16 ++ debian/patches/add-server.py | 71 ++++++++ debian/patches/add-wifi-init | 169 ++++++++++++++++++ debian/patches/series | 2 + debian/rules | 24 +++ debian/source/format | 1 + 14 files changed, 383 insertions(+) create mode 100644 debian/.debhelper/generated/keyboard-hook/installed-by-dh_install create mode 100644 debian/.debhelper/generated/keyboard-hook/installed-by-dh_installdocs create mode 100644 debian/.debhelper/generated/keyboard-hook/postinst.service create mode 100644 debian/.debhelper/generated/keyboard-hook/prerm.service create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/install create mode 100644 debian/keyboard-hook.service create mode 100644 debian/patches/add-server.py create mode 100644 debian/patches/add-wifi-init create mode 100644 debian/patches/series create mode 100755 debian/rules create mode 100644 debian/source/format diff --git a/debian/.debhelper/generated/keyboard-hook/installed-by-dh_install b/debian/.debhelper/generated/keyboard-hook/installed-by-dh_install new file mode 100644 index 0000000..f2e5d16 --- /dev/null +++ b/debian/.debhelper/generated/keyboard-hook/installed-by-dh_install @@ -0,0 +1,3 @@ +./usr/bin/easywifi-root.py +./usr/bin/server.py +./etc/init.d diff --git a/debian/.debhelper/generated/keyboard-hook/installed-by-dh_installdocs b/debian/.debhelper/generated/keyboard-hook/installed-by-dh_installdocs new file mode 100644 index 0000000..e69de29 diff --git a/debian/.debhelper/generated/keyboard-hook/postinst.service b/debian/.debhelper/generated/keyboard-hook/postinst.service new file mode 100644 index 0000000..603f4d8 --- /dev/null +++ b/debian/.debhelper/generated/keyboard-hook/postinst.service @@ -0,0 +1,30 @@ +# Automatically added by dh_installsystemd/13.6ubuntu1 +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # This will only remove masks created by d-s-h on package removal. + deb-systemd-helper unmask 'keyboard-hook.service' >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled 'keyboard-hook.service'; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable 'keyboard-hook.service' >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state 'keyboard-hook.service' >/dev/null || true + fi +fi +# End automatically added section +# Automatically added by dh_installsystemd/13.6ubuntu1 +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + if [ -n "$2" ]; then + _dh_action=restart + else + _dh_action=start + fi + deb-systemd-invoke $_dh_action 'keyboard-hook.service' >/dev/null || true + fi +fi +# End automatically added section diff --git a/debian/.debhelper/generated/keyboard-hook/prerm.service b/debian/.debhelper/generated/keyboard-hook/prerm.service new file mode 100644 index 0000000..6f28fdc --- /dev/null +++ b/debian/.debhelper/generated/keyboard-hook/prerm.service @@ -0,0 +1,5 @@ +# Automatically added by dh_installsystemd/13.6ubuntu1 +if [ -z "${DPKG_ROOT:-}" ] && [ "$1" = remove ] && [ -d /run/systemd/system ] ; then + deb-systemd-invoke stop 'keyboard-hook.service' >/dev/null || true +fi +# End automatically added section diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..6d3a937 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +keyboard-hook (0.1.0-1) UNRELEASED; urgency=medium + + * Initial release (Closes: #nnnn) + + -- qiurui > Mon, 08 Apr 2024 15:35:08 +0800 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..42180c3 --- /dev/null +++ b/debian/control @@ -0,0 +1,16 @@ +Source: keyboard-hook +Section: unknown +Priority: optional +Maintainer: qiurui > +Build-Depends: debhelper-compat (= 13) +Standards-Version: 4.6.0 +Homepage: +#Vcs-Browser: https://salsa.debian.org/debian/keyboard-hook +#Vcs-Git: https://salsa.debian.org/debian/keyboard-hook.git +Rules-Requires-Root: no + +Package: keyboard-hook +Architecture: any +Depends: python3 +Description: + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..f95e108 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,39 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: keyboard-hook +Upstream-Contact: +Source: + +Files: * +Copyright: + +License: GPL-3.0+ + +Files: debian/* +Copyright: 2024 qiurui > +License: GPL-3.0+ + +License: GPL-3.0+ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see . + . + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid picking licenses with terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. +# +# If you need, there are some extra license texts available in two places: +# /usr/share/debhelper/dh_make/licenses/ +# /usr/share/common-licenses/ diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..8225ef8 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +usr/bin/* /usr/bin/ +etc/* /etc/ diff --git a/debian/keyboard-hook.service b/debian/keyboard-hook.service new file mode 100644 index 0000000..102b1fd --- /dev/null +++ b/debian/keyboard-hook.service @@ -0,0 +1,16 @@ +[Unit] +Description=keyboard-hook +After=network-online.target +Wants=network-online.target systemd-networkd-wait-online.service + +StartLimitIntervalSec=500 +StartLimitBurst=5 + +[Service] +Restart=on-failure +RestartSec=5s + +ExecStart=/usr/bin/python /usr/bin/server.py + +[Install] +WantedBy=multi-user.target diff --git a/debian/patches/add-server.py b/debian/patches/add-server.py new file mode 100644 index 0000000..04fbd30 --- /dev/null +++ b/debian/patches/add-server.py @@ -0,0 +1,71 @@ +Description: + TODO: Put a short summary on the line above and replace this paragraph + with a longer explanation of this change. Complete the meta-information + with other relevant fields (see below for details). To make it easier, the + information below has been extracted from the changelog. Adjust it or drop + it. + . + keyboard-hook (0.1.0-1) UNRELEASED; urgency=medium + . + * Initial release (Closes: #nnnn) +Author: qiurui > + +--- +The information above should follow the Patch Tagging Guidelines, please +checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here +are templates for supplementary fields that you might want to add: + +Origin: , +Bug: +Bug-Debian: https://bugs.debian.org/ +Bug-Ubuntu: https://launchpad.net/bugs/ +Forwarded: +Reviewed-By: +Last-Update: 2024-04-08 + +--- /dev/null ++++ keyboard-hook-0.1.0/usr/bin/server.py +@@ -0,0 +1,43 @@ ++#coding:utf-8 ++import os ++from socket import * ++ ++NULL_CHAR = chr(0) ++ ++def write_report(report): ++ with open('/dev/hidg0','rb+') as fd: ++ fd.write(report) ++ ++#''代表服务器为 localhost ++myHost = '' ++#在一个非保留端口号上进行监听 ++myPort = 50009 ++#设置一个TCP socket对象 ++sockobj = socket(AF_INET, SOCK_STREAM) ++#绑定端口号 ++sockobj.bind((myHost, myPort)) ++#监听,允许5个连结 ++sockobj.listen(5) ++#直到进程结束时才结束循环 ++while True: ++ #等待客户端连接 ++ connection, address = sockobj.accept( ) ++ #连接是一个新的socket ++ print ('Server connected by', address) ++ while True: ++ #读取客户端套接字的下一行 ++ data = connection.recv(1024) ++ #如果没有数量的话,那么跳出循环 ++ if not data: break ++ if data == "hid open": ++ os.popen('ls /sys/class/udc | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC') ++ print("hid open") ++ elif data == "hid close": ++ os.popen('echo > /sys/kernel/config/usb_gadget/g1/UDC') ++ print("hid close") ++ else: ++ write_report(data) ++ #发送一个回复至客户端 ++ connection.send('server => ' + data) ++ #当socket关闭时eof ++ connection.close( ) diff --git a/debian/patches/add-wifi-init b/debian/patches/add-wifi-init new file mode 100644 index 0000000..60b2eea --- /dev/null +++ b/debian/patches/add-wifi-init @@ -0,0 +1,169 @@ +Description: + TODO: Put a short summary on the line above and replace this paragraph + with a longer explanation of this change. Complete the meta-information + with other relevant fields (see below for details). To make it easier, the + information below has been extracted from the changelog. Adjust it or drop + it. + . + keyboard-hook (0.1.0-1) UNRELEASED; urgency=medium + . + * Initial release (Closes: #nnnn) +Author: qiurui > + +--- +The information above should follow the Patch Tagging Guidelines, please +checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here +are templates for supplementary fields that you might want to add: + +Origin: , +Bug: +Bug-Debian: https://bugs.debian.org/ +Bug-Ubuntu: https://launchpad.net/bugs/ +Forwarded: +Reviewed-By: +Last-Update: 2024-04-08 + +--- /dev/null ++++ keyboard-hook-0.1.0/etc/init.d/init.d/bootstrapping.sh +@@ -0,0 +1,35 @@ ++#!/bin/bash ++ ++sleep 5 ++if [[ ! -f "~/debugwifi.log" ]];then ++ touch ~/debugwifi.log ++fi ++ ++echo "connect start" > ~/debugwifi.log ++timedatectl >> ~/debugwifi.log ++ ++nmcli dev wifi list > /dev/null ++sleep 1 ++/usr/bin/python3 /usr/bin/easywifi-root.py & ++echo "connect success" ++ ++ ++#mount -t configfs none /sys/kernel/config/ ++modprobe usb_f_hid ++mkdir /sys/kernel/config/usb_gadget/g1 ++echo 0x0525 >/sys/kernel/config/usb_gadget/g1/idVendor ++echo 0xa4ac >/sys/kernel/config/usb_gadget/g1/idProduct ++mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 ++mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 ++echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/protocol ++echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/subclass ++echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length ++echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc ++mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 ++echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes ++echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower ++mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ++ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ ++ ++ ++/usr/bin/python /usr/bin/server.py > /dev/null & +--- /dev/null ++++ keyboard-hook-0.1.0/etc/init.d/rc3.d/S99bootstrapping +@@ -0,0 +1,35 @@ ++#!/bin/bash ++ ++sleep 5 ++if [[ ! -f "~/debugwifi.log" ]];then ++ touch ~/debugwifi.log ++fi ++ ++echo "connect start" > ~/debugwifi.log ++timedatectl >> ~/debugwifi.log ++ ++nmcli dev wifi list > /dev/null ++sleep 1 ++/usr/bin/python3 /usr/bin/easywifi-root.py & ++echo "connect success" ++ ++ ++#mount -t configfs none /sys/kernel/config/ ++modprobe usb_f_hid ++mkdir /sys/kernel/config/usb_gadget/g1 ++echo 0x0525 >/sys/kernel/config/usb_gadget/g1/idVendor ++echo 0xa4ac >/sys/kernel/config/usb_gadget/g1/idProduct ++mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 ++mkdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0 ++echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/protocol ++echo 1 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/subclass ++echo 512 >/sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_length ++echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc ++mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1 ++echo 0xc0 >/sys/kernel/config/usb_gadget/g1/configs/c.1/bmAttributes ++echo 500 >/sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower ++mkdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409 ++ln -s /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/ /sys/kernel/config/usb_gadget/g1/configs/c.1/ ++ ++ ++/usr/bin/python /usr/bin/server.py > /dev/null & +--- /dev/null ++++ keyboard-hook-0.1.0/usr/bin/easywifi-root.py +@@ -0,0 +1,64 @@ ++import subprocess ++import os ++ ++ ++def sub_command_run(cmd,grep): ++ result = subprocess.Popen(cmd, stdout=subprocess.PIPE) ++ if grep == 1: ++ value = subprocess.Popen(['grep','/dev/mmcblk0p1'], stdin=result.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ++ else: ++ value = result ++ out = value.communicate()[0].decode('utf-8') ++ return out ++ ++def is_mounted(part): ++ result = subprocess.run('mount',capture_output=True,text=True) ++ output = result.stdout ++ if part in output: ++ return True ++ else: ++ return False ++''' ++def get_activited_ssid(SSID): ++ cmd = "iwgetid -r" ++ cmd = cmd.split() ++ result = sub_command_run(cmd,0) ++ return result ++''' ++ ++if os.path.exists("/dev/mmcblk0p2") == False: ++ cmd="fdisk -l /dev/mmcblk0" ++ cmd=cmd.split() ++ password="orangepi" ++ result = sub_command_run(cmd,1) ++ sector_list = result.split() ++ sector_start = int(sector_list[2]) + 1 ++ format_cmd = "/bin/bash /usr/bin/format.sh " + str(sector_start) ++ format_cmd = format_cmd.split() ++ sub_command_run(format_cmd,0) ++ ++part = "/dev/mmcblk0p2" ++ ++if is_mounted(part) == False: ++ cmd = "mount " + part + " /mnt" ++ cmd = cmd.split() ++ sub_command_run(cmd,0) ++ ++if os.path.exists("/mnt/wifi.txt") == True: ++ f=open("/mnt/wifi.txt") ++ count=0 ++ Lines=f.readlines() ++ for line in Lines: ++ count +=1 ++ if count==1: ++ network=line.strip().split("=")[1] ++ elif count==2: ++ password=line.strip().split("=")[1] ++ else: ++ break ++else: ++ network="Q" ++ password="123123123" ++ ++result = subprocess.run(['nmcli', "d", "wifi", "connect", network, "password", str(password)], stdout=subprocess.PIPE) ++print(result.stdout.decode('utf-8')) +\ No newline at end of file diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..78eab50 --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,2 @@ +add-wifi-init +add-server.py diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..5d846df --- /dev/null +++ b/debian/rules @@ -0,0 +1,24 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- \ +# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt)