Skip to content

Instantly share code, notes, and snippets.

@Alanaktion
Last active November 9, 2017 21:02
Show Gist options
  • Save Alanaktion/a4f7ddfa67479c197bca to your computer and use it in GitHub Desktop.
Save Alanaktion/a4f7ddfa67479c197bca to your computer and use it in GitHub Desktop.
A perfect Xubuntu setup
#!/bin/bash
# This script is designed to run on Xubuntu 14.04, but should work on
# most Ubuntu and Debian-based distros
##################
# Define globals #
##################
SETUPNAME="Alan's Xubuntu Setup"
DISTRO=`lsb_release -c | awk '{ print $NF }'`
# Prompt user for a y/n response
function prompt() {
local prompt_response
echo -ne "\e[0;32m$1\e[0m"
echo -n " [y/n] "
read prompt_response
[[ $prompt_response == 'y' ]] && return 0
return 1
}
# Prompt user for a Yes/No response with an ncurses dialog
function dprompt() {
msg_len=$((6+${#1}))
dialog --title "$SETUPNAME" \
--yesno "\n $1" 7 $msg_len
return "$?"
}
# Clear screen, show cancellation message, and exit
function die() {
clear
echo -e "\e[1;31mInstallation canceled!\e[0m"
exit 1
}
#################
# Initial setup #
#################
# Verify user is not root
if [ "$USER" == "root" ]; then
echo -e "\e[1;31mYou are currently running as root, which is unsupported.\e[0m"
prompt "\e[1;31mContinue anyway?\e[0m"
if [ "$?" > 0 ]; then
exit 1
fi
fi
# Install dialog if it's not currently installed
if !(hash dialog 2>/dev/null); then
echo "Installing required program: 'dialog'."
sudo apt-get install -y dialog
fi
# Check if user set to passwordless in sudoers; if not, offer to add entry
`sudo grep "^$USER" /etc/sudoers | grep "NOPASSWD"`
if [ "$?" == 1 ]; then
dprompt "Enable passwordless sudo for current user ($USER)?"
if [ "$?" == 0 ]; then
clear
/usr/bin/sudo /bin/bash -c \
"echo '$USER ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers"
fi
fi
############################
# Prompt for installations #
############################
role=(`dialog --backtitle "$SETUPNAME" \
--checklist "Install roles:" 10 40 3 \
1 'Web Development' off \
2 'Image Editing' off \
3 'Qt Development' off \
4 'Windows Compatibility' off 3>&2 2>&1 1>&3`) || die
if [[ "${role[@]}" =~ "1" ]]; then
webserver=(`dialog --backtitle "$SETUPNAME" \
--radiolist "Select web server:" 10 40 3 \
1 'nginx + PHP5-FPM' on \
2 'nginx + HHVM + PHP5 CLI' off \
3 'Apache2 + PHP' off 3>&2 2>&1 1>&3`) || die
fi
extra=(`dialog --backtitle "$SETUPNAME" \
--checklist "Install extras:" 15 40 8 \
1 'Node.js (with npm)' on \
2 'Ruby (with RVM)' on \
3 'Additional themes' off \
4 'Pithos (Pandora client)' off \
5 'Sublime Text 3' off \
6 'VirtualBox 5.0' off \
7 'Nerdy Stuff' off 3>&2 2>&1 1>&3`) || die
if [[ "${extra[@]}" =~ "1" ]]; then
dprompt "Install useful npm packages?"
install_npm_packages="$?"
fi
if [[ $XDG_CURRENT_DESKTOP == 'XFCE' ]]; then
`xfce4-about --version | head -n 1 | grep "4.12"`
if [ "$?" == 1 ]; then
dprompt "Update to Xfce 4.12?"
update_xfce="$?"
fi
fi
if [[ $XDG_CURRENT_DESKTOP == 'Unity' ]]; then
dprompt "Install gnome-session-fallback as an alternative to Unity?"
install_gsf="$?"
fi
if [[ "${extra[@]}" =~ "5" ]]; then
dprompt "Automatically update Sublime (uses webupd8 PPA)?"
install_subl_ppa="$?"
fi
####################
# Set up new repos #
####################
clear
echo -e "\e[0;36mConfiguring repos...\e[0m"
sudo apt-get install -y software-properties-common
# Web Development Role
if [[ "${role[@]}" =~ "1" ]]; then
# HHVM
if [[ "$webserver" == "2" ]]; then
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 \
0x5a16e7281be7a449
sudo add-apt-repository "deb http://dl.hhvm.com/ubuntu $DISTRO main"
fi
fi
# Xfce 4.12
if [[ $XDG_CURRENT_DESKTOP == 'XFCE' ]]; then
if [ $update_xfce == 0 ]; then
sudo add-apt-repository ppa:xubuntu-dev/xfce-4.12 -y
sudo add-apt-repository ppa:xubuntu-dev/extras -y
fi
fi
# Additional themes
if [[ "${extra[@]}" =~ "3" ]]; then
sudo add-apt-repository ppa:noobslab/themes -y
sudo add-apt-repository ppa:noobslab/icons -y
fi
# Pithos
if [[ "${extra[@]}" =~ "4" ]]; then
sudo add-apt-repository ppa:pithos/ppa -y
fi
# Sublime Text 3
if [[ "${extra[@]}" =~ "5" ]]; then
if [ $install_subl_ppa == 0 ]; then
sudo add-apt-repository ppa:webupd8team/sublime-text-3 -y
fi
fi
# Virtualbox 5.0
if [[ "${extra[@]}" =~ "6" ]]; then
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | \
sudo apt-key add -
echo "deb http://download.virtualbox.org/virtualbox/debian $DISTRO contrib" \
sudo tee /etc/apt/sources.list.d/virtualbox.list
fi
# Nerdy stuff
if [[ "${extra[@]}" =~ "7" ]]; then
sudo add-apt-repository ppa:alex-wv/pulseaudio-equalizer-ppa -y
fi
#######################
# Update package list #
#######################
echo -e "\e[0;36mUpdating package lists...\e[0m"
sudo apt-get update
if [ $? != 0 ]; then
echo -e "\e[0;31mFailed to update package lists!\e[0m"
exit 1
fi
##########################
# Install system updates #
##########################
echo -e "\e[0;36mInstalling updates...\e[0m"
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
####################
# Install packages #
####################
echo -e "\e[0;36mInstalling new packages...\e[0m"
packages="htop vim curl wget"
# Web Development Role
if [[ "${role[@]}" =~ "1" ]]; then
packages="$packages mysql-server-5.6 mysql-client-5.6"
packages="$packages php5-cli php5-gd php5-mcrypt php5-mysql php5-json"
packages="$packages php5-curl"
if [[ "$webserver" == "1" ]]; then
packages="$packages nginx php5-fpm"
fi
if [[ "$webserver" == "2" ]]; then
packages="$packages nginx hhvm"
fi
if [[ "$webserver" == "3" ]]; then
packages="$packages apache2 php5"
fi
fi
# Image editing role
if [[ "${role[@]}" =~ "2" ]]; then
packages="$packages gimp inkscape imagemagick ufraw optipng"
fi
# Qt Development Role
if [[ "${role[@]}" =~ "3" ]]; then
packages="$packages build-essential qtcreator qtcreator-doc"
fi
# Windows application role
if [[ "${role[@]}" =~ "3" ]]; then
packages="$packages wine mono-complete"
fi
# Gnome Session Fallback
if [[ $XDG_CURRENT_DESKTOP == 'Unity' ]]; then
if [ $install_gsf == 0 ]; then
packages="$packages gnome-session-fallback"
fi
fi
# Node.js
if [[ "${extra[@]}" =~ "1" ]]; then
packages="$packages npm nodejs nodejs-legacy"
fi
# Pithos
if [[ "${extra[@]}" =~ "4" ]]; then
packages="$packages pithos"
fi
# Sublime Text 3
if [[ "${extra[@]}" =~ "5" ]]; then
if [ $install_subl_ppa == 0 ]; then
packages="$packages sublime-text-installer"
fi
fi
# Virtualbox 5.0
if [[ "${extra[@]}" =~ "6" ]]; then
packages="$packages dkms virtualbox-5.0"
fi
# Nerdy stuff
if [[ "${extra[@]}" =~ "7" ]]; then
packages="$packages build-essential pulseaudio-equalizer cmatrix elinks"
packages="$packages exfat-utils exfat-fuse meld qalc dconf-tools dos2unix"
packages="$packages nmap nethack speedometer sysstat gpick optipng"
packages="$packages android-tools-adb android-tools-fastboot"
packages="$packages tmux screen w3af"
fi
# Install packages
sudo apt-get install -y $packages
######################
# Configure packages #
######################
# Web Development Role
if [[ "${role[@]}" =~ "1" ]]; then
# All web servers
sudo mkdir -p /var/www
sudo chown www-data:www-data /var/www
# HHVM
if [[ "$webserver" == "2" ]]; then
sudo /usr/share/hhvm/install_fastcgi.sh
sudo update-rc.d hhvm defaults
sudo /etc/init.d/hhvm restart
fi
# nginx
if [[ "$webserver" != "3" ]]; then
sudo sed -i 's/root \/usr\/share\/nginx\/html/root \/var\/www/g' /etc/nginx/sites-enabled/default
sudo /etc/init.d/nginx restart
fi
fi
# Node.js npm packages
if [[ "${extra[@]}" =~ "1" ]]; then
if [ $install_npm_packages == 0 ]; then
sudo -Hi npm install -g bower gulp grunt-cli jshint
fi
fi
# Ruby with rvm
if [[ "${extra[@]}" =~ "2" ]]; then
gpg --keyserver hkp://keys.gnupg.net --recv-keys \
409B6B1796C275462A1703113804BB82D39DC0E3
/usr/bin/curl -L https://get.rvm.io | bash -s stable --ruby
. ~/.rvm/scripts/rvm
echo 'source ~/.rvm/scripts/rvm' >> $HOME/.bashrc
type ruby
fi
# Additional themes (Noobslab and .debs from Phpizza mirror)
if [[ "${extra[@]}" =~ "3" ]]; then
# Noobslab themes
sudo apt-get install -y dorian-theme-3.12 numix-gtk-theme azure-gtk-theme \
flatice-theme flatbird-theme hackstation-theme zukitwo zukiwi \
windos-10-themes ylmfos-icons ylmfos-theme win-themes win-icons
# Install custom themes
mkdir -p $HOME/Downloads/Themes
cd $HOME/Downloads/Themes
wget https://mirror.phpizza.com/deb/mediterranean-gtk-themes.deb
sudo dpkg -i mediterranean-gtk-themes.deb
wget https://mirror.phpizza.com/deb/mac-osx-cursor-theme.deb
sudo dpkg -i mac-osx-cursor-theme.deb
cd $HOME
echo -e "\e[0;35mNew cursor can be selected by running this:\e[0m"
echo -e "\e[0;35msudo update-alternatives --config x-cursor-theme\e[0m"
echo
fi
# Sublime Text 3 non-PPA
if [[ "${extra[@]}" =~ "5" ]]; then
if [ $install_subl_ppa != 0 ]; then
echo "Installing Sublime Text b3083. A newer build may be available online."
mkdir -p $HOME/Downloads/Applications
cd $HOME/Downloads/Applications
wget http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3083_amd64.deb
sudo dpkg -i sublime-text_build-3083_amd64.deb
cd $HOME
fi
fi
# if [ $install_vbox == 0 ]; then
# prompt "Install PHPVirtualBox?"
# if [ $? == 0 ]; then
# echo -n "Choose a password for the VirtualBox user:"
# read vboxpass
# sudo useradd vboxuser
# sudo chpasswd <<< "vboxuser:$vboxpass"
# echo "VBOXWEB_USER=vboxuser" | sudo tee /etc/default/virtualbox
# TODO: Set up the PHP side
# mkdir -p $HOME/Downloads/Applications
# cd $HOME/Downloads/Applications
# wget https://mirror.phpizza.com/php/phpvirtualbox-5.0-5.zip
# unzip phpvirtualbox-5.0-5.zip
# sudo mv phpvirtualbox-5.0-5 /var/www/vbox
# cp /var/www/vbox/config.php-example /var/www/vbox/config.php
# sudo chown -R www-data:www-data /var/www/vbox
# then, replace the username and password in config.php with vboxuser's
# fi
# fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment