From be13745d17780c85baa43d59a40dca565dd9f5b0 Mon Sep 17 00:00:00 2001 From: Stephan Wendel <43513802+KwadFan@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:10:44 +0200 Subject: [PATCH] fix: fix error autologin on serial tty (#242) * fix: fix autologin on serial tty This fixes issue that after connection to a serial console it trys to autologin with user 'orangepi', which does not exist in our images Signed-off-by: Stephan Wendel * feat: add workaround for orangepi images Apply release file workaround for OrangePI based images. Signed-off-by: Stephan Wendel --- src/modules/mainsailos/start_chroot_script | 9 +++- src/modules/orangepi/config | 3 ++ src/modules/orangepi/end_chroot_script | 24 +++-------- src/modules/orangepi/start_chroot_script | 50 ++++++++++++++++------ 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/modules/mainsailos/start_chroot_script b/src/modules/mainsailos/start_chroot_script index 89b426a17..97e7d3494 100644 --- a/src/modules/mainsailos/start_chroot_script +++ b/src/modules/mainsailos/start_chroot_script @@ -40,8 +40,15 @@ echo "${DIST_NAME} release ${DIST_VERSION} ($(get_parent))" > /etc/"${DIST_NAME, ### on the original armbian-release file. ### To get around that, we simple symlink mainsailos-release to ### aaaa-release, which is directly read by moonraker. +### Substep 1: Do for armbian releases if [[ -f "/etc/armbian-release" ]]; then - echo_green "Apply release file workaround ..." + echo_green "Apply release file workaround (armbian based image) ..." + ln -s /etc/"${DIST_NAME,,}"-release /etc/aaaa-release +fi +### END Substep 1 +### Substep 2: Apply same for OrangePI bsed Images +if [[ -f "/etc/orangepi-release" ]]; then + echo_green "Apply release file workaround (orangepi based image) ..." ln -s /etc/"${DIST_NAME,,}"-release /etc/aaaa-release fi ## END Step 2 diff --git a/src/modules/orangepi/config b/src/modules/orangepi/config index 6196ce5f7..dab971308 100644 --- a/src/modules/orangepi/config +++ b/src/modules/orangepi/config @@ -23,6 +23,9 @@ bash-completion" [[ -n "$ORANGEPI_ADD_OVERLAYS_OPIZ2" ]] || ORANGEPI_ADD_OVERLAYS_OPIZ2="i2c3 uart5 spi-spidev" [[ -n "$ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS" ]] || ORANGEPI_ADD_OVERLAYS_OPIZ2_PARAMS="param_spidev_spi_bus=1 param_spidev_spi_cs=1" +## Disable Autologin on gettys +[[ -n "$ORANGEPI_DISABLE_GETTY_AUTOLOGIN" ]] || ORANGEPI_DISABLE_GETTY_AUTOLOGIN="1" + ### EXPERIMENTAL: Install orangepi-config from source git repo [[ -n "$ORANGEPI_INSTALL_OPI_CONFIG" ]] || ORANGEPI_INSTALL_OPI_CONFIG="true" [[ -n "$ORANGEPI_OPI_CONFIG_URL" ]] || ORANGEPI_OPI_CONFIG_URL="https://raw.githubusercontent.com/orangepi-xunlong/orangepi-build/next/external/cache/sources/orangepi-config/" diff --git a/src/modules/orangepi/end_chroot_script b/src/modules/orangepi/end_chroot_script index 1a872a189..8ae4e7609 100644 --- a/src/modules/orangepi/end_chroot_script +++ b/src/modules/orangepi/end_chroot_script @@ -18,27 +18,15 @@ source /common.sh install_cleanup_trap ## Clean up -## Step 1: Remove autologin and lock root account -if [ -f "/etc/systemd/system/getty@.service.d/override.conf" ]; then - rm -f /etc/systemd/system/getty@.service.d/override.conf -fi -## END - -## Step 2: Disable autologin on serial console -if [ -f "/etc/systemd/system/serial-getty@.service.d/override.conf" ]; then - sed -i 's/--autologin root //' /etc/systemd/system/serial-getty@.service.d/override.conf -fi -## END - -## Step 3: Delete root passwd +## Step 1: Delete root passwd (disables root login) ### Deleting root passwd doesn't let you unlock the account sudo passwd -d root -## END +## END Step 1 -## Step 4: Lock root account +## Step 2: Lock root account (disables root login) sudo passwd -l root -## END +## END Step 2 -## Step 5: Remove passwdless sudo +## Step 3: Remove passwdless sudo sed -i '/'"${BASE_USER}"' ALL=(ALL:ALL) NOPASSWD:ALL/d' /etc/sudoers -## END +## END Step 3 diff --git a/src/modules/orangepi/start_chroot_script b/src/modules/orangepi/start_chroot_script index cb2596e55..32e18bf50 100644 --- a/src/modules/orangepi/start_chroot_script +++ b/src/modules/orangepi/start_chroot_script @@ -35,6 +35,10 @@ is_board_type() { echo "${board}" } +get_gettyconf_dirs() { + find "${1}" -type d -name "*getty@*" +} + # Base User groups # Shameless "stolen" from # https://github.com/guysoft/CustomPiOS/blob/devel/src/variants/armbian/pre_chroot_script @@ -85,25 +89,16 @@ if [ -f "/root/.not_logged_in_yet" ]; then fi ## END Step 4 -## Step 5: Move armbian-release to display mainsailos-release -if [[ -f "/etc/orangepi-release" ]]; then - echo_green "OrangePi release file found! moving to: 'orangepi-release-info.txt'" - mv /etc/orangepi-release /etc/orangepi-release-info.txt -else - echo_red "OrangePi release file not found! [SKIPPED]" -fi -## END Step 5 - -## Step 6: Patch dynamic motd +## Step 5: Patch dynamic motd echo_green "Patch dynamic motd ..." unpack /filesystem/root / chmod +x /etc/update-motd.d/* if [ -f "/etc/default/orangepi-motd" ]; then sed -i 's/^MOTD_DISABLE=""/MOTD_DISABLE="header tips"/' /etc/default/orangepi-motd fi -## END Step 6 +## END Step 5 -## Step 7: Enable SPI interface by default +## Step 6: Enable SPI interface by default echo_green "Enable interfaces on Orange Pi SBC's ..." ### Substep 1: Copy default config to backup file @@ -136,9 +131,9 @@ fi echo "spi-dev" >> "${ORANGEPI_MODULES_FILE}" echo_green "Enable SPI interface on Orange Pi SBC's ... DONE!" -## END Step 7 +## END Step 6 -## Step 8: Install orangepi-config from git source repository +## Step 7: Install orangepi-config from git source repository if [[ "${ORANGEPI_INSTALL_OPI_CONFIG}" == "true" ]]; then echo_green "Install orangepi-config from git sources ..." @@ -191,4 +186,31 @@ if [[ "${ORANGEPI_INSTALL_OPI_CONFIG}" == "true" ]]; then else echo_red "WARN: orangepi-config install not configured ... [SKIPPED]" fi +## END Step 7 + +## Step 8: Fix tty and serial-tty autologin +### NOTE: Since OrangePI OS uses for its getty override.conf files +### the location of '/lib/systemd/system/[serial-]getty@.service.d' +### instead the appropriate location in etc, we have to fix that. +if [[ "${ORANGEPI_DISABLE_GETTY_AUTOLOGIN}" = "1" ]]; then + echo_green "Disable 'getty' autologin ..." + + ### Substep 1: copy '/lib/systemd/system/[serial-]getty@.service.d' + for dir in $(get_gettyconf_dirs /usr/lib/systemd/system); do + cp -R "${dir}" /etc/systemd/system + done + ### End Substep 1 + + ### Substep 2: Modify 'override.conf', delete autologin + for conf in $(get_gettyconf_dirs /etc/systemd/system); do + if [[ -f "${conf}/override.conf" ]]; then + echo_green "Found '${conf}/override.conf', trying to modify ..." + sed -i 's/--autologin orangepi //' "${conf}/override.conf" + else + echo_green "No '${conf}/override.conf' found, modifying skipped!" + fi + done + ### END Substep 2 + echo_green "Disable 'getty' autologin ... DONE!" +fi ## END Step 8