Skip to content

Commit

Permalink
Tidy serial options
Browse files Browse the repository at this point in the history
  • Loading branch information
spl237 committed Oct 18, 2023
1 parent b5c0076 commit a5bd201
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions raspi-config
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ do_i2c() {
fi
}

get_serial() {
get_serial_cons() {
if grep -q -E "console=(serial0|ttyAMA0|ttyS0)" $CMDLINE ; then
echo 0
else
Expand Down Expand Up @@ -1136,7 +1136,7 @@ get_serial_hw() {
fi
}

do_serial_console() {
do_serial_cons() {
if [ $1 -eq 0 ] ; then
if grep -q "console=ttyAMA0" $CMDLINE ; then
if [ -e /proc/device-tree/aliases/serial0 ]; then
Expand All @@ -1155,7 +1155,7 @@ do_serial_console() {
fi
}

do_serial_hardware() {
do_serial_hw() {
if [ $1 -eq 0 ] ; then
if is_pifive ; then
set_config_var dtparam=uart0 on $CONFIG
Expand All @@ -1176,63 +1176,53 @@ do_serial() {
DEFAULTH=--defaultno
CURRENTS=0
CURRENTH=0
if [ $(get_serial) -eq 0 ]; then
if [ $(get_serial_cons) -eq 0 ]; then
DEFAULTS=
CURRENTS=1
fi
if [ $(get_serial_hw) -eq 0 ]; then
DEFAULTH=
CURRENTH=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2
RET=$?
else
RET=$1
fi
whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2
RET=$?

This comment has been minimized.

Copy link
@mrnuke

mrnuke Apr 26, 2024

This change right here removes the ability to do a non-interactive config change for the serial port. Is this intentional?

This comment has been minimized.

Copy link
@spl237

spl237 Apr 26, 2024

Author

If you want to do a non-interactive change, you should call the individual functions do_serial_cons and do_serial_hw - this do_serial function is only for interactive use, as it wraps those two individual functions in a menu.

This comment has been minimized.

Copy link
@mrnuke

mrnuke Apr 26, 2024

Cool! Thank you for the clarification!

if [ $RET -eq $CURRENTS ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
do_serial_console 0
do_serial_cons 0
SSTATUS=enabled
do_serial_hardware 0
do_serial_hw 0
HSTATUS=enabled
elif [ $RET -eq 1 ] || [ $RET -eq 2 ]; then
do_serial_console 1
elif [ $RET -eq 1 ]; then
do_serial_cons 1
SSTATUS=disabled
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2
RET=$?
else
RET=$((2 - RET))
fi
whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2
RET=$?
if [ $RET -eq $CURRENTH ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
do_serial_hardware 0
do_serial_hw 0
HSTATUS=enabled
elif [ $RET -eq 1 ]; then
do_serial_hardware 1
do_serial_hw 1
HSTATUS=disabled
else
return $RET
fi
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1
fi
whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1
}

do_serial_pi5() {
DEFAULTS=--defaultno
DEFAULTH=--defaultno
CURRENTS=0
CURRENTH=0
if [ $(get_serial) -eq 0 ]; then
if [ $(get_serial_cons) -eq 0 ]; then
DEFAULTS=
CURRENTS=1
fi
Expand All @@ -1246,10 +1236,10 @@ do_serial_pi5() {
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
do_serial_console 0
do_serial_cons 0
SSTATUS=enabled
elif [ $RET -eq 1 ]; then
do_serial_console 1
do_serial_cons 1
SSTATUS=disabled
else
return $RET
Expand All @@ -1260,10 +1250,10 @@ do_serial_pi5() {
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
do_serial_hardware 0
do_serial_hw 0
HSTATUS=enabled
elif [ $RET -eq 1 ]; then
do_serial_hardware 1
do_serial_hw 1
HSTATUS=disabled
else
return $RET
Expand Down

0 comments on commit a5bd201

Please sign in to comment.