#!/bin/bash
#  +-----------------------------------------------------------------------------+
#  TWIX - TWEAK Unix
#  Copyright (C) 2004-2009 Pete Boyd
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  Contact us at inkwire-at-thegoldenear-dot-org
#  +-----------------------------------------------------------------------------+

# For debugging purposes, invoke Bash with -v

top_menu()
{
clear
echo "==============================================================================="
echo "  Twix - TWEAK Unix - Debian Setup & Configuration. Version 0.3.7."
echo "==============================================================================="
echo ""
echo "A. General Software (applicable to both desktops and servers)"
echo ""
echo "B. Desktop Software, Part 1"
echo ""
echo "C. Desktop Software, Part 2"
echo ""
echo "D. Server Software (+ server software useful on a desktop)"
echo ""
echo "-------------------------------------------------------------------------------"
echo "G. Package Management"
echo "H. Package Repository Configuration - official Debian repositories"
echo "I. Package Repository Configuration - other repositories"
echo "-------------------------------------------------------------------------------"
echo "R. Roaming Computing System (Windows Edition) 3.0 - 3.5 Configuration"
echo "-------------------------------------------------------------------------------"
echo "L. Display Licence"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read TOP_CHOICE
clear

case "$TOP_CHOICE" in
 "a" | "A")
  general_software_menu ;;
 "b" | "B")
  desktop_menu ;;
 "c" | "C")
  desktop_menu_more ;;
 "d" | "D")
  server_menu ;;
 "g" | "G")
  package_management_menu ;;
 "h" | "H")
  official_repository_menu ;;
 "i" | "I")
  other_repository_menu ;;
 "r" | "R")
  rcs_menu ;;
 "l" | "L")
  display_licence
  pause
  top_menu ;;
 "q" | "Q")
  FINISHED=true
  exit 0 ;;
 *)
  top_menu ;;
esac
}
####################################################################




##################################################################
display_licence()
##################################################################
{
echo "TWIX - TWEAK Unix"
echo "Copyright (C) 2004 - 2007 Pete Boyd"
echo ""
echo "This program is free software: you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation, either version 3 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program.  If not, see <http://www.gnu.org/licenses/>."
echo ""
echo "Contact us at inkwire-at-thegoldenear-dot-org"
}
##################################################################





####################################################################
general_software_menu()
{
clear
echo "==============================================================================="
echo "  General software (applicable to both desktops and servers)"
echo "==============================================================================="
echo "A. CD/DVD writing (command-line) [3.1/Sarge]"
echo "A2. CD/DVD writing (command-line) [4.0/Etch]"
echo "E. Linux kernels..."
echo "F. Tools for Linux kernel compilation"
echo "G. Minor useful command-line tools"
echo "H. Archivers (arc arj bzip2 cabextract cpio lha [non-free] lzop nomarch pax tnef"
echo "   p7zip-full unrar unzip zip ytnef zoo)[Sarge/Etch; p7zip-full/ytnef Etch-only]"
echo "   [Sarge/Etch tho p7zip-full + ytnef Etch-only; lha is non-free]"
echo "J. Use files/printers shared from another Windows/Samba"
echo "K. ZIP drives and disks (dosfstools) [command-line]"
echo "L. Dial-up networking with an analog modem (wvdial)"
echo "M. Wireless networking [Debian 3.0 Sarge]"
echo "N. Wireless networking [Debian 3.1 Etch]"
echo "O. Bluetooth (tools + daemons (bluez-utils); BCM firmware (bluez-firmware))"
echo "P. PCMCIA (pcmcia-cs) [Sarge/3.1]"
echo "P2. PCMCIA (pcmciautils) [Etch/4.0]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read GENERAL_CHOICE
clear

case "$GENERAL_CHOICE" in
 "a" | "A")
  cd_dvd_writing_cli_sarge
  pause
  general_software_menu ;;
 "a2" | "A2")
  cd_dvd_writing_cli_etch
  pause
  general_software_menu ;;
 "e" | "E")
  linux_kernel_menu
  pause
  general_software_menu ;;
 "f" | "F")
  linux_kernel_compilation
  pause
  general_software_menu ;;
 "g" | "G")
  minor_software
  pause
  general_software_menu ;;
 "h" | "H")
  aptitude install arc arj bzip2 cabextract cpio lha lzop nomarch p7zip-full pax tnef unrar unzip zip ytnef zoo
  pause
  general_software_menu ;;
 "j" | "J")
  samba-client
  pause
  general_software_menu ;;
 "k" | "K")
  zip_drives_cli
  pause
  general_software_menu ;;
 "l" | "L")
  dialup-analog
  pause
  general_software_menu ;;
 "m" | "M")
  wireless_menu_sarge
  pause
  general_software_menu ;;
 "n" | "N")
  wireless_menu_etch
  pause
  general_software_menu ;;
 "o" | "O")
  aptitude install bluez-utils bluez-firmware
  pause
  general_software_menu ;;
 "p" | "P")
  aptitude install pcmcia-cs
  pause
  general_software_menu ;;
 "p2" | "P2")
  aptitude install pcmciautils
  pause
  general_software_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  general_software_menu ;;
esac
}
####################################################################




##################################################################
##################################################################
desktop_menu()
{
clear
echo "==============================================================================="
echo "  Desktop System Software Installation, part 1."
echo "==============================================================================="
echo "A. X windows and the GDM login manager"
echo "B. Desktop Environment: GNOME"
echo "C. Desktop Environment: XFCE..."
echo "D. Office suite (word processors, spreadsheet, layout, etc).."
echo "E. Internet applications..."
echo "F. Web editing (Bluefish [Gnomic]; minor tools) [3.1/Sarge]"
echo "F2. Web editing (Bluefish [Gnomic]; minor tools) [4.0/Etch]"
echo "G. Enhanced image viewer (gthumb; for GNOME)"
echo "H. libdvdcss2 DVD decryption [requires debian-multimedia.org source]"
echo "I. GNOME update manager and update notifier [Etch/4.0]"
echo "J. Java Runtime Environment (JRE) builder [suited to 3.1/Sarge]"
echo "J2. Sun Java SE Runtime Environment 5.0 + browser plug-in [4.0/Etch][non-free]"
echo "L. Printing..."
echo "M. Scanning..."
echo "N. Digital still and video cameras..."
echo "O. Image Editing..."
echo "P. CD/DVD writing (GNOME and command-line) (Gnomebaker) [3.1/Sarge]"
echo "P2. CD/DVD writing (GNOME and command-line) (Gnomebaker) [4.0/Etch]"
echo "S. CD audio - rip, copy, encode [CLI/GUI; Gnomic; 3.1/Sarge]"
echo "S2. CD audio - rip, copy, encode [CLI/GUI; Gnomic; 4.0/Etch]"
echo "V. Databases..."
echo "X. Laptop Computers..."
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read DESKTOP_CHOICE
clear

case "$DESKTOP_CHOICE" in
 "a" | "A")
  x
  pause
  desktop_menu ;;
 "b" | "B")
  gnome
  pause
  desktop_menu ;;
 "c" | "C")
  xfce_menu
  pause
  desktop_menu ;;
 "d" | "D")
  office_suite_menu
  pause
  desktop_menu ;;
 "e" | "E")
  internet_apps_menu
  pause
  desktop_menu ;;
 "f" | "F")
  web-edit-sarge
  pause
  desktop_menu ;;
 "f2" | "F2")
  web-edit-etch
  pause
  desktop_menu ;;
 "g" | "G")
  image-viewing
  pause
  desktop_menu ;;
 "h" | "H")
  aptitude install libdvdcss2
  pause
  desktop_menu ;;
 "i" | "I")
  ldap-client
  pause
  desktop_menu ;;
 "i" | "I")
  echo "GNOME update manager and notifier:"
  echo ""
  aptitude install update-manager update-notifier
  pause
  desktop_menu ;;
 "j" | "J")
  jre
  pause
  desktop_menu ;;
 "j2" | "J2")
  jre5
  pause
  desktop_menu ;;
 "k" | "K")
  audio
  pause
  desktop_menu ;;
 "l" | "L")
  printing
  pause
  desktop_menu ;;
 "m" | "M")
  scanning
  pause
  desktop_menu ;;
 "n" | "N")
  camera_menu
  pause
  desktop_menu ;;
 "o" | "O")
  image_editing_menu
  pause
  desktop_menu ;;
 "p" | "P")
  cd_dvd_writing_gnome_sarge
  pause
  desktop_menu ;;
 "p2" | "P2")
  cd_dvd_writing_gnome_etch
  pause
  desktop_menu ;;
 "s" | "S")
  cd-audio-sarge
  pause
  desktop_menu ;;
 "s2" | "S2")
  cd-audio-etch
  pause
  desktop_menu ;;
 "v" | "V")
  database_menu
  pause
  desktop_menu ;;
 "x" | "X")
  laptops
  pause
  desktop_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  desktop_menu ;;
esac
}




desktop_menu_more()
{
clear
echo "==============================================================================="
echo "  Desktop System Software Installation, part 2."
echo "==============================================================================="
echo "A. Work with Windows NTFS and FAT filesystems [to do: split CLI/GUI; Gnomic]"
echo "B. Running Windows Programs (WINE)"
echo "C. Access an LDAP server"
echo "D. ZIP drives and disks (jazip) [X GUI]"
echo "E. GNOME Bluetooth preferences + Bluetooth PIN applet"
echo "F. Simple Backup Suite for desktop use [Gnomic; 4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "J. Audio architectures..."
echo "K. Audio editing with Audacity"
echo "L  LADSPA sound effects (for use with Audacity, Ardour, GNU Sound, GStreamer)"
echo "M. Video editing (avidemux; requires the debian-multimedia.org source)"
echo "N. Copying DVD movies [CLI] [3.1/Sarge]"
echo "N2. Copying DVD movies [CLI] [4.0/Etch]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read DESKTOP_MORE_CHOICE
clear

case "$DESKTOP_MORE_CHOICE" in
 "a" | "A")
  windows-filesystem
  pause
  desktop_menu_more ;;
 "b" | "B")
  windows-programs
  pause
  desktop_menu_more ;;
 "c" | "C")
  ldap-client
  pause
  desktop_menu_more ;;
 "d" | "D")
  zip_drives_gui
  pause
  desktop_menu_more ;;
 "e" | "E")
  aptitude install bluez-gnome
  pause
  desktop_menu_more ;;
 "f" | "F")
  aptitude install sbackup
  pause
  desktop_menu_more ;;
 "j" | "J")
  audio_menu
  pause
  desktop_menu_more ;;
 "k" | "K")
  audio-editing
  pause
  desktop_menu_more ;;
 "l" | "L")
  ladspa
  pause
  desktop_menu_more ;;
 "m" | "M")
  video-edit
  pause
  desktop_menu_more ;;
 "n" | "N")
  copying-dvd-sarge
  pause
  desktop_menu_more ;;
 "n2" | "N2")
  copying-dvd-etch
  pause
  desktop_menu_more ;;
 "q" | "Q")
  top_menu ;;
 *)
  desktop_menu_more ;;
esac
}






wireless_menu_sarge()
{
clear
echo "==============================================================================="
echo " Wireless Networking - Sarge"
echo "==============================================================================="
echo "Linux Kernel Modules and Accompanying Utilities"
echo ""
echo "A. ACX100/ACX111 - source code for kernel module [contrib] (also need firmware)"
echo "B. Atmel at76c50x firmware [non-free] (kernel module included in kernel)"
echo "C. Intersil Prism2/2.5/3 Host AP utilities (kernel module included in kernel)"
echo "D. Intel IPW2100 'Centrino' source code for kernel module [contrib] (need fw)"
echo "E. Intel IPW2200 'Centrino' source code for kernel module [contrib] (need fw)"
echo "F. ndiswrapper"
echo "G. ndiswrapper kernel module for kernel 2.6.8-3 on 386"
echo "H. ndiswrapper kernel module for kernel 2.6.8-3 on 686"
echo "I. ndiswrapper kernel module for kernel 2.6.8-3 on K7"
echo "J. ndiswrapper utilities"
echo "-------------------------------------------------------------------------------"
echo "For Using The Device"
echo ""
echo "J. wireless tools + client support for WPA and WPA2 (IEEE 802.11i)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "
read WIRELESS_SARGE_CHOICE
clear

case "$WIRELESS_SARGE_CHOICE" in

 "a" | "A")
  aptitude install acx100-source
  pause
  wireless_menu_sarge ;;
 "b" | "B")
  aptitude install atmel-firmware
  pause
  wireless_menu_sarge ;;
 "c" | "C")
  aptitude install hostap-utils
  pause
  wireless_menu_sarge ;;
 "d" | "D")
  aptitude install ipw2100-source
  pause
  wireless_menu_sarge ;;
 "e" | "E")
  aptitude install ipw2200-source
  pause
  wireless_menu_sarge ;;
 "f" | "F")
  aptitude install ndiswrapper
  pause
  wireless_menu_sarge ;;
 "g" | "G")
  aptitude install ndiswrapper-modules-2.6.8-3-386
  pause
  wireless_menu_sarge ;;
 "h" | "H")
  aptitude install ndiswrapper-modules-2.6.8-3-686
  pause
  wireless_menu_sarge ;;
 "i" | "I")
  aptitude install ndiswrapper-modules-2.6.8-3-k7
  pause
  wireless_menu_sarge ;;
 "j" | "J")
  aptitude install ndiswrapper-utils
  pause
  wireless_menu_sarge ;;
 "k" | "K")
  aptitude install wireless-tools wpasupplicant
  pause
  wireless_menu_sarge ;;
 "q" | "Q")
    general_software_menu ;;
 *)
  wireless_menu_sarge ;;
esac
}







wireless_menu_etch()
{
clear
echo "==============================================================================="
echo " Wireless Networking - Etch"
echo "==============================================================================="
echo "Linux Kernel Modules and Accompanying Utilities"
echo ""
echo "A. ACX100/ACX111 - source code for kernel module [contrib] (also need firmware)"
echo "B. Atmel at76c50x - firmware for kernel module included in kernel [non-free]"
echo "C. Broadcom 43xx - utility for extracting firmware"
echo "D. Intersil Prism2/2.5/3 Host AP utilities (kernel module included in kernel)"
echo "E. Intel Centrino - IPW2100, IPW2200, IPW2915, IPW3945..."
echo "F. linux-wlan-ng for Intersil Prism2/2.5/3 + PLX9052 based PCI-PCMCIA adapter"
echo "   802.11b - source, firmware downloader [contrib], utilities, documentation"
echo "G. Atheros - madwifi source [non-free], tools [contrib], docs [non-free]"
echo "H. ndiswrapper common scripts required to use the utilities"
echo "I. ndiswrapper source"
echo "J. ndiswrapper utilities 1.1"
echo "K. ndiswrapper utilities 1.9"
echo "L. Ralink RT2400 kernel module source"
echo "M. Ralink RT2400 GUI"
echo "N. Ralink RT2500 kernel module source"
echo "O. Ralink RT2500 GUI"
echo "P. Ralink RT2570 kernel module source"
echo "R. Ralink RT2x00 (RT2400/2500/2570) kernel module source (experimental driver)"
echo "S. ZyDAS ZD1211 source [main], firmware [non-free]"
echo "-------------------------------------------------------------------------------"
echo "For Using The Device"
echo ""
echo "T. wireless tools + client support for WPA and WPA2 (IEEE 802.11i)"
echo "U. Network Manager and GNOME Network Manager [Gnomic]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "
read WIRELESS_ETCH_CHOICE
clear

case "$WIRELESS_ETCH_CHOICE" in

 "a" | "A")
  aptitude install acx100-source
  pause
  wireless_menu_etch ;;
 "b" | "B")
  aptitude install atmel-firmware
  pause
  wireless_menu_etch ;;
 "c" | "C")
  aptitude install bcm43xx-fwcutter
  pause
  wireless_menu_etch ;;
 "d" | "D")
  aptitude install hostap-utils
  pause
  wireless_menu_etch ;;
 "e" | "E")
  centrino_menu_etch
  pause
  wireless_menu_etch ;;
 "f" | "F")
  aptitude install linux-wlan-ng-source linux-wlan-ng-firmware linux-wlan-ng linux-wlan-ng-doc
  pause
  wireless_menu_etch ;;
 "g" | "G")
  aptitude install madwifi-source madwifi-tools madwifi-doc
  pause
  wireless_menu_etch ;;
 "h" | "H")
  aptitude install ndiswrapper-common
  pause
  wireless_menu_etch ;;
 "i" | "I")
  aptitude install ndiswrapper-source
  pause
  wireless_menu_etch ;;
 "j" | "J")
  aptitude install ndiswrapper-utils-1.1
  pause
  wireless_menu_etch ;;
 "k" | "K")
  aptitude install ndiswrapper-utils-1.9
  pause
  wireless_menu_etch ;;
 "l" | "L")
  aptitude install rt2400-source
  pause
  wireless_menu_etch ;;
 "m" | "M")
  aptitude install rt2400
  pause
  wireless_menu_etch ;;
 "n" | "N")
  aptitude install rt2500-source
  pause
  wireless_menu_etch ;;
 "o" | "O")
  aptitude install rt2500
  pause
  wireless_menu_etch ;;
 "p" | "P")
  aptitude install rt2570-source
  pause
  wireless_menu_etch ;;
 "q" | "Q")
  general_software_menu ;;
 "r" | "R")
  aptitude install rt2x00-source
  pause
  wireless_menu_etch ;;
 "s" | "S")
  aptitude install zd1211-source zd1211-firmware
  pause
  wireless_menu_etch ;;
 "t" | "T")
  aptitude install wireless-tools wpasupplicant
  pause
  wireless_menu_etch ;;
 "u" | "U")
  aptitude install network-manager network-manager-gnome
  pause
  wireless_menu_etch ;;
 *)
  wireless_menu_etch ;;
esac
}







centrino_menu_etch()
{
clear
echo "==============================================================================="
echo " Wireless Networking - Intel PRO/Wireless (IPW) 'Centrino' - Etch"
echo "==============================================================================="
echo "A. IPW2100 kernel module for Linux kernel 2.6 on 486"
echo "B. IPW2100 kernel module for Linux kernel 2.6 on 686"
echo "C. IPW2100 kernel module for Linux kernel 2.6 on 686-bigmem"
echo "D. IPW2100 kernel module for Linux kernel 2.6 on AMD64"
echo "E. IPW2100 kernel module for Linux kernel 2.6 on K7"
echo "F. IPW2100 source code for Linux kernel module [contrib]"
echo ""
echo "G. IPW2200 kernel module for Linux kernel 2.6 on 486"
echo "H. IPW2200 kernel module for Linux kernel 2.6 on 686"
echo "I. IPW2200 kernel module for Linux kernel 2.6 on 686-bigmem"
echo "J. IPW2200 kernel module for Linux kernel 2.6 on AMD64"
echo "K. IPW2200 kernel module for Linux kernel 2.6 on K7"
echo "L. IPW2200 source code for Linux kernel module [contrib]"
echo ""
echo "M. IPW3945 kernel module for Linux kernel 2.6 on 486"
echo "N. IPW3945 kernel module for Linux kernel 2.6 on 686"
echo "O. IPW3945 kernel module for Linux kernel 2.6 on 686-bigmem"
echo "P. IPW3945 kernel module for Linux kernel 2.6 on AMD64"
echo "R. IPW3945 kernel module for Linux kernel 2.6 on K7"
echo "S. IPW3945 binary firmware [non-free]"
echo "T. IPW3945 binary userspace regulatory daemon [non-free]"
echo "U. IPW3945 source code for Linux kernel module [contrib]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "
read CENTRINO_ETCH_CHOICE
clear

case "$CENTRINO_ETCH_CHOICE" in

 "a" | "A")
  aptitude install ipw2100-modules-2.6-486
  pause
  centrino_menu_etch ;;
 "b" | "B")
  aptitude install ipw2100-modules-2.6-686
  pause
  centrino_menu_etch ;;
 "c" | "C")
  aptitude install ipw2100-modules-2.6-686-bigmem
  pause
  centrino_menu_etch ;;
 "d" | "D")
  aptitude install ipw2100-modules-2.6-amd64
  pause
  centrino_menu_etch ;;
 "e" | "E")
  aptitude install ipw2100-modules-2.6-k7
  pause
  centrino_menu_etch ;;
 "f" | "F")
  aptitude install ipw2100-source
  pause
  centrino_menu_etch ;;
 "g" | "G")
  aptitude install ipw2200-modules-2.6-486
  pause
  centrino_menu_etch ;;
 "h" | "H")
  aptitude install ipw2200-modules-2.6-686
  pause
  centrino_menu_etch ;;
 "i" | "I")
  aptitude install ipw2200-modules-2.6-686-bigmem
  pause
  centrino_menu_etch ;;
 "j" | "J")
  aptitude install ipw2200-modules-2.6-amd64
  pause
  centrino_menu_etch ;;
 "k" | "K")
  aptitude install ipw2200-modules-2.6-k7
  pause
  centrino_menu_etch ;;
 "l" | "L")
  aptitude install ipw2200-source
  pause
  centrino_menu_etch ;;
 "m" | "M")
  aptitude install ipw3945-modules-2.6-486
  pause
  centrino_menu_etch ;;
 "n" | "N")
  aptitude install ipw3945-modules-2.6-686
  pause
  centrino_menu_etch ;;
 "o" | "O")
  aptitude install ipw3945-modules-2.6-686-bigmem
  pause
  centrino_menu_etch ;;
 "p" | "P")
  aptitude install ipw3945-modules-2.6-amd64
  pause
  centrino_menu_etch ;;
 "q" | "Q")
  desktop_menu_more ;;
 "r" | "R")
  aptitude install ipw3945-modules-2.6-k7
  pause
  centrino_menu_etch ;;
 "s" | "S")
  aptitude install firmware-ipw3945
  pause
  centrino_menu_etch ;;
 "t" | "T")
  aptitude install ipw3945d
  pause
  centrino_menu_etch ;;
 "u" | "U")
  aptitude install ipw3945-source
  pause
  centrino_menu_etch ;;
 *)
  centrino_menu_etch ;;
esac
}







audio_menu()
{
clear
echo "==============================================================================="
echo " Audio architectures"
echo "==============================================================================="
echo "A. ALSA - Advanced Linux Sound Architecture (alsa-base)"
echo "B. ALSA wrapper for OSS applications (alsa-oss)"
echo "C. ALSA utilities (alsa-utils)"
echo "-------------------------------------------------------------------------------"
echo "D. Utility programs for the AWE32/64 and Emu10k1 driver (awesfx)"
echo "-------------------------------------------------------------------------------"
echo "E. JACK Audio Connection Kit sound server (jackd)"
echo "F. JACK graphical interface (qjackctl, jackeq)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read AUDIO_CHOICE
clear

case "$AUDIO_CHOICE" in

 "a" | "A")
  aptitude install alsa-base
  pause
  audio_menu ;;
 "b" | "B")
  aptitude install alsa-oss
  pause
  audio_menu ;;
 "c" | "C")
  aptitude install alsa-utils
  pause
  audio_menu ;;
 "d" | "D")
  aptitude install awesfx
  pause
  audio_menu ;;
 "e" | "E")
  aptitude install jackd jack-tools
  pause
  audio_menu ;;
 "f" | "F")
  aptitude install qjackctl jackeq
  pause
  audio_menu ;;
 "q" | "Q")
  desktop_menu_more ;;
 *)
  audio_menu ;;
esac
}






database_menu()
{
clear
echo "==============================================================================="
echo "  Desktop databases"
echo "==============================================================================="
echo "A. openoffice.org Base (see OpenOffice section for related packages)"
echo "-------------------------------------------------------------------------------"
echo "E. text based client for accessing a remote MySQL server and documentation"
echo "   (mysql-client)"
echo "(for MySQL server, see the server section)"
echo "I. MySQL Administrator - GUI administration tool (mysql-admin) [GTK]"
echo "J. MySQL Query Browser - GUI database query tool (mysql-query-browser) [Gnomic]"
echo "-------------------------------------------------------------------------------"
echo "N. ODBC connector for connecting to a remote ODBC database (unixodbc)"
echo "-------------------------------------------------------------------------------"
echo "P. ODBC driver for MySQL; connect to MySQL db servers using ODBC (libmyodbc)"
echo "R. ODBC Configuration using a GUI (godbcconfig) [3.1/Sarge] [Gnomic]"
echo "-------------------------------------------------------------------------------"
echo "T. ODBC driver for PostgreSQL (odbc-postgresql)"
echo "-------------------------------------------------------------------------------"
echo "V. JET / MS Access database (MDB) tools and ODBC driver (mdbtools)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read DATABASE_CHOICE
clear

case "$DATABASE_CHOICE" in
 "a" | "A")
  aptitude install openoffice.org-base
  pause
  database_menu ;;
 "e" | "E")
  aptitude install mysql-client
  pause
  database_menu ;;
 "i" | "I")
  aptitude install mysql-admin
  pause
  database_menu ;;
 "j" | "J")
  aptitude install mysql-query-browser
  pause
  database_menu ;;
 "n" | "N")
  aptitude install unixodbc
  pause
  database_menu ;;
 "p" | "P")
  aptitude install libmyodbc
  pause
  database_menu ;;
 "r" | "R")
  aptitude install godbcconfig
  pause
  database_menu ;;
 "t" | "T")
  aptitude install odbc-postgresql
  pause
  database_menu ;;
 "v" | "V")
  aptitude install mdbtools
  pause
  database_menu ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  database_menu ;;
esac
}






linux_kernel_menu()
{
clear
echo "==============================================================================="
echo "  Debian Linux kernels for PCs (kernels for other architectures aren't covered)"
echo "==============================================================================="
echo "Latest Linux 2.6 series (for Etch/4.0 or Lenny/5.0) - optimised for:"
echo "A. all 486 compatible architectures (will work on all x86 machines)"
echo "B. Intel Pentium-Pro/Celeron/Pentium II/Pentium III/Pentium 4/Core/etcetera"
echo "C. AMD K7 (Athlon/Duron/Thunderbird)"
echo "D. Intel Pentium-Pro/Celeron/Pentium II/Pentium III/Pentium 4/Core w/4-64GB RAM"
echo "E. AMD64 (Intel IA-32e / EM64T / Intel 64)"
echo "-------------------------------------------------------------------------------"
echo "Latest Linux 2.6 series (for Debian 3.1 Sarge) - optimised for:"
echo "F. all 386 compatible architectures (will work on all x86 machines)"
echo "G. Intel Pentium-Pro/Celeron/Pentium II/Pentium III/Pentium IV"
echo "H. AMD K7 (Athlon/Duron/Thunderbird)"
echo "-------------------------------------------------------------------------------"
echo "I. Latest Linux 2.6.24 Etch'n'Half kernel auto optimised for your achitecture"
echo "Latest Linux 2.6.24 Etch'n'Half kernel - optimised for:"
echo "J. all 486 compatible architectures (will work on all x86 machines)"
echo "K. Intel Pentium-Pro/Celeron/Pentium II/Pentium III/Pentium 4/Core/etcetera"
echo "L. Intel Pentium-Pro/Celeron/Pentium II/Pentium III/Pentium 4/Core w/4-64GB RAM"
echo "M. AMD64 (Intel IA-32e / EM64T / Intel 64)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read KERNEL_CHOICE
clear

case "$KERNEL_CHOICE" in

 "a" | "A")
  linux-kernel-etch-486
  pause
  linux_kernel_menu ;;
 "b" | "B")
  linux-kernel-etch-686
  pause
  linux_kernel_menu ;;
 "c" | "C")
  linux-kernel-etch-k7
  pause
  linux_kernel_menu ;;
 "d" | "D")
  linux-kernel-etch-686-bigmem
  pause
  linux_kernel_menu ;;
 "e" | "E")
  linux-kernel-etch-amd64
  pause
  linux_kernel_menu ;;
 "f" | "F")
  linux-kernel-sarge-386
  pause
  linux_kernel_menu ;;
 "g" | "G")
  linux-kernel-sarge-686
  pause
  linux_kernel_menu ;;
 "h" | "H")
  linux-kernel-sarge-k7
  pause
  linux_kernel_menu ;;
 "i" | "I")
  linux-kernel-etchnhalf-generic
  pause
  linux_kernel_menu ;;
 "j" | "J")
  linux-kernel-etchnhalf-486
  pause
  linux_kernel_menu ;;
 "k" | "K")
  linux-kernel-etchnhalf-686
  pause
  linux_kernel_menu ;;
 "l" | "L")
  linux-kernel-etchnhalf-686-bigmem
  pause
  linux_kernel_menu ;;
 "m" | "M")
  linux-kernel-etchnhalf-amd64
  pause
  linux_kernel_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  linux_kernel_menu ;;
esac
}



##################################################################
x()
##################################################################
{
echo "X windows:"
echo ""
aptitude install read-edid mdetect x-window-system-core gdm
echo ""
}
#################################################################



##################################################################
gnome()
##################################################################
{
echo "Desktop Environment: GNOME:"
echo ""
aptitude install gnome menu baobab update-manager update-notifier

echo ""
}
##################################################################





##################################################################
package_management_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Package management"
echo "==============================================================================="
echo "A. Update the list of available packages (AKA update)"
echo "B. Upgrade installed packages to their most recent version."
echo "   Packages shouldn't be removed or new packages installed. (AKA upgrade)"
echo "C. Upgrade installed packages to their most recent version, removing or"
echo "   installing packages as necessary. (AKA dist-upgrade)"
echo "-------------------------------------------------------------------------------"
echo "D. Remove all previously downloaded .deb files from the package cache directory"
echo "E. Remove any cached packages which can no longer be downloaded"
echo "F. List installed packages"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read PACKAGE_MANAGEMENT_CHOICE
clear

case "$PACKAGE_MANAGEMENT_CHOICE" in
 "a" | "A")
  aptitude update
  pause
  package_management_menu ;;
 "b" | "B")
  aptitude upgrade
  pause
  package_management_menu ;;
 "c" | "C")
  aptitude dist-upgrade
  pause
  package_management_menu ;;
 "d" | "D")
  aptitude clean
  pause
  package_management_menu ;;
 "e" | "E")
  aptitude autoclean
  pause
  package_management_menu ;;
 "f" | "F")
  dpkg -l|more
  pause
  package_management_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  package_management_menu ;;
esac
}






##################################################################
official_repository_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Package Repository Configuration - Official Debian Repositories"
echo "==============================================================================="
echo "F. Add Debian Volatile repository - 3.1/Sarge - main and contrib"
echo "G. Add Debian Volatile repository - 4.0/Etch - main and contrib"
echo "(Note you'd be better to use a mirror server instead)"
echo "-------------------------------------------------------------------------------"
echo "J. Add Debian Volatile Sloppy repository - 3.1/Sarge - main and contrib"
echo "K. Add Debian Volatile Sloppy repository - 4.0/Etch - main and contrib"
echo "(Note you'd be better to use a mirror server instead)"
echo "-------------------------------------------------------------------------------"
echo "N. Add sarge-proposed-updates (main and contrib) [UK repository]"
echo "O. Add sarge-proposed-updates (main, contrib and non-free) [UK repository]"
echo "P. Add etch-proposed-updates (main and contrib) [UK repository]"
echo "R. Add etch-proposed-updates (main, contrib and non-free) [UK repository]"
echo "(Note you'd be better to use a mirror server instead) [UK repository]"
echo "-------------------------------------------------------------------------------"
echo "U. Debian Testing security updates"
echo "-------------------------------------------------------------------------------"
echo "Z. Install Debian archive keyring for package signing [4.0/Etch]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read REPOSITORY_CHOICE
clear

case "$REPOSITORY_CHOICE" in
 "f" | "F")
  volatile_sarge_main_contrib
  pause
  official_repository_menu ;;
 "g" | "G")
  volatile_etch_main_contrib
  pause
  official_repository_menu ;;
 "j" | "J")
  volatile_sloppy_sarge_main_contrib
  pause
  official_repository_menu ;;
 "k" | "K")
  volatile_sloppy_etch_main_contrib
  pause
  official_repository_menu ;;
 "n" | "N")
  proposed_updates_sarge_main_contrib
  pause
  official_repository_menu ;;
 "o" | "O")
  proposed_updates_sarge_main_contrib_nonfree
  pause
  official_repository_menu ;;
 "p" | "P")
  proposed_updates_etch_main_contrib
  pause
  official_repository_menu ;;
 "r" | "R")
  proposed_updates_etch_main_contrib_nonfree
  pause
  official_repository_menu ;;
 "u" | "U")
  testing_security_updates
  pause
  official_repository_menu ;;
 "z" | "Z")
  aptitude install debian-archive-keyring
  pause
  official_repository_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  official_repository_menu ;;
esac
}



##################################################################
other_repository_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Package Repository Configuration - Other Repositories"
echo "==============================================================================="
echo "A. Add backports.org repository - 4.0/Etch - main and contrib"
echo "B. Add backports.org repository - 4.0/Etch - main, contrib and non-free"
echo "(Note you'd be better to use a mirror server instead)"
echo "-------------------------------------------------------------------------------"
echo "E. Add debian-multimedia.org repository + keyring - 3.1/Sarge - i386/Sparc"
echo "F. Add debian-multimedia.org repository + keyring - 3.1/Sarge - amd64"
echo "G. Add debian-multimedia.org repository + keyring - 4.0/Etch - i386/ia64/"
echo "                                                    sparc/alpha/amd64/hppa"
echo "H. Add debian-multimedia.org repository + keyring - Lenny - same archs as Etch"
echo "I. Add debian-multimedia.org repository + keyring - Testing - same archs Etch"
echo "(Note you'd be better to use a mirror server instead)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read REPOSITORY_CHOICE
clear

case "$REPOSITORY_CHOICE" in
 "a" | "A")
  backports_org_etch_main_contrib
  pause
  other_repository_menu ;;
 "b" | "B")
  backports_org_etch_main_contrib_nonfree
  pause
  other_repository_menu ;;
 "e" | "E")
  debian_multimedia_sarge_i386_sparc
  pause
  other_repository_menu ;;
 "f" | "F")
  debian_multimedia_sarge_amd64
  pause
  other_repository_menu ;;
 "g" | "G")
  debian_multimedia_etch
  pause
  other_repository_menu ;;
 "h" | "H")
  debian_multimedia_lenny
  pause
  other_repository_menu ;;
 "i" | "I")
  debian_multimedia_testing
  pause
  other_repository_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  other_repository_menu ;;
esac
}




##################################################################
testing_security_updates()
##################################################################
{
echo "Adding the security updates repository (main) for Debian Testing..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Security updates repository for Debian Testing" >> /etc/apt/sources.list
echo "deb http://security.debian.org testing/updates main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################


##################################################################
proposed_updates_sarge_main_contrib()
##################################################################
{
echo "Adding the Debian proposed-updates repository (main and contrib)"
echo "for Debian 3.1/Sarge..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian proposed-updates repository for Debian 3.1/Sarge" >> /etc/apt/sources.list
echo "deb http://ftp.uk.debian.org/debian/ sarge-proposed-updates main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################


##################################################################
proposed_updates_sarge_main_contrib_nonfree()
##################################################################
{
echo "Adding the Debian proposed-updates repository (main, contrib and non-free)"
echo "for Debian 3.1/Sarge..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian proposed-updates repository for Debian 3.1/Sarge" >> /etc/apt/sources.list
echo "deb http://ftp.uk.debian.org/debian/ sarge-proposed-updates main contrib non-free" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################


##################################################################
proposed_updates_etch_main_contrib()
##################################################################
{
echo "Adding the Debian proposed-updates repository (main and contrib)"
echo "for Debian 4.0/Etch..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian proposed-updates repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://ftp.uk.debian.org/debian/ etch-proposed-updates main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################


##################################################################
proposed_updates_etch_main_contrib_nonfree()
##################################################################
{
echo "Adding the Debian proposed-updates repository (main, contrib and non-free)"
echo "for Debian 4.0/Etch..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian proposed-updates repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://ftp.uk.debian.org/debian/ etch-proposed-updates main contrib non-free" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################




##################################################################
volatile_sarge_main_contrib()
##################################################################
{
echo "Adding the Debian Volatile repository (main and contrib)"
echo "for Debian 3.1/Sarge..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Volatile repository for Debian 3.1/Sarge" >> /etc/apt/sources.list
echo "deb http://volatile.debian.org/debian-volatile sarge/volatile main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################



##################################################################
volatile_etch_main_contrib()
##################################################################
{
echo "Adding the Debian Volatile repository (main and contrib)"
echo "for Debian 4.0/Etch..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Volatile repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://volatile.debian.org/debian-volatile etch/volatile main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################



##################################################################
volatile_sloppy_sarge_main_contrib()
##################################################################
{
echo "Adding the Debian Volatile Sloppy repository (main and "
echo "contrib) for Debian 3.1/Sarge..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Volatile Sloppy repository for Debian 3.1/Sarge" >> /etc/apt/sources.list
echo "deb http://volatile.debian.org/debian-volatile sarge/volatile-sloppy main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################



##################################################################
volatile_sloppy_etch_main_contrib()
##################################################################
{
echo "Adding the Debian Volatile Sloppy repository (main and "
echo "contrib) for Debian 4.0/Etch..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Volatile Sloppy repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://volatile.debian.org/debian-volatile etch/volatile-sloppy main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo ""
}
##################################################################




##################################################################
debian_multimedia_etch()
##################################################################
{
echo "Adding the debian-multimedia.org repository for"
echo "Debian 4.0/Etch, i386/ia64/sparc/alpha/amd64/hppa "
echo "architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Multimedia repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://www.debian-multimedia.org etch main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo "Adding debian-multimedia keyring for Apt signing..."
echo aptitude install debian-multimedia-keyring
echo ""
}
##################################################################



##################################################################
debian_multimedia_lenny()
##################################################################
{
echo "Adding the debian-multimedia.org repository for"
echo "Debian Lenny, i386/ia64/sparc/alpha/amd64/hppa "
echo "architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Multimedia repository for Debian Lenny" >> /etc/apt/sources.list
echo "deb http://www.debian-multimedia.org lenny main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo "Adding debian-multimedia keyring for Apt signing..."
echo aptitude install debian-multimedia-keyring
echo ""
}
##################################################################



##################################################################
debian_multimedia_testing()
##################################################################
{
echo "Adding the debian-multimedia.org repository for"
echo "Debian Testing, i386/ia64/sparc/alpha/amd64/hppa "
echo "architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Multimedia repository for Debian Testing" >> /etc/apt/sources.list
echo "deb http://www.debian-multimedia.org testing main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo "Adding debian-multimedia keyring for Apt signing..."
echo aptitude install debian-multimedia-keyring
echo ""
}
##################################################################


##################################################################
debian_multimedia_sarge_i386_sparc()
##################################################################
{
echo "Adding the debian-multimedia.org repository for"
echo "Debian 3.1/Sarge, i386 and Sparc architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Multimedia repository for Debian 3.1/Sarge (i386 and Sparc architectures)" >> /etc/apt/sources.list
echo "deb http://mirror.home-dn.net/debian-multimedia sarge main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update

echo ""
}
##################################################################


##################################################################
debian_multimedia_sarge_amd64()
##################################################################
{
echo "Adding the debian-multimedia.org repository for"
echo "Debian 3.1/Sarge, amd64 architecture..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Debian Multimedia repository for Debian 3.1/Sarge (amd64 architecture)" >> /etc/apt/sources.list
echo "deb http://cyberspace.ucla.edu/marillat/ sarge main" >> /etc/apt/sources.list
echo "deb http://mirror.home-dn.net/debian-multimedia sarge main" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update

echo ""
}
##################################################################



##################################################################
backports_org_etch_main_contrib()
##################################################################
{
echo "Adding the backports.org repository (main, contrib) for"
echo "Debian 4.0/Etch, i386 and Sparc architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Backports.org repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://www.backports.org/debian etch-backports main contrib" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo "Installing backports.org's archive key..."
aptitude install debian-backports-keyring

echo ""
}
##################################################################
  

##################################################################
backports_org_etch_main_contrib_nonfree()
##################################################################
{
echo "Adding the backports.org repository"
echo "(main, contrib and non-free) for Debian 4.0/Etch, "
echo "i386 and Sparc architectures..."
echo ""

echo "" >> /etc/apt/sources.list
echo "# Backports.org repository for Debian 4.0/Etch" >> /etc/apt/sources.list
echo "deb http://www.backports.org/debian etch-backports main contrib non-free" >> /etc/apt/sources.list
echo ""

echo "Updating the list of available packages..."
aptitude update
echo ""

echo "Installing backports.org's archive key..."
aptitude install debian-backports-keyring

echo ""
}
##################################################################





##################################################################
xfce_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " XFCE lightweight desktop environment"
echo "==============================================================================="
echo "A. XFCE - core"
echo ""
echo "B. XFCE - some plug-ins"
echo "(datetime, iconbox [3.1/Sarge only], minicmd, mixer,"
echo "showdesktop [3.1/Sarge only], terminal, xfprint4, xfce4-appfinder)"
echo ""
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read XFCE_CHOICE
clear

case "$XFCE_CHOICE" in
 "a" | "A")
  xfce_core
  pause
  xfce_menu ;;
 "b" | "B")
  xfce_plugins
  pause
  xfce_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  xfce_menu ;;
esac
}
##################################################################


##################################################################
xfce_core()
##################################################################
{
echo "Desktop Environment: XFCE - core:"
echo ""
aptitude install xfce4
echo ""
}
##################################################################


##################################################################
xfce_plugins()
##################################################################
{
echo "Desktop Environment: XFCE - components:"
echo "(Note: xfce4-iconbox and xfce4-showdesktop-plugin are only required in Debian 3.1/Sarge)"
echo ""
aptitude install xfce4-datetime-plugin xfce4-iconbox xfce4-minicmd-plugin xfce4-mixer xfce4-showdesktop-plugin xfce4-terminal xfprint4 xfce4-appfinder
echo""
}
##################################################################
##################################################################



##################################################################
minor_software()
##################################################################
{
echo "Minor command-line tools:"
echo ""
aptitude install traceroute tcpdump zip unzip tree less lynx pwgen nmap wipe
echo ""
}



##################################################################
office_suite_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Office suite"
echo "==============================================================================="
echo "A. OpenOffice.org (word processor, spreadsheet, presentation)..."
echo "-------------------------------------------------------------------------------"
echo "L. Abiword (word processor)"
echo "M. Scribus 1.2 series (layout) (docs require non-free)"
echo "M2. Scribus 1.3 development series (layout) (docs require non-free) [4.0/Etch]"
echo "N. Xpdf - lightweight, fast, PDF viewer; alternative to Gpdf. [X]"
echo "-------------------------------------------------------------------------------"
echo "P. Typefaces/fonts - various"
echo "R. Typefaces/fonts - Microsoft TrueType Core Fonts [contrib]"
echo "-------------------------------------------------------------------------------"
echo "S. Aspell spellchecker (for Abiword/Evolution/Gaim)"
echo "*. Myspell spellchecker (for OpenOffice/Mozilla) is built in"
echo "-------------------------------------------------------------------------------"
echo "T. Aspell spellchecker dictionary - English"
echo "U. Myspell spellchecker dictionary - En-GB"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read EDITORS_CHOICE
clear

case "$EDITORS_CHOICE" in
 "a" | "A")
  openoffice_menu
  pause
  office_suite_menu ;;
 "l" | "L")
  aptitude install abiword abiword-plugins abiword-plugins-gnome abiword-help
  pause
  office_suite_menu ;;
 "m" | "M")
  aptitude install scribus scribus-template scribus-doc
  pause
  office_suite_menu ;;
 "m2" | "M2")
  aptitude install scribus-ng scribus-template scribus-ng-doc
  pause
  office_suite_menu ;;
 "n" | "N")
  aptitude install xpdf
  pause
  office_suite_menu ;;
 "p" | "P")
  aptitude install ttf-freefont ttf-bitstream-vera
  pause
  office_suite_menu ;;
 "r" | "R")
  aptitude install msttcorefonts
  pause
  office_suite_menu ;;
 "s" | "S")
  aptitude install aspell aspell-doc
  pause
  office_suite_menu ;;
 "t" | "T")
  aptitude install aspell-en
  pause
  office_suite_menu ;;
 "u" | "U")
  aptitude install myspell-en-gb
  pause
  office_suite_menu ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  office_suite_menu ;;
esac
}
##################################################################





##################################################################
openoffice_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Openoffice"
echo "==============================================================================="
echo "A. OpenOffice.org (word processor, spreadsheet, presentation) [3.1/Sarge]"
echo "A2. OpenOffice.org (word pro., spreadsheet, presentation, database) [4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "B  OpenOffice.org help - English [3.1/Sarge]"
echo "B2  OpenOffice.org help - English (GB) [4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "C. OpenOffice.org GNOME integration [3.1/Sarge]"
echo "C2. OpenOffice.org GNOME and GTK integration [4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "D. OpenOffice.org hyphenation (En-GB) [3.1/Sarge; contrib]"
echo "E. OpenOffice.org thesaurus (En-US) (en-UK avail. soon? bug 280992)"
echo "-------------------------------------------------------------------------------"
echo "F. OpenOffice.org Evolution integration"
echo "G. OpenOffice.org KDE integration"
echo "H. OpenOffice.org GTK integration (for XFCE) [4.0/Etch]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read OPENOFFICE_CHOICE
clear

case "$OPENOFFICE_CHOICE" in
 "a" | "A")
  aptitude install openoffice.org openoffice.org-mimelnk
  pause
  openoffice_menu ;;
 "a2" | "A2")
  aptitude install openoffice.org
  pause
  openoffice_menu ;;
 "b" | "B")
  aptitude install openoffice.org-help-en
  pause
  openoffice_menu ;;
 "b2" | "B2")
  aptitude install openoffice.org-help-en-gb
  pause
  openoffice_menu ;;
 "c" | "C")
  aptitude install openoffice.org-gtk-gnome openoffice.org-gnomevfs
  pause
  openoffice_menu ;;
 "c2" | "C2")
  aptitude install openoffice.org-gnome
  pause
  openoffice_menu ;;
 "d" | "D")
  aptitude install openoffice.org-hyphenation-en-gb
  pause
  openoffice_menu ;;
 "e" | "E")
  aptitude install openoffice.org-thesaurus-en-us
  pause
  openoffice_menu ;;
 "f" | "F")
  aptitude install openoffice.org-evolution
  pause
  openoffice_menu ;;
 "g" | "G")
  aptitude install openoffice.org-kde
  pause
  openoffice_menu ;;
 "h" | "H")
  aptitude install openoffice.org-gtk
  pause
  openoffice_menu ;;
 "q" | "Q")
  office_suite_menu ;;
 *)
  openoffice_menu ;;
esac
}



##################################################################
web-edit-sarge()
##################################################################
{
echo "Web editing (bluefish tidy tidy-doc weblint-perl php4-cli libxml2-utils):"
echo ""
aptitude install bluefish tidy tidy-doc weblint-perl libxml2-utils
echo ""
}
##################################################################


##################################################################
web-edit-etch()
##################################################################
{
echo "Web editing (bluefish tidy tidy-doc weblint-perl php5-cli libxml2-utils):"
echo ""
aptitude install bluefish tidy tidy-doc weblint-perl php5-cli libxml2-utils
echo ""
}
##################################################################



##################################################################
internet_apps_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Internet (client) applications"
echo "==============================================================================="
echo "A. Lynx command-line web browser"
echo "B. Mozilla Firefox / Iceweasel (web browser) and plug-ins..."
echo "C. Mozilla Thunderbird / IceDove (email) and plug-ins..."
echo "H. Evolution (email, groupware) + Exchange & webcal plug-ins"
echo "M. XChat (IRC)"
echo "M2. XChat-GNOME (IRC) [Etch/4.0]"
echo "N. Gaim (instant messaging)"
echo "O. gFTP (multi-protocol file transfer)"
echo "P. Sylpheed Claws (light email client), spam/virus plugins [Gnomic; 4.0/Etch]"
echo "P2. Sylpheed Claws GTK2 (light email client), spam/virus plugins [4.0/Etch]"
echo "R. Firestarter firewall"
echo "S. tsclient + support for VNC, RDP, XDMCP; remove grdesktop [4.0/Etch]"
echo "T. Liferea (RSS reader) [Gnomic]"
echo "U. Freeloader (torrent / Bittorrent downloader) [Gnomic]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read INTERNET_APPS_CHOICE
clear

case "$INTERNET_APPS_CHOICE" in
 "a" | "A")
  aptitude install lynx
  pause
  internet_apps_menu ;;
 "b" | "B")
  firefox_menu ;;
 "c" | "C")
  thunderbird_menu ;;
 "h" | "H")
  aptitude install evolution evolution-exchange evolution-webcal
  pause
  internet_apps_menu ;;
 "m" | "M")
  aptitude install xchat
  pause
  internet_apps_menu ;;
 "m2" | "M2")
  aptitude install xchat-gnome
  pause
  internet_apps_menu ;;
 "n" | "N")
  aptitude install gaim
  pause
  internet_apps_menu ;;
 "o" | "O")
  aptitude install gftp-gtk
  pause
  internet_apps_menu ;;
 "p" | "P")
  aptitude install sylpheed-claws sylpheed-claws-doc sylpheed-claws-clamav sylpheed-claws-spamassassin
  pause
  internet_apps_menu ;;
 "p2" | "P2")
  aptitude install sylpheed-claws-gtk2 sylpheed-claws-gtk2-doc sylpheed-claws-gtk2-clamav sylpheed-claws-gtk2-spamassassin
  pause
  internet_apps_menu ;;
 "r" | "R")
  aptitude install firestarter
  pause
  internet_apps_menu ;;
 "s" | "S")
  aptitude install tsclient xvnc4viewer rdesktop xnest
  aptitude remove grdesktop
  pause
  internet_apps_menu ;;
 "t" | "T")
  aptitude install liferea
  pause
  internet_apps_menu ;;
 "u" | "U")
  aptitude install freeloader
  pause
  internet_apps_menu ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  internet_apps_menu ;;
esac
}
##################################################################





##################################################################
firefox_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Mozilla Firefox / Iceweasel (web browser) and plug-ins"
echo "==============================================================================="
echo "A. Mozilla Firefox (web browser) [3.1/Sarge]"
echo "B. Mozilla Firefox (GNOME integration) [3.1/Sarge]"
echo "C. Mozilla Firefox En-GB locale [3.1/Sarge]"
echo "D. Mozilla Firefox DOM inspector [3.1/Sarge]"
echo "-------------------------------------------------------------------------------"
echo "I. Iceweasel (AKA Mozilla Firefox) (web browser) [4.0/Etch]"
echo "J. Iceweasel (AKA Mozilla Firefox) (GNOME integration) [4.0/Etch]"
echo "K. Iceweasel (AKA Mozilla Firefox) En-GB locale [4.0/Etch]"
echo "L. Iceweasel (AKA Mozilla Firefox) DOM inspector [4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "R. Macromedia Flash plug-in [Non-free]"
echo "S. Mozilla Venkman JavaScript debugger - Firefox/Iceweasel/Thunderbird/IceDove"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read INTERNET_APPS_CHOICE
clear

case "$INTERNET_APPS_CHOICE" in
 "a" | "A")
  aptitude install firefox latex-xft-fonts
  pause
  firefox_menu ;;
 "b" | "B")
  aptitude install firefox-gnome-support latex-xft-fonts
  pause
  firefox_menu ;;
 "c" | "C")
  aptitude install firefox-locale-en-gb latex-xft-fonts
  pause
  firefox_menu ;;
 "d" | "D")
  aptitude install firefox-dom-inspector
  pause
  firefox_menu ;;
 "i" | "I")
  aptitude install iceweasel latex-xft-fonts
  echo "Note that latex-xft-fonts will fail to install on Debian Etch"
  pause
  firefox_menu ;;
 "j" | "J")
  aptitude install iceweasel-gnome-support latex-xft-fonts
  echo "Note that latex-xft-fonts will fail to install on Debian Etch"
  pause
  firefox_menu ;;
 "k" | "K")
  aptitude install iceweasel-l10n-en-gb  latex-xft-fonts
  echo "Note that latex-xft-fonts will fail to install on Debian Etch"
  pause
  firefox_menu ;;
 "l" | "L")
  aptitude install iceweasel-dom-inspector
  pause
  firefox_menu ;;
 "r" | "R")
  aptitude install flashplugin-nonfree
  pause
  firefox_menu ;;
 "s" | "S")
  aptitude install mozilla-venkman
  pause
  firefox_menu ;;
 "q" | "Q")
  internet_apps_menu ;;
 *)
  thunderbird_menu ;;
esac
}
##################################################################



##################################################################
thunderbird_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Mozilla Thunderbird / IceDove (mail client) and plug-ins"
echo "==============================================================================="
echo "A. Mozilla Thunderbird (email) [3.1/Sarge]"
echo "B. Mozilla Thunderbird Enigmail plug-in [3.1/Sarge]"
echo "-------------------------------------------------------------------------------"
echo "F. IceDove (AKA Mozilla Thunderbird) (email) [4.0/Etch]"
echo "G. IceDove (AKA Mozilla Thunderbird) (GNOME integration) [4.0/Etch]"
echo "H. IceDove (AKA Mozilla Thunderbird) En-GB locale [4.0/Etch]"
echo "I. IceDove (AKA Mozilla Thunderbird) Enigmail plug-in [4.0/Etch]"
echo "-------------------------------------------------------------------------------"
echo "S. Mozilla Venkman JavaScript debugger - Firefox/Iceweasel/Thunderbird/IceDove"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read INTERNET_APPS_CHOICE
clear

case "$INTERNET_APPS_CHOICE" in
 "a" | "A")
  aptitude install mozilla-thunderbird
  pause
  thunderbird_menu ;;
 "b" | "B")
  aptitude install mozilla-thunderbird-enigmail
  pause
  thunderbird_menu ;;
 "f" | "F")
  aptitude install icedove
  pause
  thunderbird_menu ;;
 "g" | "G")
  aptitude install icedove-gnome-support
  pause
  thunderbird_menu ;;
 "h" | "H")
  aptitude install icedove-locale-en-gb 
  pause
  thunderbird_menu ;;
 "i" | "I")
  aptitude install enigmail
  pause
  thunderbird_menu ;;
 "q" | "Q")
  internet_apps_menu ;;
 "s" | "S")
  aptitude install mozilla-venkman
  pause
  thunderbird_menu ;;
 *)
  thunderbird_menu ;;
esac
}
##################################################################




##################################################################
image-viewing()
##################################################################
{
echo "Image viewing:"
echo ""
aptitude install gthumb
echo ""
}
##################################################################



##################################################################
image_editing_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Image editing"
echo "==============================================================================="
echo "A. GIMP (English-specific), including help and support for printing"
echo ""
echo "B. GIMP extra brushes, palettes, and gradients"
echo ""
echo "C. GIMP gtkam plug-in, for digital still cameras supported by"
echo "   gphoto"
echo ""
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read IMAGE_EDIT_CHOICE
clear

case "$IMAGE_EDIT_CHOICE" in
 "a" | "A")
  image_editing_gimp
  pause
  image_editing_menu ;;
 "b" | "B")
  image_editing_gimp_data_extras
  pause
  image_editing_menu ;;
 "c" | "C")
  image_editing_gimp_gtkam
  pause
  image_editing_menu ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  image_editing_menu ;;
esac
}


##################################################################
image_editing_gimp()
##################################################################
{
echo "Image editing - GIMP - (English-specific):"
echo ""
aptitude install gimp gimp-helpbrowser gimp-help-en gimp-print
echo ""
}
##################################################################


##################################################################
image_editing_gimp_data_extras()
##################################################################
{
echo "Image editing - GIMP - extra brushes, palettes, and gradients:"
echo ""
aptitude install gimp-data-extras
echo ""
}
##################################################################


##################################################################
image_editing_gimp_gtkam()
##################################################################
{
echo "Image editing - GIMP - :"
echo ""
aptitude install gtkam-gimp
echo ""
}
##################################################################


##################################################################
audio-editing()
##################################################################
{
echo "Audio editing:"
echo ""
aptitude install audacity alsa-oss tap-plugins swh-plugins ladspa-sdk cmt caps blop ladspa-plugin
echo ""
}

##################################################################
ladspa()
##################################################################
{
echo "LADSPA sound effetcts:"
echo ""
aptitude install tap-plugins swh-plugins ladspa-sdk cmt caps blop ladspa-plugin ladspa-plugins
echo ""
echo "(In case this is Debian 3.1/Sarge, we try to install ladspa-plugins"
echo "which it has as a seperate package that merged into ladspa-plugin"
echo "for Debian 4.0/Etch)"
echo ""
}

##################################################################
jre()
##################################################################
{
echo "Java Runtime Environment (JRE) builder:"
echo ""
aptitude install java-package
echo ""
echo "You'll need to do some manual steps to get the Java Runtime"
echo "Environment running: download the JRE; create the Debian"
echo "package with make-jpkg; install the package."
echo "See http://thegoldenear.org/toolbox/unices/desktop-system-setup-debian-testing.html#jre"
echo "or http://thegoldenear.org/toolbox/unices/desktop-system-setup-debian-sarge.html#jre"
echo ""
}


##################################################################
jre5()
##################################################################
{
echo "Sun Java Platform Standard Edition Runtime Environment 5.0 and plug-in for browsers:"
echo ""
aptitude install sun-java5-jre and sun-java5-plugin
echo ""
}


##################################################################
audio()
##################################################################
{
echo "Sound:"
echo ""
aptitude install alsa-base alsa-utils
echo ""
}


##################################################################
printing()
##################################################################
{
clear
echo "==============================================================================="
echo "               Debian Desktop System Setup - CUPS Printing"
echo "==============================================================================="
echo "Packages for printing to local printers"
echo "-------------------------------------------------------------------------------"
echo "A. CUPS server"
echo "B. CUPS drivers..."
echo "C. Foomatic database for various print drivers..."
echo "D. Foomatic PPD files..."
echo "E. The Foomatic print filter system (another package may have pulled it in)"
echo "F. A GNOME-based Foomatic interface"
echo "G. Printconf - auto setup of parallel & USB printers with CUPS"
echo "H. Maintenance utility for Epson Stylus printers"
echo ""
echo "Packages for printing to local or remote printers"
echo "-------------------------------------------------------------------------------"
echo "I. Various"
echo "   (cupsys-client, cupsys-pt, cupsys-bsd, gs-esp (ESP Ghostscript), psfontmgr,"
echo "    a2ps, enscript, smbclient)"
echo ""
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read PRINTER_CHOICE
clear

case "$PRINTER_CHOICE" in
 "a" | "A")
  printing-cups-server
  pause
  printing ;;
 "b" | "B")
  cups
  pause
  printing ;;
 "c" | "C")
  foomatic-drivers
  pause
  printing ;;
 "d" | "D")
  foomatic-ppd
  pause
  printing ;;
 "e" | "E")
  echo "Installing the Foomatic system..."
  aptitude install foomatic-db-engine netcat
  pause
  printing ;;
 "f" | "F")
  echo "Installing a GNOME-based Foomatic interface..."
  aptitude install foomatic-gui netcat nmap smbclient pconf-detect
  pause
  printing ;;
 "g" | "G")
  echo "Installing a GNOME-based Foomatic interface..."
  aptitude install printconf
  pause
  printing ;;
 "h" | "H")
  printing-epson
  pause
  printing ;;
 "i" | "I")
  printing-general
  pause
  printing ;;
 "q" | "Q")
  top_menu ;;
 *)
  printing ;;
esac
}



##################################################################
cups()
##################################################################
{
clear
echo "==============================================================================="
echo "            Debian Desktop System Setup - CUPS Print Drivers"
echo "==============================================================================="
echo "A. Gimp-Print [Sarge/3.1] (for Epson, Canon, Lexmark, +)"
echo ""
echo "B. Gutenprint [Etch/4.0] (for Epson, Canon, Lexmark, +)"
echo ""
echo "C. HPIJS (HP JetDirect, USB SFP InkJet, some LaserJets)"
echo ""
echo "D. HPLIP (HP JetDirect, USB SFP InkJet, some LaserJets,"
echo "   scanning and photo-card access on most HP MFP)"
echo ""
echo "E. HPOJ (parallel MFP incl. OfficeJet, some LaserJets,"
echo "   PSC and PhotoSmart) - not widely recommended"
echo ""
echo "F. PNM2PPA - HP Deskjet 7xx, 820 and 1000 printers"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read CUPS_CHOICE
clear

case "$CUPS_CHOICE" in
 "a" | "A")
  printing-gimpprint
  pause
  cups ;;
 "b" | "B")
  printing-gutenprint
  pause
  cups ;;
 "c" | "C")
  printing-hpijs
  pause
  cups ;;
 "d" | "D")
  printing-hplip
  pause
  cups ;;
 "e" | "E")
  printing-hpoj
  pause
  cups ;;
 "f" | "F")
  printing-pnm2ppa
  pause
  cups ;;
 "q" | "Q")
  printing ;;
 *)
  cups ;;
esac
}



##################################################################
foomatic-drivers()
##################################################################
{
clear
echo "==============================================================================="
echo " Debian Desktop System Setup - Interface between Foomatic & print driver"
echo "==============================================================================="
echo "A. Foomatic support for printers using Gimp-Print [Sarge/3.1]"
echo "   or Gutenprint [Etch/4.0]"
echo ""
echo "B. Foomatic support for printers using HPIJS"
echo ""
echo "C. Support for printing to ZjStream-based printers (foo2zjs)"
echo "   (Minolta/QMS magicolor 2200 DL/2300 DL, Konica Minolta 2430 DL,"
echo "   Minolta Color PageWorks/Pro L and HP LaserJet 1000/1005/1018/1020/1022)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read FOOMATICDRIVERS_CHOICE
clear

case "$FOOMATICDRIVERS_CHOICE" in
 "a" | "A")
  printing-foomatic-db-gutenprint
  pause
  foomatic-drivers ;;
 "b" | "B")
  printing-foomatic-db-hpijs
  pause
  foomatic-drivers ;;
 "c" | "C")
  printing-foo2zjs
  pause
  foomatic-drivers ;;
 "q" | "Q")
  printing ;;
 *)
  foomatic-drivers ;;
esac
}




##################################################################
foomatic-ppd()
##################################################################
{
clear
echo "==============================================================================="
echo " Debian Desktop System Setup - Foomatic PPD files"
echo "==============================================================================="
echo "A. PPD files for printers supported through the HPLIP/HPIJS driver."
echo "   (for non-PostScript printers) [Etch/4.0]"
echo ""
echo "B. All prebuilt PPD files available from linuxprinting.org"
echo "   (for non-PostScript printers)"
echo ""
echo "-------------------------------------------------------------------------------"
echo ""
echo "C. linuxprinting.org manufacturer supplied PPD files"
echo "   (for PostScript printers) [Etch/4.0]"
echo ""
echo "D.  PPDs for HP printers not in the linuxprinting.org manufacturer supplied PPD"
echo "    files package (for PostScript printers) [Sarge/3.1, Etch/4.0]"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read FOOMATICPPD_CHOICE
clear

case "$FOOMATICPPD_CHOICE" in
 "a" | "A")
  aptitude install hplip-ppds
  pause
  foomatic-ppd ;;
 "b" | "B")
  aptitude install foomatic-filters-ppds
  pause
  foomatic-ppd ;;
 "c" | "C")
  aptitude install linuxprinting.org-ppds
  pause
  foomatic-ppd ;;
 "d" | "D")
  aptitude install hp-ppd
  pause
  foomatic-ppd ;;
 "q" | "Q")
  printing ;;
 *)
  foomatic-ppd ;;
esac
}




##################################################################
printing-cups-server()
##################################################################
{
echo "Printing - CUPS server:"
echo ""
aptitude install cupsys
echo ""
}


##################################################################
printing-gimpprint()
##################################################################
{
echo "Printing - Gimp-Print for Debian 3.1 Sarge:"
echo ""
aptitude install cupsys-driver-gimpprint gimpprint-locales gimpprint-doc
echo ""
echo ""
}


##################################################################
printing-gutenprint()
##################################################################
{
echo "Printing - Gutenprint for Etch/4.0:"
echo ""
aptitude install cupsys-driver-gutenprint gutenprint-locales gutenprint-doc
echo ""
}


##################################################################
printing-hpijs()
##################################################################
{
echo "Printing - hpijs:"
echo ""
aptitude install hpijs
echo ""
}


##################################################################
printing-hplip()
##################################################################
{
echo "Printing - hplip:"
echo ""
aptitude install hplip
echo ""
}


##################################################################
printing-hpoj()
##################################################################
{
echo "Printing - hpoj:"
echo ""
aptitude install hpoj
echo ""
}



##################################################################
printing-pnm2ppa()
##################################################################
{
echo "Printing - pnm2ppa:"
echo ""
aptitude install pnm2ppa psutils
echo ""
}


##################################################################
printing-epson()
##################################################################
{
echo "Printing - utility for Epson Stylus printers:"
echo ""
aptitude install escputil
echo ""
}


##################################################################
printing-general()
##################################################################
{
echo "Printing - required packages for either local or remote printers:"
echo ""
aptitude install cupsys-client cupsys-pt cupsys-bsd gs-esp psfontmgr a2ps enscript smbclient
echo ""
}


##################################################################
printing-foomatic-db-gutenprint()
##################################################################
{
echo "Printing - :"
echo ""
aptitude install foomatic-db-gutenprint foomatic-db-gimpprint
echo ""
}


##################################################################
printing-foomatic-db-hpijs()
##################################################################
{
echo "Printing - :"
echo ""
aptitude install foomatic-db-hpijs
echo ""
}


##################################################################
printing-foo2zjs()
##################################################################
{
echo "Printing - :"
echo ""
aptitude install foo2zjs
echo ""
}



##################################################################
printing-foomatic-filters-ppds()
##################################################################
{
echo "Printing - PPD files for non-PostScript printers:"
echo ""
aptitude install foomatic-filters-ppds
echo ""
}


##################################################################
printing-linuxprinting.org-ppds()
##################################################################
{
echo "Printing - linuxprinting.org manufacturer supplied PPD files for PostScript printers:"
echo ""
aptitude install linuxprinting.org-ppds
echo ""
}


##################################################################
printing-hp-ppd()
##################################################################
{
echo "Printing - PPD files for PostScript printers:"
echo ""
aptitude install hp-ppd
echo ""
}


##################################################################
printing-foomatic()
##################################################################
{
echo "Printing - :"
echo ""
aptitude install foomatic-db-engine netcat
echo ""
}


##################################################################
printing-foomatic-gnome()
##################################################################
{
echo "Printing - GNOME-based Foomatic interface:"
echo ""
aptitude install foomatic-gui netcat nmap smbclient pconf-detect
echo ""
}


##################################################################
printing-printconf()
##################################################################
{
echo "Printing - printconf - auto setup for parallel and USB port printers:"
echo ""
aptitude install printconf
echo ""
}






##################################################################
scanning()
##################################################################
{
clear
echo "==============================================================================="
echo "               Scanning"
echo "==============================================================================="
echo "A. Sane - the driver required if scanner directly attached"
echo ""
echo "B. some backends (drivers) not yet included in Sane"
echo "-------------------------------------------------------------------------------"
echo ""
echo "C. XSane - the graphical scanning software"
echo ""
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read SCANNING_CHOICE
clear

case "$SCANNING_CHOICE" in
 "a" | "A")
  scanning_sane
  pause
  scanning ;;
 "b" | "B")
  scanning_extras
  pause
  scanning ;;
 "c" | "C")
  scanning_xsane
  pause
  scanning ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  scanning ;;
esac
}



##################################################################
scanning_sane()
##################################################################
{
echo "Sane:"
echo ""
aptitude install sane
echo ""
}


##################################################################
scanning_extras()
##################################################################
{
echo "Sane - extra backends"
echo ""
aptitude install libsane-extras
echo ""
}


##################################################################
scanning_xsane()
##################################################################
{
echo "XSane:"
echo ""
aptitude install xsane
echo ""
}



##################################################################
camera_menu()
##################################################################
{
clear
echo "==============================================================================="
echo " Cameras"
echo "==============================================================================="
echo "A. Digital camera (with USB interface) - command-line interface (gtkam)"
echo ""
echo "B. Digital camera (with USB interface) - GNOME interface (gphoto)"
echo ""
echo "C. Digital video camera (with IEEE1394/Firewire/i.Link)"
echo "   (DV / camcorder / cameras with tapes) capture and"
echo "   non-linear editing - Kino [GTK]"
echo ""
echo "D. Digital video camera (with IEEE1394/Firewire/i.Link)"
echo "   (DCAM / IIDC) capture - Coriander [GTK]"
echo ""
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read CAMERA_CHOICE
clear

case "$CAMERA_CHOICE" in
 "a" | "A")
  usb_camera_cli
  pause
  camera_menu ;;
 "b" | "B")
  usb_camera_gnome
  pause
  camera_menu ;;
 "c" | "C")
  dv_camera_gnome
  pause
  camera_menu ;;
 "d" | "D")
  dcam_camera_gnome
  pause
  camera_menu ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  camera_menu ;;
esac
}
##################################################################


##################################################################
usb_camera_cli()
##################################################################
{
echo "Digital Camera (with USB interface) - command-line interface:"
echo ""
aptitude install gtkam
echo ""
}
##################################################################

##################################################################
usb_camera_gnome()
##################################################################
{
echo "Digital Camera (with USB interface) - GNOME interface"
echo ""
aptitude install gphoto2
echo ""
}
##################################################################

##################################################################
dv_camera_gnome()
##################################################################
{
echo "Digital video camera (with IEEE1394/Firewire/i.Link)"
echo "(DV / camcorder / cameras with tapes) capture and"
echo "non-linear editing - Kino [GTK]"
echo ""
aptitude install kino dvgrab
echo ""
}
##################################################################


##################################################################
dcam_camera_gnome()
##################################################################
{
echo "Digital video camera (with IEEE1394/Firewire/i.Link)"
echo "(DCAM / IIDC) capture - Coriander [GTK]"
echo ""
aptitude install coriander
echo ""
}
##################################################################


##################################################################
video-edit()
##################################################################
{
echo "Video Editing (requires the debian-multimedia.org source):"
echo ""
aptitude install avidemux
echo ""
}


##################################################################
cd_dvd_writing_cli_sarge()
##################################################################
{
echo "CD/DVD writing - writing data files to CD/DVD - command-line tools [Debian 3.1 Sarge]:"
echo ""
aptitude install cdrecord mkisofs cdrdao cdrtools-doc dvd+rw-tools
echo ""
}
##################################################################

##################################################################
cd_dvd_writing_cli_etch()
##################################################################
{
echo "CD/DVD writing - writing data files to CD/DVD - command-line tools [Debian 4.0 Etch]:"
echo ""
aptitude install wodim genisoimage cdrdao cdrkit-doc dvd+rw-tools
echo ""
}
##################################################################

##################################################################
cd_dvd_writing_gnome_sarge()
##################################################################
{
echo "CD/DVD writing - writing data files to CD/DVD - GNOME and command-line tools:"
echo ""
aptitude install cdrtools-doc dvd+rw-tools gnomebaker
# gnomebaker depends on cdrecord, mkisofs and cdrdao
echo ""
}
##################################################################

##################################################################
cd_dvd_writing_gnome_etch()
##################################################################
{
echo "CD/DVD writing - writing data files to CD/DVD - GNOME and command-line tools:"
echo ""
aptitude install cdrkit-doc dvd+rw-tools gnomebaker
# gnomebaker depends on cdrecord, genisoimage and cdrdao
echo ""
}
##################################################################



##################################################################
cd-audio-sarge()
##################################################################
{
echo "CD audio - rip, copy and encode"
echo ""
aptitude install cdda2wav cdparanoia vorbis-tools cdrecord cdrkit-doc sound-juicer
echo ""
}


##################################################################
cd-audio-etch()
##################################################################
{
echo "CD audio - rip, copy and encode"
echo ""
aptitude install icedax cdparanoia vorbis-tools wodim cdrkit-doc sound-juicer
echo ""
}


##################################################################
copying-dvd-sarge()
##################################################################
{
echo "Copying DVD Movies:"
echo ""
aptitude install dvdbackup dvd+rw-tools vobcopy mkisofs
echo ""
}
##################################################################


##################################################################
copying-dvd-etch()
##################################################################
{
echo "Copying DVD Movies:"
echo ""
aptitude install dvdbackup dvd+rw-tools vobcopy genisoimage
echo ""
}
##################################################################


##################################################################
windows-filesystem()
##################################################################
{
echo "Working with Windows file systems (ntfsprogs, libntfs-gnomevfs, dosfstools):"
echo ""
aptitude install ntfsprogs dosfstools
aptitude install libntfs-gnomevfs
echo ""
}
##################################################################


##################################################################
samba-server()
##################################################################
{
echo "Sharing this machine's Windows/Samba files/printers:"
echo ""
aptitude install samba samba-doc smbclient
echo ""
}
##################################################################


##################################################################
samba-client()
##################################################################
{
echo "Using Windows/Samba files/printers on another machine:"
echo ""
aptitude install smbclient smbfs
echo ""
}


##################################################################
ldap-client()
##################################################################
{
echo "LDAP client:"
echo ""
aptitude install ldap-utils libpam-ldap libnss-ldap nscd
# libnss-ldap is required for Webmin
echo ""
}



##################################################################
laptops()
##################################################################
{
clear
echo "==============================================================================="
echo "               Debian Desktop System Setup - Laptops"
echo "==============================================================================="
echo "A. Laptops in general"
echo "B. IBM ThinkPad [3.1/Sarge]"
echo "G. Synaptics touchpad GNOME configuration"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "

read LAPTOPS_CHOICE
clear

case "$LAPTOPS_CHOICE" in
 "a" | "A")
  laptops-general
  pause
  laptops ;;
 "b" | "B")
  laptops-thinkpad
  pause
  laptops ;;
 "g" | "G")
  aptitude install gsynaptics
  pause
  laptops ;;
 "q" | "Q")
  desktop_menu ;;
 *)
  laptops ;;
esac
}


##################################################################
laptops-general()
##################################################################
{
echo "Laptop Computers in general:"
echo ""
aptitude install laptop-mode-tools
echo ""

echo "If your laptop has APM, consider installing apmd."
echo "If your laptop has ACPI, consider installing  acpi and acpid."
echo ""
}


##################################################################
laptops-thinkpad()
##################################################################
{
echo "Laptop Computers - IBM ThinkPad:"
echo ""
aptitude install thinkpad-base tpctl thinkpad-source
echo ""

echo "If your ThinkPad has APM, you want to additionally install apmd"
echo "If your ThinkPad doesn't have APM, you want to additionally install acpi, acpid and ibm-acpi"
echo ""
}




##################################################################
zip_drives_cli()
##################################################################
{
echo "ZIP drives and disks - command-line:"
echo ""
aptitude install dosfstools
echo ""
}
##################################################################


##################################################################
zip_drives_gui()
##################################################################
{
echo "ZIP drives and disks - GUI:"
echo ""
aptitude install jazip
echo ""
}
##################################################################


##################################################################
windows-programs()
##################################################################
{
echo "Running Windows Programs:"
echo "(Note that winesetuptk is available in Debian 3.1 Sarge, but not 4.1 Etch)"
echo ""
aptitude install wine winesetuptk
echo ""
}



##################################################################
dialup-analog()
##################################################################
{
echo "Dial-up Networking with an analog modem:"
echo ""
aptitude install wvdial
echo ""
}



##################################################################
linux-kernel-etch-486()
##################################################################
{
echo "Latest Linux 2.6 series (for Etch/4.0) - optimised for 486:"
echo ""
aptitude install linux-image-486
echo ""
}

##################################################################
linux-kernel-etch-686()
##################################################################
{
echo "Latest Linux 2.6 series (for Etch/4.0) - optimised for 686:"
echo ""
aptitude install linux-image-686
echo ""
}


##################################################################
linux-kernel-etch-686-bigmem()
##################################################################
{
echo "Latest Linux 2.6 series (for Etch/4.0) - optimised for 686 with 4-64GB RAM:"
echo ""
aptitude install linux-image-686-bigmem
echo ""
}

##################################################################
linux-kernel-etch-k7()
##################################################################
{
echo "Latest Linux 2.6 series (for Etch/4.0) - optimised for k7:"
echo ""
aptitude install linux-image-k7
echo ""
}

##################################################################
linux-kernel-sarge-386()
##################################################################
{
echo "Latest Linux 2.6 series (for Debian 3.1 Sarge) - optimised for 386:"
echo ""
aptitude install kernel-image-2.6-386
echo ""
}

##################################################################
linux-kernel-sarge-686()
##################################################################
{
echo "Latest Linux 2.6 series (for Debian 3.1 Sarge) - optimised for 686:"
echo ""
aptitude install kernel-image-2.6-686
echo ""
}

##################################################################
linux-kernel-sarge-k7()
##################################################################
{
echo "Latest Linux 2.6 series (for Debian 3.1 Sarge) - optimised for k7:"
echo ""
aptitude install kernel-image-2.6-k7
echo ""
}

##################################################################
linux-kernel-etchnhalf-generic()
##################################################################
{
echo "Latest Linux 2.6.24 Etch'n'Half kernel auto optimised for your achitecture:"
echo ""
aptitude install linux-latest-2.6-etchnhalf
echo ""
}

##################################################################
linux-kernel-etchnhalf-486()
##################################################################
{
echo "Latest Linux 2.6.24 Etch'n'Half kernel - optimised for 486:"
echo ""
aptitude install linux-image-2.6-486-etchnhalf
echo ""
}

##################################################################
linux-kernel-etchnhalf-686()
##################################################################
{
echo "Latest Linux 2.6.24 Etch'n'Half kernel - optimised for 686:"
echo ""
aptitude install linux-image-2.6-686-etchnhalf
echo ""
}

##################################################################
linux-kernel-etchnhalf-686-bigmem()
##################################################################
{
echo "Latest Linux 2.6.24 Etch'n'Half kernel - optimised for 686 with 4-64GB RAM:"
echo ""
aptitude install linux-image-2.6-686-etchnhalf-bigmem
echo ""
}

##################################################################
linux-kernel-etchnhalf-amd64()
##################################################################
{
echo "Latest Linux 2.6.24 Etch'n'Half kernel - optimised for AMD64:"
echo ""
aptitude install linux-image-2.6-etchnhalf-amd64
echo ""
}









##################################################################
linux_kernel_compilation()
##################################################################
{
echo ""
echo "Kernel Compilation:"
echo "You want linux-source-x-x-x"
echo ""
aptitude install kernel-package fakeroot build-essential libncurses5-dev
echo ""
}




####################################################################
server_menu()
{
clear
echo "==============================================================================="
echo "  Server System Software Installation"
echo "==============================================================================="
echo "A.   Print server (using CUPS)..."
echo "B.   LDAP server"
echo "C.   Share this machine's files/printers using Samba (shared to Unix & Windows)"
echo "D.   Scanner server (using Sane)"
echo "E.   Web server and PHP..."
echo "G.   Database server (MySQL)"
echo "H.   MySQL web-based administration (phpMyAdmin)"
echo "H2.  MySQL web-based administration (phpMyAdmin using PHP5+Apache2) [4.0/Etch]"
echo "I.   NFS server"
echo "J.   Version control system (using Subversion)"
echo "K.   DHCP server"
echo "L.   IRC server (using Dancer)"
echo "M.   Mail server... [3.1/Sarge]"
echo "N.   Terminal server (using LTSP, the Linux Terminal Server Project)"
echo "O.   OpenSSH client and server [3.1/Sarge]"
echo "O2.  OpenSSH server [4.0/Etch]"
echo "==============================================================================="
echo -n "Choose your option [append U to uninstall, P to purge; choose 'Q' to quit]: "

read SERVER_CHOICE
clear

case "$SERVER_CHOICE" in
 "a" | "A")
  printing
  pause
  server_menu ;;
 "b" | "B")
  ldap-server
  pause
  server_menu ;;
 "c" | "C")
  samba-server
  pause
  server_menu ;;
 "d" | "D")
  scanning_sane
  pause
  server_menu ;;
 "e" | "E")
  web_server_menu ;;
 "g" | "G")
  mysql-server
  pause
  server_menu ;;
 "h" | "H")
  phpmyadmin
  pause
  server_menu ;;
 "h2" | "H2")
  phpmyadmin_etch
  pause
  server_menu ;;
 "i" | "I")
  nfs-server
  pause
  server_menu ;;
 "j" | "J")
  subversion-server
  pause
  server_menu ;;
 "k" | "K")
  dhcp-server
  pause
  server_menu ;;
 "l" | "L")
  irc-server
  pause
  server_menu ;;
 "m" | "M")
  mail_server_menu
  pause
  server_menu ;;
 "n" | "N")
  ltsp-server
  pause
  server_menu ;;
 "o" | "O")
  echo "SSH client and server..."
  echo""
  aptitude install ssh
  pause
  server_menu ;;
 "o2" | "O2")
  echo "SSH server..."
  echo""
  aptitude install openssh-server
  pause
  server_menu ;;
 "q" | "Q")
  top_menu ;;
 *)
  server_menu ;;
esac
}
####################################################################




####################################################################
web_server_menu()
{
clear
echo "==============================================================================="
echo "  Web Server Software Installation"
echo "==============================================================================="
echo "A.   Apache 1.3 series HTTP server"
echo "B.   Apache 2.2 series HTTP server (with Worker MPM)"
echo "C.   Apache 2.2 series HTTP server (with Prefork MPM)"
echo "D.   Apache 2.2 series HTTP server (with Event MPM)"
echo ""
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo ""
echo "K.   PHP 4 and PEAR [3.1/Sarge]"
echo "K2.  PHP 5 (+ Apache 2.2 series (with Prefork MPM)) + PEAR [4.0/Etch]"
echo "==============================================================================="
echo -n "Choose your option [append U to uninstall, P to purge; choose 'Q' to quit]: "

read WEB_SERVER_CHOICE
clear

case "$WEB_SERVER_CHOICE" in
 "a" | "A")
  echo "Apache 1.3 series HTTP server:"
  aptitude install apache apache-doc
  pause
  web_server_menu ;;
 "b" | "B")
  echo "Apache 2.2 series HTTP server (with Worker MPM):"
  aptitude install apache2-mpm-worker apache2-doc
  pause
  web_server_menu ;;
 "c" | "C")
  echo "Apache 2.2 series HTTP server (with Prefork MPM):"
  aptitude install apache2-mpm-prefork apache2-doc
  pause
  web_server_menu ;;
 "d" | "D")
  echo "Apache 2.2 series HTTP server (with Event MPM):"
  aptitude install apache2-mpm-event apache2-doc
  pause
  web_server_menu ;;
 "k" | "K")
  php4
  pause
  web_server_menu ;;
 "k2" | "K2")
  php5
  pause
  web_server_menu ;;
 "q" | "Q")
  server_menu ;;
 *)
  web_server_menu ;;
esac
}
####################################################################




##################################################################
ldap-server()
##################################################################
{
echo "LDAP server:"
echo ""
aptitude install slapd ldap-utils
echo ""
}
##################################################################



##################################################################
php4()
##################################################################
{
echo "PHP 4 and PEAR:"
echo ""
aptitude install php4 php4-pear
echo ""
}
##################################################################


##################################################################
php5()
##################################################################
{
echo "PHP 5 (+ Apache 2.2 series (with Prefork MPM)) + PEAR:"
echo ""
aptitude install libapache2-mod-php5 php-pear php5-dev
echo ""
}
##################################################################


##################################################################
mysql-server()
##################################################################
{
echo "Installing MySQL server..."
echo ""
aptitude install mysql-server

echo ""
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "You should set a password now for MySQL because it defaults to not having one."
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
echo "This MySQL defaults to listening only on localhost, so it won't allow remote"
echo "connections. If you need remote connections to MySQL, set the 'bind-address'"
echo "setting in /etc/mysql/my.cnf to this machine's IP address or hostname."
echo "If you want it to listen on localhost and for remote connections then remove"
echo "bind-address altogether."

echo ""
}
##################################################################


##################################################################
phpmyadmin()
##################################################################
{
echo "phpMyAdmin for database administration:"
echo ""
aptitude install phpmyadmin
echo ""
}
##################################################################


##################################################################
phpmyadmin_etch()
##################################################################
{
echo "phpMyAdmin for database administration (using PHP5 and  Apache2 for Debian 4.0 Etch):"
echo ""
aptitude install phpmyadmin libapache2-mod-php5 php5-mysql php5-mysql
echo ""
}
##################################################################




####################################################################
mail_server_menu()
{
clear
echo "==============================================================================="
echo "  Mail Server (use in conjunction with 'ISP-style Email Service for Sarge' doc)"
echo "==============================================================================="
echo "A.UP Install mail server [3.1/Sarge]"
echo "     (Postfix, Courier POP3/IMAP, Cyrus SASL, AMaViS, ClamAV, SpamAssassin,"
echo "     Squirrelmail). Based on Christoph Haas' ISP-style Email Service"
echo "     (workaround.org/articles/ispmail-sarge/) (REQUIRES MYSQL BE INSTALLED 1ST)"
echo "     (take care with purging as it may remove Samba, Apache, PHP)"
echo "B.   Install Fetchmail to collect mail from host receiving it on your behalf"
echo "H.U  Configure mail server [3.1/Sarge]"
echo "     - amavisd.conf's sql_select_policy must be uncommented manually"
echo "     - /etc/postfix/main.cf's myhostname & mynetworks may need changing for you"
echo "     - assumes MySQL server is on the same machine & you have root access"
echo "     - 'undo' removes config files, not database or any mail"
echo "I.   Add a relay host to Postfix that will deliver mail on your behalf"
echo "J.   Configure Fetchmail (creates template config file you need to hand edit)"
echo "K.   Run Squirrelmail configuration utility"
echo "L.   Look at all configuration files edited by this program"
echo "O.   Create a new virtual domain for email"
echo "P.   Create a new email account"
echo "R.   Create a mail forwarding / alias"
#echo "To Do: backup mail database"

echo "==============================================================================="
echo -n "Choose your option [append U to uninstall, P to purge; choose 'Q' to quit]: "

read MAIL_SERVER_CHOICE
clear

case "$MAIL_SERVER_CHOICE" in
 "a" | "A")
  mail-server
  pause
  mail_server_menu ;;
 "au" | "AU" | "Au" | "aU")
  undo-mail-server
  pause
  mail_server_menu ;;
 "ap" | "AP" | "Ap" | "aP")
  purge-mail-server
  pause
  mail_server_menu ;;
 "b" | "B")
  aptitude install fetchmail
  pause
  mail_server_menu ;;
 "h" | "H")
  configure-mail-server
  pause
  mail_server_menu ;;
 "hu" | "HU" | "Hu" | "hU")
  undo-configure-mail-server
  pause
  mail_server_menu ;;
 "i" | "I")
  postfix_relay_host
  pause
  mail_server_menu ;;
 "j" | "J")
  fetchmail_config
  pause
  mail_server_menu ;;
 "k" | "K")
  /usr/sbin/squirrelmail-configure
  pause
  mail_server_menu ;;
 "l" | "L")
  show_mail_config_files
  pause
  mail_server_menu ;;
 "o" | "O")
  create_mail_virtual_domain
  pause
  mail_server_menu ;;
 "p" | "P")
  create_mail_user
  pause
  mail_server_menu ;;
 "q" | "Q")
  server_menu ;;
 "r" | "R")
  create_mail_forwarding
  pause
  mail_server_menu ;;
 *)
  mail_server_menu ;;
esac
}
####################################################################



##################################################################
mail-server()
##################################################################
{
echo "Installing Postfix..."
echo "(When asked about the type of mail delivery, choose 'Local only')"
aptitude install postfix postfix-mysql postfix-doc

echo ""
echo "Installing Courier components for POP3/IMAP access..."
aptitude install courier-authdaemon courier-authmysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl

echo ""
echo "Installing packags for authenticated SMTP..."
aptitude install postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql openssl

echo ""
echo "Installing packages to scan incoming email for viruses and spam..."
echo "(Note: lha requires non-free)"
aptitude install amavisd-new spamassassin clamav clamav-daemon zoo unzip unarj lha
echo "(configuration directories instead of configuration files to enable web-based administration? I chose directories)"

echo ""
echo "Installing Squirrelmail for a web mail interface..."
aptitude install squirrelmail
echo ""
}
##################################################################


##################################################################
undo-mail-server()
##################################################################
{
echo "Uninstalling mail server..."
echo "(not uninstalling zoo unzip unarj lha)"
echo ""
aptitude remove postfix postfix-mysql postfix-doc courier-authdaemon \
courier-authmysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl \
postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql \
amavisd-new spamassassin clamav clamav-daemon squirrelmail
echo ""
}
##################################################################


##################################################################
purge-mail-server()
##################################################################
{
echo "Purging mail server..."
echo "(not uninstalling zoo unzip unarj lha or openssl"
echo "as they may be otherwise required )"
echo ""
aptitude purge postfix postfix-mysql postfix-doc courier-authdaemon \
courier-authmysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl \
postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql \
amavisd-new spamassassin clamav clamav-daemon squirrelmail
echo ""
}
##################################################################


##################################################################
show_mail_config_files()
##################################################################
{
echo "/etc/postfix/mysql-virtual_domains.cf"
echo "-------------------------------------"
more /etc/postfix/mysql-virtual_domains.cf
pause
clear

echo "/etc/postfix/mysql-virtual_forwardings.cf"
echo "----------------------------------------"
more /etc/postfix/mysql-virtual_forwardings.cf
pause
clear

echo "/etc/postfix/mysql-virtual_mailboxes.cf"
echo "---------------------------------------"
more /etc/postfix/mysql-virtual_mailboxes.cf
pause
clear

echo "/etc/postfix/mysql-virtual_email2email.cf"
echo "-----------------------------------------"
more /etc/postfix/mysql-virtual_email2email.cf
pause
clear

echo "/etc/postfix/main.cf"
echo "--------------------"
more /etc/postfix/main.cf
pause
clear

echo "/etc/postfix/sasl/smtpd.conf"
echo "----------------------------"
more /etc/postfix/sasl/smtpd.conf
pause
clear

echo "/etc/courier/authdaemonrc"
echo "-------------------------"
more /etc/courier/authdaemonrc
pause
clear

echo "/etc/courier/authmysqlrc"
echo "------------------------"
more /etc/courier/authmysqlrc
clear

echo "/etc/postfix/smtpd.key"
echo "----------------------"
more /etc/postfix/smtpd.key
pause
clear

echo "/etc/postfix/smtpd.cert"
echo "----------------------"
more /etc/postfix/smtpd.cert
pause
clear

echo "/etc/fetchmailrc"
echo "----------------"
echo "(You'll only have this if you've optionally installed then manually configured Fetchmail)"
more /etc/fetchmailrc
}
##################################################################


##################################################################
configure-mail-server()
##################################################################
{
echo ""
echo "Creating a database, called 'provider'"
echo "(You will be asked for the password for the MySQL root user)"
mysqladmin -u root -p create provider

echo ""
echo "Connecting as root to MySQL server; creating a database user"
echo "(provider_admin@localhost and provider_admin@localhost.localdomain)"
echo "who has sufficient permissions (SELECT, INSERT) to access the "
echo "database for email administration."
echo "(If your domain differs from 'localdomain' you will need to change it)"
echo -n ""
read -s -p "Enter password to use for provider_admin: " MAIL_DB_USER_PWD

echo ""
echo "Creating provider_admin@localhost..."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "grant select, insert on provider.* to provider_admin@localhost identified by '$MAIL_DB_USER_PWD';"

echo ""
echo "Creating provider_admin@localhost.localdomain..."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "grant select, insert on provider.* to provider_admin@localhost.localdomain identified by '$MAIL_DB_USER_PWD';"

echo ""
echo "Reloading the permissions information in MySQL..."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "flush privileges;"

echo ""
echo "Create the database tables that will contain the control information for Postfix..."
echo "Create a table for the virtual domain name."
echo "This table will need to have a row for each virtual domain."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "USE provider; \
CREATE TABLE domains ( \
domain varchar(50) NOT NULL, \
PRIMARY KEY (domain) \
) TYPE=MyISAM;"

echo ""
echo "Create a table for 'forwardings', used to alias one email address to another."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "USE provider; \
CREATE TABLE forwardings ( \
source varchar(80) NOT NULL, \
destination TEXT NOT NULL, \
PRIMARY KEY (source) ) TYPE=MyISAM;"

echo ""
echo "Create a 'users' table with information about your user accounts."
echo "(You will be asked for the password for the MySQL root user)"
mysql -u root -p -e "USE provider; \
CREATE TABLE users ( \
email varchar(80) NOT NULL, \
password varchar(20) NOT NULL, \
PRIMARY KEY (email) \
) TYPE=MyISAM;"

echo ""
echo "Tell Postfix where the control information is stored in the database..."

echo "Create /etc/postfix/mysql-virtual_domains.cf..."
# If the file already exists and is writable then make a backup of it designated
# by date and time and remove the original so we can put in a new one.
if [ -e /etc/postfix/mysql-virtual_domains.cf ]
  then 
    mv /etc/postfix/mysql-virtual_domains.cf mysql-virtual_domains-`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`.cf
  else
    touch /etc/postfix/mysql-virtual_domains.cf
fi

echo ""
echo "(This is a simple mapping of your virtual domain name (LHS) to the string"
echo "'virtual' (RHS). This mapping is used for the virtual_mailbox_domains definition"
echo "where just the LHS matters."

echo ""
echo "user = provider_admin
password = $MAIL_DB_USER_PWD
dbname = provider
table = domains
select_field = 'virtual'
where_field = domain
hosts = 127.0.0.1" >> /etc/postfix/mysql-virtual_domains.cf

echo ""
echo "Create /etc/postfix/mysql-virtual_forwardings.cf..."
echo "(This mapping reads the 'forwardings' table to provide a way to redirect email"
echo "addresses. It simply maps the 'source' column to the 'destination' column."
echo "We will use it for the virtual_alias_maps mapping)."
if [ -e /etc/postfix/mysql-virtual_forwardings.cf ]
  then 
    mv /etc/postfix/mysql-virtual_forwardings.cf mysql-virtual_forwardings-`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`.cf
  else
    touch /etc/postfix/mysql-virtual_forwardings.cf
fi

echo ""
echo "user = provider_admin
password = $MAIL_DB_USER_PWD
dbname = provider
table = forwardings
select_field = destination
where_field = source
hosts = 127.0.0.1" >> /etc/postfix/mysql-virtual_forwardings.cf

echo ""
echo "Create /etc/postfix/mysql-virtual_mailboxes.cf..."
echo "(This definition file deals with user mailboxes. It tells Postfix where to store"
echo "email for a specific email address. We will use it in the"
echo "virtual_mailbox_maps mapping)."
if [ -e /etc/postfix/mysql-virtual_mailboxes.cf ]
  then 
    mv /etc/postfix/mysql-virtual_mailboxes.cf mysql-virtual_mailboxes-`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`.cf
  else
    touch /etc/postfix/mysql-virtual_mailboxes.cf
fi

echo ""
echo "user = provider_admin
password = $MAIL_DB_USER_PWD
dbname = provider
table = users
select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
where_field = email
hosts = 127.0.0.1" >> /etc/postfix/mysql-virtual_mailboxes.cf

echo ""
echo "Create /etc/postfix/mysql-virtual_email2email.cf..."
echo "(This deals with a quirk of virtual domains in the precedence of the"
echo "virtual_alias_maps mapping when using catch-all addresses."
echo "This is a simple mapping for all email addresses in the users table to themselves"
echo "to work around the problem)."
if [ -e /etc/postfix/mysql-virtual_email2email.cf ]
  then 
    mv /etc/postfix/mysql-virtual_email2email.cf mysql-virtual_email2email.-`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`.cf
  else
    touch /etc/postfix/mysql-virtual_email2email.cf
fi

echo ""
echo "user = provider_admin
password = $MAIL_DB_USER_PWD
dbname = provider
table = users
select_field = email
where_field = email
hosts = 127.0.0.1" >> /etc/postfix/mysql-virtual_email2email.cf

echo ""
echo "Make sure nobody but root can read these files. Otherwise everybody on your system"
echo "could read your database access password in plain text..."

echo ""
echo "Set the group of these files to 'postfix'..."
chgrp postfix /etc/postfix/mysql-virtual_*.cf

echo ""
echo "Make the files readable by the group..."
chmod u=rw,g=r,o= /etc/postfix/mysql-virtual_*.cf

echo ""
echo "To save assigning a unique UID (user ID) to every user, create a pseudo-user who"
echo "will become the owner of all mailboxes..."
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m


echo ""
echo "Making the following configuration changes to the Postfix configuration file"
echo "/etc/postfix/main.cf..."
echo ""
echo "Removing inet_interfaces, Debian sets it to loopback-only, the default is all"
echo "Changing myhostname from localhost.localdomain to $HOSTNAME.localdomain"
echo ""
echo "(NOTE: YOU MAY WANT TO CHANGE THE 'MYHOSTNAME' SETTING FOR YOUR SITUATION!)"
echo ""
echo "Leaving mydestination setting as yours should have been picked up by debconf"
echo "Changing mynetworks from 127.0.0.0/8 to 127.0.0.0/8, 10.0.0.0/8 but your local network may differ!"
echo ""
echo "(NOTE: YOU MAY WANT TO CHANGE THE 'MYNETWORKS' SETTING FOR YOUR SITUATION!)"
echo ""
echo "insert an unset virtual_alias_domains"
echo "insert virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_forwardings.cf mysql:/etc/postfix/mysql-virtual_email2email.cf"
echo "insert virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains.cf"
echo "insert virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailboxes.cf"
echo "insert virtual_mailbox_base = /home/vmail"
echo "insert virtual_uid_maps = static:5000"
echo "insert virtual_gid_maps = static:5000"
echo "insert smtpd_sasl_auth_enable = yes"
echo "insert broken_sasl_auth_clients = yes"
echo "insert smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"
echo "insert smtpd_use_tls = yes"
echo "insert smtpd_tls_cert_file = /etc/postfix/smtpd.cert"
echo "insert smtpd_tls_key_file = /etc/postfix/smtpd.key"

perl -pi.bak \
-e 's/inet_interfaces = loopback-only//g;' \
-e 's/myhostname = localhost.localdomain/myhostname = '$HOSTNAME'.localdomain/g;' \
-e 's/mynetworks = 127.0.0.0\/8/mynetworks = 127.0.0.0\/8, 10.0.0.0\/8/g;' \
/etc/postfix/main.cf

echo "
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_forwardings.cf mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key" >> /etc/postfix/main.cf


echo ""
echo "Restart Posfix..."
/etc/init.d/postfix restart

echo ""
echo "Testing Posfix..."
echo "If you don't see any warnings here ->"
postfix check
echo " <- then this part is complete."
pause

echo ""
echo "Make Postfix understand authenticated SMTP (Auth-SMTP)..."

mkdir /etc/postfix/sasl
# (this already existed on one installation I did)

echo ""
echo "Creating the Cyrus SASL configuration file (/etc/postfix/sasl/smtpd.conf)"
echo "with the following settings:"
echo "pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: plain login cram-md5 digest-md5
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: provider_admin
sql_passwd: $MAIL_DB_USER_PWD
sql_database: provider
sql_select: select password from users where email='%u@%r'"

echo "
pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: plain login cram-md5 digest-md5
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: provider_admin
sql_passwd: $MAIL_DB_USER_PWD
sql_database: provider
sql_select: select password from users where email='%u@%r'" \
>> /etc/postfix/sasl/smtpd.conf

echo "Tighten security on /etc/postfix/sasl/smtpd.conf..."
chown root:postfix /etc/postfix/sasl/smtpd.conf
chmod u=rw,g=r,o= /etc/postfix/sasl/smtpd.conf

echo ""
echo "Create a certificate that is valid for ten years..."
echo ""
echo "You will now be asked a few question about the fields of the certificate."
echo "It does not matter what you enter. Just fill the fields."
echo "One exception though - the Common Name must be the hostname of your mail server."
echo ""
openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 \
-nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509

echo ""
echo "Make sure at least the key file is not readable for the whole wide world..."
chmod u=rw,g=r,o= /etc/postfix/smtpd.key
chown root:postfix /etc/postfix/smtpd.key

echo ""
echo "Configure the POP3 / IMAP service by..."

echo ""
echo "Changing authmodulelist=\"authpam\" to \"authmysql\" in Courier authdaemon"
echo "configuration file /etc/courier/authdaemonrc"
echo "
authmodulelist=\"authmysql\"" >> /etc/courier/authdaemonrc

echo ""
echo "Making the following configuration changes to the Courier authdaemon"
echo "configuruation file /etc/courier/authmysqlrc..."
echo "MYSQL_USERNAME from admin to provider_admin"
echo "MYSQL_PASSWORD from admin to $MAIL_DB_USER_PWD"
echo "MYSQL_DATABASE from mysql to provider"
echo "MYSQL_USER_TABLE from passwd to users"
echo "commenting out MYSQL_CRYPT_PWFIELD"
echo "MYSQL_CLEAR_PWFIELD from commented out to password"
echo "MYSQL_UID_FIELD from uid to 5000"
echo "MYSQL_GID_FIELD from gid to 5000"
echo "MYSQL_LOGIN_FIELD from id to email"
echo "MYSQL_HOME_FIELD from home to \"/home/vmail\""
echo "commenting out MYSQL_NAME_FIELD"
echo "uncommenting MYSQL_MAILDIR_FIELD and setting to \
CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')"

perl -pi.bak \
-e 's/MYSQL_USERNAME\t\tadmin/MYSQL_USERNAME\t\tprovider_admin/g;' \
-e 's/MYSQL_PASSWORD\t\tadmin/MYSQL_PASSWORD\t\t'$MAIL_DB_USER_PWD'/g;' \
-e 's/MYSQL_DATABASE\t\tmysql/MYSQL_DATABASE\t\tprovider/g;' \
-e 's/MYSQL_USER_TABLE\tpasswd/MYSQL_USER_TABLE\tusers/g;' \
-e 's/MYSQL_CRYPT_PWFIELD\tcrypt/#MYSQL_CRYPT_PWFIELD\tcrypt/g;' \
-e 's/# MYSQL_CLEAR_PWFIELD\tclear/MYSQL_CLEAR_PWFIELD\tpassword/g;' \
-e 's/MYSQL_UID_FIELD\t\tuid/MYSQL_UID_FIELD\t\t5000/g;' \
-e 's/MYSQL_GID_FIELD\t\tgid/MYSQL_GID_FIELD\t\t5000/g;' \
-e 's/MYSQL_LOGIN_FIELD\tid/MYSQL_LOGIN_FIELD\temail/g;' \
-e 's/MYSQL_HOME_FIELD\thome/MYSQL_HOME_FIELD\t\"\/home\/vmail\"/g;' \
-e 's/MYSQL_NAME_FIELD\tname/#MYSQL_NAME_FIELD\tname/g;' \
-e "s/# MYSQL_MAILDIR_FIELD\tmaildir/MYSQL_MAILDIR_FIELD CONCAT\
\(SUBSTRING_INDEX\(email,'\@',-1\),'\/',SUBSTRING_INDEX\(email,'\@',1\),'\/'\)/g" \
/etc/courier/authmysqlrc

echo "Restart the Courier authdaemon process..."
/etc/init.d/courier-authdaemon restart


echo ""
echo "Making the following configuration changes to the AMaViS configuruation file"
echo "/etc/amavis/amavisd.conf..."

echo ""
echo "Changing $mydomain = 'example.com'; to $mydomain = 'localhost';"
echo "Leaving commented out '@bypass_virus_checks_acl = qw( . );' as it is"
echo "Leaving commented out '@bypass_spam_checks_acl = qw( . );' as it is"
echo "Changing '# @lookup_sql_dsn =' to '@lookup_sql_dsn = ( [ 'DBI:mysql:provider', 'provider_admin', '$MAIL_DB_USER_PWD' ] );'"
echo "Changing '# $sql_select_policy = 'SELECT *,users.id FROM users,policy'.' to '$sql_select_policy = 'SELECT \"Y\" as local FROM domains WHERE CONCAT(\"@\",domain) IN (%k)';'"
echo "Leaving '$final_virus_destiny = D_DISCARD;' as it is"
echo "Changing '$final_banned_destiny     = D_BOUNCE;' to '$final_banned_destiny = D_REJECT;'"
echo "(TO DO: WE PROBABLY WANT TO ENABLE SOME FILE TYPES INSTEAD, SUCH AS .DOC!)"
echo "Changing '$final_spam_destiny       = D_REJECT;' to '$final_spam_destiny = D_PASS;'"
echo "Changing '$sa_tag_level_deflt  = 4.0;' to '$sa_tag_level_deflt = -1000;'"
echo "Changing '$sa_tag2_level_deflt = 6.3;' to '$sa_tag2_level_deflt = 5.0;'"
echo "Changing '$sa_kill_level_deflt = $sa_tag2_level_deflt;' to '$sa_kill_level_deflt = 10;'"
echo "Leaving '$sa_spam_subject_tag = '***SPAM*** ';' as it is"
echo "leaving @av_scanners setting as it is,"
echo "(TO DO: BUT IS THERE ANYTHING WRONG WITH LEAVING IN ANY FOR VIRUS SCANNERS WE DON'T HAVE?)"
echo "Changing '$sa_local_tests_only = 1;' to '$sa_local_tests_only = 0;'"

perl -pi.bak \
-e "s/$mydomain = 'example.com';/$mydomain = 'localhost';/g;" \
-e "s/# \@lookup_sql_dsn =/\@lookup_sql_dsn = ( [ 'DBI:mysql:provider', 'provider_admin', '"$MAIL_DB_USER_PWD"' ] );/g;" \
-e "s/\$sql\_select\_policy = 'SELECT \*\,users\.id FROM users\,policy'\./\$sql\_select\_policy = 'SELECT \"Y\" as local FROM domains WHERE CONCAT(\"\@\",domain) IN (%k)';/g;" \
-e 's/$final_banned_destiny     = D_BOUNCE;/$final_banned_destiny = D_REJECT;/g;' \
-e 's/$final_spam_destiny       = D_REJECT;/$final_spam_destiny = D_PASS;/g;' \
-e 's/$sa_tag_level_deflt  = 4.0;/$sa_tag_level_deflt = -1000;/g;' \
-e 's/$sa_tag2_level_deflt = 6.3;/$sa_tag2_level_deflt = 5.0;/g;' \
-e 's/$sa_kill_level_deflt = $sa_tag2_level_deflt;/$sa_kill_level_deflt = 10;/g;' \
-e 's/$sa_local_tests_only = 1;/$sa_local_tests_only = 0;/g;' \
/etc/amavis/amavisd.conf

echo ""
echo "Add the user 'clamav' to the group 'amavis' for clamd, the daemon variant of the"
echo "ClamAV scanner..."
adduser clamav amavis

echo ""
echo "Restarting the amavis service to activate the changes..."
/etc/init.d/amavis restart

echo ""
echo "Tell Postfix to use AMaViS..."
echo "
content_filter = amavis:[127.0.0.1]:10024
receive_override_options = no_address_mappings" >> /etc/postfix/main.cf

echo ""
echo "Define the amavis service in Postfix..."
echo "
amavis unix - - - - 2 smtp
   -o smtp_data_done_timeout=1200
   -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - - - - smtpd
   -o content_filter=
   -o local_recipient_maps=
   -o relay_recipient_maps=
   -o smtpd_restriction_classes=
   -o smtpd_client_restrictions=
   -o smtpd_helo_restrictions=
   -o smtpd_sender_restrictions=
   -o smtpd_recipient_restrictions=permit_mynetworks,reject
   -o mynetworks=127.0.0.0/8
   -o strict_rfc821_envelopes=yes
   -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks" >> \
/etc/postfix/master.cf

echo ""
echo "Make sure there are still no errors in the Postfix configuration..."
postfix reload
postfix check

echo ""
echo "NOTE: WE DON'T DO ANY SPAM TRAINING HERE YET, SEE:"
# This is what AMaViS has recorded into its database
sa-learn --dbpath /var/lib/amavis/.spamassassin/bayes --dump magic


echo ""
echo "Setup Squirrelmail by adding its configuration to the Apache configuration..."
ln -s /etc/squirrelmail/apache.conf /etc/apache/conf.d/squirrelmail.conf

echo ""
echo "Note: the Squirrelmail web mail interface should now be available at"
echo "something like http://server/squirrelmail/."

echo ""
echo "Configure the Squirrelmail Apache configuration to respond to mail.server..."
echo "

<VirtualHost *:80>
  DocumentRoot /usr/share/squirrelmail
  ServerName mail.server
</VirtualHost>" >> /etc/squirrelmail/apache.conf

echo ""
echo "To get mail.server to load Squirrelmail you'll have to add mail.server"
echo "pointing to your server's IP address in your DNS server."

echo ""
}

