1 |
commit: f723db403f7a32a302b62686d549633999a2e9b2 |
2 |
Author: Marco Scardovi <marco <AT> scardovi <DOT> com> |
3 |
AuthorDate: Thu Jun 24 12:16:46 2021 +0000 |
4 |
Commit: Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 24 12:18:56 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=f723db40 |
7 |
|
8 |
app-mobilephone/usb-tethering: add new package |
9 |
|
10 |
this package enable the usb tethering for pinephone |
11 |
|
12 |
Package-Manager: Portage-3.0.20, Repoman-3.0.3 |
13 |
Signed-off-by: Marco Scardovi <marco <AT> scardovi.com> |
14 |
|
15 |
app-mobilephone/usb-tethering/files/dhcpd.conf | 5 ++ |
16 |
.../files/dhcpd4.service-customexec.conf | 9 +++ |
17 |
.../files/tmpfiles.d.danctnix-usb.conf | 2 + |
18 |
app-mobilephone/usb-tethering/files/usb-tethering | 77 ++++++++++++++++++++++ |
19 |
.../usb-tethering/files/usb-tethering.service | 12 ++++ |
20 |
app-mobilephone/usb-tethering/metadata.xml | 8 +++ |
21 |
.../usb-tethering/usb-tethering-0.1.ebuild | 33 ++++++++++ |
22 |
7 files changed, 146 insertions(+) |
23 |
|
24 |
diff --git a/app-mobilephone/usb-tethering/files/dhcpd.conf b/app-mobilephone/usb-tethering/files/dhcpd.conf |
25 |
new file mode 100644 |
26 |
index 000000000..d7600ea7e |
27 |
--- /dev/null |
28 |
+++ b/app-mobilephone/usb-tethering/files/dhcpd.conf |
29 |
@@ -0,0 +1,5 @@ |
30 |
+option domain-name-servers 8.8.8.8, 8.8.4.4; |
31 |
+option subnet-mask 255.255.255.0; |
32 |
+subnet 10.15.19.0 netmask 255.255.255.0 { |
33 |
+ range 10.15.19.100 10.15.19.254; |
34 |
+} |
35 |
|
36 |
diff --git a/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf b/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf |
37 |
new file mode 100644 |
38 |
index 000000000..82e4c9d20 |
39 |
--- /dev/null |
40 |
+++ b/app-mobilephone/usb-tethering/files/dhcpd4.service-customexec.conf |
41 |
@@ -0,0 +1,9 @@ |
42 |
+[Service] |
43 |
+PIDFile=/run/danctnix/dhcpd4.pid |
44 |
+ |
45 |
+# We need to fix this ASAP, dhcpd won't run with dhcp user, this needs |
46 |
+# to be investigated. |
47 |
+User=root |
48 |
+ |
49 |
+ExecStart= |
50 |
+ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/danctnix/dhcpd.conf -pf /run/danctnix/dhcpd4.pid -lf /run/danctnix/dhcpd4.lease |
51 |
|
52 |
diff --git a/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf b/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf |
53 |
new file mode 100644 |
54 |
index 000000000..960f43802 |
55 |
--- /dev/null |
56 |
+++ b/app-mobilephone/usb-tethering/files/tmpfiles.d.danctnix-usb.conf |
57 |
@@ -0,0 +1,2 @@ |
58 |
+d /run/danctnix 0755 root root |
59 |
+f /run/danctnix/dhcpd4.lease 0644 root root |
60 |
|
61 |
diff --git a/app-mobilephone/usb-tethering/files/usb-tethering b/app-mobilephone/usb-tethering/files/usb-tethering |
62 |
new file mode 100644 |
63 |
index 000000000..aaa63eb55 |
64 |
--- /dev/null |
65 |
+++ b/app-mobilephone/usb-tethering/files/usb-tethering |
66 |
@@ -0,0 +1,77 @@ |
67 |
+#!/bin/sh |
68 |
+ |
69 |
+# ConfigFS script is taken from postmarketOS |
70 |
+# https://postmarketos.org |
71 |
+ |
72 |
+# These are very important, it defines what is the device: |
73 |
+ |
74 |
+deviceinfo_usb_idVendor="0x1F3A" |
75 |
+deviceinfo_usb_idProduct="0xEFE8" |
76 |
+deviceinfo_manufacturer="DanctNIX" |
77 |
+deviceinfo_name="Arch Linux Mobile" |
78 |
+ |
79 |
+# We'll let them know that this device is Arch ARM. |
80 |
+deviceinfo_usb_serialnumber="Arch" |
81 |
+ |
82 |
+setup_usb_network_configfs() { |
83 |
+ # See: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt |
84 |
+ CONFIGFS=/sys/kernel/config/usb_gadget/ |
85 |
+ |
86 |
+ if ! [ -e "$CONFIGFS" ]; then |
87 |
+ echo " $CONFIGFS does not exist, skipping configfs usb gadget" |
88 |
+ return |
89 |
+ fi |
90 |
+ |
91 |
+ # Default values for USB-related deviceinfo variables |
92 |
+ usb_idVendor="${deviceinfo_usb_idVendor:-0x18D1}" # default: Google Inc. |
93 |
+ usb_idProduct="${deviceinfo_usb_idProduct:-0xD001}" # default: Nexus 4 (fastboot) |
94 |
+ usb_serialnumber="${deviceinfo_usb_serialnumber:-postmarketOS}" |
95 |
+ usb_rndis_function="${deviceinfo_usb_rndis_function:-rndis.usb0}" |
96 |
+ |
97 |
+ echo " Setting up an USB gadget through configfs" |
98 |
+ # Create an usb gadet configuration |
99 |
+ mkdir $CONFIGFS/g1 || echo " Couldn't create $CONFIGFS/g1" |
100 |
+ echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor" |
101 |
+ echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct" |
102 |
+ |
103 |
+ # Create english (0x409) strings |
104 |
+ mkdir $CONFIGFS/g1/strings/0x409 || echo " Couldn't create $CONFIGFS/g1/strings/0x409" |
105 |
+ |
106 |
+ # shellcheck disable=SC2154 |
107 |
+ echo "$deviceinfo_manufacturer" > "$CONFIGFS/g1/strings/0x409/manufacturer" |
108 |
+ echo "$usb_serialnumber" > "$CONFIGFS/g1/strings/0x409/serialnumber" |
109 |
+ # shellcheck disable=SC2154 |
110 |
+ echo "$deviceinfo_name" > "$CONFIGFS/g1/strings/0x409/product" |
111 |
+ |
112 |
+ # Create rndis function. The function can be named differently in downstream kernels. |
113 |
+ mkdir $CONFIGFS/g1/functions/"$usb_rndis_function" \ |
114 |
+ || echo " Couldn't create $CONFIGFS/g1/functions/$usb_rndis_function" |
115 |
+ |
116 |
+ # Create configuration instance for the gadget |
117 |
+ mkdir $CONFIGFS/g1/configs/c.1 \ |
118 |
+ || echo " Couldn't create $CONFIGFS/g1/configs/c.1" |
119 |
+ mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 \ |
120 |
+ || echo " Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409" |
121 |
+ echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \ |
122 |
+ || echo " Couldn't write configration name" |
123 |
+ |
124 |
+ # Link the rndis instance to the configuration |
125 |
+ ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \ |
126 |
+ || echo " Couldn't symlink $usb_rndis_function" |
127 |
+ |
128 |
+ # Check if there's an USB Device Controller |
129 |
+ if [ -z "$(ls /sys/class/udc)" ]; then |
130 |
+ echo " No USB Device Controller available" |
131 |
+ return |
132 |
+ fi |
133 |
+ |
134 |
+ # Link the gadget instance to an USB Device Controller. This activates the gadget. |
135 |
+ # See also: https://github.com/postmarketOS/pmbootstrap/issues/338 |
136 |
+ # shellcheck disable=SC2005 |
137 |
+ echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || echo " Couldn't write UDC" |
138 |
+} |
139 |
+ |
140 |
+# And we go. |
141 |
+setup_usb_network_configfs |
142 |
+ip address add 10.15.19.82/24 dev usb0 |
143 |
+ip link set usb0 up |
144 |
|
145 |
diff --git a/app-mobilephone/usb-tethering/files/usb-tethering.service b/app-mobilephone/usb-tethering/files/usb-tethering.service |
146 |
new file mode 100644 |
147 |
index 000000000..25620f7da |
148 |
--- /dev/null |
149 |
+++ b/app-mobilephone/usb-tethering/files/usb-tethering.service |
150 |
@@ -0,0 +1,12 @@ |
151 |
+# systemd service file for usb-tethering |
152 |
+ |
153 |
+[Unit] |
154 |
+Wants=dhcpd4.service |
155 |
+Description=USB Tethering |
156 |
+ |
157 |
+[Service] |
158 |
+Type=oneshot |
159 |
+ExecStart=/bin/bash /usr/lib/danctnix/usb-tethering |
160 |
+ |
161 |
+[Install] |
162 |
+WantedBy=multi-user.target |
163 |
|
164 |
diff --git a/app-mobilephone/usb-tethering/metadata.xml b/app-mobilephone/usb-tethering/metadata.xml |
165 |
new file mode 100644 |
166 |
index 000000000..144c8091c |
167 |
--- /dev/null |
168 |
+++ b/app-mobilephone/usb-tethering/metadata.xml |
169 |
@@ -0,0 +1,8 @@ |
170 |
+<?xml version='1.0' encoding='UTF-8'?> |
171 |
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> |
172 |
+<pkgmetadata> |
173 |
+ <maintainer type="person"> |
174 |
+ <email>marco@××××××××.com</email> |
175 |
+ <name>Marco Scardovi</name> |
176 |
+ </maintainer> |
177 |
+</pkgmetadata> |
178 |
|
179 |
diff --git a/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild b/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild |
180 |
new file mode 100644 |
181 |
index 000000000..7ef20b167 |
182 |
--- /dev/null |
183 |
+++ b/app-mobilephone/usb-tethering/usb-tethering-0.1.ebuild |
184 |
@@ -0,0 +1,33 @@ |
185 |
+# Copyright 1999-2021 Gentoo Authors |
186 |
+# Distributed under the terms of the GNU General Public License v2 |
187 |
+ |
188 |
+EAPI=7 |
189 |
+ |
190 |
+inherit systemd |
191 |
+ |
192 |
+DESCRIPTION="USB tethering on Pine64/ConfigFS systems" |
193 |
+HOMEPAGE="https://github.com/dreemurrs-embedded/Pine64-Arch" |
194 |
+ |
195 |
+LICENSE="GPL-2+" |
196 |
+SLOT="0" |
197 |
+KEYWORDS="~arm64" |
198 |
+ |
199 |
+DEPEND=" |
200 |
+ net-misc/dhcp |
201 |
+ sys-apps/systemd |
202 |
+" |
203 |
+RDEPEND="${DEPEND}" |
204 |
+ |
205 |
+S="${WORKDIR}" |
206 |
+ |
207 |
+src_install() { |
208 |
+ exeinto "/usr/lib/danctnix" |
209 |
+ doexe "${FILESDIR}/usb-tethering" |
210 |
+ systemd_dounit "${FILESDIR}"/usb-tethering.service |
211 |
+ insinto "/usr/lib/tmpfiles.d/" |
212 |
+ doins "${FILESDIR}"/tmpfiles.d.danctnix-usb.conf |
213 |
+ insinto "/etc/systemd/system/dhcpd4.service.d/" |
214 |
+ doins "${FILESDIR}"/dhcpd4.service-customexec.conf |
215 |
+ insinto "/etc/danctnix/" |
216 |
+ doins "${FILESDIR}"/dhcpd.conf |
217 |
+} |