Skip to content

Commit

Permalink
fix: fix error autologin on serial tty (mainsail-crew#242)
Browse files Browse the repository at this point in the history
* 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 <me@stephanwe.de>

* feat: add workaround for orangepi images

Apply release file workaround for OrangePI based images.

Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan authored and miklschmidt committed Feb 25, 2024
1 parent 30e6afb commit 608d051
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
9 changes: 8 additions & 1 deletion src/modules/mainsailos/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/modules/orangepi/config
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
24 changes: 6 additions & 18 deletions src/modules/orangepi/end_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 36 additions & 14 deletions src/modules/orangepi/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ..."

Expand Down Expand Up @@ -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

0 comments on commit 608d051

Please sign in to comment.