Last active
August 29, 2015 13:57
-
-
Save alghanmi/9402336 to your computer and use it in GitHub Desktop.
USCLUG VM Generation Script for Workshops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCRIPT_USERNAME="usclug" | |
SCRIPT_USERHOME="/home/$SCRIPT_USERNAME" | |
echo "**" | |
echo "** System Setup" | |
echo "**" | |
cp /etc/apt/sources.list /etc/apt/sources.list.default | |
echo "deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free" | tee /etc/apt/sources.list | |
echo "deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free" | tee -a /etc/apt/sources.list | |
echo "" | tee -a /etc/apt/sources.list | |
echo "deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free" | tee -a /etc/apt/sources.list | |
echo "deb-src http://ftp.debian.org/debian/ wheezy-updates main contrib non-free" | tee -a /etc/apt/sources.list | |
echo "" | tee -a /etc/apt/sources.list | |
echo "deb http://security.debian.org/ wheezy/updates main contrib non-free" | tee -a /etc/apt/sources.list | |
echo "deb-src http://security.debian.org/ wheezy/updates main contrib non-free" | tee -a /etc/apt/sources.list | |
## Debian Packports | |
echo "# Debian Backports" | tee /etc/apt/sources.list.d/debian-backports.list | |
echo "deb http://ftp.debian.org/debian/ wheezy-backports main" | tee -a /etc/apt/sources.list.d/debian-backports.list | |
echo "deb-src http://ftp.debian.org/debian/ wheezy-backports main" | tee -a /etc/apt/sources.list.d/debian-backports.list | |
## Debian Testing | |
echo "# Debian Testing" | tee /etc/apt/sources.list.d/debian-testing.list | |
echo "deb http://ftp.us.debian.org/debian testing main" | tee -a /etc/apt/sources.list.d/debian-testing.list | |
echo "deb-src http://ftp.us.debian.org/debian testing main" | tee -a /etc/apt/sources.list.d/debian-testing.list | |
## Nginx Official Package | |
echo "# Nginx" | tee /etc/apt/sources.list.d/nginx.list | |
echo "deb http://nginx.org/packages/debian/ wheezy nginx" | tee -a /etc/apt/sources.list.d/nginx.list | |
echo "deb-src http://nginx.org/packages/debian/ wheezy nginx" | tee -a /etc/apt/sources.list.d/nginx.list | |
apt-key adv --keyserver pgp.mit.edu --recv-keys ABF5BD827BD9BF62 | |
## Midori Lightweight Browser | |
echo "#Midori" | tee /etc/apt/sources.list.d/midori.list | |
echo "deb http://ppa.launchpad.net/midori/ppa/ubuntu trusty main" | tee /etc/apt/sources.list.d/midori.list | |
echo "deb-src http://ppa.launchpad.net/midori/ppa/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/midori.list | |
apt-key adv --keyserver pgp.mit.edu --recv-keys 61E5F6C1A69241F1 | |
## APT Pinning | |
## The following configuration only allows packages to be | |
## explicitly installed from testing. | |
echo "Package: *" | tee /etc/apt/preferences.d/wheezy | |
echo "Pin: release o=Debian,a=stable" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Pin-Priority: 800" | tee -a /etc/apt/preferences.d/wheezy | |
echo "" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Package: *" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Pin: release o=Debian,a=testing" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Pin-Priority: 300" | tee -a /etc/apt/preferences.d/wheezy | |
echo "" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Package: *" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Pin: release o=Debian" | tee -a /etc/apt/preferences.d/wheezy | |
echo "Pin-Priority: -1" | tee -a /etc/apt/preferences.d/wheezy | |
## Give Nginx official package priority over debian repos | |
echo "Package: nginx nginx-debug" | tee /etc/apt/preferences.d/nginx | |
echo "Pin: origin nginx.org" | tee -a /etc/apt/preferences.d/nginx | |
echo "Pin-Priority: 901" | tee -a /etc/apt/preferences.d/nginx | |
## Update system | |
echo "**" | |
echo "** Update Installed Packages" | |
echo "**" | |
apt-get update | |
apt-get upgrade | |
apt-get dist-upgrade | |
## Install Packages | |
echo "**" | |
echo "** Install New Packages" | |
echo "**" | |
apt-get install \ | |
ssh openssh-server openssl build-essential binutils tmux \ | |
module-assistant \ | |
sudo ntp lsb-release tree htop traceroute curl \ | |
bash-completion dialog \ | |
python python-pip ruby \ | |
subversion subversion-tools git mercurial \ | |
vim vim-scripts emacs23 emacs-goodies-el nano \ | |
enscript highlight astyle colordiff diffstat \ | |
unzip zip p7zip \ | |
xorg openbox obconf tint2 \ | |
lxterminal midori | |
echo "**" | |
echo "** Configuration" | |
echo "**" | |
# Allow VM to build kernel modules (mainly for VBox settings) | |
m-a prepare | |
# User Management | |
usermod -a -G sudo $SCRIPT_USERNAME | |
usermod -a -G adm $SCRIPT_USERNAME | |
usermod -a -G www-data $SCRIPT_USERNAME | |
usermod -a -G vboxsf $SCRIPT_USERNAME | |
# GRUB Timeout | |
sed -i "s/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/" /etc/default/grub | |
update-grub | |
# Local information | |
dpkg-reconfigure tzdata | |
locale-gen en_US.UTF-8 | |
update-locale LANG=en_US.UTF-8 | |
dpkg-reconfigure locales | |
select-default-wordlist | |
# Updaing alternatives to set defaults for editor and terminal emulator | |
update-alternatives --config editor | |
update-alternatives --config x-terminal-emulator | |
# Install Inconsolata font (variant) | |
mkdir -p /usr/share/fonts/opentype | |
curl --silent http://media.nodnod.net/Inconsolata-dz.otf.zip | zcat > /usr/share/fonts/opentype/Inconsolata-dz.otf | |
fc-cache -fv | |
##GUI Configuration | |
sed -i 's/^id:.*:initdefault:.*/id:5:initdefault:/' /etc/inittab | |
## Update system | |
echo "**" | |
echo "** System Clean-up" | |
echo "**" | |
apt-get autoremove | |
apt-get clean | |
apt-get autoclean | |
echo "**" | |
echo "** User Configuration" | |
echo "**" | |
sed -i 's/^HISTCONTROL=.*/HISTCONTROL=ignoredups/' $SCRIPT_USERHOME/.bashrc | |
sed -i 's/^HISTSIZE=.*/HISTSIZE=10000/' $SCRIPT_USERHOME/.bashrc | |
sed -i '/^HISTFILESIZE=.*/ a\ | |
PROMPT_COMMAND="history -a;"' $SCRIPT_USERHOME/.bashrc | |
sed -i 's/^#force_color_prompt=.*/force_color_prompt=yes/' $SCRIPT_USERHOME/.bashrc | |
sed -i '/if \[ \"$color_prompt\" \= yes \]\; then/{N;s/\n.*//;}' $SCRIPT_USERHOME/.bashrc | |
sed -i '/if \[ \"$color_prompt\" \= yes \]\; then/ a\ | |
PS1=\'\'\${debian_chroot:+\(\$debian_chroot\)}\\\\[\\\\033[01\;32m\\\\]\\\\u@\\\\h\\\\[\\\\033[00m\\\\]:\\\\[\\\\033[01\;34m\\\\]\\\\w\ \\\\[\\\\033[31m\\\\]\$\(__git_ps1\ \"\(%s\)\"\)\\\\[\\\\033[00m\\\\]\\\\[\\\\033[00m\\\\]\\\\$\ \''' $SCRIPT_USERHOME/.bashrc | |
# User-specific GUI Configuration | |
echo "exec openbox-session" >> $SCRIPT_USERHOME/.xinitrc | |
chmod +x $SCRIPT_USERHOME/.xinitrc | |
chown $SCRIPT_USERNAME:$SCRIPT_USERNAME $SCRIPT_USERHOME/.xinitrc | |
mkdir $SCRIPT_USERHOME/.config | |
mkdir $SCRIPT_USERHOME/.config/openbox | |
touch $SCRIPT_USERHOME/.config/openbox/autostart.sh | |
echo "# Tint2 Panel/Task Bar" >> $SCRIPT_USERHOME/.config/openbox/autostart.sh | |
echo "(sleep 2s && tint2) &" >> $SCRIPT_USERHOME/.config/openbox/autostart.sh | |
echo "(sleep 2s && lxterminal) &" >> $SCRIPT_USERHOME/.config/openbox/autostart.sh | |
sed 's/<name>sans<\/name>/<name>dejvu sans<\/name>/' /etc/xdg/openbox/rc.xml > $SCRIPT_USERHOME/.config/openbox/rc.xml | |
chmod 755 $SCRIPT_USERHOME/.config $SCRIPT_USERHOME/.config/openbox $SCRIPT_USERHOME/.config/openbox/autostart.sh | |
chown -R $SCRIPT_USERNAME:$SCRIPT_USERNAME $SCRIPT_USERHOME/.config | |
# Start GUI on Login | |
echo '' >> $SCRIPT_USERHOME/.bashrc | |
echo '#Auto-start OpenBox on login' >> $SCRIPT_USERHOME/.bashrc | |
echo 'if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then' >> $SCRIPT_USERHOME/.bashrc | |
echo ' startx' >> $SCRIPT_USERHOME/.bashrc | |
echo 'fi' >> $SCRIPT_USERHOME/.bashrc | |
#Add nano syntax highlighting | |
find /usr/share/nano/ -name "*.nanorc" -print | sed -e 's/^\(.*\)$/include "\1"/g' >> $SCRIPT_USERHOME/.nanorc | |
chown $SCRIPT_USERNAME:$SCRIPT_USERNAME $SCRIPT_USERHOME/.nanorc | |
# Git basics | |
su - $SCRIPT_USERNAME -c "git config --global core.editor vi" | |
su - $SCRIPT_USERNAME -c "git config --global color.diff auto" | |
su - $SCRIPT_USERNAME -c "git config --global color.status auto" | |
su - $SCRIPT_USERNAME -c "git config --global color.branch auto" | |
su - $SCRIPT_USERNAME -c "git config --global color.interactive auto" | |
su - $SCRIPT_USERNAME -c "git config --global color.ui auto" | |
su - $SCRIPT_USERNAME -c "git config --global core.autocrlf input" | |
su - $SCRIPT_USERNAME -c "git config --global push.default simple" | |
su - $SCRIPT_USERNAME -c "git config --global merge.tool vimdiff" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some basic user configuration after launching X and starting the terminal
When creating an appliance make sure to compact properly, by running the following commands on the VM:
rm usclug-vm.sh dd if=/dev/zero of=fillfile bs=1M rm fillfile history -c sudo shutdown -h now
Then, on the host side:
Also, you may want to enable ssh access by:
Optionally, you may add the following tweaks:
Devices
->Shared Clipboard
->Bidirectional