Last active
August 29, 2015 14:13
-
-
Save kaidesu/2f3ff09a25e65a1a0e87 to your computer and use it in GitHub Desktop.
Post Install
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
#!/usr/bin/env bash | |
_success() { | |
echo -e "\e[1;32m$1\e[0m" | |
} | |
_error() { | |
echo -e "\e[1;41;37m$1\e[0m" | |
} | |
_info() { | |
echo -e "\e[1;33m$1\e[0m" | |
} | |
commandExists() { | |
command -v "$1" > /dev/null 2>&1 | |
} | |
installPackage() { | |
if [[ "$2" = "" ]]; then | |
local packages="$1" | |
else | |
local packages="$2" | |
fi | |
if commandExists "$1"; then | |
_info "$1 is already installed" | |
return | |
fi | |
echo -n "Installing $packages... " | |
sudo apt-get install -q -y $packages >> post_install.log 2>&1 & | |
local pid=$! | |
spinner $pid | |
wait $pid | |
if test $? -eq 0; then | |
_success "OK" | |
else | |
_error "Error installing $packages. See post_install.log" | |
fi | |
} | |
confirm() { | |
local choices | |
local question | |
local defaultResponse | |
case "$1" in | |
"-y") | |
choices="Yn" | |
question="$2" | |
defaultResponse=0 | |
;; | |
"-n") | |
choices="yN" | |
question="$2" | |
defaultResponse=1 | |
;; | |
*) | |
choices="yn" | |
question="$1" | |
;; | |
esac | |
while true; do | |
read -ep "$question [$choices]: " userChoice | |
case $userChoice in | |
[yY]* ) return 0;; | |
[nN]* ) return 1;; | |
"" ) if [[ "$defaultResponse" != "" ]]; then return $defaultResponse; fi;; | |
esac | |
done | |
} | |
# Courtesy of http://fitnr.com/showing-file-download-progress-using-wget.html | |
download() { | |
local url=$1 | |
echo -n " " | |
wget -P /tmp --progress=dot $url 2>&1 | grep --line-buffered "%" | \ | |
sed -u -e "s, \.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' | |
echo -ne "\b\b\b\b" | |
_success "OK" | |
} | |
# Courtesy of http://fitnr.com/showing-a-bash-spinner.html | |
spinner() { | |
local pid=$1 | |
local delay=0.75 | |
local spinstr='|/-\' | |
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do | |
local temp=${spinstr#?} | |
printf " [%c] " "$spinstr" | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
printf "\b\b\b\b\b\b" | |
done | |
printf " \b\b\b\b" | |
} | |
installStorm() { | |
echo -n "Downloading $1... " | |
local STORM_FILENAME=$(basename "$2") | |
download "$2" | |
echo -n "Extracting $1... " | |
(cd "$HOME/Applications" && dtrx --one=rename -n "/tmp/$STORM_FILENAME") | |
_success "OK" | |
} | |
clear && printf '\e[3J' | |
# ---------------------------------- # | |
# --- Start of post installation --- # | |
# ---------------------------------- # | |
echo "" > post_install.log | |
sudo echo "===========================================================" | |
echo " ____ __ ____ __ ____" | |
echo " / __ \____ _____/ /_ / _/___ _____/ /_____ _/ / /" | |
echo " / /_/ / __ \/ ___/ __/ / // __ \/ ___/ __/ __. / / / " | |
echo " / ____/ /_/ (__ ) /_ _/ // / / (__ ) /_/ /_/ / / / " | |
echo " /_/ \____/____/\__/ /___/_/ /_/____/\__/\__,_/_/_/ " | |
echo " " | |
echo "===========================================================" | |
# Install PHPStorm? | |
confirm -y "Download and install PHPStorm v8.0.2 (129MB)?" | |
installPHPStorm=$? | |
if test $installPHPStorm -eq 0; then | |
read -ep "PHPStorm file URL: " -i "http://download.jetbrains.com/webide/PhpStorm-8.0.2.tar.gz" PHPStormUrl | |
fi | |
# Create Home directories | |
declare -a directories=("$HOME/Applications" "$HOME/Code") | |
for dir in "${directories[@]}"; do | |
if [[ ! -d "$dir" ]]; then | |
echo -n "Creating $dir directory... " | |
mkdir -p "$dir" >> post_install.log 2>&1 & | |
spinner $! | |
_success "OK" | |
fi | |
done | |
# Google Chrome PPA | |
echo -n "Adding/Updating Google Chrome PPA... " | |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - >> post_install.log 2>&1 | |
echo "deb https://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list >> post_install.log 2>&1 | |
_success "OK" | |
# Java PPA | |
echo -n "Adding/Updating Oracle Java PPA... " | |
sudo add-apt-repository -y "ppa:webupd8team/java" >> post_install.log 2>&1 & | |
spinner $! | |
_success "OK" | |
# Plank PPA | |
echo -n "Adding/Updating Plank PPA... " | |
sudo add-apt-repository -y "ppa:ricotz/docky" >> post_install.log 2>&1 & | |
spinner $! | |
_success "OK" | |
# Sublime Text 3 PPA | |
echo -n "Adding/Updating Sublime Text 3 PPA... " | |
sudo add-apt-repository -y "ppa:webupd8team/sublime-text-3" >> post_install.log 2>&1 & | |
spinner $! | |
_success "OK" | |
# RabbitVCS PPA | |
echo -n "Adding/Updating RabbitVCS PPA... " | |
sudo add-apt-repository -y "ppa:rabbitvcs/ppa" >> post_install.log 2>&1 & | |
spinner $! | |
_success "OK" | |
# Update sources | |
echo -n "Updating sources... " | |
sudo apt-get -qq -y update >> post_install 2>&1 & | |
spinner $! | |
_success "OK" | |
# Accept future Oracle installation without asking user | |
echo -n "Pre-accepting future Oracle installation license... " | |
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections | |
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections | |
_success "OK" | |
# Install all software | |
installPackage "curl" | |
installPackage "dtrx" | |
installPackage "git" | |
installPackage "plank" | |
installPackage "java" "oracle-java7-installer" | |
installPackage "sublime-text-installer" | |
# Install PHPStorm | |
if test $installPHPStorm -eq 0; then | |
installStorm "PHPStorm" "$PHPStormUrl" | |
fi | |
# Configure Git | |
echo -n "Configuring Git... " | |
git config --global user.email "[email protected]" | |
git config --global user.name "Shea Lewis" | |
_success "OK" | |
# TODO: Install LAMP server through tasksel | |
# TODO: Install and configure missing PHP modules | |
# TODO: Install Composer | |
# TODO: Install Laravel installer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment