-
Notifications
You must be signed in to change notification settings - Fork 1
/
teardown-usb.sh
executable file
·103 lines (79 loc) · 1.98 KB
/
teardown-usb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -eu
set -o pipefail
if (( $(id -u) != 0 )); then
echo "Please, run as root"
exit 1
fi
SDPATH="$(dirname "${BASH_SOURCE[0]}")"
if [[ ! -d "${SDPATH}" ]]; then SDPATH="${PWD}"; fi
SDPATH="$(cd "${SDPATH}" && pwd)"
readonly SDPATH
cd "${SDPATH}"; echo + cd "${PWD}"
# /b/; Teardown systemd script that sets up USB Device Descriptor
# /b/{
echo
CMD=('systemctl disable rpi4-usb.service ||:')
echo + "${CMD[*]}" && eval "${CMD[*]}"
readonly STOW_NAME=rpi4-ethernet-over-usb
if [[ -d /usr/local/stow/${STOW_NAME} ]]
then
echo
cd /usr/local/stow; echo + cd "${PWD}"
echo
CMD=(stow -vD "${STOW_NAME}")
echo + "${CMD[*]}" && "${CMD[@]}"
echo
CMD=(rm -rvf "${STOW_NAME}")
echo + "${CMD[*]}" && "${CMD[@]}"
else
echo
CMD=(rm -vf /usr/local/bin/rpi4-usb.sh)
echo + "${CMD[*]}" && "${CMD[@]}"
echo
CMD=(rm -vf /usr/local/lib/systemd/system/rpi4-usb.service)
echo + "${CMD[*]}" && "${CMD[@]}"
fi
# /b/}
# /b/; Disable libcomposite module
# /b/{
if grep -qE '^\s*libcomposite\s*$' /etc/modules
then
echo
CMD=(cp -vf /etc/modules /etc/modules.teardown-usb-bkp)
echo + "${CMD[*]}" && "${CMD[@]}"
echo
CMD=(sed -zE -i)
CMD+=("'s/[^\n]*libcomposite\s*\n//g'")
CMD+=(/etc/modules)
echo + "${CMD[*]}" && eval "${CMD[*]}"
fi
# /b/}
# /b/; Remove dwc2 from /boot/cmdline.txt
# /b/{
if grep -qE 'modules-load=dwc2' /boot/cmdline.txt
then
echo
CMD=(cp -f /boot/cmdline.txt /boot/cmdline.txt.setup-usb-bkp)
echo + "${CMD[*]}" && "${CMD[@]}"
echo
CMD=(sed -E -i)
CMD+=("'s/\s+modules-load=dwc2\s+/ /'")
CMD+=(/boot/cmdline.txt)
echo + "${CMD[*]}" && eval "${CMD[*]}"
fi
# /b/}
# /b/; Remove dwc2 from /boot/config.txt
# /b/{
if grep -qE '^\s*dtoverlay\s*=\s*dwc2\s*$' /boot/config.txt
then
echo
CMD=(cp -vf /boot/config.txt /boot/config.txt.teardown-usb-bkp)
echo + "${CMD[*]}" && "${CMD[@]}"
echo
CMD=(sed -zE -i)
CMD+=("'s/[^\n]*dtoverlay\s*=\s*dwc2\s*\n//g'")
CMD+=(/boot/config.txt)
echo + "${CMD[*]}" && eval "${CMD[*]}"
fi
# /b/}