a2server/docs/ivanx/scripts/a2server-7-console.txt
2015-10-23 05:09:22 -07:00

105 lines
5.1 KiB
Bash

#!/bin/bash
# --- Ubuntu Server console optimizaton (optional)
# This script helps when running on the Linux console within the VM.
echo
userPw=$(sudo grep "^$USER" /etc/shadow | cut -f 2 -d ':')
[[ $userPw == "$(echo 'apple2' | perl -e '$_ = <STDIN>; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isApple2Pw=1 || isApple2Pw=
[[ $userPw == "$(echo 'raspberry' | perl -e '$_ = <STDIN>; chomp; print crypt($_, $ARGV[0])' "${userPw%"${userPw#\$*\$*\$}"}")" ]] && isRaspberryPw=1 || isRaspberryPw=
password="your password"
[[ $isApple2Pw ]] && password="'apple2'"
[[ $isRaspberryPw ]] && password="'raspberry'"
isDebian=
[[ ( -f /etc/debian_version ) && ( $(cut -c 1-2 < /etc/debian_version) == "7." ) && ( $(uname -m) == "i686" ) ]] && isDebian=1
if [[ $isDebian ]]; then
if { lspci 2> /dev/null | grep -q VirtualBox; }; then
echo "A2SERVER: Disabling VirtualBox console screen blanking..."
sudo sed -i 's/^BLANK_DPMS=off/BLANK_DPMS=on/' /etc/kbd/config
sudo sed -i 's/^BLANK_TIME=[^0].$/BLANK_TIME=0/' /etc/kbd/config
sudo /etc/init.d/kbd restart &> /dev/null
sudo /etc/init.d/console-setup restart &> /dev/null
fi
fi
# check that we're on Ubuntu
if [[ $(lsb_release -d 2> /dev/null | grep Ubuntu) ]]; then
# don't do any of this if we're logged in via SSH
if [[ $SSH_CLIENT || $REMOTEHOST ]]; then
echo "A2SERVER: Logged in via SSH,not performing console optimization."
echo "Run setup from the console if you want to optimize the console."
else
# if we've already done this stuff, don't do it again
if [[ ! -x /etc/update-motd.d/10-help-text ]]; then
echo "A2SERVER: Ubuntu console has already been optimized."
else
echo "Ubuntu console optimization for use in a virtual machine will:"
echo "- show the default username/password on the login screen"
echo "- remove the documentation URL and system statistics shown after login"
echo "- ensure the screen clears before showing the login prompt"
echo "- prevent the screen from dimming after 10 minutes (once logged in)"
echo "- eliminate a harmless but annoying startup error about piix_smbus"
echo "- fix an Ubuntu 10.04 issue with slow scrolling"
echo
if [[ ! $autoAnswerYes ]]; then
echo -n "Do you want to optimize the Ubuntu console? "
read
fi
if [[ $autoAnswerYes || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
echo "A2SERVER: Optimizing console..."
# remind the user how to log in (we're going for functionality here, not security)
if [[ ! $(grep $USER\/$password /etc/issue) ]]; then
sudo sed -i '/^Log in with.*$/d' /etc/issue
echo "Log in with '$USER' / '$password'." | sudo tee -a /etc/issue > /dev/null
echo | sudo tee -a /etc/issue > /dev/null
fi
# If after logging in, you don't like the documentation URL and
# system info (or an error about it) being displayed, type:
sudo chmod -x /etc/update-motd.d/10-help-text
sudo chmod -x /etc/update-motd.d/50-landscape-sysinfo
# If the screen doesn't clear for login after the boot messages, and
# you'd like it to, type:
sudo sed -i 's/X_DEFAULT=""/X_DEFAULT="quiet"/g' /etc/default/grub
sudo update-grub
# If you see a piix4_smbus error on startup, it is harmless, but if you
# want to eliminate it, type:
echo -e '\nblacklist i2c_piix4' \
| sudo tee -a /etc/modprobe.d/blacklist.conf > /dev/null
sudo update-initramfs -u -k all
# If you want to prevent the Ubuntu screen from going blank after ten
# minutes of inactivity (once you are logged in), type:
echo -e \
'\n[[ $SSH_CLIENT || $REMOTEHOST ]] || setterm -blank 0 -powersave off -powerdown 0' \
| sudo tee -a /etc/profile > /dev/null
setterm -blank 0 -powersave off -powerdown 0
# (note: These next lines addresses an issue only for Ubuntu 10.04.)
# Type "ps aux" and press return. If you see slow text scrolling, type:
if [[ "$(lsb_release -rs 2> /dev/null)" == "10.04" ]]; then
echo -e '\nblacklist vga16fb' \
| sudo tee -a /etc/modprobe.d/blacklist-framebuffer.conf > /dev/null
if [[ ! $SSH_CLIENT ]]; then
echo "Restarting now is recommended. To resume setup, log back"
echo -n "in, press up-arrow, and press return. Restart now? "
read; R=${REPLY:0:1}
[[ $R != "y" ]] && [[ $R != "Y" ]] || sudo shutdown -r now
fi
fi
fi
fi
fi
fi