-
Notifications
You must be signed in to change notification settings - Fork 28
/
remove.sh
executable file
·107 lines (89 loc) · 2.78 KB
/
remove.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
104
105
106
107
#!/bin/bash
USBFILE=/usr/local/sbin/usb-gadget.sh
UNITFILE=/lib/systemd/system/usb-gadget.service
CONFIG_FILE=/boot/firmware/config.txt
CMDLINE_FILE=/boot/firmware/cmdline.txt
# some usefull functions
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
# check if $CONFIG_FILE exists or go back to old path
if [[ ! -e $CONFIG_FILE ]]; then
CONFIG_FILE=/boot/config.txt
CMDLINE_FILE=/boot/cmdline.txt
fi
cat << EOF
This script will modify '$CONFIG_FILE', '$CMDLINE_FILE' and other files.
Warning, It might brick your device!
Do not run unless you understand what it is doing.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Continue with modifications?
EOF
! confirm && exit
if [ -e "$UNITFILE" ]; then
echo "disabling and removing usb-gadget unit"
sudo systemctl disable usb-gadget
# Removed /etc/systemd/system/sysinit.target.wants/usb-gadget.service.
sudo rm "$UNITFILE"
sudo systemctl daemon-reload
fi
if [ -e /etc/usb-gadgets ]; then
echo "removing /etc/usb-gadgets"
sudo rm -Rf /etc/usb-gadgets
fi
if [ -e "$USBFILE" ]; then
echo "removing $USBFILE"
sudo rm "$USBFILE"
fi
if [ -e /etc/dnsmasq.d/usb-gadget ]; then
echo "removing dnsmasq config and uninstalling dnsmasq"
sudo rm /etc/dnsmasq.d/usb-gadget
sudo systemctl stop dnsmasq
sudo apt purge dnsmasq
fi
if [ -e /etc/network/interfaces.d/usb0 ]; then
echo "removing interface config for usb0"
sudo ifdown usb0
sudo rm /etc/network/interfaces.d/usb0
fi
if $(grep -q modules-load=dwc2 $CMDLINE_FILE) ; then
echo
echo "remove line modules-load=dwc2 from $CMDLINE_FILE"
if ! confirm ; then
exit
fi
cat $CMDLINE_FILE
sudo sed -i '${s/ modules-load=dwc2//}' $CMDLINE_FILE
cat $CMDLINE_FILE
fi
if $(grep -q 'denyinterfaces usb0' /etc/dhcpcd.conf) ; then
echo
echo "remove line 'denyinterfaces usb0' from /etc/dhcpcd.conf"
if ! confirm ; then
exit
fi
sudo sed -i '${s/denyinterfaces usb0//}' /etc/dhcpcd.conf
fi
if $(grep -q '^libcomposite' /etc/modules) ; then
echo
echo "remove line 'libcomposite' from /etc/modules"
if ! confirm ; then
exit
fi
sudo sed -i '${s/^libcomposite//}' /etc/modules
fi