Finished porting yes/no questions to askYesNo

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.
This commit is contained in:
T. Joseph Carter 2015-10-13 14:56:30 -07:00
parent 2918a24b45
commit b3189fe14d
2 changed files with 86 additions and 16 deletions

View File

@ -4,16 +4,52 @@
# Set up A2SERVER to support Samba (Windows File Sharing) # Set up A2SERVER to support Samba (Windows File Sharing)
# this script can also be used if new shares are introduced # this script can also be used if new shares are introduced
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
}
[[ -f /tmp/a2server-autoAnswerDefault ]] && autoAnswerDefault=1 || autoAnswerDefault= [[ -f /tmp/a2server-autoAnswerDefault ]] && autoAnswerDefault=1 || autoAnswerDefault=
if [[ ! $autoAnswerDefault || -f /tmp/a2server-setupWindowsSharing ]]; then if [[ ! $autoAnswerDefault || -f /tmp/a2server-setupWindowsSharing ]]; then
if [[ ! $autoAnswerDefault ]]; then if [[ ! $autoAnswerDefault ]]; then
echo echo
echo -n "Should Windows computers be able to connect to A2SERVER? " askYesNo "Should Windows computers be able to connect to A2SERVER?" 0
read
fi fi
if [[ $autoAnswerDefault || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then if [ $? -eq 0 ]; then
echo "A2SERVER: Setting up Windows file sharing..." echo "A2SERVER: Setting up Windows file sharing..."
sudo true sudo true

View File

@ -5,6 +5,43 @@
# This script helps when running on the Linux console within the VM. # 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 echo
userPw=$(sudo grep "^$USER" /etc/shadow | cut -f 2 -d ':') userPw=$(sudo grep "^$USER" /etc/shadow | cut -f 2 -d ':')
@ -42,19 +79,16 @@ if [[ $(lsb_release -d 2> /dev/null | grep Ubuntu) ]]; then
echo "A2SERVER: Ubuntu console has already been optimized." echo "A2SERVER: Ubuntu console has already been optimized."
else else
echo "Ubuntu console optimization for use in a virtual machine will:" askYesNo "Do you want to optimize the Ubuntu console?" 0 \
echo "- show the default username/password on the login screen" "Ubuntu console optimization for use in a virtual machine will:
echo "- remove the documentation URL and system statistics shown after login" - show the default username/password on the login screen
echo "- ensure the screen clears before showing the login prompt" - remove the documentation URL and system statistics shown after login
echo "- prevent the screen from dimming after 10 minutes (once logged in)" - ensure the screen clears before showing the login prompt
echo "- eliminate a harmless but annoying startup error about piix_smbus" - prevent the screen from dimming after 10 minutes (once logged in)
echo "- fix an Ubuntu 10.04 issue with slow scrolling" - eliminate a harmless but annoying startup error about piix_smbus
echo - fix an Ubuntu 10.04 issue with slow scrolling"
if [[ ! $autoAnswerDefault ]]; then
echo -n "Do you want to optimize the Ubuntu console? " if [ $? -eq 0 ]; then
read
fi
if [[ $autoAnswerDefault || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
echo "A2SERVER: Optimizing console..." echo "A2SERVER: Optimizing console..."