From 6d9f608dd057e4197f1fb0e0aaac705f9fac1504 Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Fri, 30 Oct 2015 04:13:31 -0700 Subject: [PATCH] Add baud to source tree --- setup/baud.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 setup/baud.txt diff --git a/setup/baud.txt b/setup/baud.txt new file mode 100644 index 0000000..7d48f8e --- /dev/null +++ b/setup/baud.txt @@ -0,0 +1,29 @@ +#!/bin/bash + +if [[ $1 == "-d" ]]; then + shift + setgetty=1 +else + setgetty= +fi + +if [[ $1 -ne 300 && $1 -ne 1200 && $1 -ne 2400 && $1 -ne 4800 && $1 -ne 9600 && $1 -ne 19200 && $1 -ne 38400 && $1 -ne 57600 && $1 -ne 115200 ]]; then + echo 'Usage: baud [-d] 300|1200|2400|4800|9600|19200|38400|57600|115200'; + echo ' -d sets default speed for all serial port shells (takes effect on logout)' + echo ' omitting -d makes change temporary and immediate' +else + if [[ $setgetty ]]; then + sudo sed -i "s/ttyAMA0 .* /ttyAMA0 $1 /" /etc/inittab; + sudo sed -i "s/ttyAMA0,[0-9]*/ttyAMA0,$1/g" /boot/cmdline.txt; + sudo sed -i "s/\(ttyUSB.*\) .* /\1 $1 /g" /etc/inittab; + sudo init q; + sudo pkill -f "/sbin/getty" + else + if [[ $(tty | grep tty) ]]; then + stty -F $(tty) $1 + fi + fi +fi + +echo -e "$(tput bold)$(tty) current $(stty -a -F $(tty) | grep -o 'speed .* baud')$(tput sgr0)" +echo -e "$(tput bold)default speed at login: $(grep ttyUSB /etc/inittab | sed 's/^.*ttyUSB[^ ]* \(.*\) .*$/\1/') baud$(tput sgr0)"