Skip to content

Commit

Permalink
refactor: outsource boot_logs and systemctl_services
Browse files Browse the repository at this point in the history
  • Loading branch information
pabera committed Jan 22, 2024
1 parent b89435f commit 8e4ec13
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 74 deletions.
51 changes: 51 additions & 0 deletions installation/options/boot_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
source ../includes/02_helpers.sh

if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then
print_lc "Error: Invalid or no argument provided.
Usage: ./boot_logs.sh <arg>
where <arg> can be 'enable' or 'disable'"
exit 1
fi

arg="$1"
boot_cmdline_path=$(get_boot_cmdline_path)
boot_cmdline_options="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram"

if [ "$arg" = "enable" ]; then
print_lc "Enable Boot logs..."

if [ -s "${boot_cmdline_path}" ]; then
for option in $boot_cmdline_options; do
sudo sed -i "s/\s*$option\s*/ /" "${boot_cmdline_path}"
done
fi
elif [ "$arg" = "disable" ]; then
print_lc "Disable Boot logs..."

if [ ! -s "${boot_cmdline_path}" ];then
sudo tee "${boot_cmdline_path}" <<-EOF
${boot_cmdline_options}
EOF
else
for option in $boot_cmdline_options
do
if ! grep -qiw "$option" "${boot_cmdline_path}" ; then
sudo sed -i "s/$/ $option/" "${boot_cmdline_path}"
fi
done
fi
fi

# Test
if [ "$arg" = "enable" ]; then
for option in $boot_cmdline_options
do
verify_file_does_not_contain_string $option "${boot_cmdline_path}"
done
elif [ "$arg" = "disable" ]; then
for option in $boot_cmdline_options
do
verify_file_contains_string_once $option "${boot_cmdline_path}"
done
fi
57 changes: 57 additions & 0 deletions installation/options/systemctl_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
source ../includes/02_helpers.sh

if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then
print_lc "Error: Invalid or no argument provided.
Usage: ./systemctl_services.sh <arg>
where <arg> can be 'enable' or 'disable'"
exit 1
fi

arg="$1"

if [ "$arg" = "enable" ]; then
print_lc "Enable default services..."

sudo systemctl enable keyboard-setup.service
sudo systemctl enable triggerhappy.service
sudo systemctl enable triggerhappy.socket
sudo systemctl enable raspi-config.service
sudo systemctl enable apt-daily.service
sudo systemctl enable apt-daily-upgrade.service
sudo systemctl enable apt-daily.timer
sudo systemctl enable apt-daily-upgrade.timer
elif [ "$arg" = "disable" ]; then
print_lc "Disable default services..."

sudo systemctl disable keyboard-setup.service
sudo systemctl disable triggerhappy.service
sudo systemctl disable triggerhappy.socket
sudo systemctl disable raspi-config.service
sudo systemctl disable apt-daily.service
sudo systemctl disable apt-daily-upgrade.service
sudo systemctl disable apt-daily.timer
sudo systemctl disable apt-daily-upgrade.timer
fi

# Test
if [ "$arg" = "enable" ]; then
verify_optional_service_enablement keyboard-setup.service enabled
verify_optional_service_enablement triggerhappy.service enabled
verify_optional_service_enablement triggerhappy.socket enabled
verify_optional_service_enablement raspi-config.service enabled
verify_optional_service_enablement apt-daily.service enabled
verify_optional_service_enablement apt-daily-upgrade.service enabled
verify_optional_service_enablement apt-daily.timer enabled
verify_optional_service_enablement apt-daily-upgrade.timer enabled

elif [ "$arg" = "disable" ]; then
verify_optional_service_enablement keyboard-setup.service disabled
verify_optional_service_enablement triggerhappy.service disabled
verify_optional_service_enablement triggerhappy.socket disabled
verify_optional_service_enablement raspi-config.service disabled
verify_optional_service_enablement apt-daily.service disabled
verify_optional_service_enablement apt-daily-upgrade.service disabled
verify_optional_service_enablement apt-daily.timer disabled
verify_optional_service_enablement apt-daily-upgrade.timer disabled
fi
76 changes: 2 additions & 74 deletions installation/routines/optimize_boot_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,8 @@

# Reference: https://panther.software/configuration-code/raspberry-pi-3-4-faster-boot-time-in-few-easy-steps/

OPTIMIZE_DHCP_CONF="/etc/dhcpcd.conf"
OPTIMIZE_BOOT_CMDLINE_OPTIONS="consoleblank=1 logo.nologo quiet loglevel=0 plymouth.enable=0 vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fastboot noatime nodiratime noram"
OPTIMIZE_DHCP_CONF_HEADER="## Jukebox DHCP Config"
OPTIMIZE_BOOT_CONF_HEADER="## Jukebox Boot Config"

_optimize_disable_irrelevant_services() {
log " Disable keyboard-setup.service"
sudo systemctl disable keyboard-setup.service

log " Disable triggerhappy.service"
sudo systemctl disable triggerhappy.service
sudo systemctl disable triggerhappy.socket

log " Disable raspi-config.service"
sudo systemctl disable raspi-config.service

log " Disable apt-daily.service & apt-daily-upgrade.service"
sudo systemctl disable apt-daily.service
sudo systemctl disable apt-daily-upgrade.service
sudo systemctl disable apt-daily.timer
sudo systemctl disable apt-daily-upgrade.timer
./../options/systemctl_services.sh disable
}

_optimize_handle_bluetooth() {
Expand Down Expand Up @@ -53,65 +34,12 @@ _optimize_handle_boot_screen() {
fi
}

# TODO: Allow both Enable and Disable
_optimize_handle_boot_logs() {
if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then
log " Disable boot logs"

if [ ! -s "${RPI_BOOT_CMDLINE_FILE}" ];then
sudo tee "${RPI_BOOT_CMDLINE_FILE}" <<-EOF
${OPTIMIZE_BOOT_CMDLINE_OPTIONS}
EOF
else
for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS
do
if ! grep -qiw "$option" "${RPI_BOOT_CMDLINE_FILE}" ; then
sudo sed -i "s/$/ $option/" "${RPI_BOOT_CMDLINE_FILE}"
fi
done
fi
./../options/boot_logs.sh disable
fi
}


_optimize_check() {
print_verify_installation

verify_optional_service_enablement keyboard-setup.service disabled
verify_optional_service_enablement triggerhappy.service disabled
verify_optional_service_enablement triggerhappy.socket disabled
verify_optional_service_enablement raspi-config.service disabled
verify_optional_service_enablement apt-daily.service disabled
verify_optional_service_enablement apt-daily-upgrade.service disabled
verify_optional_service_enablement apt-daily.timer disabled
verify_optional_service_enablement apt-daily-upgrade.timer disabled

# if [ "$DISABLE_BLUETOOTH" = true ] ; then
# verify_optional_service_enablement hciuart.service disabled
# verify_optional_service_enablement bluetooth.service disabled
# fi

# if [ "$ENABLE_STATIC_IP" = true ] ; then
# verify_file_contains_string_once "${OPTIMIZE_DHCP_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}"
# verify_file_contains_string "${CURRENT_INTERFACE}" "${OPTIMIZE_DHCP_CONF}"
# verify_file_contains_string "${CURRENT_IP_ADDRESS}" "${OPTIMIZE_DHCP_CONF}"
# verify_file_contains_string "${CURRENT_GATEWAY}" "${OPTIMIZE_DHCP_CONF}"
# fi
# if [ "$DISABLE_IPv6" = true ] ; then
# verify_file_contains_string_once "${OPTIMIZE_IPV6_CONF_HEADER}" "${OPTIMIZE_DHCP_CONF}"
# fi
# if [ "$DISABLE_BOOT_SCREEN" = true ] ; then
# verify_file_contains_string_once "${OPTIMIZE_BOOT_CONF_HEADER}" "${RPI_BOOT_CONFIG_FILE}"
# fi

if [ "$DISABLE_BOOT_LOGS_PRINT" = true ] ; then
for option in $OPTIMIZE_BOOT_CMDLINE_OPTIONS
do
verify_file_contains_string_once $option "${RPI_BOOT_CMDLINE_FILE}"
done
fi
}

_run_optimize_boot_time() {
_optimize_disable_irrelevant_services
_optimize_handle_bluetooth
Expand Down

0 comments on commit 8e4ec13

Please sign in to comment.