Last active
June 25, 2016 04:11
-
-
Save calvinbui/1eec1f4b62048252e64e to your computer and use it in GitHub Desktop.
Post Ubuntu Installation
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
#!/bin/bash | |
# Download from bit.ly/finish-setup | |
# Check for root | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
# Pretty colours | |
print_title() { | |
echo -e "\033[1;36m$@\033[0m" | |
} | |
print_question() { | |
echo -e -n "\033[1;31m$@\033[0m" | |
} | |
print_info() { | |
echo -e "\033[1;32m$@\033[0m" | |
} | |
print_title() { | |
echo -e "\033[1;33m$@\033[0m" | |
} | |
echo '' | |
print_title '#------------------------------------#' | |
print_title '# Ubuntu Post-Install Script #' | |
print_title '# By Calvin #' | |
print_title '#------------------------------------#' | |
echo '' | |
# # Apt-Cacher Proxy | |
# print_title "-------------------------------" | |
# print_title "INSTALLING THE APT CACHER PROXY" | |
# print_title "-------------------------------" | |
# echo '' | |
# while [ -z "$network" ] ; do | |
# print_question "Are we on the Admin[1] or DMZ network[2]? Enter 0 to skip: " && read network | |
# done | |
# if [ $network == "1" ] || [ $network == "Admin" ] || [ $network == "admin" ] ; then | |
# network="admin" | |
# echo '' | |
# print_info 'Installing Apt-cacher Admin-Cache' | |
# echo '' | |
# wget -O - http://bit.ly/admin-cache | bash | |
# elif [ $network == "2" ] || [ $network == "DMZ" ] || [ $network == "dmz" ] ; then | |
# network="dmz" | |
# echo '' | |
# print_info 'Installing Apt-cacher DMZ-Cache' | |
# echo '' | |
# wget -O - http://bit.ly/dmz-cache | bash | |
# else | |
# network="none" | |
# fi | |
# Run Updates and install VMware-tools if necessary | |
echo '' | |
print_title "-------------------------------" | |
print_title " SYSTEM UPDATES " | |
print_title "-------------------------------" | |
echo '' | |
while [ -z "$runupdates" ] ; do | |
print_question "Run updates (y/n) ? " && read runupdates | |
done | |
if [ $runupdates = "y" ] ; then | |
echo '' | |
print_info "Running apt-get update" | |
echo '' | |
apt-get update | |
echo '' | |
print_info "Apt-get complete" | |
echo '' | |
print_info "Running apt-get dist-upgrade" | |
echo '' | |
apt-get dist-upgrade -y | |
echo '' | |
print_info "Dist-upgrade complete" | |
echo '' | |
fi | |
echo '' | |
print_title "-------------------------------" | |
print_title " OPEN VM TOOLS " | |
print_title "-------------------------------" | |
echo '' | |
# Prompt if this is a VM to install Open VM Tools | |
while [ -z "$vm" ] ; do | |
print_question "This a VM (y/n): " && read vm | |
done | |
if [ $vm == "y" ] || [ $vm == "yes" ] ; then | |
if [ $runupdates = "n" ] ; then | |
echo '' | |
print_info "Running apt-get update" | |
echo '' | |
apt-get update | |
fi | |
echo '' | |
print_info 'Installing Open VM tools' | |
echo '' | |
apt-get install open-vm-tools -y | |
fi | |
#Set Network | |
echo '' | |
print_title "-------------------------------" | |
print_title " NETWORKING " | |
print_title "-------------------------------" | |
echo '' | |
while [ -z "$createnetwork" ] ; do | |
print_question "Set a static IP (y/n)?: " && read createnetwork | |
done | |
if [ $createnetwork == "y" ] || [ $createnetwork == "yes" ] ; then | |
print_question "IP Address for this machine: " && read ipaddress | |
if [ $network == "admin" ] ; then | |
networkaddr="10.0.0.0" | |
netmask="255.255.254.0" | |
broadcastaddr="10.0.1.255" | |
gatewayaddr="10.0.0.1" | |
dns="10.0.0.1" | |
elif [ $network == "dmz " ] ; then | |
networkaddr="10.0.9.0" | |
netmask="255.255.255.0" | |
broadcastaddr="10.0.9.255" | |
gatewayaddr="10.0.9.1" | |
dns="10.0.9.1" | |
else | |
print_question "Network Address (x.x.x.x): " && read networkaddr | |
print_question "Subnet Mask (x.x.x.x): " && read netmask | |
print_question "Broadcast Address (x.x.x.x): " && read broadcastaddr | |
print_question "Gateway Address (x.x.x.x): " && read gatewayaddr | |
print_question "DNS Server (x.x.x.x): " && read dns | |
fi | |
print_info "Replacing /etc/network/interfaces with static IP" | |
echo " | |
# This file describes the network interfaces available on your system | |
# and how to activate them. For more information, see interfaces(5). | |
# The loopback network interface | |
auto lo | |
iface lo inet loopback | |
# The primary network interface | |
auto eth0 | |
iface eth0 inet static | |
address $ipaddress | |
network $networkaddr | |
netmask $netmask | |
broadcast $broadcastaddr | |
gateway $gatewayaddr | |
dns-nameservers $dns" > /etc/network/interfaces | |
print_info "Networking Complete" | |
fi | |
# Create system shares | |
echo '' | |
print_title "-------------------------------" | |
print_title " NETWORK SHARES " | |
print_title "-------------------------------" | |
echo '' | |
while [ -z "$createshares" ] ; do | |
print_question "Create network shares? (y/n): " && read createshares | |
done | |
if [ $createshares == "y" ] || [ $createshares == "yes" ] ; then | |
echo 'Installing autofs and cifs-utils' | |
apt-get install cifs-utils autofs -y | |
print_question "Username for shares: " && read shareuname | |
print_question "Password for shares: " && read sharepw | |
if [ $network == "admin" ] ; then | |
shareip="10.0.0.5/files" | |
sharedomain="home" | |
sharename="hdd" | |
elif [ $network == "dmz " ] ; then | |
shareip="10.0.9.5/files" | |
sharedomain="home" | |
sharename="hdd" | |
else | |
print_question "Share IP Address (x.x.x.x/share): " && read shareip | |
print_question "Domain (e.g. home): " && read sharedomain | |
print_question "Share Name (e.g. hdd): " && read sharename | |
fi | |
echo '' | |
print_info "Pushing settings to /etc/auto.mnt" | |
echo '' | |
echo "$sharename -fstype=cifs,rw,noperm,username=$shareuname,domain=$sharedomain,password=$sharepw ://$shareip" > /etc/auto.mnt | |
echo '' | |
print_info "Adding auto.mnt to master file" | |
echo '' | |
echo '/mnt /etc/auto.mnt' >> /etc/auto.master | |
echo '' | |
fi | |
# REBOOT | |
echo '' | |
print_title "-------------------------------" | |
print_title " FINISHED " | |
print_title "-------------------------------" | |
echo '' | |
print_question "Reboot (y/n) : " && read reboot | |
if [ $reboot == "y" ] || [ $reboot == "yes" ] ; then | |
reboot | |
else | |
print_info "All done" | |
fi | |
# delete itself | |
update-rc.d finish-setup disable | |
rm $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment