mirror of
https://github.com/RasppleII/a2server.git
synced 2025-03-11 15:29:48 +00:00
Didn't touch the Samba workgroup question for now since it's the only question that asks anything else. Maybe when this stuff gets refactored to remove duplication.
141 lines
5.6 KiB
Bash
Executable File
141 lines
5.6 KiB
Bash
Executable File
#! /bin/bash
|
|
# vim: set tabstop=4 shiftwidth=4 expandtab filetype=sh:
|
|
|
|
# --- Ubuntu Server console optimizaton (optional)
|
|
|
|
# This script helps when running on the Linux console within the VM.
|
|
|
|
function askYesNo()
|
|
# Ask a yes/no question of the user, with potential default
|
|
# arg1: Prompt text
|
|
# arg2: Default; 0 for yes, 1 for no, anything else for no default
|
|
# arg3: Info text for the user
|
|
# returns: 0 for yes, 1 for no
|
|
{
|
|
local default
|
|
|
|
case "$2" in
|
|
0) default="y" ;;
|
|
1) default="n" ;;
|
|
*) default="" ;;
|
|
esac
|
|
|
|
if [ -n "$autoAnswerDefault" -a -n "$default" ]; then
|
|
return $2
|
|
fi
|
|
|
|
if [ -n "$3" ]; then
|
|
echo
|
|
echo "$3"
|
|
echo
|
|
fi
|
|
while :; do
|
|
echo -n "$1 "
|
|
[ -n "$default" ] && echo -n "[$default] "
|
|
read
|
|
case "$REPLY" in
|
|
[Yy]*) return 0 ;;
|
|
[Nn]*) return 1 ;;
|
|
"") [ -n "$default" ] && return $2 ;;
|
|
*) echo "Please answer yes or no." ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
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
|
|
askYesNo "Do you want to optimize the Ubuntu console?" 0 \
|
|
"Ubuntu console optimization for use in a virtual machine will:
|
|
- show the default username/password on the login screen
|
|
- remove the documentation URL and system statistics shown after login
|
|
- ensure the screen clears before showing the login prompt
|
|
- prevent the screen from dimming after 10 minutes (once logged in)
|
|
- eliminate a harmless but annoying startup error about piix_smbus
|
|
- fix an Ubuntu 10.04 issue with slow scrolling"
|
|
|
|
if [ $? -eq 0 ]; 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
|