##################################################################




##################################################################
undo-configure-mail-server()
##################################################################
{
echo "Removing mail server configuration files..."

echo ""
echo "Removing /etc/postfix/mysql-virtual_domains.cf..."
rm /etc/postfix/mysql-virtual_domains.cf

echo ""
echo "Removing /etc/postfix/mysql-virtual_forwardings.cf..."
rm /etc/postfix/mysql-virtual_forwardings.cf

echo ""
echo "Removing /etc/postfix/mysql-virtual_mailboxes.cf..."
rm /etc/postfix/mysql-virtual_mailboxes.cf

echo ""
echo "Removing /etc/postfix/mysql-virtual_email2email.cf..."
rm /etc/postfix/mysql-virtual_email2email.cf

echo ""
echo "Leaving pseudo-user vmail who owns all mailboxes in..."
#echo "(without removing mail in their home directory /home/vmail)..."
#groupdel vmail
#userdel vmail

echo ""
echo "Removing /etc/postfix/main.cf..."
rm /etc/postfix/main.cf

echo "
echo "Removing /etc/courier/authdaemonrc..."
rm /etc/courier/authdaemonrc

echo ""
echo "Removing /etc/courier/authmysqlrc..."
rm /etc/courier/authmysqlrc

echo ""
echo Removing /etc/amavis/amavisd.conf..."
rm /etc/amavis/amavisd.conf

echo ""
echo "Removing /etc/postfix/master.cf..."
rm /etc/postfix/master.cf

echo "Remove the /var/www/squirrelmail/ URL for SquirrelMail access..."
rm /var/www/squirrelmail

echo ""
}

##################################################################


##################################################################
postfix_relay_host()
##################################################################
{
echo -n "Enter the relay host's host name or IP address: "
read RELAYHOST

echo "
relayhost = [$RELAYHOST]
" >> /etc/postfix/main.cf

echo ""
echo "Done. This is any relayhost settings now in the Postfix configuration file:"
cat /etc/postfix/main.cf | grep relayhost
}
##################################################################



##################################################################
fetchmail_config()
##################################################################
{
echo "Creating template Fetchmail configuration file for you to hand edit..."

echo "
# Fetchmail configuration file
# /etc/fetchmailrc for system-wide daemon mode
# Version 1.0

# How often to poll servers, in seconds. The default is 300.
set daemon     90

# Logging - don't log to syslog, instead log to the specified log file
# (Beware that if you're using the log for troubleshooting, it can grow quickly)
# (The log file wants to be editable by the user fetchmail)
# (How do we cycle the log file? /etc/logrotate.conf?)
#set no syslog
#set logfile /var/log/fetchmail


# The verbose syntax is like this
# poll SERVERNAME protocol PROTOCOL
#	user USERNAME with password PASSWORD is LOCALUSERNAME here;

# Example of various user accounts on the same server
# poll pop.provider.net proto pop3
#	user \"jsmith\" with pass \"password\" is \"smith\" here
#	user jones with pass \"password\" is \"jjones\" here

# Example of a multi-drop mailbox
# poll pop.provider.net localdomains loonytoons.org toons.org:
#	user your_username with pass your_password to * here


# SOME USEFUL OPTIONS
# keep - Don't delete seen messages from server
# no keep - Delete seen messages from server (default)
# fetchall - Fetch all messages whether seen or not
# no fetchall - Retrieve only new messages (default)" >> \
/etc/fetchmailrc

echo ""
echo "Set restrictive permissions on the Fetchmail configuration file because it contains passwords..."
chmod 0600 /etc/fetchmailrc
chown fetchmail /etc/fetchmailrc
#? chmod g+w /etc/fetchmailrc

echo ""
echo "Create the Fetchmail log file, change its owner to fetchmail and give root write access to it..."
touch /var/log/fetchmail
chown fetchmail /var/log/fetchmail
chmod g+w /var/log/fetchmail
}
##################################################################




##################################################################
create_mail_virtual_domain()
##################################################################
{
echo -n "Enter the new domain name: "
read NEW_DOMAIN

# If the domain already exists, don't try to create it.
echo ""
echo "Checking to see if that domain already exists"
echo "(You'll have to enter the password for the MySQL provider_admin database user)..."
DOMAIN_EXIST_TEST=`mysql -u provider_admin -p -D provider \
--exec="SELECT domain FROM domains WHERE domain='$NEW_DOMAIN'" | sed -e '1d'`
# The result of this is the name of the domain on its own if successful, 
# nothing if its unsuccessful, stored in the environment variable.
if [ -z $DOMAIN_EXIST_TEST ]; then
	echo ""
	echo "Creating the new domain '$NEW_DOMAIN'"
	echo "(You'll have to enter the password for the MySQL root database user)..."
        mysql -u root -p -D provider --exec="INSERT INTO domains VALUES('$NEW_DOMAIN')"
else
	echo "The domain '$NEW_DOMAIN' already exists!"
fi
echo ""
}
##################################################################


##################################################################
create_mail_user()
##################################################################
{
set NEW_MAIL_ADDRESS
set NEW_MAIL_PASSWORD
set DOMAIN
set USERNAME
set DOMAIN_TEST
set NEW_MAIL_ADDRESS_TEST

echo -n "Enter the full new email address (i.e. user@domain.org): "
read NEW_MAIL_ADDRESS
read -s -p "Enter the new email account's password: " NEW_MAIL_PASSWORD

# seperate username and domain into variables
DOMAIN=`echo $NEW_MAIL_ADDRESS | sed -e 's@[a-zA-Z0-9]*\@@@'`
USERNAME=`echo $NEW_MAIL_ADDRESS | sed -e 's@\@[a-zA-z0-9.]*@@'`
# These regexes could be more accurate
# ERROR: sed: -e expression #1, char 19: Invalid range end

echo ""
echo "Searching to see if the domain $DOMAIN exists..."
echo "(You'll have to enter the password for the MySQL provider_admin database user)"

# Check if this domain exists in the database.
DOMAIN_TEST=`mysql -u provider_admin -p -D provider --exec="SELECT domain FROM domains WHERE domain='$DOMAIN'" | sed -e '1d'`

# If that domain doesn't exist, say so and quit.
if [ -z $DOMAIN_TEST ]; then
	echo ""
	echo "Either there was a problem accessing the database (see above);"
        echo "or the domain '$DOMAIN' doesn't exist, if so you need to create it first!"
	pause
	mail_server_menu
fi

echo ""
echo "Searching to see if the username $USERNAME exists..."
echo "(You'll have to enter the password for the MySQL provider_admin database user)"

# Check if this username exists in the database.
NEW_MAIL_ADDRESS_TEST=`mysql -u provider_admin -p -D provider --exec="SELECT email FROM users WHERE email='$NEW_MAIL_ADDRESS'" | sed -e '1d'`

# If that domain doesn't exist, say so and quit.
if [ -z $NEW_MAIL_ADDRESS_TEST ]; then
# !!!! NEED TO CHANGE THIS TO INVERT IT TO CHECK IT DOESN'T ALREADY EXIST !!!!
	echo ""
	echo "Either there was a problem accessing the database (see above);"
        echo "or the address '$NEW_MAIL_ADDRESS' already exists."
	pause
	mail_server_menu
fi


# Insert user into mysql table, create maildir
# (You cannot fetch emails from a mailbox unless at least one email has been sent
# there. Users would get cryptic error messages. So send a welcome email to new users)
echo ""
echo "Creating the user $NEW_MAIL_ADDRESS in the database"
echo "(You'll have to enter the password for the MySQL root database user)"

# Create the new mail account, sending log to mysql.err
mysql -u root -p -D provider \
--exec="INSERT INTO users VALUES('$NEW_MAIL_ADDRESS','$NEW_MAIL_PASSWORD')" 2> mysql.err

if [ $? -eq 0 ]; then
        rm -f mysql.err
        echo ""
        echo "Succesfully added $NEW_MAIL_ADDRESS."
        echo "Sending them a welcome message... "
        echo -e "Welcome to your new email account.\r\nEverything should be working, let us know if it isn't." | mail -s "Welcome" $NEW_MAIL_ADDRESS

	echo "Check the log to see what the messages were to see if it was ok:"
	echo "Wait for a moment for the mail log to catch up"
	sleep 3
	# pause - do we need to instead pause?
	tail /var/log/mail.log

        #if [ $? -eq 0 ]; then
                #sleep 1 # necessary otherwise the copy fails
                #echo "Done."
                # cp -R $SPAM_FOLDER /home/vmail/$DOMAIN/$USERNAME/.Spam && echo "Created spam folder"
        #else
                #echo "fail! (I haven't created spam folder)"
                #echo "Check /var/log/mail.log for details"
        #fi
else
        echo "Failed adding new user:"
        cat mysql.err
        rm -f mysql.err
fi

echo ""
}
##################################################################


##################################################################
create_mail_forwarding()
##################################################################
{
set LHS
set RHS
set DOMAIN
set USERNAME
set MAIL_ADDRESS_TEST

echo -n "Enter the new email address alias you want to add: "
read LHS

echo -n "Enter the existing email address you want mail to the alias $LHS to instead go to: "
read RHS

# CHECK IF THE RHS EMAIL ADDRESS IS VALID

# seperate username and domain into variables
#DOMAIN=`echo $RHS | sed -e 's@[a-zA-Z0-9]*\@@@'`
#USERNAME=`echo $RHS | sed -e 's@\@[a-zA-z0-9.]*@@'`
# These regexes could be more accurate
# sed: -e expression #1, char 19: Invalid range end
# USERNAME IS COMING OUT BLANK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

echo "Checking the existing mail address you provided already exists"
echo ""
#echo "Searching to see if the domain $DOMAIN exists..."
echo "(You'll have to enter the password for the provider_admin database user)"

# Check if this domain exists in the database.
MAIL_ADDRESS_TEST=`mysql -u provider_admin -p -D provider --exec="SELECT email FROM users WHERE email='$RHS'" | sed -e '1d'`
#### THIS DOESN'T WORK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! says it doesn't exist

# If that address doesn't exist, say so and quit.
if [ -z $DOMAIN_TEST ]; then
	echo ""
	echo "Either there was a problem accessing the database (see above);"
        echo "or the email address '$RHS' doesn't exist."
	pause
	mail_server_menu
fi


# !!!! SHOULD CHECK THE LHS DOMAIN EXISTS


# IF THE EMAIL ADDRESS WAS VALID THEN WE CONTINUE
echo ""
echo "Adding the forwarding..."
echo "(You'll be prompted for the MySQL root user's password)"
mysql -u root -p -D provider \
--exec="INSERT INTO forwardings (source, destination) VALUES('$LHS', '$RHS')"

echo ""
}
##################################################################


##################################################################
nfs-server()
##################################################################
{
echo "NFS server:"
echo ""
aptitude install nfs-kernel-server portmap
echo ""
}
##################################################################


##################################################################
subversion-server()
##################################################################
{
echo "Version control system using Subversion:"
echo ""
aptitude install subversion subversion-dav
echo ""
}
##################################################################


##################################################################
dhcp-server()
##################################################################
{
echo "DHCP server:"
echo ""
aptitude install dhcp3-server
echo ""
}
##################################################################


##################################################################
irc-server()
##################################################################
{
echo "IRC server using Dancer:"
echo ""
aptitude install dancer-ircd dancer-ircd-doc dancer-services
echo ""
}
##################################################################


##################################################################
ltsp-server()
##################################################################
{
echo "Linux Terminal Server:"
echo ""
aptitude install ltsp-utils dhcp3-server tftpd-hp nfs-kernel-server xdm
echo ""
}
##################################################################





rcs_menu()
{
clear
echo "==============================================================================="
echo " Roaming Computing System (Windows Edition) 3.0 - 3.5 Configuration"
echo "==============================================================================="
#echo "A. Install and configure a Samba Domain Controller"
echo "E. Create an organisation-wide group, directory and share (S:)"
echo "F. Create a sub-group and a restricted shared directory just for them (R:)"
echo "-------------------------------------------------------------------------------"
echo "M. Create a new user account"
echo "N. Remove a user account"
echo "-------------------------------------------------------------------------------"
echo "O. Add a user to a group (i.e. for access to shared, restricted or a sub-group)"
echo "P. Remove a user from a group (i.e. from the organisation group)"
echo "-------------------------------------------------------------------------------"
echo "R. Backup a user's Windows profile"
echo "S. Restore a user's Windows profile from their last backup (CAUTION!)"
echo "==============================================================================="
echo -n "Choose which option to apply ['Q' to quit]: "
read RCS_CHOICE
clear

case "$RCS_CHOICE" in
 "_a_" | "_A_")
   echo "Beware: If you're already running Samba this could disrupt your existing setup!"
   echo -n "Are you sure you want to install and configure Samba (Y/N)? "
   read INPUT
   case "$INPUT" in
    "y" | "Y")
      setup_samba_pdc
      echo ""
      echo -n "Press [Enter] to continue"
      read PAUSEKEY
      rcs_menu ;;
    "n" | "N")
      rcs_menu ;;
    *)
      rcs_menu ;;
   esac ;;
 "e" | "E")
  shared_org_directories
  pause
  rcs_menu ;;
 "f" | "F")
  restricted_group_directory
  pause
  rcs_menu ;;
 "m" | "M")
  add_users
  pause
  rcs_menu ;;
 "n" | "N")
  remove_user
  pause
  rcs_menu ;;
 "o" | "O")
  add_user_to_group
  pause
  rcs_menu ;;
 "p" | "P")
  remove_user_from_group
  pause
  rcs_menu ;;
 "r" | "R")
  backup_windows_profile
  pause
  rcs_menu ;;
 "s" | "S")
  restore_windows_profile
  pause
  rcs_menu ;;
 "q" | "Q")
  FINISHED=true
  top_menu ;;
 *)
  rcs_menu ;;
esac
}




##################################################################
#check_for_input()
##################################################################
#_MESSAGE = MESSAGE

#unset INPUT_VALUE
#while [ -z "$INPUT_VALUE" ]; do
#echo -n "$_MESSAGE"
#read INPUT_VALUE
# if [ -z "$INPUT_VALUE" ]; then
#   echo "Please enter something!"
# else
#   echo return 0
# fi
#done

#return "$INPUT_VALUE"

##################################################################


##################################################################
add_user_to_group()
##################################################################
{
unset USER_NAME
while [ -z "$USER_NAME" ]; do
  echo -n "Enter the username : "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  fi
done

unset SUB_GROUP
while [ -z "$SUB_GROUP" ]; do
  echo -n "Enter the group to add them to : "
  read SUB_GROUP
  if [ -z "$SUB_GROUP" ]; then
    echo "Please enter something!"
  fi
done

addgroup "$USER_NAME" "$SUB_GROUP"

}
##################################################################


##################################################################
remove_user()
##################################################################
{
echo "Remove a Roaming Computing System user account."
echo "(This may or may not leave all their files intact)"
echo ""

unset USER_NAME
while [ -z "$USER_NAME" ]; do
  echo -n "Enter the username : "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  fi
done

echo "removing Samba account (you'll need to enter your Samba password)..."
net rpc user delete "$USER_NAME"
echo ""
}
##################################################################


##################################################################
add_users()
##################################################################
{
unset USER_NAME
while [ -z "$USER_NAME" ]; do
  echo -n "Enter the new Samba account username: "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  else
   echo ""
   echo "Adding "$USER_NAME"'s Samba account"
   echo "(You'll need to enter your Samba password)"
   net rpc user add "$USER_NAME"
   echo ""
   echo "Setting their password (same as their username, which should be changed at the"
   echo "earliest opportunity. You'll need to enter your Samba password)"
   net rpc password "$USER_NAME" "$USER_NAME"
   smbpasswd -e "$USER_NAME"
   mkdir /home/samba/profiles/"$USER_NAME"
   chown "$USER_NAME" /home/samba/profiles/"$USER_NAME"
  echo ""
  fi
done

echo ""
echo "You now need to login to Windows and configure their account."
echo ""
}
##################################################################


##################################################################
batch_add_users()
##################################################################
{
unset SAMBA_PASSWORD
while [ -z "$USER_NAME" ]; do
  echo -n "Enter the new Samba account username: "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  else

    unset USER_NAME
    while [ -z "$USER_NAME" ]; do
      echo -n "Enter the new Samba account username: "
      read USER_NAME
      if [ -z "$USER_NAME" ]; then
        echo "Please enter something!"
      else
       echo ""
       echo "Adding "$USER_NAME"'s Samba account"
       echo "(You'll need to enter your Samba password)"
       net rpc user add "$USER_NAME"
       echo ""
       echo "Setting their password (same as their username, which should be changed at the"
       echo "earliest opportunity. You'll need to enter your Samba password)"
       net rpc password "$USER_NAME" "$USER_NAME"
       smbpasswd -e "$USER_NAME"
       mkdir /home/samba/profiles/"$USER_NAME"
       chown "$USER_NAME" /home/samba/profiles/"$USER_NAME"
      echo ""
      fi
    done

  fi
done
}
##################################################################


##################################################################
add_user_to_group()
##################################################################
{
unset GROUP
unset USER_NAME

while [ -z "$USER_NAME" ]; do
  echo -n "Enter the Samba account username you want to add to a group: "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  else

  while [ -z "$GROUP" ]; do
    echo ""
    echo "There might be various groups you can add them to, for instance:"
    echo "- <your organisation name>-staff for access to shared drive (S:)"
    echo "- any sub-group(s) you might have for separate departments"
    echo -n "Enter the name of the group to add them to: "
    read GROUP
    echo ""
    if [ -z "$GROUP" ]; then echo "Please enter something!"
    else
     echo "Adding "$USER_NAME" to "$GROUP"..."
     addgroup "$USER_NAME" "$GROUP"
     echo ""
    fi
  done

  fi
done
}
##################################################################


##################################################################
add_users_from_file()
##################################################################
{
unset INFILE
while [ -z "$INFILE" ]; do
  echo -n "Enter input filename : "
  read INFILE
  if [ -z "$INFILE" ]; then
    echo "Please enter something!"
  fi
done

if [ ! -f "$INFILE" ]; then
echo "Unable to stat "$INFILE""
exit 2
fi

while read LINE
do
 USER_NAME=`echo "$LINE" | cut -d ',' -f1`
 FULLNAME=`echo "$LINE" | cut -d ',' -f2`
 ORGANISATION_GROUP=`echo "$LINE" | cut -d ',' -f3`
 SUB_GROUP=`echo "$LINE" | cut -d ',' -f4`

 adduser "$USER_NAME"
 adduser "$USER_NAME" "$ORGANISATION_GROUP"
 adduser "$USER_NAME" "$SUB_GROUP"

 smbpasswd -a "$USER_NAME"
 mkdir /home/samba/profiles/"$USER_NAME"
 chown "$USER_NAME"."$USER_NAME" /home/samba/profiles/"$USER_NAME"
 chmod o-rwx /home/samba/profiles/"$USER_NAME" -R
 mkdir /home/samba/profiles/"$USER_NAME"/templates

 cp /home/samba/profiles/template/* /home/samba/profiles/"$USER_NAME"/ -R
 chown "$USER_NAME" /home/samba/profiles/"$USER_NAME" -R
 #? chgrp "$USER_NAME" /home/samba/profiles/"$USER_NAME" -R
done < "$INFILE"
}
##################################################################


##################################################################
remove_user_from_group()
##################################################################
{
unset USER_NAME
while [ -z "$USER_NAME" ]; do
  echo -n "Enter the username : "
  read USER_NAME
  if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
  fi
done

unset SUB_GROUP
while [ -z "$SUB_GROUP" ]; do
  echo -n "Enter the group to remove them from : "
  read SUB_GROUP
  if [ -z "$SUB_GROUP" ]; then
    echo "Please enter something!"
  fi
done

deluser "$USER_NAME" "$SUB_GROUP"

}
##################################################################



##################################################################
shared_org_directories()
##################################################################
{
unset ORGANISATION_GROUP
while [ -z "$ORGANISATION_GROUP" ]; do
  echo -n "Enter the name of the group to use to represent your organisation : "
  read ORGANISATION_GROUP
  if [ -z "$ORGANISATION_GROUP" ]; then
    echo "Please enter something!"
  fi
done

echo ""
echo "Creating a group called '"$ORGANISATION_GROUP"'..."
addgroup "$ORGANISATION_GROUP"

echo ""
echo "Creating top-level directory for creating shared space under..."
mkdir /home/"$ORGANISATION_GROUP"
#chmod...???

echo ""
echo "Creating a shared directory for everyone..."
mkdir /home/"$ORGANISATION_GROUP"/shared

echo ""
echo "Setting permissions on shared directory..."
chmod 2770 /home/"$ORGANISATION_GROUP"/shared

echo ""
echo "Setting the group the shared directory belongs to to that of the organisation..."
chgrp "$ORGANISATION_GROUP" /home/"$ORGANISATION_GROUP"/shared

echo ""
echo "Creating a shared templates directory within the shared directory..."
mkdir /home/"$ORGANISATION_GROUP"/shared/templates


# assuming our smb.conf is being used, set the directory name for the organisation-wide 
# shared directory in smb.conf's [shared] section
echo ""
echo "Setting organisation-wide shared directory to /home/"$ORGANISATION_GROUP"/shared in Samba's configuration file (smb.conf) (assuming you're using our example smb.conf)..."
perl -pi.orig -e "s/\/home\/organisation_name_goes_here\/shared/\/home\/"$ORGANISATION_GROUP"\/shared/gi" /etc/samba/smb.conf

echo ""
echo "Restarting Samba..."
/etc/init.d/samba restart
}
##################################################################



##################################################################
restricted_group_directory()
##################################################################
{
unset ORGANISATION
while [ -z "$ORGANISATION" ]; do
echo -n "Enter the name you use in this system to represent your organisation : "
read ORGANISATION
 if [ -z "$ORGANISATION" ]; then
   echo ""
   echo "Please enter something!"
 fi
done


# check if this shared directory exists; if it doesn't then advise them to run option E and call 'pause' which will then return them to the main menu
if [ -n "$ORGANISATION" ] && [ ! -d /home/"$ORGANISATION" ]; then
  echo ""
  echo "The directory /home/"$ORGANISATION" doesn't exist!"
  echo "You should run the relevant option from the menu to create it before"
  echo "running this option!"
# if the shared directory doesn't exist then quit, otherwise do the rest of this section
else


# check if org name isn't blank and the restricted directory exists; if it doesn't exist, create it
if [ -n "$ORGANISATION" ] && [ ! -d /home/"$ORGANISATION"/restricted ]; then
  echo ""
  echo "You don't have a restricted directory in which to locate sub-group directories,"
  echo "so creating it..."
  mkdir /home/"$ORGANISATION"/restricted

  echo ""
  echo "Changing the group of the restricted directory to the organisation group..."
  chgrp "$ORGANISATION"-staff /home/"$ORGANISATION"/restricted

  echo ""
  echo "Setting permissions on restricted directory..."
  chmod 0750 /home/"$ORGANISATION"/restricted
fi


unset SUB_GROUP
while [ -z "$SUB_GROUP" ]; do
  echo ""
  echo -n "Enter the sub-group name that you want to add a directory for : "
  read SUB_GROUP
   if [ -z "$SUB_GROUP" ]; then
     echo "Please enter something!"
   else
     echo ""
     echo "Creating a group called '"$SUB_GROUP"'..."
     addgroup "$SUB_GROUP"
   fi
done


echo ""
echo "Creating shared space for the group..."
mkdir /home/"$ORGANISATION"/restricted/"$SUB_GROUP"

echo ""
echo "Setting permissions on shared directory..."
echo "(such that one group member can't see the files of another group)..."
chmod 2770 /home/"$ORGANISATION"/restricted/"$SUB_GROUP"

echo ""
echo "Setting the group the shared directory belongs to to that of the sub-group..."
chgrp "$SUB_GROUP" /home/"$ORGANISATION"/restricted/"$SUB_GROUP"

# end of: if the shared directory doesn't exist then quit, otherwise do the rest of this section
fi
}
##################################################################



##################################################################
backup_windows_profile()
##################################################################
{
 unset USER_NAME
 while [ -z "$USER_NAME" ]; do
   echo -n "Enter username to backup: "
   read USER_NAME
   if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
   fi
 done

 # if USER_NAME isn't empty (-n), location exists and is a directory (-d), rename it with an extension for the current date and time
 if [ -n "$USER_NAME" ] && [ -d /home/samba/profiles-backup/"$USER_NAME" ]; then
   echo "A backup of their profile already exists; renaming it with an extension of the current date and time (`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`)"
   mv /home/samba/profiles-backup/"$USER_NAME" /home/samba/profiles-backup/"$USER_NAME"-`date +%Y`-`date +%b`-`date +%d`-`date +%H`-`date +%M`-`date +%S`
 fi

 # if the directory for saving profile backups in doesn't exist, create it
 if [ ! -d /home/samba/profiles-backup ]; then
   echo "The directory for backing up profiles to doesn't already exist so creating it..."
   mkdir /home/samba/profiles-backup
 fi

 echo "Making backup of profile..."
 cp /home/samba/profiles/"$USER_NAME" /home/samba/profiles-backup/"$USER_NAME" -R
}
##################################################################


##################################################################
restore_windows_profile()
##################################################################
{
 unset USER_NAME
 while [ -z "$USER_NAME" ]; do
   echo -n "Enter username to restore: "
   read USER_NAME
   if [ -z "$USER_NAME" ]; then
    echo "Please enter something!"
   fi
 done

 # if USER_NAME isn't empty and a backup exists for this user and its a directory
 if [ -n "$USER_NAME" ] && [ -d /home/samba/profiles-backup/"$USER_NAME" ]; then

   # check if that user has an existing profile
   if [ -d /home/samba/profiles/"$USER_NAME" ]; then

      unset PROFILE_CHOICE
      while [ -z "$PROFILE_CHOICE" ]; do
        echo -n "Are you sure you want to wipe out their existing Windows profile with this backup profile?: "
        read PROFILE_CHOICE

        if [ "$PROFILE_CHOICE" = "Y" ] || [ "$PROFILE_CHOICE" = "y" ]; then
            echo "Restoring from the backup..."
            cp /home/samba/profiles-backup/"$USER_NAME" /home/samba/profiles/"$USER_NAME" -R
        elif [ "$PROFILE_CHOICE" = "N" ] || [ "$PROFILE_CHOICE" = "n" ]; then
          PROFILE_CHOICE=exit
        else
          unset PROFILE_CHOICE
        fi

      done

   else
     echo "That user doesn't have a Windows profile directory to restore to!"
   fi

 else
   echo "There isn't a backup to restore from for that user!"
 fi
}
##################################################################



##################################################################
setup_samba_pdc()
##################################################################
{
#################
#INSTALLING SAMBA
#################
echo ""
echo "Updating repository information..."
apt-get update

echo ""
echo "Installing Samba..."
apt-get install samba

###################################
#USERNAMES AND DIRECTORIES - SYSTEM
###################################
echo ""
echo "Creating 'admins' and 'machines' groups..."
addgroup --gid 200 admins
addgroup --gid 201 machines

echo ""
echo "Creating directories for Samba to use with Windows..."

echo ""
echo "Creating directory to use as a container for other Windows related directories..."
mkdir /home/samba

echo ""
echo "Creating directory for Windows profiles..."
mkdir /home/samba/profiles

echo ""
echo "Setting permissions on Windows profiles directory..."
chmod 1757 /home/samba/profiles
echo ""

echo ""
echo "Creating directory for Windows profile backups..."
mkdir /home/samba/configured-profiles-backup

echo ""
echo "Creating directory for Windows clients logging on..."
mkdir -m 0775 /home/netlogon

echo ""
echo "Changing ownership of Windows logon directory..."
chown root.admins /home/netlogon


# note: do we need to set permissions for all of these:
echo ""
echo "Making /usr/windows as a container for putting Windows related files in..."
mkdir /usr/windows

echo ""
echo "Making /usr/windows/programs for installing any shared Windows programs to..."
mkdir /usr/windows/programs

echo ""
echo "Making /usr/windows/updates as a container for putting update directories in such as for Windows client anti-virus software..."
mkdir /usr/windows/updates

echo ""
echo "Making /usr/windows/updates/anti-virus for downloading anti-virus software updates to..."
mkdir /usr/windows/updates/anti-virus

echo ""
echo "Making /usr/windows/software for using as a Windows software installer repository..."
mkdir /usr/windows/software

echo ""
echo "Making /usr/windows/preferences for storing commonly used preference files in..."
mkdir /usr/windows/preferences

#############################
#THE SAMBA CONFIGURATION FILE
#############################
cd /etc/samba

echo ""
echo "Installing 'wget' which we need to be able to download our example smb.conf Samba configuration file..."
apt-get install wget


# if smb-conf-pdc.txt exists, rename it smb-conf-pdc.txt.previous
if [ -e /etc/samba/smb-conf-pdc.txt ]; then
  echo ""
  echo "/etc/samba/smb-conf-pdc.txt already exists, renaming it smb-conf-pdc.txt.previous before we download another version"
  mv /etc/samba/smb-conf-pdc.txt /etc/samba/smb-conf-pdc.txt.previous
fi

echo ""
echo "Downloading our example smb.conf Samba configuration file..."
wget -nv http://thegoldenear.org/toolbox/unices/smb-conf-pdc.txt


# Define Windows domain name
echo ""
unset DOMAIN_NAME
while [ -z "$DOMAIN_NAME" ]; do
 echo -n "What Windows domain name do you want to use?: "
 read DOMAIN_NAME

 # if nothing entered, ask for it again. If something entered, check if config file exists and insert domain name, or give error message
 if [ -z "$DOMAIN_NAME" ]; then
   echo "Please enter something!"
 else

  if [ -e /etc/samba/smb-conf-pdc.txt ]; then
    echo "Setting Windows domain name to '"$DOMAIN_NAME"'..."
    perl -pi.orig -e "s/domain_name_goes_here/"$DOMAIN_NAME"/gi" /etc/samba/smb-conf-pdc.txt
  else
    echo "ERROR: The file /etc/samba/smb-conf-pdc.txt doesn't exist!"
  fi

 fi
done


# Define machine's name
echo ""
unset HOST_NAME
while [ -z "$HOST_NAME" ]; do
echo "This machine's hostname is '"$HOSTNAME"'. Enter the name you want it known as to"
echo -n "Windows clients (we usually use a name like file-server) : "
read HOST_NAME

 # if nothing entered, ask for it again. If something entered, check if config file exists and insert domain name, or give error message
 if [ -z "$HOST_NAME" ]; then
   echo "Please enter something!"
 else

  if [ -e /etc/samba/smb-conf-pdc.txt ]; then
    echo "Setting machine name to '"$HOST_NAME"'..."
    perl -pi.orig -e "s/netbios\ name\ =\ file\-server/netbios\ name\ \=\ "$HOST_NAME"/gi" /etc/samba/smb-conf-pdc.txt
  else
    echo "ERROR: The file /etc/samba/smb-conf-pdc.txt doesn't exist!"
  fi

 fi
done


#backup the existing template configuration file
if [ -e /etc/samba/smb.conf ]; then

      unset CONFIG_CHOICE
      while [ -z "$CONFIG_CHOICE" ]; do
        echo ""
        echo "Warning: Samba's configuration file (/etc/samba/smb.conf) already exists!"
        echo "Are you sure you want to replace it"
        echo -n "(a backup will be saved as smb.conf.original) (Y/N)? "
        read CONFIG_CHOICE

        if [ "$CONFIG_CHOICE" = "Y" ] || [ "$CONFIG_CHOICE" = "y" ]; then
        echo ""
          echo "Backing up existing smb.conf and replacing it with ours..."
          cp smb.conf smb.conf.original
          cp smb-conf-pdc.txt smb.conf
        elif [ "$CONFIG_CHOICE" = "N" ] || [ "$CONFIG_CHOICE" = "n" ]; then
        echo ""
          echo "smb.conf not touched."
          echo "In future if you want to replace smb.conf re-run this option and choose 'Y'"
          echo "or manually copy smb-conf-pdc.txt to smb.conf"
          CONFIG_CHOICE=exit
        else
          unset CONFIG_CHOICE
        fi

      done

else
  echo "Creating smb.conf Samba configuration file..."
  cp smb-conf-pdc.txt smb.conf
fi

echo ""
echo "================================================================================================="
echo "You'll need to change the IP addresses in Samba's configuration file"
echo "(/etc/samba/smb.conf) to match your environment"
echo "================================================================================================="

echo ""
echo "Restarting Samba..."
/etc/init.d/samba restart

echo ""
echo "Creating Samba account and profile directories for the user 'root'..."
mkdir /home/samba/profiles/root
chown root /home/samba/profiles/root
chmod g-rwx,o-rwx /home/samba/profiles/root -R
# ? chgrp users /home/samba/profiles/root ?
smbpasswd -a root


#####################
#WINDOWS LOGON SCRIPT
#####################
echo ""
cd /home/netlogon

# if NETLOGON.BAT exists, rename it NETLOGON.BAT.previous
if [ -e /home/netlogon/NETLOGON.BAT ]; then
  echo ""
  echo "/home/netlogon/NETLOGON.BAT already exists, renaming it /home/netlogon/NETLOGON.BAT.previous before we download another version"
  mv /home/netlogon/NETLOGON.BAT /home/netlogon/NETLOGON.BAT.previous
fi

echo "Downloading our example logon script (NETLOGON.BAT)..."
wget -nv http://thegoldenear.org/toolbox/unices/samba/NETLOGON.BAT

echo ""
echo "Setting permissions on logon script such that everyone can read it..."
chmod a+r /home/netlogon/NETLOGON.BAT
}
##################################################################


##################################################################
pause()
{
echo ""
echo -n "Press [Enter] to continue"
read PAUSEKEY
}
##################################################################



#MAIN SCRIPT
#pause
top_menu
exit 0
