-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuartspeed.sh
executable file
·104 lines (93 loc) · 2.96 KB
/
uartspeed.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
#!/bin/bash
# Copyright (C) 2018 - 2020 Lee C. Bussy (@LBussy)
#
# This file is part of LBussy's BrewPi Tools Remix (BrewPi-Tools-RMX).
#
# BrewPi Tools RMX 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.
#
# BrewPi Tools RMX 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 BrewPi Tools RMX. If not, see <https://www.gnu.org/licenses/>.
# See: 'original-license.md' for notes about the original project's
# license and credits.
############
### Set up script constants
############
THISSCRIPT="uartspeed.sh" # Don't change for dev
LINK="uartspeed.brewpiremix.com"
CMDLINE="curl -L $LINK | sudo bash"
INPUT="/usr/bin/btuart"
OUTPUT="btuart.bak"
SEARCHSTRING="\$HCIATTACH /dev/serial1 bcm43xx"
############
### Make sure command is running with sudo
############
asroot() {
local retval shadow
if [ -n "$SUDO_USER" ]; then REALUSER="$SUDO_USER"; else REALUSER=$(whoami); fi
if [ "$REALUSER" == "root" ]; then
# We're not gonna run as the root user
echo -e "\nThis script may not be run from the root account, use 'sudo' instead."
exit 1
fi
### Check if we have root privs to run
if [[ "$EUID" -ne 0 ]]; then
sudo -n true 2> /dev/null
retval="$?"
if [ "$retval" -eq 0 ]; then
echo -e "\nNot running as root, relaunching correctly."
sleep 2
eval "$CMDLINE"
exit "$?"
else
# sudo not available, give instructions
echo -e "\nThis script must be run with root privileges."
echo -e "Enter the following command as one line:"
echo -e "$CMDLINE" 1>&2
exit 1
fi
fi
# And get the user home directory
shadow="$( (getent passwd "$REALUSER") 2>&1)"
retval="$?"
if [ "$retval" -eq 0 ]; then
HOMEPATH="$(echo "$shadow" | cut -d':' -f6)"
else
echo -e "\nUnable to retrieve $REALUSER's home directory. Manual work may be necessary."
exit 1
fi
}
backup() {
cp "$INPUT" "$OUTPUT"
echo "$INPUT backed up to $HOMEPATH/$OUTPUT."
}
update() {
while IFS= read -r line
do
if [[ "$line" == *"$SEARCHSTRING"* ]]
then
baud=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 4)
eval sed -i 's/$baud/115200/g' "$INPUT"
fi
done < "$INPUT"
echo "$INPUT updated."
}
reset_daemon() {
echo "Restarting bluetooth."
systemctl restart bluetooth
echo "Bluetooth daemon restarted. Please restart any client scripts."
}
main {
asroot
backup
update
reset_daemon
}
main() && exit 0