Last active
February 5, 2024 17:30
-
-
Save melissacoleman/9a9860574c859ce606bfa0b3ed4e63bc to your computer and use it in GitHub Desktop.
Remove all console messages on Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ ! $UID -eq 0 ]]; then | |
echo "you must run this as root:" | |
echo "sudo $0" | |
exit 1 | |
fi | |
touch /home/pi/.hushlogin | |
# Make backups if first time running | |
if [ ! -f /etc/rc.local-backup ]; then | |
cp -a /etc/rc.local /etc/rc.local-backup | |
echo -e "\e[91mcreated backup of /etc/rc.local\e[30m" | |
fi | |
if [ ! -f /etc/issue-backup ]; then | |
cp -a /etc/issue /etc/issue-backup | |
echo -e "\e[91mcreated backup of /etc/issue\e[30m" | |
fi | |
if [ ! -f /boot/cmdline-backup.txt ]; then | |
cp -a /boot/cmdline.txt /boot/cmdline-backup.txt | |
echo -e "\e[91mcreated backup of /boot/cmdline.txt\e[30m" | |
fi | |
if [ ! -f /etc/systemd/system/autologin\@-backup.service ]; then | |
cp -a /etc/systemd/system/autologin\@.service /etc/systemd/system/autologin\@-backup.service | |
echo -e "\e[91mcreated backup of /etc/systemd/system/autologin\@.service\e[30m" | |
fi | |
if [ ! -f /etc/pam.d/login-backup ]; then | |
cp -a /etc/pam.d/login /etc/pam.d/login-backup | |
echo -e "\e[91mcreated backup of /etc/pam.d/login\e[30m" | |
fi | |
# Change /boot/cmdline.txt: replace tty1 with tty3 and add arguments | |
sed -i 's/console=tty1/console=tty3/g' "/boot/cmdline.txt" | |
if !(grep -q "quiet splash loglevel=0 logo.nologo" "/boot/cmdline.txt";) then | |
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' /boot/cmdline.txt # Delete all trailing blank lines at end of file (only). And save with -i | |
sed -i '${s/$/ quiet splash loglevel=0 logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles/}' "/boot/cmdline.txt" | |
fi | |
echo -e "\e[91mOUTPUT of /boot/cmdline.txt:\e[30m" | |
cat /boot/cmdline.txt | |
# Change ExecStart on /etc/systemd/system/autologin@.service | |
if !(grep -q "\-\-skip-login" "/etc/systemd/system/autologin@.service";) then | |
sed -i 's/ExecStart=-\/sbin\/agetty --autologin pi --noclear %I $TERM/ExecStart=-\/sbin\/agetty --skip-login --noclear --noissue --login-options \"-f pi\" %I $TERM/g' "/etc/systemd/system/autologin@.service" | |
fi | |
echo -e "\e[91mOUTPUT of /etc/systemd/system/autologin\@.service:\e[30m" | |
cat /etc/systemd/system/autologin\@.service | |
# Tell dmesg to be quiet in /etc/rc.local | |
if grep -q "dmesg --console-off" "/etc/rc.local"; then | |
echo -e "\e[91malready inserted dmesg --console-off in /etc/rc.local\e[30m" | |
else | |
echo "insert dmesg --console-off" | |
sed -i "/exit 0/ i #Suppress Kernel Messages\ndmesg --console-off" "/etc/rc.local" | |
fi | |
echo -e "\e[91mOUTPUT of /etc/rc.local:\e[30m" | |
cat /etc/rc.local | |
# Remove entire content of file /etc/issue | |
sed -i d /etc/issue | |
echo -e "\e[91mOUTPUT of /etc/issue:\e[30m" | |
cat /etc/issue | |
# Change ExecStart on /etc/pam.d/login | |
if grep -q "pam_exec.so type=open_session stdout \/bin\/uname -snrvm" "/etc/pam.d/login"; then | |
sed -i 's/pam_exec.so type=open_session stdout \/bin\/uname -snrvm/session optional pam_exec.so type=open_session stdout/g' "/etc/pam.d/login" | |
fi | |
echo -e "\e[91mOUTPUT of /etc/pam.d/login:\e[30m" | |
cat /etc/pam.d/login | |
# Change prompt to $ in the console by editing ~/.bashrc | |
# Word of warning if you intend to show no prompt indicator: | |
# consoles without any indicators can be a bit confusing mid-development. | |
if !(grep -q "PS1=\"$\"" "/home/pi/.bashrc";) then | |
sed -i '${s/$/\nPS1="$"/}' "/home/pi/.bashrc" | |
fi | |
echo -e "\e[91mOUTPUT of ~/.bashrc:\e[30m" | |
cat /home/pi/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment